ardea 0.2.0 → 0.3.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,175 @@
1
+ import https from 'node:https';
2
+ import http from 'node:http';
3
+
4
+ /** SDK configuration. */
5
+ interface ArdeaConfig {
6
+ /** Canary API key (must start with cnry_sk_). */
7
+ apiKey: string;
8
+ /** Backend endpoint URL. */
9
+ endpoint?: string;
10
+ /** Automatically start periodic flush. */
11
+ autoFlush?: boolean;
12
+ }
13
+ /** @deprecated Use ArdeaConfig instead. */
14
+ type CanaryConfig = ArdeaConfig;
15
+ interface BaseEvent {
16
+ ts: number;
17
+ sdk_instance_id?: string;
18
+ process_id?: number;
19
+ parent_process_id?: number;
20
+ process_kind?: string;
21
+ process_label?: string;
22
+ thread_id?: number;
23
+ call_sequence?: number;
24
+ framework_session_id?: string;
25
+ agent_name?: string;
26
+ agent_version?: string;
27
+ source?: string;
28
+ source_plane?: "declared";
29
+ capture_mode?: "declared";
30
+ }
31
+ /** Agent feedback event. */
32
+ interface FeedbackEvent extends BaseEvent {
33
+ event_type: "feedback";
34
+ source: string;
35
+ worked: boolean;
36
+ context: string;
37
+ friction_points?: string[];
38
+ provider?: string;
39
+ endpoint_pattern?: string;
40
+ }
41
+ /** Union of all event types. */
42
+ type CanaryEvent = FeedbackEvent;
43
+
44
+ /**
45
+ * Event buffer with ring buffer, gzip flush, retry, and session cache.
46
+ *
47
+ * Mirrors sdk/src/ardea/buffer.py.
48
+ */
49
+
50
+ declare class EventBuffer {
51
+ private _buffer;
52
+ private _sessionCache;
53
+ private _sessionCacheEventCount;
54
+ private _apiKey;
55
+ private _endpoint;
56
+ private _timer;
57
+ private _stopped;
58
+ /** Reference to the original (unpatched) https.request for anti-recursion. */
59
+ private _originalHttpsRequest;
60
+ /** Reference to the original (unpatched) http.request for anti-recursion. */
61
+ private _originalHttpRequest;
62
+ constructor(apiKey: string, endpoint?: string, autoFlush?: boolean, originalHttpsRequest?: typeof https.request, originalHttpRequest?: typeof http.request);
63
+ /** Add an event to the ring buffer. */
64
+ push(event: CanaryEvent): void;
65
+ /** Return a copy of events for the given session from the cache. */
66
+ getSessionEvents(sessionId: string): CanaryEvent[];
67
+ /** Remove session events from the cache. */
68
+ clearSession(sessionId: string): void;
69
+ /** Remove and return up to `count` events from the buffer. */
70
+ drain(count: number): CanaryEvent[];
71
+ /** Get all buffered events (without draining). For reporter access. */
72
+ peek(): CanaryEvent[];
73
+ /** Number of buffered events. */
74
+ get length(): number;
75
+ /** Drain a batch and send to backend. */
76
+ flush(): Promise<void>;
77
+ /** Stop flush timer and drain all remaining events. */
78
+ shutdown(): Promise<void>;
79
+ /** POST events to the backend with gzip compression. */
80
+ private _send;
81
+ }
82
+
83
+ /**
84
+ * Session correlation via AsyncLocalStorage.
85
+ *
86
+ * Node.js equivalent of sdk/src/canary/context.py using
87
+ * AsyncLocalStorage instead of ContextVar.
88
+ */
89
+ interface SessionSignals {
90
+ sdk_instance_id: string;
91
+ process_id: number;
92
+ parent_process_id?: number;
93
+ process_kind?: string;
94
+ process_label?: string;
95
+ thread_id: number;
96
+ call_sequence: number;
97
+ framework_session_id?: string;
98
+ agent_name?: string;
99
+ agent_version?: string;
100
+ }
101
+ /**
102
+ * Return session correlation signals for the current execution context.
103
+ */
104
+ declare function getSessionSignals(): SessionSignals;
105
+ /**
106
+ * Set the framework session ID for the current async context.
107
+ *
108
+ * If no async context is active, this becomes the default session ID used
109
+ * by subsequent feedback/reporting calls on this process.
110
+ */
111
+ declare function setFrameworkSession(sessionId: string): void;
112
+ /**
113
+ * Clear the framework session ID for the current async context.
114
+ */
115
+ declare function clearFrameworkSession(): void;
116
+ /**
117
+ * Run a function with a scoped framework session ID.
118
+ *
119
+ * The session ID propagates through async call chains automatically.
120
+ */
121
+ declare function runWithSession<T>(sessionId: string, fn: () => T): T;
122
+
123
+ /**
124
+ * Detect which AI agent framework is running via environment variables.
125
+ */
126
+ interface AgentInfo {
127
+ agent_name: string | null;
128
+ agent_version: string | null;
129
+ }
130
+ declare function detectAgent(): AgentInfo;
131
+ declare function resetAgentCache(): void;
132
+
133
+ /**
134
+ * ardea — MCP tools for AI agents to report API experiences.
135
+ */
136
+
137
+ /**
138
+ * Initialize Canary SDK for manual feedback submission.
139
+ */
140
+ declare function init(config: CanaryConfig): void;
141
+ /**
142
+ * Shut down the SDK and flush any queued feedback events.
143
+ */
144
+ declare function shutdown(): Promise<void>;
145
+ /**
146
+ * Submit manual feedback.
147
+ */
148
+ declare function survey(options: {
149
+ worked?: boolean;
150
+ context?: string;
151
+ frictionPoints?: string[];
152
+ provider?: string;
153
+ sessionId?: string;
154
+ }): void;
155
+ /**
156
+ * Get the global EventBuffer (for advanced usage / adapters).
157
+ */
158
+ declare function getBuffer(): EventBuffer | null;
159
+
160
+ /** Alias for init — Ardea rebrand entry point. */
161
+ declare const Ardea: {
162
+ init: typeof init;
163
+ shutdown: typeof shutdown;
164
+ survey: typeof survey;
165
+ getBuffer: typeof getBuffer;
166
+ };
167
+ /** @deprecated Use Ardea instead. */
168
+ declare const Canary: {
169
+ init: typeof init;
170
+ shutdown: typeof shutdown;
171
+ survey: typeof survey;
172
+ getBuffer: typeof getBuffer;
173
+ };
174
+
175
+ export { Ardea, type ArdeaConfig, Canary, type CanaryConfig, type CanaryEvent, type FeedbackEvent, clearFrameworkSession, detectAgent, getBuffer, getSessionSignals, init, resetAgentCache, runWithSession, setFrameworkSession, shutdown, survey };
@@ -0,0 +1,175 @@
1
+ import https from 'node:https';
2
+ import http from 'node:http';
3
+
4
+ /** SDK configuration. */
5
+ interface ArdeaConfig {
6
+ /** Canary API key (must start with cnry_sk_). */
7
+ apiKey: string;
8
+ /** Backend endpoint URL. */
9
+ endpoint?: string;
10
+ /** Automatically start periodic flush. */
11
+ autoFlush?: boolean;
12
+ }
13
+ /** @deprecated Use ArdeaConfig instead. */
14
+ type CanaryConfig = ArdeaConfig;
15
+ interface BaseEvent {
16
+ ts: number;
17
+ sdk_instance_id?: string;
18
+ process_id?: number;
19
+ parent_process_id?: number;
20
+ process_kind?: string;
21
+ process_label?: string;
22
+ thread_id?: number;
23
+ call_sequence?: number;
24
+ framework_session_id?: string;
25
+ agent_name?: string;
26
+ agent_version?: string;
27
+ source?: string;
28
+ source_plane?: "declared";
29
+ capture_mode?: "declared";
30
+ }
31
+ /** Agent feedback event. */
32
+ interface FeedbackEvent extends BaseEvent {
33
+ event_type: "feedback";
34
+ source: string;
35
+ worked: boolean;
36
+ context: string;
37
+ friction_points?: string[];
38
+ provider?: string;
39
+ endpoint_pattern?: string;
40
+ }
41
+ /** Union of all event types. */
42
+ type CanaryEvent = FeedbackEvent;
43
+
44
+ /**
45
+ * Event buffer with ring buffer, gzip flush, retry, and session cache.
46
+ *
47
+ * Mirrors sdk/src/ardea/buffer.py.
48
+ */
49
+
50
+ declare class EventBuffer {
51
+ private _buffer;
52
+ private _sessionCache;
53
+ private _sessionCacheEventCount;
54
+ private _apiKey;
55
+ private _endpoint;
56
+ private _timer;
57
+ private _stopped;
58
+ /** Reference to the original (unpatched) https.request for anti-recursion. */
59
+ private _originalHttpsRequest;
60
+ /** Reference to the original (unpatched) http.request for anti-recursion. */
61
+ private _originalHttpRequest;
62
+ constructor(apiKey: string, endpoint?: string, autoFlush?: boolean, originalHttpsRequest?: typeof https.request, originalHttpRequest?: typeof http.request);
63
+ /** Add an event to the ring buffer. */
64
+ push(event: CanaryEvent): void;
65
+ /** Return a copy of events for the given session from the cache. */
66
+ getSessionEvents(sessionId: string): CanaryEvent[];
67
+ /** Remove session events from the cache. */
68
+ clearSession(sessionId: string): void;
69
+ /** Remove and return up to `count` events from the buffer. */
70
+ drain(count: number): CanaryEvent[];
71
+ /** Get all buffered events (without draining). For reporter access. */
72
+ peek(): CanaryEvent[];
73
+ /** Number of buffered events. */
74
+ get length(): number;
75
+ /** Drain a batch and send to backend. */
76
+ flush(): Promise<void>;
77
+ /** Stop flush timer and drain all remaining events. */
78
+ shutdown(): Promise<void>;
79
+ /** POST events to the backend with gzip compression. */
80
+ private _send;
81
+ }
82
+
83
+ /**
84
+ * Session correlation via AsyncLocalStorage.
85
+ *
86
+ * Node.js equivalent of sdk/src/canary/context.py using
87
+ * AsyncLocalStorage instead of ContextVar.
88
+ */
89
+ interface SessionSignals {
90
+ sdk_instance_id: string;
91
+ process_id: number;
92
+ parent_process_id?: number;
93
+ process_kind?: string;
94
+ process_label?: string;
95
+ thread_id: number;
96
+ call_sequence: number;
97
+ framework_session_id?: string;
98
+ agent_name?: string;
99
+ agent_version?: string;
100
+ }
101
+ /**
102
+ * Return session correlation signals for the current execution context.
103
+ */
104
+ declare function getSessionSignals(): SessionSignals;
105
+ /**
106
+ * Set the framework session ID for the current async context.
107
+ *
108
+ * If no async context is active, this becomes the default session ID used
109
+ * by subsequent feedback/reporting calls on this process.
110
+ */
111
+ declare function setFrameworkSession(sessionId: string): void;
112
+ /**
113
+ * Clear the framework session ID for the current async context.
114
+ */
115
+ declare function clearFrameworkSession(): void;
116
+ /**
117
+ * Run a function with a scoped framework session ID.
118
+ *
119
+ * The session ID propagates through async call chains automatically.
120
+ */
121
+ declare function runWithSession<T>(sessionId: string, fn: () => T): T;
122
+
123
+ /**
124
+ * Detect which AI agent framework is running via environment variables.
125
+ */
126
+ interface AgentInfo {
127
+ agent_name: string | null;
128
+ agent_version: string | null;
129
+ }
130
+ declare function detectAgent(): AgentInfo;
131
+ declare function resetAgentCache(): void;
132
+
133
+ /**
134
+ * ardea — MCP tools for AI agents to report API experiences.
135
+ */
136
+
137
+ /**
138
+ * Initialize Canary SDK for manual feedback submission.
139
+ */
140
+ declare function init(config: CanaryConfig): void;
141
+ /**
142
+ * Shut down the SDK and flush any queued feedback events.
143
+ */
144
+ declare function shutdown(): Promise<void>;
145
+ /**
146
+ * Submit manual feedback.
147
+ */
148
+ declare function survey(options: {
149
+ worked?: boolean;
150
+ context?: string;
151
+ frictionPoints?: string[];
152
+ provider?: string;
153
+ sessionId?: string;
154
+ }): void;
155
+ /**
156
+ * Get the global EventBuffer (for advanced usage / adapters).
157
+ */
158
+ declare function getBuffer(): EventBuffer | null;
159
+
160
+ /** Alias for init — Ardea rebrand entry point. */
161
+ declare const Ardea: {
162
+ init: typeof init;
163
+ shutdown: typeof shutdown;
164
+ survey: typeof survey;
165
+ getBuffer: typeof getBuffer;
166
+ };
167
+ /** @deprecated Use Ardea instead. */
168
+ declare const Canary: {
169
+ init: typeof init;
170
+ shutdown: typeof shutdown;
171
+ survey: typeof survey;
172
+ getBuffer: typeof getBuffer;
173
+ };
174
+
175
+ export { Ardea, type ArdeaConfig, Canary, type CanaryConfig, type CanaryEvent, type FeedbackEvent, clearFrameworkSession, detectAgent, getBuffer, getSessionSignals, init, resetAgentCache, runWithSession, setFrameworkSession, shutdown, survey };