@agentlensai/sdk 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Amit Paz
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.
@@ -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/__tests__/client.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Tests for AgentLensClient (Story 13.1)
3
+ */
4
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
5
+ import { AgentLensClient } from '../client.js';
6
+ import { AgentLensError, AuthenticationError, NotFoundError, ValidationError, ConnectionError, } from '../errors.js';
7
+ // ─── Helpers ────────────────────────────────────────────────────────
8
+ function mockFetch(status, body) {
9
+ return vi.fn().mockResolvedValue({
10
+ ok: status >= 200 && status < 300,
11
+ status,
12
+ text: () => Promise.resolve(JSON.stringify(body)),
13
+ json: () => Promise.resolve(body),
14
+ });
15
+ }
16
+ function createClient(fetchFn) {
17
+ return new AgentLensClient({
18
+ url: 'http://localhost:3400',
19
+ apiKey: 'als_test123',
20
+ fetch: fetchFn,
21
+ });
22
+ }
23
+ // ─── Tests ──────────────────────────────────────────────────────────
24
+ describe('AgentLensClient', () => {
25
+ describe('constructor', () => {
26
+ it('strips trailing slash from URL', () => {
27
+ const fn = mockFetch(200, { events: [], total: 0, hasMore: false });
28
+ const client = new AgentLensClient({ url: 'http://localhost:3400/', fetch: fn });
29
+ client.queryEvents();
30
+ expect(fn).toHaveBeenCalledWith(expect.stringMatching(/^http:\/\/localhost:3400\/api/), expect.anything());
31
+ });
32
+ });
33
+ describe('queryEvents', () => {
34
+ it('returns typed EventQueryResult', async () => {
35
+ const expected = { events: [], total: 0, hasMore: false };
36
+ const fn = mockFetch(200, expected);
37
+ const client = createClient(fn);
38
+ const result = await client.queryEvents();
39
+ expect(result).toEqual(expected);
40
+ });
41
+ it('sends correct query params', async () => {
42
+ const fn = mockFetch(200, { events: [], total: 0, hasMore: false });
43
+ const client = createClient(fn);
44
+ await client.queryEvents({
45
+ sessionId: 'ses_abc',
46
+ eventType: 'tool_call',
47
+ limit: 10,
48
+ order: 'asc',
49
+ });
50
+ const url = fn.mock.calls[0][0];
51
+ expect(url).toContain('sessionId=ses_abc');
52
+ expect(url).toContain('eventType=tool_call');
53
+ expect(url).toContain('limit=10');
54
+ expect(url).toContain('order=asc');
55
+ });
56
+ it('handles array eventType', async () => {
57
+ const fn = mockFetch(200, { events: [], total: 0, hasMore: false });
58
+ const client = createClient(fn);
59
+ await client.queryEvents({ eventType: ['tool_call', 'tool_error'] });
60
+ const url = fn.mock.calls[0][0];
61
+ expect(url).toContain('eventType=tool_call%2Ctool_error');
62
+ });
63
+ it('sends Authorization header with apiKey', async () => {
64
+ const fn = mockFetch(200, { events: [], total: 0, hasMore: false });
65
+ const client = createClient(fn);
66
+ await client.queryEvents();
67
+ const opts = fn.mock.calls[0][1];
68
+ expect(opts.headers['Authorization']).toBe('Bearer als_test123');
69
+ });
70
+ });
71
+ describe('getEvent', () => {
72
+ it('returns a single event', async () => {
73
+ const event = { id: 'ev_1', eventType: 'tool_call', sessionId: 'ses_abc' };
74
+ const fn = mockFetch(200, event);
75
+ const client = createClient(fn);
76
+ const result = await client.getEvent('ev_1');
77
+ expect(result.id).toBe('ev_1');
78
+ });
79
+ it('throws NotFoundError for 404', async () => {
80
+ const fn = mockFetch(404, { error: 'Event not found' });
81
+ const client = createClient(fn);
82
+ await expect(client.getEvent('ev_missing')).rejects.toThrow(NotFoundError);
83
+ });
84
+ });
85
+ describe('getSessions', () => {
86
+ it('returns typed SessionQueryResult', async () => {
87
+ const expected = { sessions: [], total: 0, hasMore: false };
88
+ const fn = mockFetch(200, expected);
89
+ const client = createClient(fn);
90
+ const result = await client.getSessions();
91
+ expect(result).toEqual(expected);
92
+ });
93
+ it('sends status and agent filters', async () => {
94
+ const fn = mockFetch(200, { sessions: [], total: 0, hasMore: false });
95
+ const client = createClient(fn);
96
+ await client.getSessions({ status: 'error', agentId: 'agent-1' });
97
+ const url = fn.mock.calls[0][0];
98
+ expect(url).toContain('status=error');
99
+ expect(url).toContain('agentId=agent-1');
100
+ });
101
+ });
102
+ describe('getSession', () => {
103
+ it('returns a single session', async () => {
104
+ const session = { id: 'ses_abc', status: 'active' };
105
+ const fn = mockFetch(200, session);
106
+ const client = createClient(fn);
107
+ const result = await client.getSession('ses_abc');
108
+ expect(result.id).toBe('ses_abc');
109
+ });
110
+ });
111
+ describe('getSessionTimeline', () => {
112
+ it('returns timeline with chain validity', async () => {
113
+ const expected = { events: [], chainValid: true };
114
+ const fn = mockFetch(200, expected);
115
+ const client = createClient(fn);
116
+ const result = await client.getSessionTimeline('ses_abc');
117
+ expect(result.chainValid).toBe(true);
118
+ expect(result.events).toEqual([]);
119
+ });
120
+ });
121
+ describe('health', () => {
122
+ it('does not send Authorization header', async () => {
123
+ const fn = mockFetch(200, { status: 'ok', version: '0.1.0' });
124
+ const client = createClient(fn);
125
+ await client.health();
126
+ const opts = fn.mock.calls[0][1];
127
+ expect(opts.headers['Authorization']).toBeUndefined();
128
+ });
129
+ });
130
+ describe('error handling', () => {
131
+ it('throws AuthenticationError for 401', async () => {
132
+ const fn = mockFetch(401, { error: 'Invalid API key' });
133
+ const client = createClient(fn);
134
+ await expect(client.queryEvents()).rejects.toThrow(AuthenticationError);
135
+ });
136
+ it('throws ValidationError for 400', async () => {
137
+ const fn = mockFetch(400, { error: 'Validation failed', details: [{ path: 'limit', message: 'too big' }] });
138
+ const client = createClient(fn);
139
+ await expect(client.queryEvents()).rejects.toThrow(ValidationError);
140
+ });
141
+ it('throws AgentLensError for other HTTP errors', async () => {
142
+ const fn = mockFetch(500, { error: 'Internal server error' });
143
+ const client = createClient(fn);
144
+ await expect(client.queryEvents()).rejects.toThrow(AgentLensError);
145
+ });
146
+ it('throws ConnectionError when fetch rejects', async () => {
147
+ const fn = vi.fn().mockRejectedValue(new Error('ECONNREFUSED'));
148
+ const client = createClient(fn);
149
+ await expect(client.queryEvents()).rejects.toThrow(ConnectionError);
150
+ });
151
+ it('ConnectionError includes the original error message', async () => {
152
+ const fn = vi.fn().mockRejectedValue(new Error('ECONNREFUSED'));
153
+ const client = createClient(fn);
154
+ try {
155
+ await client.queryEvents();
156
+ expect.fail('should throw');
157
+ }
158
+ catch (err) {
159
+ expect(err).toBeInstanceOf(ConnectionError);
160
+ expect(err.message).toContain('ECONNREFUSED');
161
+ }
162
+ });
163
+ });
164
+ });
165
+ //# sourceMappingURL=client.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.test.js","sourceRoot":"","sources":["../../src/__tests__/client.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,E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,YAAY,CAAC,EAAE,CAAC,CAAC;YAEhC,MAAM,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;YACnE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;YAChE,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;YAEhC,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;gBAC3B,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAC9B,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;gBAC5C,MAAM,CAAE,GAAuB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;YACrE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @agentlens/sdk — AgentLensClient
3
+ *
4
+ * Typed HTTP client for the AgentLens REST API.
5
+ * Uses native fetch — works in Node.js ≥ 18 and browsers.
6
+ */
7
+ import type { EventQuery, EventQueryResult, AgentLensEvent, Session, SessionQuery } from '@agentlens/core';
8
+ export interface AgentLensClientOptions {
9
+ /** Base URL of the AgentLens server (e.g. "http://localhost:3400") */
10
+ url: string;
11
+ /** API key for authentication */
12
+ apiKey?: string;
13
+ /** Custom fetch implementation (defaults to global fetch) */
14
+ fetch?: typeof globalThis.fetch;
15
+ }
16
+ export interface SessionQueryResult {
17
+ sessions: Session[];
18
+ total: number;
19
+ hasMore: boolean;
20
+ }
21
+ export interface TimelineResult {
22
+ events: AgentLensEvent[];
23
+ chainValid: boolean;
24
+ }
25
+ export interface HealthResult {
26
+ status: string;
27
+ version: string;
28
+ }
29
+ export declare class AgentLensClient {
30
+ private readonly baseUrl;
31
+ private readonly apiKey?;
32
+ private readonly _fetch;
33
+ constructor(options: AgentLensClientOptions);
34
+ /**
35
+ * Query events with filters and pagination.
36
+ */
37
+ queryEvents(query?: EventQuery): Promise<EventQueryResult>;
38
+ /**
39
+ * Get a single event by ID.
40
+ */
41
+ getEvent(id: string): Promise<AgentLensEvent>;
42
+ /**
43
+ * Query sessions with filters and pagination.
44
+ */
45
+ getSessions(query?: SessionQuery): Promise<SessionQueryResult>;
46
+ /**
47
+ * Get a single session by ID.
48
+ */
49
+ getSession(id: string): Promise<Session>;
50
+ /**
51
+ * Get the full timeline of events for a session, with hash chain verification.
52
+ */
53
+ getSessionTimeline(sessionId: string): Promise<TimelineResult>;
54
+ /**
55
+ * Check server health (no auth required).
56
+ */
57
+ health(): Promise<HealthResult>;
58
+ private request;
59
+ }
60
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,YAAY,EACb,MAAM,iBAAiB,CAAC;AAWzB,MAAM,WAAW,sBAAsB;IACrC,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAID,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;gBAErC,OAAO,EAAE,sBAAsB;IAS3C;;OAEG;IACG,WAAW,CAAC,KAAK,GAAE,UAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAoBpE;;OAEG;IACG,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAMnD;;OAEG;IACG,WAAW,CAAC,KAAK,GAAE,YAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAexE;;OAEG;IACG,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI9C;;OAEG;IACG,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAQpE;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC;YAMvB,OAAO;CAwDtB"}
package/dist/client.js ADDED
@@ -0,0 +1,144 @@
1
+ /**
2
+ * @agentlens/sdk — AgentLensClient
3
+ *
4
+ * Typed HTTP client for the AgentLens REST API.
5
+ * Uses native fetch — works in Node.js ≥ 18 and browsers.
6
+ */
7
+ import { AgentLensError, AuthenticationError, NotFoundError, ValidationError, ConnectionError, } from './errors.js';
8
+ // ─── Client ─────────────────────────────────────────────────────────
9
+ export class AgentLensClient {
10
+ baseUrl;
11
+ apiKey;
12
+ _fetch;
13
+ constructor(options) {
14
+ // Strip trailing slash
15
+ this.baseUrl = options.url.replace(/\/+$/, '');
16
+ this.apiKey = options.apiKey;
17
+ this._fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
18
+ }
19
+ // ─── Events ──────────────────────────────────────────────
20
+ /**
21
+ * Query events with filters and pagination.
22
+ */
23
+ async queryEvents(query = {}) {
24
+ const params = new URLSearchParams();
25
+ if (query.sessionId)
26
+ params.set('sessionId', query.sessionId);
27
+ if (query.agentId)
28
+ params.set('agentId', query.agentId);
29
+ if (query.eventType) {
30
+ params.set('eventType', Array.isArray(query.eventType) ? query.eventType.join(',') : query.eventType);
31
+ }
32
+ if (query.severity) {
33
+ params.set('severity', Array.isArray(query.severity) ? query.severity.join(',') : query.severity);
34
+ }
35
+ if (query.from)
36
+ params.set('from', query.from);
37
+ if (query.to)
38
+ params.set('to', query.to);
39
+ if (query.search)
40
+ params.set('search', query.search);
41
+ if (query.limit != null)
42
+ params.set('limit', String(query.limit));
43
+ if (query.offset != null)
44
+ params.set('offset', String(query.offset));
45
+ if (query.order)
46
+ params.set('order', query.order);
47
+ return this.request(`/api/events?${params.toString()}`);
48
+ }
49
+ /**
50
+ * Get a single event by ID.
51
+ */
52
+ async getEvent(id) {
53
+ return this.request(`/api/events/${encodeURIComponent(id)}`);
54
+ }
55
+ // ─── Sessions ────────────────────────────────────────────
56
+ /**
57
+ * Query sessions with filters and pagination.
58
+ */
59
+ async getSessions(query = {}) {
60
+ const params = new URLSearchParams();
61
+ if (query.agentId)
62
+ params.set('agentId', query.agentId);
63
+ if (query.status) {
64
+ params.set('status', Array.isArray(query.status) ? query.status.join(',') : query.status);
65
+ }
66
+ if (query.from)
67
+ params.set('from', query.from);
68
+ if (query.to)
69
+ params.set('to', query.to);
70
+ if (query.tags)
71
+ params.set('tags', query.tags.join(','));
72
+ if (query.limit != null)
73
+ params.set('limit', String(query.limit));
74
+ if (query.offset != null)
75
+ params.set('offset', String(query.offset));
76
+ return this.request(`/api/sessions?${params.toString()}`);
77
+ }
78
+ /**
79
+ * Get a single session by ID.
80
+ */
81
+ async getSession(id) {
82
+ return this.request(`/api/sessions/${encodeURIComponent(id)}`);
83
+ }
84
+ /**
85
+ * Get the full timeline of events for a session, with hash chain verification.
86
+ */
87
+ async getSessionTimeline(sessionId) {
88
+ return this.request(`/api/sessions/${encodeURIComponent(sessionId)}/timeline`);
89
+ }
90
+ // ─── Health ──────────────────────────────────────────────
91
+ /**
92
+ * Check server health (no auth required).
93
+ */
94
+ async health() {
95
+ return this.request('/api/health', { skipAuth: true });
96
+ }
97
+ // ─── Internal ────────────────────────────────────────────
98
+ async request(path, options = {}) {
99
+ const { method = 'GET', body, skipAuth = false } = options;
100
+ const headers = {
101
+ 'Accept': 'application/json',
102
+ };
103
+ if (!skipAuth && this.apiKey) {
104
+ headers['Authorization'] = `Bearer ${this.apiKey}`;
105
+ }
106
+ if (body != null) {
107
+ headers['Content-Type'] = 'application/json';
108
+ }
109
+ let response;
110
+ try {
111
+ response = await this._fetch(`${this.baseUrl}${path}`, {
112
+ method,
113
+ headers,
114
+ body: body != null ? JSON.stringify(body) : undefined,
115
+ });
116
+ }
117
+ catch (err) {
118
+ throw new ConnectionError(`Failed to connect to AgentLens at ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`, err);
119
+ }
120
+ if (!response.ok) {
121
+ const text = await response.text().catch(() => '');
122
+ let parsed = null;
123
+ try {
124
+ parsed = JSON.parse(text);
125
+ }
126
+ catch {
127
+ // not JSON
128
+ }
129
+ const message = parsed?.error ?? (text || `HTTP ${response.status}`);
130
+ switch (response.status) {
131
+ case 401:
132
+ throw new AuthenticationError(message);
133
+ case 404:
134
+ throw new NotFoundError(message);
135
+ case 400:
136
+ throw new ValidationError(message, parsed?.details);
137
+ default:
138
+ throw new AgentLensError(message, response.status, 'API_ERROR', parsed?.details);
139
+ }
140
+ }
141
+ return response.json();
142
+ }
143
+ }
144
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,eAA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MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;YACnD,IAAI,MAAM,GAAiD,IAAI,CAAC;YAChE,IAAI,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;YAAC,MAAM,CAAC;gBACP,WAAW;YACb,CAAC;YACD,MAAM,OAAO,GAAG,MAAM,EAAE,KAAK,IAAI,CAAC,IAAI,IAAI,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YAErE,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;gBACxB,KAAK,GAAG;oBACN,MAAM,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;gBACzC,KAAK,GAAG;oBACN,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;gBACnC,KAAK,GAAG;oBACN,MAAM,IAAI,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;gBACtD;oBACE,MAAM,IAAI,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACrF,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAgB,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @agentlens/sdk — Typed Errors
3
+ */
4
+ /**
5
+ * Base error class for all AgentLens SDK errors.
6
+ */
7
+ export declare class AgentLensError extends Error {
8
+ readonly status: number;
9
+ readonly code: string;
10
+ readonly details?: unknown;
11
+ constructor(message: string, status: number, code: string, details?: unknown);
12
+ }
13
+ /**
14
+ * Thrown when the server returns 401 Unauthorized.
15
+ */
16
+ export declare class AuthenticationError extends AgentLensError {
17
+ constructor(message?: string);
18
+ }
19
+ /**
20
+ * Thrown when the server returns 404 Not Found.
21
+ */
22
+ export declare class NotFoundError extends AgentLensError {
23
+ constructor(resource: string, id?: string);
24
+ }
25
+ /**
26
+ * Thrown when the server returns 400 Bad Request (validation errors).
27
+ */
28
+ export declare class ValidationError extends AgentLensError {
29
+ constructor(message: string, details?: unknown);
30
+ }
31
+ /**
32
+ * Thrown when the server is unreachable or returns a 5xx error.
33
+ */
34
+ export declare class ConnectionError extends AgentLensError {
35
+ constructor(message: string, cause?: unknown);
36
+ }
37
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEtB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAO7E;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,SAA0B;CAI9C;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,cAAc;gBACnC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM;CAK1C;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,cAAc;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAI/C;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,cAAc;gBACrC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C"}
package/dist/errors.js ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @agentlens/sdk — Typed Errors
3
+ */
4
+ /**
5
+ * Base error class for all AgentLens SDK errors.
6
+ */
7
+ export class AgentLensError extends Error {
8
+ status;
9
+ code;
10
+ details;
11
+ constructor(message, status, code, details) {
12
+ super(message);
13
+ this.name = 'AgentLensError';
14
+ this.status = status;
15
+ this.code = code;
16
+ this.details = details;
17
+ }
18
+ }
19
+ /**
20
+ * Thrown when the server returns 401 Unauthorized.
21
+ */
22
+ export class AuthenticationError extends AgentLensError {
23
+ constructor(message = 'Authentication failed') {
24
+ super(message, 401, 'AUTHENTICATION_ERROR');
25
+ this.name = 'AuthenticationError';
26
+ }
27
+ }
28
+ /**
29
+ * Thrown when the server returns 404 Not Found.
30
+ */
31
+ export class NotFoundError extends AgentLensError {
32
+ constructor(resource, id) {
33
+ const msg = id ? `${resource} '${id}' not found` : `${resource} not found`;
34
+ super(msg, 404, 'NOT_FOUND');
35
+ this.name = 'NotFoundError';
36
+ }
37
+ }
38
+ /**
39
+ * Thrown when the server returns 400 Bad Request (validation errors).
40
+ */
41
+ export class ValidationError extends AgentLensError {
42
+ constructor(message, details) {
43
+ super(message, 400, 'VALIDATION_ERROR', details);
44
+ this.name = 'ValidationError';
45
+ }
46
+ }
47
+ /**
48
+ * Thrown when the server is unreachable or returns a 5xx error.
49
+ */
50
+ export class ConnectionError extends AgentLensError {
51
+ constructor(message, cause) {
52
+ super(message, 0, 'CONNECTION_ERROR', cause);
53
+ this.name = 'ConnectionError';
54
+ }
55
+ }
56
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,OAAO,CAAW;IAElC,YAAY,OAAe,EAAE,MAAc,EAAE,IAAY,EAAE,OAAiB;QAC1E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAO,GAAG,uBAAuB;QAC3C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,sBAAsB,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,cAAc;IAC/C,YAAY,QAAgB,EAAE,EAAW;QACvC,MAAM,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,QAAQ,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,YAAY,CAAC;QAC3E,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,cAAc;IACjD,YAAY,OAAe,EAAE,OAAiB;QAC5C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,cAAc;IACjD,YAAY,OAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @agentlens/sdk — Programmatic client for the AgentLens API
3
+ */
4
+ export { AgentLensClient } from './client.js';
5
+ export type { AgentLensClientOptions, SessionQueryResult, TimelineResult, HealthResult, } from './client.js';
6
+ export { AgentLensError, AuthenticationError, NotFoundError, ValidationError, ConnectionError, } from './errors.js';
7
+ export type { AgentLensEvent, EventQuery, EventQueryResult, EventType, EventSeverity, Session, SessionQuery, SessionStatus, Agent, } from '@agentlens/core';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EACV,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,YAAY,GACb,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,eAAe,GAChB,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,OAAO,EACP,YAAY,EACZ,aAAa,EACb,KAAK,GACN,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @agentlens/sdk — Programmatic client for the AgentLens API
3
+ */
4
+ // Client
5
+ export { AgentLensClient } from './client.js';
6
+ // Errors
7
+ export { AgentLensError, AuthenticationError, NotFoundError, ValidationError, ConnectionError, } from './errors.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,SAAS;AACT,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAQ9C,SAAS;AACT,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,eAAe,GAChB,MAAM,aAAa,CAAC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@agentlensai/sdk",
3
+ "version": "0.2.0",
4
+ "description": "TypeScript SDK for the AgentLens API — programmatic access to agent observability data",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Amit Paz",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/amitpaz/agentlens.git",
11
+ "directory": "packages/sdk"
12
+ },
13
+ "homepage": "https://github.com/amitpaz/agentlens/tree/main/packages/sdk",
14
+ "bugs": {
15
+ "url": "https://github.com/amitpaz/agentlens/issues"
16
+ },
17
+ "keywords": [
18
+ "agentlens",
19
+ "ai-agents",
20
+ "observability",
21
+ "sdk",
22
+ "client",
23
+ "typescript",
24
+ "api-client"
25
+ ],
26
+ "exports": {
27
+ ".": {
28
+ "import": "./dist/index.js",
29
+ "types": "./dist/index.d.ts"
30
+ }
31
+ },
32
+ "main": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "dependencies": {
38
+ "@agentlensai/core": "0.2.0"
39
+ },
40
+ "scripts": {
41
+ "build": "tsc -b",
42
+ "dev": "tsc -b --watch",
43
+ "typecheck": "tsc --noEmit",
44
+ "test": "vitest run",
45
+ "test:watch": "vitest"
46
+ }
47
+ }