@execlave/sdk 1.0.2

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,131 @@
1
+ # @execlave/sdk
2
+
3
+ Official JavaScript/TypeScript SDK for the [Execlave](https://github.com/Execlave) AI agent governance platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @execlave/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { Execlave } from '@execlave/sdk';
15
+
16
+ // Initialize the SDK
17
+ const ag = new Execlave({
18
+ apiKey: 'exe_prod_xxx', // or set EXECLAVE_API_KEY env var
19
+ environment: 'production',
20
+ });
21
+
22
+ // Register your agent (idempotent — call on startup)
23
+ const agent = await ag.registerAgent({
24
+ agentId: 'my-chatbot',
25
+ name: 'Customer Support Bot',
26
+ type: 'chatbot',
27
+ platform: 'custom',
28
+ });
29
+
30
+ // Trace an LLM call
31
+ const trace = ag.startTrace({ agentId: 'my-chatbot', sessionId: 'sess_123' });
32
+ trace.setInput(userQuestion);
33
+
34
+ const answer = await llm.call(userQuestion);
35
+
36
+ trace.setOutput(answer).setModel('gpt-4-turbo').setTokens(150, 300).setCost(0.012);
37
+ trace.finish(); // submits to buffer; flushed in background
38
+
39
+ // Or use the wrap() helper for automatic tracing
40
+ const tracedCall = ag.wrap(
41
+ async (question: string) => {
42
+ return await llm.call(question);
43
+ },
44
+ { agentId: 'my-chatbot' },
45
+ );
46
+
47
+ const result = await tracedCall('Hello!');
48
+
49
+ // Prompt management
50
+ const version = await agent.deployPrompt({
51
+ promptTemplate: 'You are a helpful assistant. Answer: {question}',
52
+ systemMessage: 'Be concise.',
53
+ modelName: 'gpt-4-turbo',
54
+ changeSummary: 'Improved conciseness',
55
+ });
56
+
57
+ // Kill-switch aware
58
+ try {
59
+ const trace = ag.startTrace();
60
+ // ...
61
+ } catch (err) {
62
+ if (err instanceof AgentPausedError) {
63
+ return 'Service temporarily unavailable.';
64
+ }
65
+ throw err;
66
+ }
67
+
68
+ // Graceful shutdown (flushes remaining traces)
69
+ await ag.shutdown();
70
+ ```
71
+
72
+ ## Configuration
73
+
74
+ | Option | Type | Default | Description |
75
+ | ---------------------- | --------- | -------------------------- | ---------------------------------- |
76
+ | `apiKey` | `string` | `EXECLAVE_API_KEY` env | API key (`ag_xxx`) |
77
+ | `baseUrl` | `string` | `https://api.execlave.com` | Execlave API URL |
78
+ | `environment` | `string` | `production` | Deployment environment |
79
+ | `asyncMode` | `boolean` | `true` | Buffer traces for background flush |
80
+ | `batchSize` | `number` | `100` | Max traces per flush batch |
81
+ | `flushIntervalMs` | `number` | `10000` | Background flush interval |
82
+ | `debug` | `boolean` | `false` | Enable debug logging |
83
+ | `enableControlChannel` | `boolean` | `true` | Poll agent status for kill-switch |
84
+ | `pollIntervalMs` | `number` | `15000` | Status poll interval |
85
+
86
+ ## API Reference
87
+
88
+ ### `Execlave`
89
+
90
+ - `ping()` — Check API connectivity
91
+ - `registerAgent(opts)` — Register an AI agent
92
+ - `startTrace(opts)` — Start a manual trace
93
+ - `wrap(fn, opts)` — Wrap a function with automatic tracing
94
+ - `checkAgentStatus(agentId?)` — Get agent status
95
+ - `flush()` — Flush buffered traces
96
+ - `shutdown()` — Flush and shut down
97
+
98
+ ### `Agent`
99
+
100
+ - `deployPrompt(opts)` — Deploy a new prompt version
101
+ - `getCurrentPrompt()` — Get the deployed prompt
102
+ - `listPromptVersions()` — List all versions
103
+ - `refreshStatus()` — Refresh agent status
104
+ - `isPaused` — Whether agent is kill-switched
105
+
106
+ ### `Trace`
107
+
108
+ - `setInput(data)` — Set input data (chainable)
109
+ - `setOutput(data)` — Set output data (chainable)
110
+ - `setModel(name)` — Set model name (chainable)
111
+ - `setTokens(prompt, completion)` — Set token counts (chainable)
112
+ - `setCost(usd)` — Set cost (chainable)
113
+ - `addMetadata(meta)` — Add metadata (chainable)
114
+ - `finish(status?, error?, errorType?)` — Submit the trace
115
+
116
+ ## Zero Dependencies
117
+
118
+ This SDK has **zero runtime dependencies**. It uses Node.js built-in `http`/`https` modules for network requests.
119
+
120
+ ## Legal
121
+
122
+ By using this SDK, you agree to the [Execlave Terms of Service](https://execlave.com/terms).
123
+
124
+ - [Privacy Policy](https://execlave.com/privacy)
125
+ - [Acceptable Use Policy](https://execlave.com/acceptable-use)
126
+ - [Responsible AI](https://execlave.com/responsible-ai)
127
+ - [Security](https://execlave.com/security)
128
+
129
+ ## License
130
+
131
+ MIT — see [LICENSE](../LICENSE) for details.
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Agent object returned from `ag.registerAgent()`.
3
+ *
4
+ * Provides prompt management methods and exposes agent metadata.
5
+ */
6
+ import type { AgentData, DeployPromptOptions, PromptVersionData } from './types';
7
+ /** Back-reference interface — avoids circular imports. */
8
+ interface ClientRef {
9
+ _request(method: string, path: string, body?: unknown): Promise<any>;
10
+ _apiPath(path: string): string;
11
+ }
12
+ export declare class Agent {
13
+ readonly id: string;
14
+ readonly agentId: string;
15
+ readonly name: string;
16
+ readonly environment: string;
17
+ status: string;
18
+ private _client;
19
+ private _data;
20
+ constructor(client: ClientRef, data: AgentData);
21
+ /** Whether this agent is currently paused via the kill switch. */
22
+ get isPaused(): boolean;
23
+ /**
24
+ * Deploy a new prompt version for this agent.
25
+ *
26
+ * @returns The created PromptVersion metadata.
27
+ */
28
+ deployPrompt(opts: DeployPromptOptions): Promise<PromptVersionData>;
29
+ /**
30
+ * Get the currently deployed prompt version for this agent.
31
+ *
32
+ * @returns PromptVersionData or null if no version is deployed.
33
+ */
34
+ getCurrentPrompt(): Promise<PromptVersionData | null>;
35
+ /**
36
+ * List all prompt versions for this agent.
37
+ */
38
+ listPromptVersions(): Promise<PromptVersionData[]>;
39
+ /** Refresh agent status from the API. */
40
+ refreshStatus(): Promise<string>;
41
+ /**
42
+ * Rollback to a specific prompt version.
43
+ *
44
+ * @param versionNumber - The version number to rollback to.
45
+ * @param reason - Required reason for the rollback.
46
+ * @returns The activated PromptVersionData.
47
+ */
48
+ rollbackToVersion(versionNumber: number, reason: string): Promise<PromptVersionData>;
49
+ /**
50
+ * Promote a staging prompt version to production.
51
+ *
52
+ * @param versionId - The version ID to promote.
53
+ * @param requireApproval - Whether to require admin approval.
54
+ * @param deploymentNotes - Notes for the deployment.
55
+ * @returns The promoted PromptVersionData.
56
+ */
57
+ promoteToProduction(versionId: string, opts?: {
58
+ requireApproval?: boolean;
59
+ deploymentNotes?: string;
60
+ }): Promise<PromptVersionData>;
61
+ /** Return raw agent data. */
62
+ toJSON(): AgentData;
63
+ }
64
+ export {};
65
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAe,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE9F,0DAA0D;AAC1D,UAAU,SAAS;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAChC;AAED,qBAAa,KAAK;IAChB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,CAAC,OAAO,CAAY;IAC3B,OAAO,CAAC,KAAK,CAAY;gBAEb,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS;IAU9C,kEAAkE;IAClE,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;;OAIG;IACG,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAmBzE;;;;OAIG;IACG,gBAAgB,IAAI,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAS3D;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAQxD,yCAAyC;IACnC,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAMtC;;;;;;OAMG;IACG,iBAAiB,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAY1F;;;;;;;OAOG;IACG,mBAAmB,CACvB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,OAAO,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAA;KAAE,GAC7D,OAAO,CAAC,iBAAiB,CAAC;IAS7B,6BAA6B;IAC7B,MAAM,IAAI,SAAS;CAGpB"}
package/dist/agent.js ADDED
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ /**
3
+ * Agent object returned from `ag.registerAgent()`.
4
+ *
5
+ * Provides prompt management methods and exposes agent metadata.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Agent = void 0;
9
+ class Agent {
10
+ constructor(client, data) {
11
+ this._client = client;
12
+ this._data = data;
13
+ this.id = data.id;
14
+ this.agentId = data.agentId;
15
+ this.name = data.name;
16
+ this.environment = data.environment;
17
+ this.status = data.status;
18
+ }
19
+ /** Whether this agent is currently paused via the kill switch. */
20
+ get isPaused() {
21
+ return this.status === 'paused';
22
+ }
23
+ /**
24
+ * Deploy a new prompt version for this agent.
25
+ *
26
+ * @returns The created PromptVersion metadata.
27
+ */
28
+ async deployPrompt(opts) {
29
+ const params = opts.modelParameters ?? {};
30
+ const payload = {
31
+ agentId: this.id,
32
+ promptTemplate: opts.promptTemplate,
33
+ systemMessage: opts.systemMessage ?? null,
34
+ modelName: opts.modelName ?? null,
35
+ temperature: params.temperature ?? null,
36
+ maxTokens: params.max_tokens ?? params.maxTokens ?? null,
37
+ // Backend schema uses 'changeSummary' not 'changeType'
38
+ changeSummary: opts.changeDescription ?? opts.changeType ?? null,
39
+ versionTag: opts.versionTag ?? null,
40
+ notes: opts.changeDescription ?? null,
41
+ };
42
+ const resp = await this._client._request('POST', this._client._apiPath('/prompt-versions'), payload);
43
+ return resp.data;
44
+ }
45
+ /**
46
+ * Get the currently deployed prompt version for this agent.
47
+ *
48
+ * @returns PromptVersionData or null if no version is deployed.
49
+ */
50
+ async getCurrentPrompt() {
51
+ const resp = await this._client._request('GET', `${this._client._apiPath('/prompt-versions')}?agentId=${encodeURIComponent(this.id)}&deployed=true`);
52
+ const versions = resp.data;
53
+ return versions.find((v) => v.isDeployed) ?? null;
54
+ }
55
+ /**
56
+ * List all prompt versions for this agent.
57
+ */
58
+ async listPromptVersions() {
59
+ const resp = await this._client._request('GET', `${this._client._apiPath('/prompt-versions')}?agentId=${encodeURIComponent(this.id)}`);
60
+ return resp.data;
61
+ }
62
+ /** Refresh agent status from the API. */
63
+ async refreshStatus() {
64
+ const resp = await this._client._request('GET', this._client._apiPath(`/agents/${this.id}/status-poll`));
65
+ this.status = resp.data?.status ?? this.status;
66
+ return this.status;
67
+ }
68
+ /**
69
+ * Rollback to a specific prompt version.
70
+ *
71
+ * @param versionNumber - The version number to rollback to.
72
+ * @param reason - Required reason for the rollback.
73
+ * @returns The activated PromptVersionData.
74
+ */
75
+ async rollbackToVersion(versionNumber, reason) {
76
+ const versions = await this.listPromptVersions();
77
+ const target = versions.find((v) => v.versionNumber === versionNumber);
78
+ if (!target) {
79
+ throw new Error(`Prompt version ${versionNumber} not found for agent ${this.agentId}`);
80
+ }
81
+ const resp = await this._client._request('POST', this._client._apiPath(`/prompt-versions/${target.id}/rollback`), {
82
+ reason,
83
+ });
84
+ return resp.data;
85
+ }
86
+ /**
87
+ * Promote a staging prompt version to production.
88
+ *
89
+ * @param versionId - The version ID to promote.
90
+ * @param requireApproval - Whether to require admin approval.
91
+ * @param deploymentNotes - Notes for the deployment.
92
+ * @returns The promoted PromptVersionData.
93
+ */
94
+ async promoteToProduction(versionId, opts) {
95
+ const resp = await this._client._request('POST', this._client._apiPath(`/prompt-versions/${versionId}/deploy`), {
96
+ environment: 'production',
97
+ requireApproval: opts?.requireApproval ?? true,
98
+ deploymentNotes: opts?.deploymentNotes ?? null,
99
+ });
100
+ return resp.data;
101
+ }
102
+ /** Return raw agent data. */
103
+ toJSON() {
104
+ return { ...this._data, status: this.status };
105
+ }
106
+ }
107
+ exports.Agent = Agent;
108
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAUH,MAAa,KAAK;IAUhB,YAAY,MAAiB,EAAE,IAAe;QAC5C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,kEAAkE;IAClE,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAAC,IAAyB;QAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,IAAI,EAAE,CAAC;QAC1C,MAAM,OAAO,GAA4B;YACvC,OAAO,EAAE,IAAI,CAAC,EAAE;YAChB,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,aAA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,oBAAoB,SAAS,SAAS,CAAC,EAAE;YAC9G,WAAW,EAAE,YAAY;YACzB,eAAe,EAAE,IAAI,EAAE,eAAe,IAAI,IAAI;YAC9C,eAAe,EAAE,IAAI,EAAE,eAAe,IAAI,IAAI;SAC/C,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,IAAyB,CAAC;IACxC,CAAC;IAED,6BAA6B;IAC7B,MAAM;QACJ,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAqB,EAAE,CAAC;IAC/D,CAAC;CACF;AA5HD,sBA4HC"}
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Execlave SDK — Main client.
3
+ *
4
+ * Provides the Execlave class for agent registration, tracing, and governance.
5
+ * Implements non-blocking trace ingestion with an in-memory circular buffer
6
+ * and a background flush interval.
7
+ */
8
+ import { Agent } from './agent';
9
+ import { Trace } from './trace';
10
+ import type { ExeclaveConfig, RegisterAgentOptions, TraceOptions, TracePayload, EnforcePolicyOptions, EnforceResult, AuthorizeCallOptions, AuthorizeResult, DiscoveredAgent, UsageStatus } from './types';
11
+ /**
12
+ * Main entry point for the Execlave JavaScript SDK.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const ag = new Execlave({ apiKey: 'exe_prod_xxx', environment: 'production' });
17
+ * const agent = await exe.registerAgent({ agentId: 'my-bot', name: 'My Bot' });
18
+ *
19
+ * const trace = exe.startTrace({ agentId: 'my-bot' });
20
+ * trace.setInput(question);
21
+ * const answer = await llm.call(question);
22
+ * trace.setOutput(answer).setModel('gpt-4').setTokens(100, 200);
23
+ * trace.finish();
24
+ *
25
+ * // Before process exit
26
+ * await exe.shutdown();
27
+ * ```
28
+ */
29
+ export declare class Execlave {
30
+ private _apiKey;
31
+ private _baseUrl;
32
+ private _apiVersion;
33
+ private _environment;
34
+ private _asyncMode;
35
+ private _batchSize;
36
+ private _flushIntervalMs;
37
+ private _debug;
38
+ private _enableControlChannel;
39
+ private _pollIntervalMs;
40
+ private _privacy;
41
+ private _enableInjectionScan;
42
+ private _mode;
43
+ private _otlpEndpoint?;
44
+ private _otelExporter;
45
+ private _otelReady;
46
+ private _state;
47
+ private _buffer;
48
+ private _agents;
49
+ private _flushTimer;
50
+ private _pollTimer;
51
+ private _heartbeatTimer;
52
+ private _socket;
53
+ private _cbFailures;
54
+ private _cbThreshold;
55
+ private _cbOpen;
56
+ private _cbOpenAt;
57
+ private _cbResetAfterMs;
58
+ private _cbLastError?;
59
+ private _policyCache;
60
+ private _policyCacheTtlMs;
61
+ private _quotaExceeded;
62
+ private _quotaCacheTtlMs;
63
+ private _enforcementOnOutage;
64
+ private _planLimitBehavior;
65
+ private _heartbeatIntervalMs;
66
+ constructor(config?: ExeclaveConfig);
67
+ /**
68
+ * Build a versioned API path.
69
+ *
70
+ * If `apiVersion` is set (e.g. `'v1'`), returns `/api/v1${path}`.
71
+ * Otherwise falls back to the legacy `/api${path}` format.
72
+ */
73
+ private apiPath;
74
+ /** Check if the Execlave API is reachable. */
75
+ ping(): Promise<boolean>;
76
+ /**
77
+ * Register (or re-register) an AI agent. Idempotent — call on startup.
78
+ *
79
+ * @returns An Agent object with prompt management methods.
80
+ */
81
+ registerAgent(opts: RegisterAgentOptions): Promise<Agent>;
82
+ /**
83
+ * Start a manual trace. Call `trace.finish()` when done.
84
+ *
85
+ * @returns A Trace handle with chainable setters.
86
+ */
87
+ startTrace(opts?: TraceOptions): Trace;
88
+ /**
89
+ * Wrap an async function with automatic tracing.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const tracedAnswer = exe.wrap(async (question: string) => {
94
+ * return await llm.call(question);
95
+ * }, { agentId: 'my-bot' });
96
+ *
97
+ * const answer = await tracedAnswer('Hello?');
98
+ * ```
99
+ */
100
+ wrap<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => Promise<TReturn>, opts?: TraceOptions): (...args: TArgs) => Promise<TReturn>;
101
+ /**
102
+ * Check the current status of a registered agent.
103
+ *
104
+ * @returns 'active', 'paused', or 'error'.
105
+ */
106
+ checkAgentStatus(agentId?: string): Promise<string>;
107
+ /** Flush all buffered traces to the API. */
108
+ flush(): Promise<void>;
109
+ /**
110
+ * Pre-execution policy enforcement.
111
+ *
112
+ * Call this **before** running the LLM to check whether policies allow execution.
113
+ * Throws `PolicyBlockedError` if any policy with `enforcement_mode='block'` is violated.
114
+ * Returns warnings for `warn`-mode violations.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * try {
119
+ * const result = await exe.enforcePolicy({
120
+ * agentId: agent.id,
121
+ * input: userQuestion,
122
+ * tools: ['web_search'],
123
+ * });
124
+ * if (result.warnings?.length) console.warn('Policy warnings:', result.warnings);
125
+ * // Safe to proceed
126
+ * const answer = await llm.call(userQuestion);
127
+ * } catch (err) {
128
+ * if (err instanceof PolicyBlockedError) {
129
+ * return 'Sorry, I cannot process that request.';
130
+ * }
131
+ * }
132
+ * ```
133
+ */
134
+ enforcePolicy(opts: EnforcePolicyOptions): Promise<EnforceResult>;
135
+ private _cbRecordSuccess;
136
+ private _cbRecordFailure;
137
+ private _cbIsOpen;
138
+ private _policyCacheKey;
139
+ private _policyCacheGet;
140
+ private _policyCacheSet;
141
+ private _toInt;
142
+ private _quotaErrorFromBody;
143
+ private _setQuotaExceeded;
144
+ private _getCachedQuotaExceeded;
145
+ private _throwIfQuotaExceeded;
146
+ private _sendHeartbeats;
147
+ private _pollApprovalDecision;
148
+ /**
149
+ * Check if one agent is authorized to call another.
150
+ *
151
+ * @returns Authorization result. Throws `ExeclaveAuthError` on 403.
152
+ */
153
+ authorizeAgentCall(opts: AuthorizeCallOptions): Promise<AuthorizeResult>;
154
+ /**
155
+ * Discover agents by capability.
156
+ *
157
+ * @param capability Optional capability to filter by (e.g. 'send_email').
158
+ * If omitted, returns all agents with capabilities.
159
+ */
160
+ discoverAgents(capability?: string): Promise<DiscoveredAgent[]>;
161
+ /**
162
+ * Return current plan usage and limits.
163
+ */
164
+ checkUsage(): Promise<UsageStatus>;
165
+ /** Flush remaining traces and shut down the SDK. */
166
+ shutdown(): Promise<void>;
167
+ /** @internal */
168
+ _bufferTrace(payload: TracePayload): void;
169
+ /** @internal */
170
+ _apiPath(path: string): string;
171
+ /** @internal */
172
+ _request(method: string, path: string, body?: unknown): Promise<any>;
173
+ private _requestRaw;
174
+ /**
175
+ * Resolve an external agentId string to the internal UUID.
176
+ * The API endpoints like /policies/enforce expect the internal UUID,
177
+ * but users naturally pass the external agentId (e.g. "my-bot").
178
+ * This looks up the cached Agent and returns its UUID (.id).
179
+ * If no match is found, returns the original value unchanged.
180
+ */
181
+ private _resolveAgentId;
182
+ private _doFlush;
183
+ private _statusPoll;
184
+ private _hashPii;
185
+ private _toText;
186
+ private _scrubText;
187
+ private _applyPrivacy;
188
+ private _scanInjection;
189
+ private _firstAgentId;
190
+ private _firstAgent;
191
+ private _ensureNotShutdown;
192
+ private _sleep;
193
+ /**
194
+ * Connect to the Socket.IO /sdk namespace for real-time control channel.
195
+ * Falls back silently to HTTP polling if socket.io-client is not installed.
196
+ */
197
+ private _connectWebSocket;
198
+ private _log;
199
+ private _logError;
200
+ }
201
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAWhC,OAAO,KAAK,EACV,cAAc,EAEd,oBAAoB,EACpB,YAAY,EACZ,YAAY,EAEZ,oBAAoB,EACpB,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,WAAW,EACZ,MAAM,SAAS,CAAC;AAsCjB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,WAAW,CAAqB;IACxC,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