@simplr-ai/ai 1.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/LICENSE +21 -0
- package/README.md +120 -0
- package/dist/index.cjs +253 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +195 -0
- package/dist/index.d.ts +195 -0
- package/dist/index.js +234 -0
- package/dist/index.js.map +1 -0
- package/dist/langchain.cjs +237 -0
- package/dist/langchain.cjs.map +1 -0
- package/dist/langchain.d.cts +21 -0
- package/dist/langchain.d.ts +21 -0
- package/dist/langchain.js +210 -0
- package/dist/langchain.js.map +1 -0
- package/dist/openai.cjs +319 -0
- package/dist/openai.cjs.map +1 -0
- package/dist/openai.d.cts +67 -0
- package/dist/openai.d.ts +67 -0
- package/dist/openai.js +290 -0
- package/dist/openai.js.map +1 -0
- package/dist/types-Y9ma4qBT.d.cts +73 -0
- package/dist/types-Y9ma4qBT.d.ts +73 -0
- package/package.json +90 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Simplr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# @simplr-ai/ai
|
|
2
|
+
|
|
3
|
+
**Use Simplr as tools inside *your* AI agent.** This package wraps Simplr's
|
|
4
|
+
fraud / identity / phone / order checks as ready-to-use **tools** for LLM agents:
|
|
5
|
+
first-class support for the **Vercel AI SDK** (`tool()` + zod), plus a
|
|
6
|
+
framework-agnostic core so the exact same tools work with **raw OpenAI
|
|
7
|
+
function-calling** and **LangChain**.
|
|
8
|
+
|
|
9
|
+
> **How this differs from the Simplr MCP servers.** `@simplr-ai/dev-mcp` helps a
|
|
10
|
+
> coding agent *build with* Simplr (integration guides + snippets), and
|
|
11
|
+
> `@simplr-ai/mcp` is a runtime **delegation gateway** that exposes *your own*
|
|
12
|
+
> registered endpoints to AI agents. **This package is neither** — it gives you
|
|
13
|
+
> Simplr's checks as tools you drop directly into the agent *you* are building,
|
|
14
|
+
> with no MCP server to run. Under the hood it mirrors the
|
|
15
|
+
> [`@simplr-ai/node`](../simplr-node-sdk) SDK's endpoints and response envelope.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @simplr-ai/ai ai zod
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`zod` is a dependency. `ai` (Vercel AI SDK) and `@langchain/core` are **optional
|
|
24
|
+
peer dependencies** — install only the one(s) for the framework you use. They are
|
|
25
|
+
imported lazily, so the package works fine if they're absent (you'll get a clear
|
|
26
|
+
error only when you call a function that needs them).
|
|
27
|
+
|
|
28
|
+
## Quick start — Vercel AI SDK
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { generateText } from "ai";
|
|
32
|
+
import { openai } from "@ai-sdk/openai";
|
|
33
|
+
import { createSimplrTools } from "@simplr-ai/ai";
|
|
34
|
+
|
|
35
|
+
const tools = createSimplrTools({ apiKey: process.env.SIMPLR_API_KEY! });
|
|
36
|
+
|
|
37
|
+
const { text } = await generateText({
|
|
38
|
+
model: openai("gpt-4o"),
|
|
39
|
+
tools, // { simplr_check_identity, simplr_score_order, simplr_phone_intelligence, simplr_report_phone_outcome }
|
|
40
|
+
maxSteps: 5,
|
|
41
|
+
prompt: "A new user signed up with user@example.com and +14155552671. Are they risky?",
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`createSimplrTools` returns an object of Vercel-AI `tool()` instances keyed by
|
|
46
|
+
tool name. Prefer a framework-free shape? Use `createSimplrToolDescriptors(config)`
|
|
47
|
+
to get plain `{ name, description, inputSchema, execute }` descriptors.
|
|
48
|
+
|
|
49
|
+
## Quick start — OpenAI function-calling
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import OpenAI from "openai";
|
|
53
|
+
import { simplrOpenAITools, executeSimplrTool } from "@simplr-ai/ai/openai";
|
|
54
|
+
|
|
55
|
+
const config = { apiKey: process.env.SIMPLR_API_KEY! };
|
|
56
|
+
const client = new OpenAI();
|
|
57
|
+
|
|
58
|
+
const res = await client.chat.completions.create({
|
|
59
|
+
model: "gpt-4o",
|
|
60
|
+
messages: [{ role: "user", content: "Is +14155552671 a risky phone number?" }],
|
|
61
|
+
tools: simplrOpenAITools(config), // [{ type: "function", function: { name, description, parameters } }]
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const call = res.choices[0].message.tool_calls?.[0];
|
|
65
|
+
if (call) {
|
|
66
|
+
const result = await executeSimplrTool(call.function.name, call.function.arguments, config);
|
|
67
|
+
// feed `result` back to the model as a tool message…
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
No OpenAI SDK is required to build the schemas — `simplrOpenAITools` returns plain
|
|
72
|
+
JSON. `executeSimplrTool` validates the model's arguments against the tool's zod
|
|
73
|
+
schema before calling the API.
|
|
74
|
+
|
|
75
|
+
## Quick start — LangChain
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
79
|
+
import { createSimplrLangChainTools } from "@simplr-ai/ai/langchain";
|
|
80
|
+
|
|
81
|
+
const tools = await createSimplrLangChainTools({ apiKey: process.env.SIMPLR_API_KEY! });
|
|
82
|
+
const model = new ChatOpenAI({ model: "gpt-4o" }).bindTools(tools);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Returns `DynamicStructuredTool` instances. Requires `@langchain/core`.
|
|
86
|
+
|
|
87
|
+
## Tool catalog
|
|
88
|
+
|
|
89
|
+
| Tool | Endpoint | What it does |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| `simplr_check_identity` | `POST /v1/check` | Score a user/event (email and/or phone) for fraud/identity risk — signups, logins, password resets. |
|
|
92
|
+
| `simplr_score_order` | `POST /v1/orders` | Score a placed order/transaction for payment fraud risk. |
|
|
93
|
+
| `simplr_phone_intelligence` | `GET /v1/check/phone/intelligence/{phone}` | Read-only lookup of stored risk intelligence for a phone number (carrier, line type, SIM-swap signals). |
|
|
94
|
+
| `simplr_report_phone_outcome` | `POST /v1/check/phone/report` | Feedback signal: report a confirmed real-world outcome for a phone to improve future scoring. |
|
|
95
|
+
|
|
96
|
+
Every check result includes `risk_score` (0–100, higher = riskier) and
|
|
97
|
+
`risk_level` — one of `low`, `medium`, `high`, `critical`. Use those to decide
|
|
98
|
+
whether to **allow**, **challenge** (step-up auth / manual review), or **block**.
|
|
99
|
+
|
|
100
|
+
## Public API by subpath
|
|
101
|
+
|
|
102
|
+
| Import | Exports |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| `@simplr-ai/ai` | `createSimplrTools(config)`, `createSimplrToolDescriptors(config)`, `SimplrClient`, `schemas`, `SimplrError`, all result types |
|
|
105
|
+
| `@simplr-ai/ai/openai` | `simplrOpenAITools(config)`, `executeSimplrTool(name, args, config)`, `zodToJsonSchema` |
|
|
106
|
+
| `@simplr-ai/ai/langchain` | `createSimplrLangChainTools(config)` |
|
|
107
|
+
|
|
108
|
+
`config` is `{ apiKey: string; baseUrl?: string; timeoutMs?: number; fetch?: typeof fetch }`.
|
|
109
|
+
|
|
110
|
+
## Security
|
|
111
|
+
|
|
112
|
+
Use a **secret key** (`sk_live_…` / `sk_test_…`) and only ever construct these
|
|
113
|
+
tools **server-side** — in your API route, agent backend, or worker. Never ship a
|
|
114
|
+
secret key (or these tool factories) to a browser, mobile app, or any client the
|
|
115
|
+
model's user controls. The key is sent as the `X-API-Key` header. Default
|
|
116
|
+
per-request timeout is 15s.
|
|
117
|
+
|
|
118
|
+
## Docs & license
|
|
119
|
+
|
|
120
|
+
Full API reference: https://docs.simplr.so/docs/sdks/ — MIT licensed.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
SimplrClient: () => SimplrClient,
|
|
24
|
+
SimplrError: () => SimplrError,
|
|
25
|
+
createSimplrToolDescriptors: () => createSimplrToolDescriptors,
|
|
26
|
+
createSimplrTools: () => createSimplrTools,
|
|
27
|
+
schemas: () => schemas_exports
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(src_exports);
|
|
30
|
+
|
|
31
|
+
// src/errors.ts
|
|
32
|
+
var SimplrError = class extends Error {
|
|
33
|
+
status;
|
|
34
|
+
body;
|
|
35
|
+
constructor(message, status, body) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = "SimplrError";
|
|
38
|
+
this.status = status;
|
|
39
|
+
this.body = body;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/client.ts
|
|
44
|
+
var DEFAULT_BASE_URL = "https://api.simplr.sh";
|
|
45
|
+
var DEFAULT_TIMEOUT_MS = 15e3;
|
|
46
|
+
function resolve(config) {
|
|
47
|
+
if (!config?.apiKey) throw new Error("@simplr-ai/ai: `apiKey` is required");
|
|
48
|
+
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
49
|
+
if (typeof fetchImpl !== "function") {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"@simplr-ai/ai: no global fetch available \u2014 use Node 18+ or pass `fetch` in config"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
apiKey: config.apiKey,
|
|
56
|
+
baseUrl: (config.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, ""),
|
|
57
|
+
timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
58
|
+
fetchImpl
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async function apiRequest(cfg, method, path, body) {
|
|
62
|
+
const controller = new AbortController();
|
|
63
|
+
const timer = setTimeout(() => controller.abort(), cfg.timeoutMs);
|
|
64
|
+
try {
|
|
65
|
+
const res = await cfg.fetchImpl(`${cfg.baseUrl}${path}`, {
|
|
66
|
+
method,
|
|
67
|
+
headers: { "Content-Type": "application/json", "X-API-Key": cfg.apiKey },
|
|
68
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0,
|
|
69
|
+
signal: controller.signal
|
|
70
|
+
});
|
|
71
|
+
const text = await res.text();
|
|
72
|
+
let parsed;
|
|
73
|
+
try {
|
|
74
|
+
parsed = text ? JSON.parse(text) : void 0;
|
|
75
|
+
} catch {
|
|
76
|
+
parsed = text;
|
|
77
|
+
}
|
|
78
|
+
if (!res.ok) {
|
|
79
|
+
const message = parsed && (parsed.message || parsed.error) || `Simplr API error ${res.status}`;
|
|
80
|
+
throw new SimplrError(message, res.status, parsed);
|
|
81
|
+
}
|
|
82
|
+
return parsed && typeof parsed === "object" && "content" in parsed ? parsed.content : parsed;
|
|
83
|
+
} catch (err) {
|
|
84
|
+
if (err instanceof SimplrError) throw err;
|
|
85
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
86
|
+
throw new SimplrError(`Request to ${path} timed out after ${cfg.timeoutMs}ms`, 0, null);
|
|
87
|
+
}
|
|
88
|
+
throw new SimplrError(err instanceof Error ? err.message : "Network error", 0, null);
|
|
89
|
+
} finally {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
var SimplrClient = class {
|
|
94
|
+
cfg;
|
|
95
|
+
constructor(config) {
|
|
96
|
+
this.cfg = resolve(config);
|
|
97
|
+
}
|
|
98
|
+
/** POST /v1/check — identity/fraud check. */
|
|
99
|
+
check(input) {
|
|
100
|
+
return apiRequest(this.cfg, "POST", "/v1/check", input);
|
|
101
|
+
}
|
|
102
|
+
/** POST /v1/orders — order fraud scoring. */
|
|
103
|
+
scoreOrder(input) {
|
|
104
|
+
return apiRequest(this.cfg, "POST", "/v1/orders", input);
|
|
105
|
+
}
|
|
106
|
+
/** GET /v1/check/phone/intelligence/{phone} — stored phone intelligence. */
|
|
107
|
+
phoneIntelligence(phone) {
|
|
108
|
+
return apiRequest(
|
|
109
|
+
this.cfg,
|
|
110
|
+
"GET",
|
|
111
|
+
`/v1/check/phone/intelligence/${encodeURIComponent(phone)}`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
/** POST /v1/check/phone/report — report a real-world phone outcome. */
|
|
115
|
+
reportPhone(input) {
|
|
116
|
+
return apiRequest(this.cfg, "POST", "/v1/check/phone/report", input);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/schemas.ts
|
|
121
|
+
var schemas_exports = {};
|
|
122
|
+
__export(schemas_exports, {
|
|
123
|
+
checkIdentitySchema: () => checkIdentitySchema,
|
|
124
|
+
phoneIntelligenceSchema: () => phoneIntelligenceSchema,
|
|
125
|
+
reportPhoneOutcomeSchema: () => reportPhoneOutcomeSchema,
|
|
126
|
+
scoreOrderSchema: () => scoreOrderSchema
|
|
127
|
+
});
|
|
128
|
+
var import_zod = require("zod");
|
|
129
|
+
var checkIdentitySchema = import_zod.z.object({
|
|
130
|
+
email: import_zod.z.string().email().optional().describe("The user's email address to evaluate (e.g. for signup/login risk)."),
|
|
131
|
+
phone: import_zod.z.string().optional().describe("The user's phone number in E.164 format (e.g. +14155552671)."),
|
|
132
|
+
event_type: import_zod.z.string().optional().describe(
|
|
133
|
+
"The lifecycle event being scored, e.g. 'signup', 'login', 'checkout', 'password_reset'. Helps tune the risk model."
|
|
134
|
+
),
|
|
135
|
+
event_id: import_zod.z.string().optional().describe("Your own idempotency / correlation id for this event, if any."),
|
|
136
|
+
metadata: import_zod.z.record(import_zod.z.unknown()).optional().describe(
|
|
137
|
+
"Arbitrary extra context about the event (e.g. { ip: '1.2.3.4', user_id: 'u_123' }). Free-form key/value object."
|
|
138
|
+
)
|
|
139
|
+
}).describe(
|
|
140
|
+
"Provide at least one of `email` or `phone`. Returns a fraud/identity risk assessment for the given user or event."
|
|
141
|
+
);
|
|
142
|
+
var scoreOrderSchema = import_zod.z.object({
|
|
143
|
+
order_id: import_zod.z.string().describe("Your unique identifier for this order."),
|
|
144
|
+
external_id: import_zod.z.string().optional().describe("An optional secondary id (e.g. your payment-processor reference)."),
|
|
145
|
+
amount: import_zod.z.number().describe("The order total as a number in the order's currency (e.g. 129.99)."),
|
|
146
|
+
currency: import_zod.z.string().describe("ISO 4217 currency code, e.g. 'USD', 'EUR', 'GBP'."),
|
|
147
|
+
fingerprint_hash: import_zod.z.string().optional().describe(
|
|
148
|
+
"Device fingerprint hash from a prior identity check, if available, to link the order to a device."
|
|
149
|
+
),
|
|
150
|
+
metadata: import_zod.z.record(import_zod.z.unknown()).optional().describe("Arbitrary extra order context (items, shipping, customer id, etc.).")
|
|
151
|
+
}).describe(
|
|
152
|
+
"Score a placed order for payment/transaction fraud risk. Returns a risk_score and risk_level for the order."
|
|
153
|
+
);
|
|
154
|
+
var phoneIntelligenceSchema = import_zod.z.object({
|
|
155
|
+
phone: import_zod.z.string().describe(
|
|
156
|
+
"The phone number to look up, in E.164 format (e.g. +14155552671). It will be URL-encoded."
|
|
157
|
+
)
|
|
158
|
+
}).describe(
|
|
159
|
+
"Fetch stored risk intelligence for a phone number (carrier, line type, SIM-swap signals, prior outcomes). Read-only, no side effects."
|
|
160
|
+
);
|
|
161
|
+
var reportPhoneOutcomeSchema = import_zod.z.object({
|
|
162
|
+
phone: import_zod.z.string().describe("The phone number the outcome applies to, in E.164 format."),
|
|
163
|
+
outcome: import_zod.z.enum([
|
|
164
|
+
"fraud",
|
|
165
|
+
"sim_swap_fraud",
|
|
166
|
+
"account_takeover",
|
|
167
|
+
"spam",
|
|
168
|
+
"bot",
|
|
169
|
+
"legitimate"
|
|
170
|
+
]).describe(
|
|
171
|
+
"The confirmed real-world outcome for this phone: 'legitimate' (good actor), 'fraud', 'sim_swap_fraud', 'account_takeover', 'spam', or 'bot'."
|
|
172
|
+
),
|
|
173
|
+
check_id: import_zod.z.string().optional().describe("The id of the original check this outcome relates to, if known."),
|
|
174
|
+
confidence: import_zod.z.number().min(0).max(1).optional().describe("Your confidence in the reported outcome, 0.0\u20131.0."),
|
|
175
|
+
metadata: import_zod.z.record(import_zod.z.unknown()).optional().describe("Arbitrary extra context about how the outcome was determined.")
|
|
176
|
+
}).describe(
|
|
177
|
+
"Report a confirmed real-world outcome for a phone number back to Simplr. This is a feedback/training signal that improves future scoring \u2014 only call it once you actually know the outcome."
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// src/tools.ts
|
|
181
|
+
var RISK_LEVEL_DOC = "The result includes `risk_score` (0\u2013100, higher = riskier) and `risk_level` (one of 'low', 'medium', 'high', 'critical').";
|
|
182
|
+
function createSimplrToolDescriptors(config) {
|
|
183
|
+
const client = new SimplrClient(config);
|
|
184
|
+
return {
|
|
185
|
+
simplr_check_identity: {
|
|
186
|
+
name: "simplr_check_identity",
|
|
187
|
+
description: "Assess the fraud/identity risk of a user or event using their email and/or phone. Use this for signups, logins, password resets, or any moment you need to decide whether to trust, challenge (e.g. step-up auth), or block a user. " + RISK_LEVEL_DOC,
|
|
188
|
+
inputSchema: checkIdentitySchema,
|
|
189
|
+
execute: (args) => client.check(args)
|
|
190
|
+
},
|
|
191
|
+
simplr_score_order: {
|
|
192
|
+
name: "simplr_score_order",
|
|
193
|
+
description: "Score a placed order/transaction for payment fraud risk given its amount, currency, and ids. Use this at checkout or post-purchase review to decide whether to approve, hold for manual review, or reject an order. " + RISK_LEVEL_DOC,
|
|
194
|
+
inputSchema: scoreOrderSchema,
|
|
195
|
+
execute: (args) => client.scoreOrder(args)
|
|
196
|
+
},
|
|
197
|
+
simplr_phone_intelligence: {
|
|
198
|
+
name: "simplr_phone_intelligence",
|
|
199
|
+
description: "Look up stored risk intelligence for a phone number (carrier, line type, SIM-swap and prior-outcome signals). Read-only with no side effects \u2014 safe to call whenever you need context about a phone number before deciding.",
|
|
200
|
+
inputSchema: phoneIntelligenceSchema,
|
|
201
|
+
execute: (args) => client.phoneIntelligence(args.phone)
|
|
202
|
+
},
|
|
203
|
+
simplr_report_phone_outcome: {
|
|
204
|
+
name: "simplr_report_phone_outcome",
|
|
205
|
+
description: "Report a confirmed real-world outcome for a phone number (e.g. 'fraud', 'sim_swap_fraud', 'legitimate') back to Simplr. This is a feedback/training signal that improves future scoring. Only call it once you actually KNOW the outcome \u2014 do not guess.",
|
|
206
|
+
inputSchema: reportPhoneOutcomeSchema,
|
|
207
|
+
execute: (args) => client.reportPhone(args)
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/index.ts
|
|
213
|
+
function createSimplrTools(config) {
|
|
214
|
+
let tool;
|
|
215
|
+
try {
|
|
216
|
+
const mod = loadAi();
|
|
217
|
+
tool = mod.tool;
|
|
218
|
+
if (typeof tool !== "function") {
|
|
219
|
+
throw new Error("`ai` is installed but does not export `tool`.");
|
|
220
|
+
}
|
|
221
|
+
} catch (err) {
|
|
222
|
+
throw new Error(
|
|
223
|
+
"@simplr-ai/ai: createSimplrTools() requires the Vercel AI SDK. Install it with `npm install ai`, or use createSimplrToolDescriptors() for a framework-agnostic alternative. (Original error: " + (err instanceof Error ? err.message : String(err)) + ")"
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
const descriptors = createSimplrToolDescriptors(config);
|
|
227
|
+
const out = {};
|
|
228
|
+
for (const key of Object.keys(descriptors)) {
|
|
229
|
+
const d = descriptors[key];
|
|
230
|
+
out[key] = tool({
|
|
231
|
+
description: d.description,
|
|
232
|
+
// The AI SDK reads either `inputSchema` (v4+) or `parameters` (v3); we set
|
|
233
|
+
// both to the zod schema so it works across versions.
|
|
234
|
+
inputSchema: d.inputSchema,
|
|
235
|
+
parameters: d.inputSchema,
|
|
236
|
+
execute: (args) => d.execute(args)
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return out;
|
|
240
|
+
}
|
|
241
|
+
function loadAi() {
|
|
242
|
+
const specifier = "ai";
|
|
243
|
+
return require(specifier);
|
|
244
|
+
}
|
|
245
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
246
|
+
0 && (module.exports = {
|
|
247
|
+
SimplrClient,
|
|
248
|
+
SimplrError,
|
|
249
|
+
createSimplrToolDescriptors,
|
|
250
|
+
createSimplrTools,
|
|
251
|
+
schemas
|
|
252
|
+
});
|
|
253
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts","../src/schemas.ts","../src/tools.ts"],"sourcesContent":["/**\n * `@simplr-ai/ai` — main entry.\n *\n * Exposes Simplr's fraud/identity/phone checks as ready-to-use tools for AI\n * agents. The primary integration is the Vercel AI SDK (`ai` package): call\n * `createSimplrTools(config)` to get an object of `tool()` instances you can pass\n * straight into `generateText`/`streamText`.\n *\n * `ai` is an OPTIONAL peer dependency and is imported lazily, so this package\n * builds and tests without it installed. If you call `createSimplrTools` without\n * `ai` present, a clear error tells you to install it (or use\n * `createSimplrToolDescriptors`, which needs no framework).\n */\nimport {\n createSimplrToolDescriptors,\n type SimplrToolDescriptor,\n type SimplrToolName,\n} from \"./tools.js\";\nimport type { SimplrAIConfig } from \"./types.js\";\n\nexport { SimplrError } from \"./errors.js\";\nexport * from \"./types.js\";\nexport {\n createSimplrToolDescriptors,\n type SimplrToolDescriptor,\n type SimplrToolName,\n} from \"./tools.js\";\nexport * as schemas from \"./schemas.js\";\nexport { SimplrClient } from \"./client.js\";\n\n/** The shape of a Vercel AI SDK `tool()` instance (kept loose to avoid a hard dep). */\nexport type VercelTool = unknown;\n\n/**\n * Create Vercel AI SDK tools for every Simplr capability, keyed by tool name.\n *\n * ```ts\n * import { generateText } from \"ai\";\n * import { openai } from \"@ai-sdk/openai\";\n * import { createSimplrTools } from \"@simplr-ai/ai\";\n *\n * const tools = createSimplrTools({ apiKey: process.env.SIMPLR_API_KEY! });\n * const { text } = await generateText({\n * model: openai(\"gpt-4o\"),\n * tools,\n * prompt: \"Is user@example.com risky to sign up?\",\n * });\n * ```\n *\n * Requires the optional peer dependency `ai`. If it isn't installed, this throws\n * with installation guidance — use `createSimplrToolDescriptors` for a\n * framework-free alternative.\n */\nexport function createSimplrTools(\n config: SimplrAIConfig,\n): Record<SimplrToolName, VercelTool> {\n let tool: (spec: any) => unknown;\n try {\n // Lazy, synchronous resolution so absence of `ai` is a clear error and the\n // return type stays simple (no Promise). `require` works under both CJS and\n // tsup's interop; in pure ESM environments where `ai` is installed this is\n // resolvable too.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const mod = loadAi();\n tool = mod.tool;\n if (typeof tool !== \"function\") {\n throw new Error(\"`ai` is installed but does not export `tool`.\");\n }\n } catch (err) {\n throw new Error(\n \"@simplr-ai/ai: createSimplrTools() requires the Vercel AI SDK. \" +\n \"Install it with `npm install ai`, or use createSimplrToolDescriptors() \" +\n \"for a framework-agnostic alternative. (Original error: \" +\n (err instanceof Error ? err.message : String(err)) +\n \")\",\n );\n }\n\n const descriptors = createSimplrToolDescriptors(config);\n const out = {} as Record<SimplrToolName, VercelTool>;\n for (const key of Object.keys(descriptors) as SimplrToolName[]) {\n const d = descriptors[key] as SimplrToolDescriptor;\n out[key] = tool({\n description: d.description,\n // The AI SDK reads either `inputSchema` (v4+) or `parameters` (v3); we set\n // both to the zod schema so it works across versions.\n inputSchema: d.inputSchema,\n parameters: d.inputSchema,\n execute: (args: unknown) => d.execute(args as any),\n });\n }\n return out;\n}\n\n/** Resolve the optional `ai` peer dependency synchronously via `require`. */\nfunction loadAi(): { tool: (spec: any) => unknown } {\n // In CJS output `require` exists directly. In ESM output tsup injects a\n // `require` shim (via createRequire) when `require` is referenced, so this\n // works under both module systems without bundling `ai` itself.\n const specifier = \"ai\";\n return (require as NodeRequire)(specifier);\n}\n","/**\n * Thrown when the Simplr API returns a non-2xx response, or a request fails\n * (network error / timeout — in which case `status` is 0 and `body` is null).\n *\n * Mirrors `SimplrError` from `@simplr-ai/node`.\n */\nexport class SimplrError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"SimplrError\";\n this.status = status;\n this.body = body;\n }\n}\n","/**\n * Thin internal HTTP client.\n *\n * This mirrors the minimal request layer of `@simplr-ai/node` (`apiRequest` +\n * the check / orders / phone endpoints) so this package has **no unbuilt\n * workspace dependency** and tests can run fully offline. If you need the full\n * SDK (bulk, edge, flags, webhooks) use `@simplr-ai/node` directly.\n */\nimport { SimplrError } from \"./errors.js\";\nimport type {\n CheckInput,\n CheckResult,\n OrderInput,\n OrderResult,\n PhoneIntelligenceResult,\n PhoneReportInput,\n PhoneReportResult,\n SimplrAIConfig,\n} from \"./types.js\";\n\nconst DEFAULT_BASE_URL = \"https://api.simplr.sh\";\nconst DEFAULT_TIMEOUT_MS = 15000;\n\ninterface ResolvedConfig {\n apiKey: string;\n baseUrl: string;\n timeoutMs: number;\n fetchImpl: typeof fetch;\n}\n\nfunction resolve(config: SimplrAIConfig): ResolvedConfig {\n if (!config?.apiKey) throw new Error(\"@simplr-ai/ai: `apiKey` is required\");\n const fetchImpl = config.fetch ?? globalThis.fetch;\n if (typeof fetchImpl !== \"function\") {\n throw new Error(\n \"@simplr-ai/ai: no global fetch available — use Node 18+ or pass `fetch` in config\",\n );\n }\n return {\n apiKey: config.apiKey,\n baseUrl: (config.baseUrl || DEFAULT_BASE_URL).replace(/\\/+$/, \"\"),\n timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,\n fetchImpl,\n };\n}\n\n/**\n * Internal request helper. Sends `X-API-Key`, applies a timeout, and unwraps the\n * API's `{ success, message, content }` envelope (returning `content`).\n */\nasync function apiRequest<T>(\n cfg: ResolvedConfig,\n method: \"GET\" | \"POST\",\n path: string,\n body?: unknown,\n): Promise<T> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), cfg.timeoutMs);\n try {\n const res = await cfg.fetchImpl(`${cfg.baseUrl}${path}`, {\n method,\n headers: { \"Content-Type\": \"application/json\", \"X-API-Key\": cfg.apiKey },\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n const text = await res.text();\n let parsed: any;\n try {\n parsed = text ? JSON.parse(text) : undefined;\n } catch {\n parsed = text;\n }\n\n if (!res.ok) {\n const message =\n (parsed && (parsed.message || parsed.error)) || `Simplr API error ${res.status}`;\n throw new SimplrError(message, res.status, parsed);\n }\n\n return (parsed && typeof parsed === \"object\" && \"content\" in parsed\n ? parsed.content\n : parsed) as T;\n } catch (err) {\n if (err instanceof SimplrError) throw err;\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new SimplrError(`Request to ${path} timed out after ${cfg.timeoutMs}ms`, 0, null);\n }\n throw new SimplrError(err instanceof Error ? err.message : \"Network error\", 0, null);\n } finally {\n clearTimeout(timer);\n }\n}\n\n/** A minimal Simplr API client exposing only the endpoints these tools need. */\nexport class SimplrClient {\n private readonly cfg: ResolvedConfig;\n\n constructor(config: SimplrAIConfig) {\n this.cfg = resolve(config);\n }\n\n /** POST /v1/check — identity/fraud check. */\n check(input: CheckInput): Promise<CheckResult> {\n return apiRequest(this.cfg, \"POST\", \"/v1/check\", input);\n }\n\n /** POST /v1/orders — order fraud scoring. */\n scoreOrder(input: OrderInput): Promise<OrderResult> {\n return apiRequest(this.cfg, \"POST\", \"/v1/orders\", input);\n }\n\n /** GET /v1/check/phone/intelligence/{phone} — stored phone intelligence. */\n phoneIntelligence(phone: string): Promise<PhoneIntelligenceResult> {\n return apiRequest(\n this.cfg,\n \"GET\",\n `/v1/check/phone/intelligence/${encodeURIComponent(phone)}`,\n );\n }\n\n /** POST /v1/check/phone/report — report a real-world phone outcome. */\n reportPhone(input: PhoneReportInput): Promise<PhoneReportResult> {\n return apiRequest(this.cfg, \"POST\", \"/v1/check/phone/report\", input);\n }\n}\n","/**\n * Zod input schemas for each Simplr tool, with rich `.describe()` text so that\n * LLMs call the tools with the right arguments. Each schema corresponds 1:1 to\n * the API request body documented in the Simplr contract.\n */\nimport { z } from \"zod\";\n\n/** Input for `simplr_check_identity` → POST /v1/check. */\nexport const checkIdentitySchema = z\n .object({\n email: z\n .string()\n .email()\n .optional()\n .describe(\"The user's email address to evaluate (e.g. for signup/login risk).\"),\n phone: z\n .string()\n .optional()\n .describe(\"The user's phone number in E.164 format (e.g. +14155552671).\"),\n event_type: z\n .string()\n .optional()\n .describe(\n \"The lifecycle event being scored, e.g. 'signup', 'login', 'checkout', 'password_reset'. Helps tune the risk model.\",\n ),\n event_id: z\n .string()\n .optional()\n .describe(\"Your own idempotency / correlation id for this event, if any.\"),\n metadata: z\n .record(z.unknown())\n .optional()\n .describe(\n \"Arbitrary extra context about the event (e.g. { ip: '1.2.3.4', user_id: 'u_123' }). Free-form key/value object.\",\n ),\n })\n .describe(\n \"Provide at least one of `email` or `phone`. Returns a fraud/identity risk assessment for the given user or event.\",\n );\n\n/** Input for `simplr_score_order` → POST /v1/orders. */\nexport const scoreOrderSchema = z\n .object({\n order_id: z\n .string()\n .describe(\"Your unique identifier for this order.\"),\n external_id: z\n .string()\n .optional()\n .describe(\"An optional secondary id (e.g. your payment-processor reference).\"),\n amount: z\n .number()\n .describe(\"The order total as a number in the order's currency (e.g. 129.99).\"),\n currency: z\n .string()\n .describe(\"ISO 4217 currency code, e.g. 'USD', 'EUR', 'GBP'.\"),\n fingerprint_hash: z\n .string()\n .optional()\n .describe(\n \"Device fingerprint hash from a prior identity check, if available, to link the order to a device.\",\n ),\n metadata: z\n .record(z.unknown())\n .optional()\n .describe(\"Arbitrary extra order context (items, shipping, customer id, etc.).\"),\n })\n .describe(\n \"Score a placed order for payment/transaction fraud risk. Returns a risk_score and risk_level for the order.\",\n );\n\n/** Input for `simplr_phone_intelligence` → GET /v1/check/phone/intelligence/{phone}. */\nexport const phoneIntelligenceSchema = z\n .object({\n phone: z\n .string()\n .describe(\n \"The phone number to look up, in E.164 format (e.g. +14155552671). It will be URL-encoded.\",\n ),\n })\n .describe(\n \"Fetch stored risk intelligence for a phone number (carrier, line type, SIM-swap signals, prior outcomes). Read-only, no side effects.\",\n );\n\n/** Input for `simplr_report_phone_outcome` → POST /v1/check/phone/report. */\nexport const reportPhoneOutcomeSchema = z\n .object({\n phone: z\n .string()\n .describe(\"The phone number the outcome applies to, in E.164 format.\"),\n outcome: z\n .enum([\n \"fraud\",\n \"sim_swap_fraud\",\n \"account_takeover\",\n \"spam\",\n \"bot\",\n \"legitimate\",\n ])\n .describe(\n \"The confirmed real-world outcome for this phone: 'legitimate' (good actor), 'fraud', 'sim_swap_fraud', 'account_takeover', 'spam', or 'bot'.\",\n ),\n check_id: z\n .string()\n .optional()\n .describe(\"The id of the original check this outcome relates to, if known.\"),\n confidence: z\n .number()\n .min(0)\n .max(1)\n .optional()\n .describe(\"Your confidence in the reported outcome, 0.0–1.0.\"),\n metadata: z\n .record(z.unknown())\n .optional()\n .describe(\"Arbitrary extra context about how the outcome was determined.\"),\n })\n .describe(\n \"Report a confirmed real-world outcome for a phone number back to Simplr. This is a feedback/training signal that improves future scoring — only call it once you actually know the outcome.\",\n );\n\nexport type CheckIdentityArgs = z.infer<typeof checkIdentitySchema>;\nexport type ScoreOrderArgs = z.infer<typeof scoreOrderSchema>;\nexport type PhoneIntelligenceArgs = z.infer<typeof phoneIntelligenceSchema>;\nexport type ReportPhoneOutcomeArgs = z.infer<typeof reportPhoneOutcomeSchema>;\n","/**\n * Framework-agnostic tool descriptors.\n *\n * Each descriptor is a plain object `{ name, description, inputSchema, execute }`.\n * The same descriptors are wrapped for Vercel AI SDK (`./index`), raw OpenAI\n * function-calling (`./openai`), and LangChain (`./langchain`).\n */\nimport type { z } from \"zod\";\nimport { SimplrClient } from \"./client.js\";\nimport {\n checkIdentitySchema,\n phoneIntelligenceSchema,\n reportPhoneOutcomeSchema,\n scoreOrderSchema,\n type CheckIdentityArgs,\n type PhoneIntelligenceArgs,\n type ReportPhoneOutcomeArgs,\n type ScoreOrderArgs,\n} from \"./schemas.js\";\nimport type {\n CheckResult,\n OrderResult,\n PhoneIntelligenceResult,\n PhoneReportResult,\n SimplrAIConfig,\n} from \"./types.js\";\n\n/** A single framework-agnostic Simplr tool descriptor. */\nexport interface SimplrToolDescriptor<Args = any, Result = any> {\n /** Stable tool name, e.g. `simplr_check_identity`. */\n name: string;\n /** Agent-facing description (when to use it, what it returns). */\n description: string;\n /** Zod schema for the tool's input arguments. */\n inputSchema: z.ZodType<Args>;\n /** Run the tool against the Simplr API and return the unwrapped result. */\n execute: (args: Args) => Promise<Result>;\n}\n\nconst RISK_LEVEL_DOC =\n \"The result includes `risk_score` (0–100, higher = riskier) and `risk_level` (one of 'low', 'medium', 'high', 'critical').\";\n\n/**\n * Build the four Simplr tool descriptors bound to a client. These are pure data\n * + closures — no AI framework is required to use them.\n */\nexport function createSimplrToolDescriptors(\n config: SimplrAIConfig,\n): {\n simplr_check_identity: SimplrToolDescriptor<CheckIdentityArgs, CheckResult>;\n simplr_score_order: SimplrToolDescriptor<ScoreOrderArgs, OrderResult>;\n simplr_phone_intelligence: SimplrToolDescriptor<\n PhoneIntelligenceArgs,\n PhoneIntelligenceResult\n >;\n simplr_report_phone_outcome: SimplrToolDescriptor<\n ReportPhoneOutcomeArgs,\n PhoneReportResult\n >;\n} {\n const client = new SimplrClient(config);\n\n return {\n simplr_check_identity: {\n name: \"simplr_check_identity\",\n description:\n \"Assess the fraud/identity risk of a user or event using their email and/or phone. \" +\n \"Use this for signups, logins, password resets, or any moment you need to decide whether to \" +\n \"trust, challenge (e.g. step-up auth), or block a user. \" +\n RISK_LEVEL_DOC,\n inputSchema: checkIdentitySchema,\n execute: (args) => client.check(args),\n },\n\n simplr_score_order: {\n name: \"simplr_score_order\",\n description:\n \"Score a placed order/transaction for payment fraud risk given its amount, currency, and ids. \" +\n \"Use this at checkout or post-purchase review to decide whether to approve, hold for manual review, or reject an order. \" +\n RISK_LEVEL_DOC,\n inputSchema: scoreOrderSchema,\n execute: (args) => client.scoreOrder(args),\n },\n\n simplr_phone_intelligence: {\n name: \"simplr_phone_intelligence\",\n description:\n \"Look up stored risk intelligence for a phone number (carrier, line type, SIM-swap and prior-outcome signals). \" +\n \"Read-only with no side effects — safe to call whenever you need context about a phone number before deciding.\",\n inputSchema: phoneIntelligenceSchema,\n execute: (args) => client.phoneIntelligence(args.phone),\n },\n\n simplr_report_phone_outcome: {\n name: \"simplr_report_phone_outcome\",\n description:\n \"Report a confirmed real-world outcome for a phone number (e.g. 'fraud', 'sim_swap_fraud', 'legitimate') back to Simplr. \" +\n \"This is a feedback/training signal that improves future scoring. Only call it once you actually KNOW the outcome — \" +\n \"do not guess.\",\n inputSchema: reportPhoneOutcomeSchema,\n execute: (args) => client.reportPhone(args),\n },\n };\n}\n\n/** The set of tool names exposed by this package. */\nexport type SimplrToolName =\n | \"simplr_check_identity\"\n | \"simplr_score_order\"\n | \"simplr_phone_intelligence\"\n | \"simplr_report_phone_outcome\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,cAAN,cAA0B,MAAM;AAAA,EAC5B;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;;;ACIA,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AAS3B,SAAS,QAAQ,QAAwC;AACvD,MAAI,CAAC,QAAQ,OAAQ,OAAM,IAAI,MAAM,qCAAqC;AAC1E,QAAM,YAAY,OAAO,SAAS,WAAW;AAC7C,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL,QAAQ,OAAO;AAAA,IACf,UAAU,OAAO,WA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3B,MAAM;AAAA,MACN,aACE;AAAA,MAGF,aAAa;AAAA,MACb,SAAS,CAAC,SAAS,OAAO,YAAY,IAAI;AAAA,IAC5C;AAAA,EACF;AACF;;;AJlDO,SAAS,kBACd,QACoC;AACpC,MAAI;AACJ,MAAI;AAMF,UAAM,MAAM,OAAO;AACnB,WAAO,IAAI;AACX,QAAI,OAAO,SAAS,YAAY;AAC9B,YAAM,IAAI,MAAM,+CAA+C;AAAA,IACjE;AAAA,EACF,SAAS,KAAK;AACZ,UAAM,IAAI;AAAA,MACR,mMAGG,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,KAChD;AAAA,IACJ;AAAA,EACF;AAEA,QAAM,cAAc,4BAA4B,MAAM;AACtD,QAAM,MAAM,CAAC;AACb,aAAW,OAAO,OAAO,KAAK,WAAW,GAAuB;AAC9D,UAAM,IAAI,YAAY,GAAG;AACzB,QAAI,GAAG,IAAI,KAAK;AAAA,MACd,aAAa,EAAE;AAAA;AAAA;AAAA,MAGf,aAAa,EAAE;AAAA,MACf,YAAY,EAAE;AAAA,MACd,SAAS,CAAC,SAAkB,EAAE,QAAQ,IAAW;AAAA,IACnD,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAGA,SAAS,SAA2C;AAIlD,QAAM,YAAY;AAClB,SAAQ,QAAwB,SAAS;AAC3C;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { S as SimplrAIConfig, C as CheckResult, O as OrderResult, P as PhoneIntelligenceResult, a as PhoneReportResult, b as CheckInput, c as OrderInput, d as PhoneReportInput } from './types-Y9ma4qBT.cjs';
|
|
3
|
+
export { e as PhoneOutcome, R as RiskLevel } from './types-Y9ma4qBT.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Zod input schemas for each Simplr tool, with rich `.describe()` text so that
|
|
7
|
+
* LLMs call the tools with the right arguments. Each schema corresponds 1:1 to
|
|
8
|
+
* the API request body documented in the Simplr contract.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Input for `simplr_check_identity` → POST /v1/check. */
|
|
12
|
+
declare const checkIdentitySchema: z.ZodObject<{
|
|
13
|
+
email: z.ZodOptional<z.ZodString>;
|
|
14
|
+
phone: z.ZodOptional<z.ZodString>;
|
|
15
|
+
event_type: z.ZodOptional<z.ZodString>;
|
|
16
|
+
event_id: z.ZodOptional<z.ZodString>;
|
|
17
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
email?: string | undefined;
|
|
20
|
+
phone?: string | undefined;
|
|
21
|
+
event_type?: string | undefined;
|
|
22
|
+
event_id?: string | undefined;
|
|
23
|
+
metadata?: Record<string, unknown> | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
email?: string | undefined;
|
|
26
|
+
phone?: string | undefined;
|
|
27
|
+
event_type?: string | undefined;
|
|
28
|
+
event_id?: string | undefined;
|
|
29
|
+
metadata?: Record<string, unknown> | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
/** Input for `simplr_score_order` → POST /v1/orders. */
|
|
32
|
+
declare const scoreOrderSchema: z.ZodObject<{
|
|
33
|
+
order_id: z.ZodString;
|
|
34
|
+
external_id: z.ZodOptional<z.ZodString>;
|
|
35
|
+
amount: z.ZodNumber;
|
|
36
|
+
currency: z.ZodString;
|
|
37
|
+
fingerprint_hash: z.ZodOptional<z.ZodString>;
|
|
38
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
order_id: string;
|
|
41
|
+
amount: number;
|
|
42
|
+
currency: string;
|
|
43
|
+
metadata?: Record<string, unknown> | undefined;
|
|
44
|
+
external_id?: string | undefined;
|
|
45
|
+
fingerprint_hash?: string | undefined;
|
|
46
|
+
}, {
|
|
47
|
+
order_id: string;
|
|
48
|
+
amount: number;
|
|
49
|
+
currency: string;
|
|
50
|
+
metadata?: Record<string, unknown> | undefined;
|
|
51
|
+
external_id?: string | undefined;
|
|
52
|
+
fingerprint_hash?: string | undefined;
|
|
53
|
+
}>;
|
|
54
|
+
/** Input for `simplr_phone_intelligence` → GET /v1/check/phone/intelligence/{phone}. */
|
|
55
|
+
declare const phoneIntelligenceSchema: z.ZodObject<{
|
|
56
|
+
phone: z.ZodString;
|
|
57
|
+
}, "strip", z.ZodTypeAny, {
|
|
58
|
+
phone: string;
|
|
59
|
+
}, {
|
|
60
|
+
phone: string;
|
|
61
|
+
}>;
|
|
62
|
+
/** Input for `simplr_report_phone_outcome` → POST /v1/check/phone/report. */
|
|
63
|
+
declare const reportPhoneOutcomeSchema: z.ZodObject<{
|
|
64
|
+
phone: z.ZodString;
|
|
65
|
+
outcome: z.ZodEnum<["fraud", "sim_swap_fraud", "account_takeover", "spam", "bot", "legitimate"]>;
|
|
66
|
+
check_id: z.ZodOptional<z.ZodString>;
|
|
67
|
+
confidence: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
69
|
+
}, "strip", z.ZodTypeAny, {
|
|
70
|
+
phone: string;
|
|
71
|
+
outcome: "fraud" | "sim_swap_fraud" | "account_takeover" | "spam" | "bot" | "legitimate";
|
|
72
|
+
metadata?: Record<string, unknown> | undefined;
|
|
73
|
+
check_id?: string | undefined;
|
|
74
|
+
confidence?: number | undefined;
|
|
75
|
+
}, {
|
|
76
|
+
phone: string;
|
|
77
|
+
outcome: "fraud" | "sim_swap_fraud" | "account_takeover" | "spam" | "bot" | "legitimate";
|
|
78
|
+
metadata?: Record<string, unknown> | undefined;
|
|
79
|
+
check_id?: string | undefined;
|
|
80
|
+
confidence?: number | undefined;
|
|
81
|
+
}>;
|
|
82
|
+
type CheckIdentityArgs = z.infer<typeof checkIdentitySchema>;
|
|
83
|
+
type ScoreOrderArgs = z.infer<typeof scoreOrderSchema>;
|
|
84
|
+
type PhoneIntelligenceArgs = z.infer<typeof phoneIntelligenceSchema>;
|
|
85
|
+
type ReportPhoneOutcomeArgs = z.infer<typeof reportPhoneOutcomeSchema>;
|
|
86
|
+
|
|
87
|
+
type schemas_CheckIdentityArgs = CheckIdentityArgs;
|
|
88
|
+
type schemas_PhoneIntelligenceArgs = PhoneIntelligenceArgs;
|
|
89
|
+
type schemas_ReportPhoneOutcomeArgs = ReportPhoneOutcomeArgs;
|
|
90
|
+
type schemas_ScoreOrderArgs = ScoreOrderArgs;
|
|
91
|
+
declare const schemas_checkIdentitySchema: typeof checkIdentitySchema;
|
|
92
|
+
declare const schemas_phoneIntelligenceSchema: typeof phoneIntelligenceSchema;
|
|
93
|
+
declare const schemas_reportPhoneOutcomeSchema: typeof reportPhoneOutcomeSchema;
|
|
94
|
+
declare const schemas_scoreOrderSchema: typeof scoreOrderSchema;
|
|
95
|
+
declare namespace schemas {
|
|
96
|
+
export { type schemas_CheckIdentityArgs as CheckIdentityArgs, type schemas_PhoneIntelligenceArgs as PhoneIntelligenceArgs, type schemas_ReportPhoneOutcomeArgs as ReportPhoneOutcomeArgs, type schemas_ScoreOrderArgs as ScoreOrderArgs, schemas_checkIdentitySchema as checkIdentitySchema, schemas_phoneIntelligenceSchema as phoneIntelligenceSchema, schemas_reportPhoneOutcomeSchema as reportPhoneOutcomeSchema, schemas_scoreOrderSchema as scoreOrderSchema };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Framework-agnostic tool descriptors.
|
|
101
|
+
*
|
|
102
|
+
* Each descriptor is a plain object `{ name, description, inputSchema, execute }`.
|
|
103
|
+
* The same descriptors are wrapped for Vercel AI SDK (`./index`), raw OpenAI
|
|
104
|
+
* function-calling (`./openai`), and LangChain (`./langchain`).
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/** A single framework-agnostic Simplr tool descriptor. */
|
|
108
|
+
interface SimplrToolDescriptor<Args = any, Result = any> {
|
|
109
|
+
/** Stable tool name, e.g. `simplr_check_identity`. */
|
|
110
|
+
name: string;
|
|
111
|
+
/** Agent-facing description (when to use it, what it returns). */
|
|
112
|
+
description: string;
|
|
113
|
+
/** Zod schema for the tool's input arguments. */
|
|
114
|
+
inputSchema: z.ZodType<Args>;
|
|
115
|
+
/** Run the tool against the Simplr API and return the unwrapped result. */
|
|
116
|
+
execute: (args: Args) => Promise<Result>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Build the four Simplr tool descriptors bound to a client. These are pure data
|
|
120
|
+
* + closures — no AI framework is required to use them.
|
|
121
|
+
*/
|
|
122
|
+
declare function createSimplrToolDescriptors(config: SimplrAIConfig): {
|
|
123
|
+
simplr_check_identity: SimplrToolDescriptor<CheckIdentityArgs, CheckResult>;
|
|
124
|
+
simplr_score_order: SimplrToolDescriptor<ScoreOrderArgs, OrderResult>;
|
|
125
|
+
simplr_phone_intelligence: SimplrToolDescriptor<PhoneIntelligenceArgs, PhoneIntelligenceResult>;
|
|
126
|
+
simplr_report_phone_outcome: SimplrToolDescriptor<ReportPhoneOutcomeArgs, PhoneReportResult>;
|
|
127
|
+
};
|
|
128
|
+
/** The set of tool names exposed by this package. */
|
|
129
|
+
type SimplrToolName = "simplr_check_identity" | "simplr_score_order" | "simplr_phone_intelligence" | "simplr_report_phone_outcome";
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Thrown when the Simplr API returns a non-2xx response, or a request fails
|
|
133
|
+
* (network error / timeout — in which case `status` is 0 and `body` is null).
|
|
134
|
+
*
|
|
135
|
+
* Mirrors `SimplrError` from `@simplr-ai/node`.
|
|
136
|
+
*/
|
|
137
|
+
declare class SimplrError extends Error {
|
|
138
|
+
readonly status: number;
|
|
139
|
+
readonly body: unknown;
|
|
140
|
+
constructor(message: string, status: number, body: unknown);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** A minimal Simplr API client exposing only the endpoints these tools need. */
|
|
144
|
+
declare class SimplrClient {
|
|
145
|
+
private readonly cfg;
|
|
146
|
+
constructor(config: SimplrAIConfig);
|
|
147
|
+
/** POST /v1/check — identity/fraud check. */
|
|
148
|
+
check(input: CheckInput): Promise<CheckResult>;
|
|
149
|
+
/** POST /v1/orders — order fraud scoring. */
|
|
150
|
+
scoreOrder(input: OrderInput): Promise<OrderResult>;
|
|
151
|
+
/** GET /v1/check/phone/intelligence/{phone} — stored phone intelligence. */
|
|
152
|
+
phoneIntelligence(phone: string): Promise<PhoneIntelligenceResult>;
|
|
153
|
+
/** POST /v1/check/phone/report — report a real-world phone outcome. */
|
|
154
|
+
reportPhone(input: PhoneReportInput): Promise<PhoneReportResult>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* `@simplr-ai/ai` — main entry.
|
|
159
|
+
*
|
|
160
|
+
* Exposes Simplr's fraud/identity/phone checks as ready-to-use tools for AI
|
|
161
|
+
* agents. The primary integration is the Vercel AI SDK (`ai` package): call
|
|
162
|
+
* `createSimplrTools(config)` to get an object of `tool()` instances you can pass
|
|
163
|
+
* straight into `generateText`/`streamText`.
|
|
164
|
+
*
|
|
165
|
+
* `ai` is an OPTIONAL peer dependency and is imported lazily, so this package
|
|
166
|
+
* builds and tests without it installed. If you call `createSimplrTools` without
|
|
167
|
+
* `ai` present, a clear error tells you to install it (or use
|
|
168
|
+
* `createSimplrToolDescriptors`, which needs no framework).
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
/** The shape of a Vercel AI SDK `tool()` instance (kept loose to avoid a hard dep). */
|
|
172
|
+
type VercelTool = unknown;
|
|
173
|
+
/**
|
|
174
|
+
* Create Vercel AI SDK tools for every Simplr capability, keyed by tool name.
|
|
175
|
+
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* import { generateText } from "ai";
|
|
178
|
+
* import { openai } from "@ai-sdk/openai";
|
|
179
|
+
* import { createSimplrTools } from "@simplr-ai/ai";
|
|
180
|
+
*
|
|
181
|
+
* const tools = createSimplrTools({ apiKey: process.env.SIMPLR_API_KEY! });
|
|
182
|
+
* const { text } = await generateText({
|
|
183
|
+
* model: openai("gpt-4o"),
|
|
184
|
+
* tools,
|
|
185
|
+
* prompt: "Is user@example.com risky to sign up?",
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* Requires the optional peer dependency `ai`. If it isn't installed, this throws
|
|
190
|
+
* with installation guidance — use `createSimplrToolDescriptors` for a
|
|
191
|
+
* framework-free alternative.
|
|
192
|
+
*/
|
|
193
|
+
declare function createSimplrTools(config: SimplrAIConfig): Record<SimplrToolName, VercelTool>;
|
|
194
|
+
|
|
195
|
+
export { CheckInput, CheckResult, OrderInput, OrderResult, PhoneIntelligenceResult, PhoneReportInput, PhoneReportResult, SimplrAIConfig, SimplrClient, SimplrError, type SimplrToolDescriptor, type SimplrToolName, type VercelTool, createSimplrToolDescriptors, createSimplrTools, schemas };
|