aida-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # aida
2
+
3
+ > AI DevOps Incident Intelligence SDK for Node.js / TypeScript.
4
+ > Auto-captures console output and errors — triggers AI-powered incident analysis.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ npm install aida
10
+ # or
11
+ yarn add aida
12
+ ```
13
+
14
+ ## Quick Start
15
+
16
+ ```typescript
17
+ import aida from 'aida';
18
+
19
+ aida.init({
20
+ apiKey: 'sk-...', // from GET /api/v1/sdk/keys
21
+ projectId: 'owner/my-repo', // your GitHub repo full name
22
+ repoName: 'owner/my-repo',
23
+ baseUrl: 'https://your-aida-backend.com',
24
+ environment: 'production',
25
+ service: 'my-api',
26
+ });
27
+
28
+ // ✅ After this line — ALL console output is auto-captured.
29
+ // ✅ uncaughtException and unhandledRejection are auto-captured.
30
+ // ✅ Error-level entries trigger the 4-agent AI incident pipeline.
31
+
32
+ console.log('Server started on port 3000'); // → captured as info log
33
+ console.error('Database connection failed'); // → captured as error, triggers AI analysis
34
+ throw new Error('Something broke'); // → captured with stack trace
35
+ ```
36
+
37
+ ## CommonJS
38
+
39
+ ```javascript
40
+ const aida = require('aida');
41
+
42
+ aida.init({ apiKey: '...', projectId: '...', repoName: '...', baseUrl: '...' });
43
+ ```
44
+
45
+ ## What Gets Captured Automatically
46
+
47
+ | Source | Level |
48
+ |---|---|
49
+ | `console.log()` | info |
50
+ | `console.info()` | info |
51
+ | `console.warn()` | warn |
52
+ | `console.error()` | error |
53
+ | `process.uncaughtException` | error (with stack trace) |
54
+ | `process.unhandledRejection` | error |
55
+
56
+ ## Manual Logging (Optional)
57
+
58
+ ```typescript
59
+ aida.error('Payment timeout', { gateway: 'stripe', latency_ms: 5000 });
60
+ aida.info('User signed up', { user_id: '123' });
61
+ ```
62
+
63
+ ## Configuration
64
+
65
+ | Option | Default | Description |
66
+ |---|---|---|
67
+ | `apiKey` | required | Bearer token from `/api/v1/sdk/keys` |
68
+ | `projectId` | required | Repo full name for linking logs to incidents |
69
+ | `repoName` | required | Same as projectId |
70
+ | `baseUrl` | required | Backend URL |
71
+ | `environment` | `"production"` | Environment tag |
72
+ | `service` | `"app"` | Service name |
73
+ | `batchSize` | `20` | Logs per HTTP request |
74
+ | `flushIntervalMs` | `2000` | Milliseconds between flushes |
75
+ | `interceptConsole` | `true` | Auto-capture console methods |
76
+ | `interceptExceptions` | `true` | Auto-capture uncaughtException |
77
+ | `interceptRejections` | `true` | Auto-capture unhandledRejection |
78
+
79
+ ## Build & Publish
80
+
81
+ CI publish (GitHub Actions):
82
+ - Tag the repo with `node-sdk-v*` or run `workflow_dispatch`.
83
+ - Required secret: `NPM_TOKEN`.
84
+
85
+ ```bash
86
+ cd node-sdk
87
+ npm install
88
+ npm run build
89
+ npm publish
90
+ ```
@@ -0,0 +1,26 @@
1
+ import { AidaConfig, LogLevel } from "./types";
2
+ export declare class AidaClient {
3
+ private readonly config;
4
+ private queue;
5
+ private flushTimer;
6
+ private readonly origLog;
7
+ private readonly origWarn;
8
+ private readonly origError;
9
+ private readonly origInfo;
10
+ private readonly runtimeMeta;
11
+ constructor(config: AidaConfig);
12
+ start(): void;
13
+ private _interceptConsole;
14
+ private _handleUncaughtException;
15
+ private _handleUnhandledRejection;
16
+ log(level: LogLevel, message: string, metadata?: Record<string, unknown>): void;
17
+ error(message: string, metadata?: Record<string, unknown>): void;
18
+ warn(message: string, metadata?: Record<string, unknown>): void;
19
+ info(message: string, metadata?: Record<string, unknown>): void;
20
+ debug(message: string, metadata?: Record<string, unknown>): void;
21
+ private _enqueue;
22
+ private _flush;
23
+ private _sendWithRetry;
24
+ shutdown(): void;
25
+ }
26
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,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dist/client.js ADDED
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ // client.ts — AIDA Node.js SDK client with automatic log interception
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.AidaClient = void 0;
38
+ const os = __importStar(require("os"));
39
+ const process = __importStar(require("process"));
40
+ class AidaClient {
41
+ constructor(config) {
42
+ this.queue = [];
43
+ this.flushTimer = null;
44
+ // Store originals so we can restore on shutdown
45
+ this.origLog = console.log.bind(console);
46
+ this.origWarn = console.warn.bind(console);
47
+ this.origError = console.error.bind(console);
48
+ this.origInfo = console.info.bind(console);
49
+ this.config = {
50
+ environment: "production",
51
+ service: "app",
52
+ batchSize: 20,
53
+ flushIntervalMs: 2000,
54
+ interceptConsole: true,
55
+ interceptExceptions: true,
56
+ interceptRejections: true,
57
+ ...config,
58
+ };
59
+ this.runtimeMeta = {
60
+ node_version: process.version,
61
+ platform: os.platform(),
62
+ arch: os.arch(),
63
+ repo_name: this.config.repoName,
64
+ };
65
+ }
66
+ // -------------------------------------------------------------------------
67
+ // Startup
68
+ // -------------------------------------------------------------------------
69
+ start() {
70
+ if (this.config.interceptConsole) {
71
+ this._interceptConsole();
72
+ }
73
+ if (this.config.interceptExceptions) {
74
+ process.on("uncaughtException", this._handleUncaughtException.bind(this));
75
+ }
76
+ if (this.config.interceptRejections) {
77
+ process.on("unhandledRejection", this._handleUnhandledRejection.bind(this));
78
+ }
79
+ this.flushTimer = setInterval(() => this._flush(), this.config.flushIntervalMs);
80
+ // Don't hold the Node process open just for this timer
81
+ if (this.flushTimer.unref)
82
+ this.flushTimer.unref();
83
+ // Auto-flush on exit
84
+ // Using beforeExit because exit is synchronous and async fetches would never complete.
85
+ process.on("beforeExit", () => {
86
+ this.shutdown();
87
+ });
88
+ process.on("SIGTERM", () => { this._flush(); });
89
+ process.on("SIGINT", () => { this._flush(); });
90
+ }
91
+ // -------------------------------------------------------------------------
92
+ // Console interception
93
+ // -------------------------------------------------------------------------
94
+ _interceptConsole() {
95
+ console.log = (...args) => {
96
+ this.origLog(...args);
97
+ this._enqueue("info", args.map(String).join(" "));
98
+ };
99
+ console.info = (...args) => {
100
+ this.origInfo(...args);
101
+ this._enqueue("info", args.map(String).join(" "));
102
+ };
103
+ console.warn = (...args) => {
104
+ this.origWarn(...args);
105
+ this._enqueue("warn", args.map(String).join(" "));
106
+ };
107
+ console.error = (...args) => {
108
+ this.origError(...args);
109
+ this._enqueue("error", args.map(String).join(" "));
110
+ };
111
+ }
112
+ // -------------------------------------------------------------------------
113
+ // Error handlers
114
+ // -------------------------------------------------------------------------
115
+ _handleUncaughtException(err) {
116
+ this._enqueue("error", `UncaughtException: ${err.message}`, {
117
+ name: err.name,
118
+ stack: err.stack?.slice(0, 3000),
119
+ });
120
+ this._flush(); // Flush synchronously before process exits
121
+ // Re-throw so the default handler still runs
122
+ this.origError("[AIDA] Uncaught exception captured:", err);
123
+ process.exit(1);
124
+ }
125
+ _handleUnhandledRejection(reason) {
126
+ const msg = reason instanceof Error ? reason.message : String(reason);
127
+ const stack = reason instanceof Error ? reason.stack?.slice(0, 3000) : undefined;
128
+ this._enqueue("error", `UnhandledRejection: ${msg}`, { stack });
129
+ }
130
+ // -------------------------------------------------------------------------
131
+ // Manual logging API
132
+ // -------------------------------------------------------------------------
133
+ log(level, message, metadata) {
134
+ this._enqueue(level, message, metadata);
135
+ }
136
+ error(message, metadata) {
137
+ this._enqueue("error", message, metadata);
138
+ }
139
+ warn(message, metadata) {
140
+ this._enqueue("warn", message, metadata);
141
+ }
142
+ info(message, metadata) {
143
+ this._enqueue("info", message, metadata);
144
+ }
145
+ debug(message, metadata) {
146
+ this._enqueue("debug", message, metadata);
147
+ }
148
+ // -------------------------------------------------------------------------
149
+ // Queue management
150
+ // -------------------------------------------------------------------------
151
+ _enqueue(level, message, extraMeta) {
152
+ if (this.queue.length >= 5000)
153
+ return; // Back-pressure cap
154
+ this.queue.push({
155
+ service: this.config.service,
156
+ environment: this.config.environment,
157
+ level,
158
+ message: String(message).slice(0, 10000),
159
+ project_id: this.config.projectId,
160
+ metadata: { ...this.runtimeMeta, ...(extraMeta ?? {}) },
161
+ });
162
+ }
163
+ // -------------------------------------------------------------------------
164
+ // HTTP flush
165
+ // -------------------------------------------------------------------------
166
+ _flush() {
167
+ if (this.queue.length === 0)
168
+ return;
169
+ const batch = this.queue.splice(0, this.config.batchSize);
170
+ // Fire-and-forget with retry — we don't await to avoid blocking
171
+ for (const entry of batch) {
172
+ this._sendWithRetry(entry, 3);
173
+ }
174
+ }
175
+ _sendWithRetry(entry, retries) {
176
+ const attempt = () => {
177
+ fetch(`${this.config.baseUrl}/api/v1/sdk/logs`, {
178
+ method: "POST",
179
+ headers: {
180
+ Authorization: `Bearer ${this.config.apiKey}`,
181
+ "Content-Type": "application/json",
182
+ },
183
+ body: JSON.stringify(entry),
184
+ }).then((res) => {
185
+ if (!res.ok && res.status >= 500 && retries > 0) {
186
+ setTimeout(() => this._sendWithRetry(entry, retries - 1), 500);
187
+ }
188
+ }).catch(() => {
189
+ if (retries > 0) {
190
+ setTimeout(() => this._sendWithRetry(entry, retries - 1), 500);
191
+ }
192
+ });
193
+ };
194
+ attempt();
195
+ }
196
+ // -------------------------------------------------------------------------
197
+ // Shutdown
198
+ // -------------------------------------------------------------------------
199
+ shutdown() {
200
+ if (this.flushTimer)
201
+ clearInterval(this.flushTimer);
202
+ this._flush();
203
+ // Restore original console methods
204
+ console.log = this.origLog;
205
+ console.warn = this.origWarn;
206
+ console.error = this.origError;
207
+ console.info = this.origInfo;
208
+ }
209
+ }
210
+ exports.AidaClient = AidaClient;
211
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA,sEAAsE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtE,uCAAyB;AACzB,iDAAmC;AAGnC,MAAa,UAAU;IAarB,YAAY,MAAkB;QAXtB,UAAK,GAAe,EAAE,CAAC;QACvB,eAAU,GAA0C,IAAI,CAAC;QAEjE,gDAAgD;QAC/B,YAAO,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,aAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtC,cAAS,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxC,aAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAKrD,IAAI,CAAC,MAAM,GAAG;YACZ,WAAW,EAAE,YAAY;YACzB,OAAO,E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;YAAE,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,mCAAmC;QACnC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3B,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC7B,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC;QAC/B,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC;IAC/B,CAAC;CACF;AAxMD,gCAwMC"}
@@ -0,0 +1,38 @@
1
+ import { AidaClient } from "./client";
2
+ import type { AidaConfig, LogLevel, LogEntry, IngestResponse } from "./types";
3
+ export { AidaClient };
4
+ export type { AidaConfig, LogLevel, LogEntry, IngestResponse };
5
+ /**
6
+ * Initialize the AIDA SDK and start automatic log capture.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import aida from 'aida';
11
+ *
12
+ * aida.init({
13
+ * apiKey: 'sk-...',
14
+ * projectId: 'owner/my-repo',
15
+ * repoName: 'owner/my-repo',
16
+ * baseUrl: 'https://your-aida-backend.com',
17
+ * environment: 'production',
18
+ * service: 'my-api',
19
+ * });
20
+ *
21
+ * // ✅ All console.log/warn/error now auto-captured
22
+ * // ✅ uncaughtException and unhandledRejection auto-captured
23
+ * // ✅ Error-level logs trigger the AI incident pipeline
24
+ * ```
25
+ */
26
+ declare function init(config: AidaConfig): AidaClient;
27
+ declare function getClient(): AidaClient | null;
28
+ declare const aida: {
29
+ init: typeof init;
30
+ getClient: typeof getClient;
31
+ log: (level: LogLevel, msg: string, meta?: Record<string, unknown>) => void | undefined;
32
+ error: (msg: string, meta?: Record<string, unknown>) => void | undefined;
33
+ warn: (msg: string, meta?: Record<string, unknown>) => void | undefined;
34
+ info: (msg: string, meta?: Record<string, unknown>) => void | undefined;
35
+ debug: (msg: string, meta?: Record<string, unknown>) => void | undefined;
36
+ };
37
+ export default aida;
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;AAI/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAO5C;AAED,iBAAS,SAAS,IAAI,UAAU,GAAG,IAAI,CAEtC;AAED,QAAA,MAAM,IAAI;;;iBAGK,QAAQ,OAAO,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;iBAErD,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBACvC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBACtC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;iBACrC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CACpD,CAAC;AAEF,eAAe,IAAI,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ // index.ts — AIDA Node.js SDK public API
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.AidaClient = void 0;
5
+ const client_1 = require("./client");
6
+ Object.defineProperty(exports, "AidaClient", { enumerable: true, get: function () { return client_1.AidaClient; } });
7
+ let _instance = null;
8
+ /**
9
+ * Initialize the AIDA SDK and start automatic log capture.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import aida from 'aida';
14
+ *
15
+ * aida.init({
16
+ * apiKey: 'sk-...',
17
+ * projectId: 'owner/my-repo',
18
+ * repoName: 'owner/my-repo',
19
+ * baseUrl: 'https://your-aida-backend.com',
20
+ * environment: 'production',
21
+ * service: 'my-api',
22
+ * });
23
+ *
24
+ * // ✅ All console.log/warn/error now auto-captured
25
+ * // ✅ uncaughtException and unhandledRejection auto-captured
26
+ * // ✅ Error-level logs trigger the AI incident pipeline
27
+ * ```
28
+ */
29
+ function init(config) {
30
+ if (_instance) {
31
+ _instance.shutdown();
32
+ }
33
+ _instance = new client_1.AidaClient(config);
34
+ _instance.start();
35
+ return _instance;
36
+ }
37
+ function getClient() {
38
+ return _instance;
39
+ }
40
+ const aida = {
41
+ init,
42
+ getClient,
43
+ log: (level, msg, meta) => _instance?.log(level, msg, meta),
44
+ error: (msg, meta) => _instance?.error(msg, meta),
45
+ warn: (msg, meta) => _instance?.warn(msg, meta),
46
+ info: (msg, meta) => _instance?.info(msg, meta),
47
+ debug: (msg, meta) => _instance?.debug(msg, meta),
48
+ };
49
+ exports.default = aida;
50
+ module.exports = aida;
51
+ module.exports.default = aida;
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,yCAAyC;;;AAEzC,qCAAsC;AAG7B,2FAHA,mBAAU,OAGA;AAGnB,IAAI,SAAS,GAAsB,IAAI,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAS,IAAI,CAAC,MAAkB;IAC9B,IAAI,SAAS,EAAE,CAAC;QACd,SAAS,CAAC,QAAQ,EAAE,CAAC;IACvB,CAAC;IACD,SAAS,GAAG,IAAI,mBAAU,CAAC,MAAM,CAAC,CAAC;IACnC,SAAS,CAAC,KAAK,EAAE,CAAC;IAClB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,SAAS;IAChB,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,IAAI,GAAG;IACX,IAAI;IACJ,SAAS;IACT,GAAG,EAAE,CAAC,KAAe,EAAE,GAAW,EAAE,IAA8B,EAAE,EAAE,CACpE,SAAS,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC;IAClC,KAAK,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC;IACnF,IAAI,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC;IACjF,IAAI,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC;IACjF,KAAK,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC;CACpF,CAAC;AAEF,kBAAe,IAAI,CAAC;AACpB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;AACtB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC"}
@@ -0,0 +1,40 @@
1
+ export type LogLevel = "error" | "warn" | "info" | "debug";
2
+ export interface AidaConfig {
3
+ /** Bearer API key from GET /api/v1/sdk/keys */
4
+ apiKey: string;
5
+ /** Project identifier — should match your GitHub repo full name (e.g. 'owner/my-repo') */
6
+ projectId: string;
7
+ /** GitHub repo full name, e.g. 'owner/my-repo' */
8
+ repoName: string;
9
+ /** Base URL of your AIDA backend — no trailing slash */
10
+ baseUrl: string;
11
+ /** Deployment environment tag, e.g. 'production', 'staging' */
12
+ environment?: string;
13
+ /** Service name tag shown in log entries */
14
+ service?: string;
15
+ /** Max log entries per HTTP batch (default: 20) */
16
+ batchSize?: number;
17
+ /** Milliseconds between batch flushes (default: 2000) */
18
+ flushIntervalMs?: number;
19
+ /** Auto-capture console.log/warn/info (default: true) */
20
+ interceptConsole?: boolean;
21
+ /** Auto-capture process.on('uncaughtException') (default: true) */
22
+ interceptExceptions?: boolean;
23
+ /** Auto-capture process.on('unhandledRejection') (default: true) */
24
+ interceptRejections?: boolean;
25
+ }
26
+ export interface LogEntry {
27
+ service: string;
28
+ environment: string;
29
+ level: LogLevel;
30
+ message: string;
31
+ project_id: string;
32
+ metadata?: Record<string, unknown>;
33
+ }
34
+ export interface IngestResponse {
35
+ id: string;
36
+ incident_triggered: boolean;
37
+ incident_id?: string;
38
+ message: string;
39
+ }
40
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,UAAU;IACzB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,0FAA0F;IAC1F,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,mEAAmE;IACnE,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,oEAAoE;IACpE,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB,EAAE,OAAO,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB"}
package/dist/types.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // types.ts — TypeScript types for the AIDA Node.js SDK
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,uDAAuD"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "aida-sdk",
3
+ "version": "1.0.0",
4
+ "description": "AIDA — AI DevOps Incident Intelligence SDK. Auto-captures logs and errors, triggers AI-powered incident analysis.",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "build:watch": "tsc --watch",
17
+ "prepublishOnly": "npm run build"
18
+ },
19
+ "keywords": ["devops", "ai", "observability", "incident", "logging", "monitoring"],
20
+ "author": "AIDA Team",
21
+ "license": "MIT",
22
+ "devDependencies": {
23
+ "typescript": "^5.4.0",
24
+ "@types/node": "^20.0.0"
25
+ },
26
+ "engines": {
27
+ "node": ">=18.0.0"
28
+ },
29
+ "files": ["dist", "README.md"],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/your-org/aida.git"
33
+ }
34
+ }