@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.
@@ -0,0 +1,237 @@
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/langchain.ts
21
+ var langchain_exports = {};
22
+ __export(langchain_exports, {
23
+ createSimplrLangChainTools: () => createSimplrLangChainTools
24
+ });
25
+ module.exports = __toCommonJS(langchain_exports);
26
+
27
+ // src/errors.ts
28
+ var SimplrError = class extends Error {
29
+ status;
30
+ body;
31
+ constructor(message, status, body) {
32
+ super(message);
33
+ this.name = "SimplrError";
34
+ this.status = status;
35
+ this.body = body;
36
+ }
37
+ };
38
+
39
+ // src/client.ts
40
+ var DEFAULT_BASE_URL = "https://api.simplr.sh";
41
+ var DEFAULT_TIMEOUT_MS = 15e3;
42
+ function resolve(config) {
43
+ if (!config?.apiKey) throw new Error("@simplr-ai/ai: `apiKey` is required");
44
+ const fetchImpl = config.fetch ?? globalThis.fetch;
45
+ if (typeof fetchImpl !== "function") {
46
+ throw new Error(
47
+ "@simplr-ai/ai: no global fetch available \u2014 use Node 18+ or pass `fetch` in config"
48
+ );
49
+ }
50
+ return {
51
+ apiKey: config.apiKey,
52
+ baseUrl: (config.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, ""),
53
+ timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
54
+ fetchImpl
55
+ };
56
+ }
57
+ async function apiRequest(cfg, method, path, body) {
58
+ const controller = new AbortController();
59
+ const timer = setTimeout(() => controller.abort(), cfg.timeoutMs);
60
+ try {
61
+ const res = await cfg.fetchImpl(`${cfg.baseUrl}${path}`, {
62
+ method,
63
+ headers: { "Content-Type": "application/json", "X-API-Key": cfg.apiKey },
64
+ body: body !== void 0 ? JSON.stringify(body) : void 0,
65
+ signal: controller.signal
66
+ });
67
+ const text = await res.text();
68
+ let parsed;
69
+ try {
70
+ parsed = text ? JSON.parse(text) : void 0;
71
+ } catch {
72
+ parsed = text;
73
+ }
74
+ if (!res.ok) {
75
+ const message = parsed && (parsed.message || parsed.error) || `Simplr API error ${res.status}`;
76
+ throw new SimplrError(message, res.status, parsed);
77
+ }
78
+ return parsed && typeof parsed === "object" && "content" in parsed ? parsed.content : parsed;
79
+ } catch (err) {
80
+ if (err instanceof SimplrError) throw err;
81
+ if (err instanceof Error && err.name === "AbortError") {
82
+ throw new SimplrError(`Request to ${path} timed out after ${cfg.timeoutMs}ms`, 0, null);
83
+ }
84
+ throw new SimplrError(err instanceof Error ? err.message : "Network error", 0, null);
85
+ } finally {
86
+ clearTimeout(timer);
87
+ }
88
+ }
89
+ var SimplrClient = class {
90
+ cfg;
91
+ constructor(config) {
92
+ this.cfg = resolve(config);
93
+ }
94
+ /** POST /v1/check — identity/fraud check. */
95
+ check(input) {
96
+ return apiRequest(this.cfg, "POST", "/v1/check", input);
97
+ }
98
+ /** POST /v1/orders — order fraud scoring. */
99
+ scoreOrder(input) {
100
+ return apiRequest(this.cfg, "POST", "/v1/orders", input);
101
+ }
102
+ /** GET /v1/check/phone/intelligence/{phone} — stored phone intelligence. */
103
+ phoneIntelligence(phone) {
104
+ return apiRequest(
105
+ this.cfg,
106
+ "GET",
107
+ `/v1/check/phone/intelligence/${encodeURIComponent(phone)}`
108
+ );
109
+ }
110
+ /** POST /v1/check/phone/report — report a real-world phone outcome. */
111
+ reportPhone(input) {
112
+ return apiRequest(this.cfg, "POST", "/v1/check/phone/report", input);
113
+ }
114
+ };
115
+
116
+ // src/schemas.ts
117
+ var import_zod = require("zod");
118
+ var checkIdentitySchema = import_zod.z.object({
119
+ email: import_zod.z.string().email().optional().describe("The user's email address to evaluate (e.g. for signup/login risk)."),
120
+ phone: import_zod.z.string().optional().describe("The user's phone number in E.164 format (e.g. +14155552671)."),
121
+ event_type: import_zod.z.string().optional().describe(
122
+ "The lifecycle event being scored, e.g. 'signup', 'login', 'checkout', 'password_reset'. Helps tune the risk model."
123
+ ),
124
+ event_id: import_zod.z.string().optional().describe("Your own idempotency / correlation id for this event, if any."),
125
+ metadata: import_zod.z.record(import_zod.z.unknown()).optional().describe(
126
+ "Arbitrary extra context about the event (e.g. { ip: '1.2.3.4', user_id: 'u_123' }). Free-form key/value object."
127
+ )
128
+ }).describe(
129
+ "Provide at least one of `email` or `phone`. Returns a fraud/identity risk assessment for the given user or event."
130
+ );
131
+ var scoreOrderSchema = import_zod.z.object({
132
+ order_id: import_zod.z.string().describe("Your unique identifier for this order."),
133
+ external_id: import_zod.z.string().optional().describe("An optional secondary id (e.g. your payment-processor reference)."),
134
+ amount: import_zod.z.number().describe("The order total as a number in the order's currency (e.g. 129.99)."),
135
+ currency: import_zod.z.string().describe("ISO 4217 currency code, e.g. 'USD', 'EUR', 'GBP'."),
136
+ fingerprint_hash: import_zod.z.string().optional().describe(
137
+ "Device fingerprint hash from a prior identity check, if available, to link the order to a device."
138
+ ),
139
+ metadata: import_zod.z.record(import_zod.z.unknown()).optional().describe("Arbitrary extra order context (items, shipping, customer id, etc.).")
140
+ }).describe(
141
+ "Score a placed order for payment/transaction fraud risk. Returns a risk_score and risk_level for the order."
142
+ );
143
+ var phoneIntelligenceSchema = import_zod.z.object({
144
+ phone: import_zod.z.string().describe(
145
+ "The phone number to look up, in E.164 format (e.g. +14155552671). It will be URL-encoded."
146
+ )
147
+ }).describe(
148
+ "Fetch stored risk intelligence for a phone number (carrier, line type, SIM-swap signals, prior outcomes). Read-only, no side effects."
149
+ );
150
+ var reportPhoneOutcomeSchema = import_zod.z.object({
151
+ phone: import_zod.z.string().describe("The phone number the outcome applies to, in E.164 format."),
152
+ outcome: import_zod.z.enum([
153
+ "fraud",
154
+ "sim_swap_fraud",
155
+ "account_takeover",
156
+ "spam",
157
+ "bot",
158
+ "legitimate"
159
+ ]).describe(
160
+ "The confirmed real-world outcome for this phone: 'legitimate' (good actor), 'fraud', 'sim_swap_fraud', 'account_takeover', 'spam', or 'bot'."
161
+ ),
162
+ check_id: import_zod.z.string().optional().describe("The id of the original check this outcome relates to, if known."),
163
+ confidence: import_zod.z.number().min(0).max(1).optional().describe("Your confidence in the reported outcome, 0.0\u20131.0."),
164
+ metadata: import_zod.z.record(import_zod.z.unknown()).optional().describe("Arbitrary extra context about how the outcome was determined.")
165
+ }).describe(
166
+ "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."
167
+ );
168
+
169
+ // src/tools.ts
170
+ var RISK_LEVEL_DOC = "The result includes `risk_score` (0\u2013100, higher = riskier) and `risk_level` (one of 'low', 'medium', 'high', 'critical').";
171
+ function createSimplrToolDescriptors(config) {
172
+ const client = new SimplrClient(config);
173
+ return {
174
+ simplr_check_identity: {
175
+ name: "simplr_check_identity",
176
+ 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,
177
+ inputSchema: checkIdentitySchema,
178
+ execute: (args) => client.check(args)
179
+ },
180
+ simplr_score_order: {
181
+ name: "simplr_score_order",
182
+ 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,
183
+ inputSchema: scoreOrderSchema,
184
+ execute: (args) => client.scoreOrder(args)
185
+ },
186
+ simplr_phone_intelligence: {
187
+ name: "simplr_phone_intelligence",
188
+ 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.",
189
+ inputSchema: phoneIntelligenceSchema,
190
+ execute: (args) => client.phoneIntelligence(args.phone)
191
+ },
192
+ simplr_report_phone_outcome: {
193
+ name: "simplr_report_phone_outcome",
194
+ 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.",
195
+ inputSchema: reportPhoneOutcomeSchema,
196
+ execute: (args) => client.reportPhone(args)
197
+ }
198
+ };
199
+ }
200
+
201
+ // src/langchain.ts
202
+ async function createSimplrLangChainTools(config) {
203
+ let DynamicStructuredTool;
204
+ try {
205
+ const specifier = "@langchain/core/tools";
206
+ const mod = await import(
207
+ /* @vite-ignore */
208
+ specifier
209
+ );
210
+ DynamicStructuredTool = mod.DynamicStructuredTool;
211
+ if (typeof DynamicStructuredTool !== "function") {
212
+ throw new Error("`@langchain/core/tools` does not export DynamicStructuredTool.");
213
+ }
214
+ } catch (err) {
215
+ throw new Error(
216
+ "@simplr-ai/ai: createSimplrLangChainTools() requires `@langchain/core`. Install it with `npm install @langchain/core`. (Original error: " + (err instanceof Error ? err.message : String(err)) + ")"
217
+ );
218
+ }
219
+ const descriptors = createSimplrToolDescriptors(config);
220
+ return Object.keys(descriptors).map((key) => {
221
+ const d = descriptors[key];
222
+ return new DynamicStructuredTool({
223
+ name: d.name,
224
+ description: d.description,
225
+ schema: d.inputSchema,
226
+ func: async (args) => {
227
+ const result = await d.execute(args);
228
+ return JSON.stringify(result);
229
+ }
230
+ });
231
+ });
232
+ }
233
+ // Annotate the CommonJS export names for ESM import in node:
234
+ 0 && (module.exports = {
235
+ createSimplrLangChainTools
236
+ });
237
+ //# sourceMappingURL=langchain.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/langchain.ts","../src/errors.ts","../src/client.ts","../src/schemas.ts","../src/tools.ts"],"sourcesContent":["/**\n * `@simplr-ai/ai/langchain` — LangChain integration.\n *\n * `createSimplrLangChainTools(config)` returns an array of `DynamicStructuredTool`\n * instances you can pass to a LangChain agent / `bindTools`. `@langchain/core`\n * is an OPTIONAL peer dependency, imported lazily — if it is missing you get a\n * clear install error rather than a build failure.\n */\nimport { createSimplrToolDescriptors, type SimplrToolName } from \"./tools.js\";\nimport type { SimplrAIConfig } from \"./types.js\";\n\n/** Loose type alias — the real type comes from `@langchain/core/tools`. */\nexport type SimplrLangChainTool = unknown;\n\n/**\n * Create LangChain `DynamicStructuredTool`s for every Simplr capability.\n *\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createSimplrLangChainTools } from \"@simplr-ai/ai/langchain\";\n *\n * const tools = await createSimplrLangChainTools({ apiKey: process.env.SIMPLR_API_KEY! });\n * const model = new ChatOpenAI({ model: \"gpt-4o\" }).bindTools(tools);\n * ```\n *\n * Requires the optional peer dependency `@langchain/core`. If it isn't\n * installed, this rejects with installation guidance.\n */\nexport async function createSimplrLangChainTools(\n config: SimplrAIConfig,\n): Promise<SimplrLangChainTool[]> {\n let DynamicStructuredTool: new (spec: any) => unknown;\n try {\n // Indirect specifier so the TS type-checker / bundler does not try to\n // resolve `@langchain/core/tools` at build time (it's an optional peer).\n const specifier = \"@langchain/core/tools\";\n const mod: any = await import(/* @vite-ignore */ specifier);\n DynamicStructuredTool = mod.DynamicStructuredTool;\n if (typeof DynamicStructuredTool !== \"function\") {\n throw new Error(\"`@langchain/core/tools` does not export DynamicStructuredTool.\");\n }\n } catch (err) {\n throw new Error(\n \"@simplr-ai/ai: createSimplrLangChainTools() requires `@langchain/core`. \" +\n \"Install it with `npm install @langchain/core`. (Original error: \" +\n (err instanceof Error ? err.message : String(err)) +\n \")\",\n );\n }\n\n const descriptors = createSimplrToolDescriptors(config);\n return (Object.keys(descriptors) as SimplrToolName[]).map((key) => {\n const d = descriptors[key];\n return new DynamicStructuredTool({\n name: d.name,\n description: d.description,\n schema: d.inputSchema,\n func: async (args: unknown) => {\n const result = await d.execute(args as any);\n // LangChain tool funcs are expected to return a string.\n return JSON.stringify(result);\n },\n });\n });\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;;;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,Q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,OAAO,WAAW,IAAI;AAAA,IAC3C;AAAA,IAEA,2BAA2B;AAAA,MACzB,MAAM;AAAA,MACN,aACE;AAAA,MAEF,aAAa;AAAA,MACb,SAAS,CAAC,SAAS,OAAO,kBAAkB,KAAK,KAAK;AAAA,IACxD;AAAA,IAEA,6BAA6B;AAAA,MAC3B,MAAM;AAAA,MACN,aACE;AAAA,MAGF,aAAa;AAAA,MACb,SAAS,CAAC,SAAS,OAAO,YAAY,IAAI;AAAA,IAC5C;AAAA,EACF;AACF;;;AJ3EA,eAAsB,2BACpB,QACgC;AAChC,MAAI;AACJ,MAAI;AAGF,UAAM,YAAY;AAClB,UAAM,MAAW,MAAM;AAAA;AAAA,MAA0B;AAAA;AACjD,4BAAwB,IAAI;AAC5B,QAAI,OAAO,0BAA0B,YAAY;AAC/C,YAAM,IAAI,MAAM,gEAAgE;AAAA,IAClF;AAAA,EACF,SAAS,KAAK;AACZ,UAAM,IAAI;AAAA,MACR,8IAEG,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,KAChD;AAAA,IACJ;AAAA,EACF;AAEA,QAAM,cAAc,4BAA4B,MAAM;AACtD,SAAQ,OAAO,KAAK,WAAW,EAAuB,IAAI,CAAC,QAAQ;AACjE,UAAM,IAAI,YAAY,GAAG;AACzB,WAAO,IAAI,sBAAsB;AAAA,MAC/B,MAAM,EAAE;AAAA,MACR,aAAa,EAAE;AAAA,MACf,QAAQ,EAAE;AAAA,MACV,MAAM,OAAO,SAAkB;AAC7B,cAAM,SAAS,MAAM,EAAE,QAAQ,IAAW;AAE1C,eAAO,KAAK,UAAU,MAAM;AAAA,MAC9B;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
@@ -0,0 +1,21 @@
1
+ import { S as SimplrAIConfig } from './types-Y9ma4qBT.cjs';
2
+
3
+ /** Loose type alias — the real type comes from `@langchain/core/tools`. */
4
+ type SimplrLangChainTool = unknown;
5
+ /**
6
+ * Create LangChain `DynamicStructuredTool`s for every Simplr capability.
7
+ *
8
+ * ```ts
9
+ * import { ChatOpenAI } from "@langchain/openai";
10
+ * import { createSimplrLangChainTools } from "@simplr-ai/ai/langchain";
11
+ *
12
+ * const tools = await createSimplrLangChainTools({ apiKey: process.env.SIMPLR_API_KEY! });
13
+ * const model = new ChatOpenAI({ model: "gpt-4o" }).bindTools(tools);
14
+ * ```
15
+ *
16
+ * Requires the optional peer dependency `@langchain/core`. If it isn't
17
+ * installed, this rejects with installation guidance.
18
+ */
19
+ declare function createSimplrLangChainTools(config: SimplrAIConfig): Promise<SimplrLangChainTool[]>;
20
+
21
+ export { type SimplrLangChainTool, createSimplrLangChainTools };
@@ -0,0 +1,21 @@
1
+ import { S as SimplrAIConfig } from './types-Y9ma4qBT.js';
2
+
3
+ /** Loose type alias — the real type comes from `@langchain/core/tools`. */
4
+ type SimplrLangChainTool = unknown;
5
+ /**
6
+ * Create LangChain `DynamicStructuredTool`s for every Simplr capability.
7
+ *
8
+ * ```ts
9
+ * import { ChatOpenAI } from "@langchain/openai";
10
+ * import { createSimplrLangChainTools } from "@simplr-ai/ai/langchain";
11
+ *
12
+ * const tools = await createSimplrLangChainTools({ apiKey: process.env.SIMPLR_API_KEY! });
13
+ * const model = new ChatOpenAI({ model: "gpt-4o" }).bindTools(tools);
14
+ * ```
15
+ *
16
+ * Requires the optional peer dependency `@langchain/core`. If it isn't
17
+ * installed, this rejects with installation guidance.
18
+ */
19
+ declare function createSimplrLangChainTools(config: SimplrAIConfig): Promise<SimplrLangChainTool[]>;
20
+
21
+ export { type SimplrLangChainTool, createSimplrLangChainTools };
@@ -0,0 +1,210 @@
1
+ // src/errors.ts
2
+ var SimplrError = class extends Error {
3
+ status;
4
+ body;
5
+ constructor(message, status, body) {
6
+ super(message);
7
+ this.name = "SimplrError";
8
+ this.status = status;
9
+ this.body = body;
10
+ }
11
+ };
12
+
13
+ // src/client.ts
14
+ var DEFAULT_BASE_URL = "https://api.simplr.sh";
15
+ var DEFAULT_TIMEOUT_MS = 15e3;
16
+ function resolve(config) {
17
+ if (!config?.apiKey) throw new Error("@simplr-ai/ai: `apiKey` is required");
18
+ const fetchImpl = config.fetch ?? globalThis.fetch;
19
+ if (typeof fetchImpl !== "function") {
20
+ throw new Error(
21
+ "@simplr-ai/ai: no global fetch available \u2014 use Node 18+ or pass `fetch` in config"
22
+ );
23
+ }
24
+ return {
25
+ apiKey: config.apiKey,
26
+ baseUrl: (config.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, ""),
27
+ timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
28
+ fetchImpl
29
+ };
30
+ }
31
+ async function apiRequest(cfg, method, path, body) {
32
+ const controller = new AbortController();
33
+ const timer = setTimeout(() => controller.abort(), cfg.timeoutMs);
34
+ try {
35
+ const res = await cfg.fetchImpl(`${cfg.baseUrl}${path}`, {
36
+ method,
37
+ headers: { "Content-Type": "application/json", "X-API-Key": cfg.apiKey },
38
+ body: body !== void 0 ? JSON.stringify(body) : void 0,
39
+ signal: controller.signal
40
+ });
41
+ const text = await res.text();
42
+ let parsed;
43
+ try {
44
+ parsed = text ? JSON.parse(text) : void 0;
45
+ } catch {
46
+ parsed = text;
47
+ }
48
+ if (!res.ok) {
49
+ const message = parsed && (parsed.message || parsed.error) || `Simplr API error ${res.status}`;
50
+ throw new SimplrError(message, res.status, parsed);
51
+ }
52
+ return parsed && typeof parsed === "object" && "content" in parsed ? parsed.content : parsed;
53
+ } catch (err) {
54
+ if (err instanceof SimplrError) throw err;
55
+ if (err instanceof Error && err.name === "AbortError") {
56
+ throw new SimplrError(`Request to ${path} timed out after ${cfg.timeoutMs}ms`, 0, null);
57
+ }
58
+ throw new SimplrError(err instanceof Error ? err.message : "Network error", 0, null);
59
+ } finally {
60
+ clearTimeout(timer);
61
+ }
62
+ }
63
+ var SimplrClient = class {
64
+ cfg;
65
+ constructor(config) {
66
+ this.cfg = resolve(config);
67
+ }
68
+ /** POST /v1/check — identity/fraud check. */
69
+ check(input) {
70
+ return apiRequest(this.cfg, "POST", "/v1/check", input);
71
+ }
72
+ /** POST /v1/orders — order fraud scoring. */
73
+ scoreOrder(input) {
74
+ return apiRequest(this.cfg, "POST", "/v1/orders", input);
75
+ }
76
+ /** GET /v1/check/phone/intelligence/{phone} — stored phone intelligence. */
77
+ phoneIntelligence(phone) {
78
+ return apiRequest(
79
+ this.cfg,
80
+ "GET",
81
+ `/v1/check/phone/intelligence/${encodeURIComponent(phone)}`
82
+ );
83
+ }
84
+ /** POST /v1/check/phone/report — report a real-world phone outcome. */
85
+ reportPhone(input) {
86
+ return apiRequest(this.cfg, "POST", "/v1/check/phone/report", input);
87
+ }
88
+ };
89
+
90
+ // src/schemas.ts
91
+ import { z } from "zod";
92
+ var checkIdentitySchema = z.object({
93
+ email: z.string().email().optional().describe("The user's email address to evaluate (e.g. for signup/login risk)."),
94
+ phone: z.string().optional().describe("The user's phone number in E.164 format (e.g. +14155552671)."),
95
+ event_type: z.string().optional().describe(
96
+ "The lifecycle event being scored, e.g. 'signup', 'login', 'checkout', 'password_reset'. Helps tune the risk model."
97
+ ),
98
+ event_id: z.string().optional().describe("Your own idempotency / correlation id for this event, if any."),
99
+ metadata: z.record(z.unknown()).optional().describe(
100
+ "Arbitrary extra context about the event (e.g. { ip: '1.2.3.4', user_id: 'u_123' }). Free-form key/value object."
101
+ )
102
+ }).describe(
103
+ "Provide at least one of `email` or `phone`. Returns a fraud/identity risk assessment for the given user or event."
104
+ );
105
+ var scoreOrderSchema = z.object({
106
+ order_id: z.string().describe("Your unique identifier for this order."),
107
+ external_id: z.string().optional().describe("An optional secondary id (e.g. your payment-processor reference)."),
108
+ amount: z.number().describe("The order total as a number in the order's currency (e.g. 129.99)."),
109
+ currency: z.string().describe("ISO 4217 currency code, e.g. 'USD', 'EUR', 'GBP'."),
110
+ fingerprint_hash: z.string().optional().describe(
111
+ "Device fingerprint hash from a prior identity check, if available, to link the order to a device."
112
+ ),
113
+ metadata: z.record(z.unknown()).optional().describe("Arbitrary extra order context (items, shipping, customer id, etc.).")
114
+ }).describe(
115
+ "Score a placed order for payment/transaction fraud risk. Returns a risk_score and risk_level for the order."
116
+ );
117
+ var phoneIntelligenceSchema = z.object({
118
+ phone: z.string().describe(
119
+ "The phone number to look up, in E.164 format (e.g. +14155552671). It will be URL-encoded."
120
+ )
121
+ }).describe(
122
+ "Fetch stored risk intelligence for a phone number (carrier, line type, SIM-swap signals, prior outcomes). Read-only, no side effects."
123
+ );
124
+ var reportPhoneOutcomeSchema = z.object({
125
+ phone: z.string().describe("The phone number the outcome applies to, in E.164 format."),
126
+ outcome: z.enum([
127
+ "fraud",
128
+ "sim_swap_fraud",
129
+ "account_takeover",
130
+ "spam",
131
+ "bot",
132
+ "legitimate"
133
+ ]).describe(
134
+ "The confirmed real-world outcome for this phone: 'legitimate' (good actor), 'fraud', 'sim_swap_fraud', 'account_takeover', 'spam', or 'bot'."
135
+ ),
136
+ check_id: z.string().optional().describe("The id of the original check this outcome relates to, if known."),
137
+ confidence: z.number().min(0).max(1).optional().describe("Your confidence in the reported outcome, 0.0\u20131.0."),
138
+ metadata: z.record(z.unknown()).optional().describe("Arbitrary extra context about how the outcome was determined.")
139
+ }).describe(
140
+ "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."
141
+ );
142
+
143
+ // src/tools.ts
144
+ var RISK_LEVEL_DOC = "The result includes `risk_score` (0\u2013100, higher = riskier) and `risk_level` (one of 'low', 'medium', 'high', 'critical').";
145
+ function createSimplrToolDescriptors(config) {
146
+ const client = new SimplrClient(config);
147
+ return {
148
+ simplr_check_identity: {
149
+ name: "simplr_check_identity",
150
+ 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,
151
+ inputSchema: checkIdentitySchema,
152
+ execute: (args) => client.check(args)
153
+ },
154
+ simplr_score_order: {
155
+ name: "simplr_score_order",
156
+ 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,
157
+ inputSchema: scoreOrderSchema,
158
+ execute: (args) => client.scoreOrder(args)
159
+ },
160
+ simplr_phone_intelligence: {
161
+ name: "simplr_phone_intelligence",
162
+ 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.",
163
+ inputSchema: phoneIntelligenceSchema,
164
+ execute: (args) => client.phoneIntelligence(args.phone)
165
+ },
166
+ simplr_report_phone_outcome: {
167
+ name: "simplr_report_phone_outcome",
168
+ 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.",
169
+ inputSchema: reportPhoneOutcomeSchema,
170
+ execute: (args) => client.reportPhone(args)
171
+ }
172
+ };
173
+ }
174
+
175
+ // src/langchain.ts
176
+ async function createSimplrLangChainTools(config) {
177
+ let DynamicStructuredTool;
178
+ try {
179
+ const specifier = "@langchain/core/tools";
180
+ const mod = await import(
181
+ /* @vite-ignore */
182
+ specifier
183
+ );
184
+ DynamicStructuredTool = mod.DynamicStructuredTool;
185
+ if (typeof DynamicStructuredTool !== "function") {
186
+ throw new Error("`@langchain/core/tools` does not export DynamicStructuredTool.");
187
+ }
188
+ } catch (err) {
189
+ throw new Error(
190
+ "@simplr-ai/ai: createSimplrLangChainTools() requires `@langchain/core`. Install it with `npm install @langchain/core`. (Original error: " + (err instanceof Error ? err.message : String(err)) + ")"
191
+ );
192
+ }
193
+ const descriptors = createSimplrToolDescriptors(config);
194
+ return Object.keys(descriptors).map((key) => {
195
+ const d = descriptors[key];
196
+ return new DynamicStructuredTool({
197
+ name: d.name,
198
+ description: d.description,
199
+ schema: d.inputSchema,
200
+ func: async (args) => {
201
+ const result = await d.execute(args);
202
+ return JSON.stringify(result);
203
+ }
204
+ });
205
+ });
206
+ }
207
+ export {
208
+ createSimplrLangChainTools
209
+ };
210
+ //# sourceMappingURL=langchain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/client.ts","../src/schemas.ts","../src/tools.ts","../src/langchain.ts"],"sourcesContent":["/**\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","/**\n * `@simplr-ai/ai/langchain` — LangChain integration.\n *\n * `createSimplrLangChainTools(config)` returns an array of `DynamicStructuredTool`\n * instances you can pass to a LangChain agent / `bindTools`. `@langchain/core`\n * is an OPTIONAL peer dependency, imported lazily — if it is missing you get a\n * clear install error rather than a build failure.\n */\nimport { createSimplrToolDescriptors, type SimplrToolName } from \"./tools.js\";\nimport type { SimplrAIConfig } from \"./types.js\";\n\n/** Loose type alias — the real type comes from `@langchain/core/tools`. */\nexport type SimplrLangChainTool = unknown;\n\n/**\n * Create LangChain `DynamicStructuredTool`s for every Simplr capability.\n *\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { createSimplrLangChainTools } from \"@simplr-ai/ai/langchain\";\n *\n * const tools = await createSimplrLangChainTools({ apiKey: process.env.SIMPLR_API_KEY! });\n * const model = new ChatOpenAI({ model: \"gpt-4o\" }).bindTools(tools);\n * ```\n *\n * Requires the optional peer dependency `@langchain/core`. If it isn't\n * installed, this rejects with installation guidance.\n */\nexport async function createSimplrLangChainTools(\n config: SimplrAIConfig,\n): Promise<SimplrLangChainTool[]> {\n let DynamicStructuredTool: new (spec: any) => unknown;\n try {\n // Indirect specifier so the TS type-checker / bundler does not try to\n // resolve `@langchain/core/tools` at build time (it's an optional peer).\n const specifier = \"@langchain/core/tools\";\n const mod: any = await import(/* @vite-ignore */ specifier);\n DynamicStructuredTool = mod.DynamicStructuredTool;\n if (typeof DynamicStructuredTool !== \"function\") {\n throw new Error(\"`@langchain/core/tools` does not export DynamicStructuredTool.\");\n }\n } catch (err) {\n throw new Error(\n \"@simplr-ai/ai: createSimplrLangChainTools() requires `@langchain/core`. \" +\n \"Install it with `npm install @langchain/core`. (Original error: \" +\n (err instanceof Error ? err.message : String(err)) +\n \")\",\n );\n }\n\n const descriptors = createSimplrToolDescriptors(config);\n return (Object.keys(descriptors) as SimplrToolName[]).map((key) => {\n const d = descriptors[key];\n return new DynamicStructuredTool({\n name: d.name,\n description: d.description,\n schema: d.inputSchema,\n func: async (args: unknown) => {\n const result = await d.execute(args as any);\n // LangChain tool funcs are expected to return a string.\n return JSON.stringify(result);\n },\n });\n });\n}\n"],"mappings":";AAMO,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;AAC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