agentsim 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # agentsim
2
+
3
+ TypeScript/JavaScript SDK for AgentSIM — autonomous OTP relay for AI agents. Zero runtime dependencies. Works in Node.js 18+, Bun, Deno, and Edge runtimes.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install agentsim
9
+ # or: bun add agentsim
10
+ ```
11
+
12
+ ## Quickstart
13
+
14
+ ```typescript
15
+ import { provision } from "agentsim";
16
+
17
+ // Using AsyncDisposable (TypeScript 5.2+, recommended)
18
+ await using num = await provision({ agentId: "checkout-bot", country: "US" });
19
+ await enterPhoneNumber(num.number); // "+14155552671"
20
+ const otp = await num.waitForOtp({ timeout: 60 });
21
+ await enterOtp(otp.otpCode); // "847291"
22
+ // number auto-released via [Symbol.asyncDispose]
23
+ ```
24
+
25
+ ```typescript
26
+ // Manual release (Node 18, no using declaration)
27
+ const num = await provision({ agentId: "checkout-bot" });
28
+ try {
29
+ const otp = await num.waitForOtp();
30
+ } finally {
31
+ await num.release();
32
+ }
33
+ ```
34
+
35
+ ## Auth
36
+
37
+ Set `AGENTSIM_API_KEY` in your environment, or pass `apiKey` to the client constructor:
38
+
39
+ ```typescript
40
+ import { AgentSimClient } from "agentsim";
41
+ const client = new AgentSimClient({ apiKey: "asm_live_xxx" });
42
+ ```
43
+
44
+ Get your API key at [agentsim.dev/dashboard](https://agentsim.dev/dashboard).
45
+
46
+ ## API
47
+
48
+ ### `provision(options)`
49
+
50
+ Provisions a number and returns a `NumberSession`.
51
+
52
+ | Option | Type | Default | Description |
53
+ |--------|------|---------|-------------|
54
+ | `agentId` | `string` | required | Identifier for your agent |
55
+ | `country` | `string` | `"US"` | ISO country code |
56
+ | `ttlSeconds` | `number` | `3600` | Auto-release after N seconds |
57
+ | `webhookUrl` | `string` | — | POST OTPs here as they arrive |
58
+ | `apiKey` | `string` | env var | Override `AGENTSIM_API_KEY` |
59
+
60
+ ### `num.waitForOtp(options?)`
61
+
62
+ Waits for an OTP to arrive on the provisioned number.
63
+
64
+ | Option | Type | Default |
65
+ |--------|------|---------|
66
+ | `timeout` | `number` | `60` |
67
+
68
+ Returns `{ otpCode: string, confidence: number | null, method: string | null }`.
69
+
70
+ Throws `OtpTimeoutError` if no OTP arrives within `timeout` seconds.
71
+
72
+ ### `num.release()`
73
+
74
+ Releases the number back to the pool early. Called automatically by `[Symbol.asyncDispose]`.
75
+
76
+ ## Error Reference
77
+
78
+ | Class | When |
79
+ |-------|------|
80
+ | `AuthenticationError` | Missing or invalid API key |
81
+ | `PoolExhaustedError` | No numbers available in requested country |
82
+ | `OtpTimeoutError` | No OTP arrived within timeout |
83
+ | `RateLimitError` | Too many requests |
84
+
85
+ ## Supported Countries
86
+
87
+ US, GB, DE, FR, NL, EE
@@ -0,0 +1,54 @@
1
+ export interface ProvisionOptions {
2
+ agentId: string;
3
+ country?: string;
4
+ serviceUrl?: string;
5
+ ttlSeconds?: number;
6
+ webhookUrl?: string;
7
+ }
8
+ export interface ReregistrationInfo {
9
+ newNumber: string;
10
+ country: string;
11
+ }
12
+ export interface OtpResult {
13
+ otpCode: string;
14
+ confidence: number | null;
15
+ method: string | null;
16
+ fromNumber: string | null;
17
+ receivedAt: string;
18
+ messageId: string | null;
19
+ }
20
+ export interface SmsMessage {
21
+ id: string;
22
+ fromNumber: string;
23
+ toNumber: string;
24
+ otpCode: string | null;
25
+ otpConfidence: string | null;
26
+ otpMethod: string | null;
27
+ otpConsumed: boolean;
28
+ otpConsumedAt: string | null;
29
+ webhookDelivered: boolean;
30
+ receivedAt: string;
31
+ }
32
+ export interface WaitForOtpOptions {
33
+ timeout?: number;
34
+ autoReroute?: boolean;
35
+ maxReroutes?: number;
36
+ onReregistrationNeeded?: (info: ReregistrationInfo) => Promise<void>;
37
+ }
38
+ export interface ProvisionedNumberData {
39
+ session_id: string;
40
+ number: string;
41
+ country: string;
42
+ agent_id: string;
43
+ status: string;
44
+ expires_at: string;
45
+ }
46
+ export declare class AgentSimClient {
47
+ private readonly apiKey;
48
+ private readonly baseUrl;
49
+ constructor(apiKey?: string, options?: {
50
+ baseUrl?: string;
51
+ });
52
+ request<T>(method: string, path: string, body?: unknown): Promise<T>;
53
+ }
54
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAuBD,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAKrD,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAkC3E"}
package/dist/client.js ADDED
@@ -0,0 +1,59 @@
1
+ import { fromApiError, AgentSimError } from "./errors.js";
2
+ const DEFAULT_BASE_URL = "https://api.agentsim.dev/v1";
3
+ function getApiKey() {
4
+ // Support both Node.js and Deno environments
5
+ if (typeof process !== "undefined" && process.env["AGENTSIM_API_KEY"]) {
6
+ return process.env["AGENTSIM_API_KEY"];
7
+ }
8
+ if (typeof Deno !== "undefined") {
9
+ const key = Deno.env.get("AGENTSIM_API_KEY");
10
+ if (key)
11
+ return key;
12
+ }
13
+ return "";
14
+ }
15
+ function getBaseUrl() {
16
+ if (typeof process !== "undefined" && process.env["AGENTSIM_BASE_URL"]) {
17
+ return process.env["AGENTSIM_BASE_URL"];
18
+ }
19
+ return DEFAULT_BASE_URL;
20
+ }
21
+ export class AgentSimClient {
22
+ apiKey;
23
+ baseUrl;
24
+ constructor(apiKey, options) {
25
+ this.apiKey = apiKey ?? getApiKey();
26
+ this.baseUrl = (options?.baseUrl ?? getBaseUrl()).replace(/\/$/, "");
27
+ }
28
+ async request(method, path, body) {
29
+ const url = `${this.baseUrl}${path}`;
30
+ const init = {
31
+ method,
32
+ headers: {
33
+ "x-api-key": this.apiKey,
34
+ "Content-Type": "application/json",
35
+ "Accept": "application/json",
36
+ },
37
+ };
38
+ if (body !== undefined) {
39
+ init.body = JSON.stringify(body);
40
+ }
41
+ let response;
42
+ try {
43
+ response = await fetch(url, init);
44
+ }
45
+ catch (err) {
46
+ throw new AgentSimError(`Network error: ${err}`, "network_error");
47
+ }
48
+ if (response.status === 204)
49
+ return undefined;
50
+ const data = await response.json().catch(() => ({}));
51
+ if (!response.ok) {
52
+ const code = typeof data["error"] === "string" ? data["error"] : "unknown_error";
53
+ const message = typeof data["message"] === "string" ? data["message"] : response.statusText;
54
+ throw fromApiError(code, message, response.status, data);
55
+ }
56
+ return data;
57
+ }
58
+ }
59
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAuD1D,MAAM,gBAAgB,GAAG,6BAA6B,CAAC;AAEvD,SAAS,SAAS;IAChB,6CAA6C;IAC7C,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACtE,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACzC,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,MAAM,GAAG,GAAI,IAAwD,CAAC,GAAG,CAAC,GAA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B,GAAG,EAAE,EAAE,eAAe,CAAC,CAAC;QACpE,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;YAAE,OAAO,SAAyB,CAAC;QAE9D,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAA4B,CAAC;QAEhF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;YACjF,MAAM,OAAO,GAAG,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;YAC5F,MAAM,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,IAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=client.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.test.d.ts","sourceRoot":"","sources":["../src/client.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,106 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { provision, PoolExhaustedError, OtpTimeoutError } from "./index.js";
3
+ import { AgentSimClient } from "./client.js";
4
+ const PROVISION_RESPONSE = {
5
+ session_id: "sess-abc123",
6
+ number: "+15551234567",
7
+ country: "US",
8
+ agent_id: "test-bot",
9
+ status: "active",
10
+ expires_at: "2026-03-16T20:00:00Z",
11
+ };
12
+ function makeFetch(status, body) {
13
+ return vi.fn().mockResolvedValue({
14
+ ok: status >= 200 && status < 300,
15
+ status,
16
+ statusText: String(status),
17
+ json: async () => body,
18
+ });
19
+ }
20
+ describe("AgentSIM TypeScript SDK", () => {
21
+ let client;
22
+ beforeEach(() => {
23
+ client = new AgentSimClient("test-key", {
24
+ baseUrl: "https://api.agentsim.io/v1",
25
+ });
26
+ });
27
+ afterEach(() => {
28
+ vi.unstubAllGlobals();
29
+ });
30
+ it("provisions a session", async () => {
31
+ vi.stubGlobal("fetch", makeFetch(201, PROVISION_RESPONSE));
32
+ const session = await provision({ agentId: "test-bot" }, client);
33
+ expect(session.number).toBe("+15551234567");
34
+ expect(session.sessionId).toBe("sess-abc123");
35
+ });
36
+ it("throws PoolExhaustedError on 503", async () => {
37
+ vi.stubGlobal("fetch", makeFetch(503, { error: "pool_exhausted", message: "No US numbers available" }));
38
+ await expect(provision({ agentId: "test-bot" }, client)).rejects.toBeInstanceOf(PoolExhaustedError);
39
+ });
40
+ it("waits for OTP", async () => {
41
+ vi.stubGlobal("fetch", vi
42
+ .fn()
43
+ .mockResolvedValueOnce({
44
+ ok: true,
45
+ status: 201,
46
+ statusText: "201",
47
+ json: async () => PROVISION_RESPONSE,
48
+ })
49
+ .mockResolvedValueOnce({
50
+ ok: true,
51
+ status: 200,
52
+ statusText: "200",
53
+ json: async () => ({
54
+ otp_code: "123456",
55
+ confidence: 0.99,
56
+ method: "regex",
57
+ from_number: "+15550000000",
58
+ received_at: "2026-03-16T18:00:00Z",
59
+ message_id: "msg-xyz",
60
+ }),
61
+ }));
62
+ const session = await provision({ agentId: "test-bot" }, client);
63
+ const result = await session.waitForOtp({ timeout: 30 });
64
+ expect(result.otpCode).toBe("123456");
65
+ });
66
+ it("throws OtpTimeoutError on 408", async () => {
67
+ vi.stubGlobal("fetch", vi
68
+ .fn()
69
+ .mockResolvedValueOnce({
70
+ ok: true,
71
+ status: 201,
72
+ statusText: "201",
73
+ json: async () => PROVISION_RESPONSE,
74
+ })
75
+ .mockResolvedValueOnce({
76
+ ok: false,
77
+ status: 408,
78
+ statusText: "408",
79
+ json: async () => ({
80
+ error: "otp_timeout",
81
+ message: "No OTP received within timeout",
82
+ }),
83
+ }));
84
+ const session = await provision({ agentId: "test-bot" }, client);
85
+ await expect(session.waitForOtp({ timeout: 30 })).rejects.toBeInstanceOf(OtpTimeoutError);
86
+ });
87
+ it("release calls DELETE", async () => {
88
+ vi.stubGlobal("fetch", vi
89
+ .fn()
90
+ .mockResolvedValueOnce({
91
+ ok: true,
92
+ status: 201,
93
+ statusText: "201",
94
+ json: async () => PROVISION_RESPONSE,
95
+ })
96
+ .mockResolvedValueOnce({
97
+ ok: true,
98
+ status: 204,
99
+ statusText: "204",
100
+ json: async () => ({}),
101
+ }));
102
+ const session = await provision({ agentId: "test-bot" }, client);
103
+ await expect(session.release()).resolves.toBeUndefined();
104
+ });
105
+ });
106
+ //# sourceMappingURL=client.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.test.js","sourceRoot":"","sources":["../src/client.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,kBAAkB,GAAG;IACzB,UAAU,EAAE,aAAa;IACzB,MAAM,EAAE,cAAc;IACtB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,sBAAsB;CACnC,CAAC;AAEF,SAAS,SAAS,CAAC,MAAc,EAAE,IAAa;IAC9C,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;QAC/B,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG;QACjC,MAAM;QACN,UAAU,EAAE,MAAM,CAAC,MAAM,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jB,KAAK,EAAE,aAAa;gBACpB,OAAO,EAAE,gCAAgC;aAC1C,CAAC;SACH,CAAC,CACL,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,MAAM,CAAC,CAAC;QACjE,MAAM,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IAC5F,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACpC,EAAE,CAAC,UAAU,CACX,OAAO,EACP,EAAE;aACC,EAAE,EAAE;aACJ,qBAAqB,CAAC;YACrB,EAAE,EAAE,IAAI;YACR,MAAM,EAAE,GAAG;YACX,UAAU,EAAE,KAAK;YACjB,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,kBAAkB;SACrC,CAAC;aACD,qBAAqB,CAAC;YACrB,EAAE,EAAE,IAAI;YACR,MAAM,EAAE,GAAG;YACX,UAAU,EAAE,KAAK;YACjB,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;SACvB,CAAC,CACL,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,MAAM,CAAC,CAAC;QACjE,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ export declare class AgentSimError extends Error {
2
+ readonly code: string;
3
+ readonly statusCode: number | undefined;
4
+ constructor(message: string, code: string, statusCode?: number);
5
+ }
6
+ export declare class AuthenticationError extends AgentSimError {
7
+ constructor(message?: string);
8
+ }
9
+ export declare class ForbiddenError extends AgentSimError {
10
+ constructor(message?: string);
11
+ }
12
+ export declare class PoolExhaustedError extends AgentSimError {
13
+ readonly country: string;
14
+ readonly availableCountries: string[];
15
+ constructor(message?: string, country?: string, availableCountries?: string[]);
16
+ }
17
+ export declare class SessionNotFoundError extends AgentSimError {
18
+ constructor(message?: string);
19
+ }
20
+ export declare class OtpTimeoutError extends AgentSimError {
21
+ constructor(message?: string);
22
+ }
23
+ export declare class RateLimitError extends AgentSimError {
24
+ constructor(message?: string);
25
+ }
26
+ export declare class CountryNotAllowedError extends AgentSimError {
27
+ readonly country: string;
28
+ readonly plan: string;
29
+ readonly allowed: string[];
30
+ constructor(message?: string, country?: string, plan?: string, allowed?: string[]);
31
+ }
32
+ export declare class ValidationError extends AgentSimError {
33
+ readonly details: unknown;
34
+ constructor(message?: string, details?: unknown);
35
+ }
36
+ export declare class ApiError extends AgentSimError {
37
+ constructor(message?: string, code?: string, statusCode?: number);
38
+ }
39
+ export declare function fromApiError(code: string, message: string, statusCode: number, data?: Record<string, unknown>): AgentSimError;
40
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE5B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAM/D;AAED,qBAAa,mBAAoB,SAAQ,aAAa;gBACxC,OAAO,SAAgC;CAIpD;AAED,qBAAa,cAAe,SAAQ,aAAa;gBACnC,OAAO,SAA4C;CAIhE;AAED,qBAAa,kBAAmB,SAAQ,aAAa;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC;gBAGpC,OAAO,SAAgD,EACvD,OAAO,SAAK,EACZ,kBAAkB,GAAE,MAAM,EAAO;CAOpC;AAED,qBAAa,oBAAqB,SAAQ,aAAa;gBACzC,OAAO,SAAuB;CAI3C;AAED,qBAAa,eAAgB,SAAQ,aAAa;gBACpC,OAAO,SAA+C;CAInE;AAED,qBAAa,cAAe,SAAQ,aAAa;gBACnC,OAAO,SAAyB;CAI7C;AAED,qBAAa,sBAAuB,SAAQ,aAAa;IACvD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;gBAGzB,OAAO,SAAgD,EACvD,OAAO,SAAK,EACZ,IAAI,SAAK,EACT,OAAO,GAAE,MAAM,EAAO;CAQzB;AAED,qBAAa,eAAgB,SAAQ,aAAa;IAChD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;gBAEd,OAAO,SAAsB,EAAE,OAAO,CAAC,EAAE,OAAO;CAK7D;AAED,qBAAa,QAAS,SAAQ,aAAa;gBAC7B,OAAO,SAAsC,EAAE,IAAI,SAAmB,EAAE,UAAU,SAAM;CAIrG;AAkBD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,aAAa,CAUf"}
package/dist/errors.js ADDED
@@ -0,0 +1,97 @@
1
+ export class AgentSimError extends Error {
2
+ code;
3
+ statusCode;
4
+ constructor(message, code, statusCode) {
5
+ super(message);
6
+ this.name = "AgentSimError";
7
+ this.code = code;
8
+ this.statusCode = statusCode;
9
+ }
10
+ }
11
+ export class AuthenticationError extends AgentSimError {
12
+ constructor(message = "Invalid or missing API key.") {
13
+ super(message, "unauthorized", 401);
14
+ this.name = "AuthenticationError";
15
+ }
16
+ }
17
+ export class ForbiddenError extends AgentSimError {
18
+ constructor(message = "API key revoked or lacking permissions.") {
19
+ super(message, "forbidden", 403);
20
+ this.name = "ForbiddenError";
21
+ }
22
+ }
23
+ export class PoolExhaustedError extends AgentSimError {
24
+ country;
25
+ availableCountries;
26
+ constructor(message = "No numbers available in the requested pool.", country = "", availableCountries = []) {
27
+ super(message, "pool_exhausted", 503);
28
+ this.name = "PoolExhaustedError";
29
+ this.country = country;
30
+ this.availableCountries = availableCountries;
31
+ }
32
+ }
33
+ export class SessionNotFoundError extends AgentSimError {
34
+ constructor(message = "Session not found.") {
35
+ super(message, "not_found", 404);
36
+ this.name = "SessionNotFoundError";
37
+ }
38
+ }
39
+ export class OtpTimeoutError extends AgentSimError {
40
+ constructor(message = "No OTP received within the timeout period.") {
41
+ super(message, "otp_timeout", 408);
42
+ this.name = "OtpTimeoutError";
43
+ }
44
+ }
45
+ export class RateLimitError extends AgentSimError {
46
+ constructor(message = "Rate limit exceeded.") {
47
+ super(message, "rate_limited", 429);
48
+ this.name = "RateLimitError";
49
+ }
50
+ }
51
+ export class CountryNotAllowedError extends AgentSimError {
52
+ country;
53
+ plan;
54
+ allowed;
55
+ constructor(message = "Country not available on your current plan.", country = "", plan = "", allowed = []) {
56
+ super(message, "country_not_allowed_on_plan", 403);
57
+ this.name = "CountryNotAllowedError";
58
+ this.country = country;
59
+ this.plan = plan;
60
+ this.allowed = allowed;
61
+ }
62
+ }
63
+ export class ValidationError extends AgentSimError {
64
+ details;
65
+ constructor(message = "Validation error.", details) {
66
+ super(message, "validation_error", 422);
67
+ this.name = "ValidationError";
68
+ this.details = details;
69
+ }
70
+ }
71
+ export class ApiError extends AgentSimError {
72
+ constructor(message = "An unexpected API error occurred.", code = "internal_error", statusCode = 500) {
73
+ super(message, code, statusCode);
74
+ this.name = "ApiError";
75
+ }
76
+ }
77
+ const CODE_MAP = {
78
+ unauthorized: (m) => new AuthenticationError(m),
79
+ forbidden: (m) => new ForbiddenError(m),
80
+ not_found: (m) => new SessionNotFoundError(m),
81
+ otp_timeout: (m) => new OtpTimeoutError(m),
82
+ rate_limited: (m) => new RateLimitError(m),
83
+ validation_error: (m) => new ValidationError(m),
84
+ country_not_allowed_on_plan: (m, d) => new CountryNotAllowedError(m, typeof d?.["country"] === "string" ? d["country"] : "", typeof d?.["plan"] === "string" ? d["plan"] : "", Array.isArray(d?.["allowed"]) ? d["allowed"] : []),
85
+ };
86
+ export function fromApiError(code, message, statusCode, data) {
87
+ if (code === "pool_exhausted") {
88
+ const country = typeof data?.["country"] === "string" ? data["country"] : "";
89
+ const availableCountries = Array.isArray(data?.["available_countries"])
90
+ ? data["available_countries"]
91
+ : [];
92
+ return new PoolExhaustedError(message, country, availableCountries);
93
+ }
94
+ const factory = CODE_MAP[code];
95
+ return factory ? factory(message, data) : new ApiError(message, code, statusCode);
96
+ }
97
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,CAAS;IACb,UAAU,CAAqB;IAExC,YAAY,OAAe,EAAE,IAAY,EAAE,UAAmB;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,aAAa;IACpD,YAAY,OAAO,GAAG,6BAA6B;QACjD,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,aAAa;IAC/C,YAAY,OAAO,GAAG,yCAAyC;QAC7D,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC;QACjC,IAAI,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24 @@
1
+ import { AgentSimClient } from "./client.js";
2
+ import { NumberSession } from "./session.js";
3
+ import type { ProvisionOptions } from "./client.js";
4
+ export { AgentSimClient } from "./client.js";
5
+ export { NumberSession } from "./session.js";
6
+ export type { ProvisionOptions, OtpResult, SmsMessage, WaitForOtpOptions, ReregistrationInfo } from "./client.js";
7
+ export { AgentSimError, AuthenticationError, ForbiddenError, PoolExhaustedError, SessionNotFoundError, OtpTimeoutError, RateLimitError, ValidationError, ApiError, } from "./errors.js";
8
+ /**
9
+ * Provision a real mobile number for the given agent. Starts a billable session.
10
+ *
11
+ * **Billing:** $0.99 per session on the Builder plan. Free on Hobby (10 sessions/month limit).
12
+ * Sessions that end with an `OtpTimeoutError` are NOT billed.
13
+ *
14
+ * Returns a `NumberSession` implementing `AsyncDisposable` — use `await using`
15
+ * in TypeScript 5.2+ for automatic release, or call `num.release()` manually.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * await using num = await provision({ agentId: "checkout-bot" });
20
+ * const otp = await num.waitForOtp({ timeout: 60 });
21
+ * ```
22
+ */
23
+ export declare function provision(options: ProvisionOptions, clientOrApiKey?: AgentSimClient | string): Promise<NumberSession>;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAyB,MAAM,aAAa,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAClH,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,eAAe,EACf,QAAQ,GACT,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,gBAAgB,EACzB,cAAc,CAAC,EAAE,cAAc,GAAG,MAAM,GACvC,OAAO,CAAC,aAAa,CAAC,CAkBxB"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ import { AgentSimClient } from "./client.js";
2
+ import { NumberSession } from "./session.js";
3
+ export { AgentSimClient } from "./client.js";
4
+ export { NumberSession } from "./session.js";
5
+ export { AgentSimError, AuthenticationError, ForbiddenError, PoolExhaustedError, SessionNotFoundError, OtpTimeoutError, RateLimitError, ValidationError, ApiError, } from "./errors.js";
6
+ /**
7
+ * Provision a real mobile number for the given agent. Starts a billable session.
8
+ *
9
+ * **Billing:** $0.99 per session on the Builder plan. Free on Hobby (10 sessions/month limit).
10
+ * Sessions that end with an `OtpTimeoutError` are NOT billed.
11
+ *
12
+ * Returns a `NumberSession` implementing `AsyncDisposable` — use `await using`
13
+ * in TypeScript 5.2+ for automatic release, or call `num.release()` manually.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * await using num = await provision({ agentId: "checkout-bot" });
18
+ * const otp = await num.waitForOtp({ timeout: 60 });
19
+ * ```
20
+ */
21
+ export async function provision(options, clientOrApiKey) {
22
+ let client;
23
+ if (clientOrApiKey instanceof AgentSimClient) {
24
+ client = clientOrApiKey;
25
+ }
26
+ else {
27
+ client = new AgentSimClient(clientOrApiKey);
28
+ }
29
+ const data = await client.request("POST", "/sessions", {
30
+ agent_id: options.agentId,
31
+ ...(options.country !== undefined ? { country: options.country } : {}),
32
+ ...(options.serviceUrl !== undefined ? { service_url: options.serviceUrl } : {}),
33
+ ttl_seconds: options.ttlSeconds ?? 3600,
34
+ ...(options.webhookUrl ? { webhook_url: options.webhookUrl } : {}),
35
+ });
36
+ return new NumberSession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AAC,EAAE,WAAW,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACnE,CAAC,CAAC;IAEH,OAAO,IAAI,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { AgentSimClient, OtpResult, ProvisionedNumberData, SmsMessage, WaitForOtpOptions } from "./client.js";
2
+ export declare class NumberSession implements AsyncDisposable {
3
+ private readonly client;
4
+ private released;
5
+ private _number;
6
+ private _country;
7
+ readonly sessionId: string;
8
+ readonly agentId: string;
9
+ readonly expiresAt: string;
10
+ readonly status: string;
11
+ get number(): string;
12
+ get country(): string;
13
+ constructor(client: AgentSimClient, data: ProvisionedNumberData);
14
+ private _pollOtp;
15
+ /**
16
+ * Wait for an OTP to arrive on the provisioned number.
17
+ *
18
+ * Throws `OtpTimeoutError` if no OTP is received within the timeout period.
19
+ * Sessions that time out are NOT billed — the $0.99 charge applies only to
20
+ * successfully provisioned sessions that do not time out.
21
+ */
22
+ waitForOtp(options?: WaitForOtpOptions): Promise<OtpResult>;
23
+ getMessages(): Promise<SmsMessage[]>;
24
+ release(): Promise<void>;
25
+ [Symbol.asyncDispose](): Promise<void>;
26
+ }
27
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,qBAAqB,EAAsB,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIvI,qBAAa,aAAc,YAAW,eAAe;IAcjD,OAAO,CAAC,QAAQ,CAAC,MAAM;IAbzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAS;IAEzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,IAAI,MAAM,IAAI,MAAM,CAAyB;IAC7C,IAAI,OAAO,IAAI,MAAM,CAA0B;gBAG5B,MAAM,EAAE,cAAc,EACvC,IAAI,EAAE,qBAAqB;YAUf,QAAQ;IAwBtB;;;;;;OAMG;IACG,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,SAAS,CAAC;IAqD/D,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IA8BpC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAOxB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7C"}
@@ -0,0 +1,102 @@
1
+ import { OtpTimeoutError } from "./errors.js";
2
+ const DEFAULT_FALLBACK_CHAIN = ["US", "GB", "DE", "FR", "NL", "EE"];
3
+ export class NumberSession {
4
+ client;
5
+ released = false;
6
+ _number;
7
+ _country;
8
+ sessionId;
9
+ agentId;
10
+ expiresAt;
11
+ status;
12
+ get number() { return this._number; }
13
+ get country() { return this._country; }
14
+ constructor(client, data) {
15
+ this.client = client;
16
+ this.sessionId = data.session_id;
17
+ this._number = data.number;
18
+ this._country = data.country;
19
+ this.agentId = data.agent_id;
20
+ this.expiresAt = data.expires_at;
21
+ this.status = data.status;
22
+ }
23
+ async _pollOtp(timeout) {
24
+ const data = await this.client.request("POST", `/sessions/${this.sessionId}/wait`, { timeout_seconds: timeout });
25
+ return {
26
+ otpCode: data.otp_code,
27
+ confidence: data.confidence,
28
+ method: data.method,
29
+ fromNumber: data.from_number,
30
+ receivedAt: data.received_at,
31
+ messageId: data.message_id,
32
+ };
33
+ }
34
+ /**
35
+ * Wait for an OTP to arrive on the provisioned number.
36
+ *
37
+ * Throws `OtpTimeoutError` if no OTP is received within the timeout period.
38
+ * Sessions that time out are NOT billed — the $0.99 charge applies only to
39
+ * successfully provisioned sessions that do not time out.
40
+ */
41
+ async waitForOtp(options = {}) {
42
+ const timeout = options.timeout ?? 60;
43
+ const autoReroute = options.autoReroute ?? false;
44
+ const maxReroutes = options.maxReroutes ?? 2;
45
+ const onReregistrationNeeded = options.onReregistrationNeeded;
46
+ if (!autoReroute)
47
+ return this._pollOtp(timeout);
48
+ // Build reroute chain: remaining countries after the current one
49
+ const currentIdx = DEFAULT_FALLBACK_CHAIN.indexOf(this._country);
50
+ const rerouteChain = currentIdx >= 0
51
+ ? [...DEFAULT_FALLBACK_CHAIN.slice(currentIdx + 1), ...DEFAULT_FALLBACK_CHAIN.slice(0, currentIdx)]
52
+ : [...DEFAULT_FALLBACK_CHAIN];
53
+ let reroutesUsed = 0;
54
+ let chainIdx = 0;
55
+ while (true) {
56
+ try {
57
+ return await this._pollOtp(timeout);
58
+ }
59
+ catch (err) {
60
+ if (!(err instanceof OtpTimeoutError) ||
61
+ reroutesUsed >= maxReroutes ||
62
+ chainIdx >= rerouteChain.length) {
63
+ throw err;
64
+ }
65
+ const nextCountry = rerouteChain[chainIdx++];
66
+ reroutesUsed++;
67
+ const rerouteData = await this.client.request("POST", `/sessions/${this.sessionId}/reroute`, { country: nextCountry });
68
+ this._number = rerouteData.new_number;
69
+ this._country = rerouteData.country;
70
+ if (onReregistrationNeeded) {
71
+ const info = { newNumber: this._number, country: this._country };
72
+ await onReregistrationNeeded(info);
73
+ }
74
+ }
75
+ }
76
+ }
77
+ async getMessages() {
78
+ const data = await this.client.request("GET", `/sessions/${this.sessionId}/messages`);
79
+ return data.messages.map((m) => ({
80
+ id: m.id,
81
+ fromNumber: m.from_number,
82
+ toNumber: m.to_number,
83
+ otpCode: m.otp_code,
84
+ otpConfidence: m.otp_confidence,
85
+ otpMethod: m.otp_method,
86
+ otpConsumed: m.otp_consumed,
87
+ otpConsumedAt: m.otp_consumed_at,
88
+ webhookDelivered: m.webhook_delivered,
89
+ receivedAt: m.received_at,
90
+ }));
91
+ }
92
+ async release() {
93
+ if (!this.released) {
94
+ this.released = true;
95
+ await this.client.request("DELETE", `/sessions/${this.sessionId}`);
96
+ }
97
+ }
98
+ async [Symbol.asyncDispose]() {
99
+ await this.release();
100
+ }
101
+ }
102
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,sBAAsB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAU,CAAC;AAE7E,MAAM,OAAO,aAAa;IAcL;IAbX,QAAQ,GAAG,KAAK,CAAC;IACjB,OAAO,CAAS;IAChB,QAAQ,CAAS;IAEhB,SAAS,CAAS;IAClB,OAAO,CAAS;IAChB,SAAS,CAAS;IAClB,MAAM,CAAS;IAExB,IAAI,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7C,IAAI,OAAO,KAAa,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE/C,YACmB,MAAsB,EACvC,IAA2B;QADV,WAAM,GAAN,MAAM,CAAgB;QAGvC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;IAEO,KAAK,CAAC,QAAQ,CAAC,OAAe;QACpC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAQp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YAC/B,SAAS,EAAE,CAAC,CAAC,UAAU;YACvB,WAAW,EAAE,CAAC,CAAC,YAAY;YAC3B,aAAa,EAAE,CAAC,CAAC,eAAe;YAChC,gBAAgB,EAAE,CAAC,CAAC,iBAAiB;YACrC,UAAU,EAAE,CAAC,CAAC,WAAW;SAC1B,CAAC,CAAC,CAAC;IACN,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,aAAa,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "agentsim",
3
+ "version": "0.1.1",
4
+ "description": "AgentSIM TypeScript SDK — autonomous OTP relay for AI agents",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": ["dist"],
15
+ "scripts": {
16
+ "build": "tsc --outDir dist",
17
+ "test": "vitest run",
18
+ "typecheck": "tsc --noEmit"
19
+ },
20
+ "dependencies": {},
21
+ "devDependencies": {
22
+ "@types/node": "^25.5.0",
23
+ "typescript": "^5.8.2",
24
+ "vitest": "^3.0.8"
25
+ },
26
+ "keywords": ["agents", "otp", "sms", "ai", "automation"],
27
+ "license": "MIT",
28
+ "author": "AgentSIM <hello@agentsim.dev>",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/agentsim/agentsim"
32
+ },
33
+ "homepage": "https://agentsim.dev",
34
+ "bugs": "https://github.com/agentsim/agentsim/issues",
35
+ "engines": {
36
+ "node": ">=18"
37
+ }
38
+ }