@compilr-dev/sdk 0.7.12 → 0.7.14

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.
Files changed (2) hide show
  1. package/dist/agent.js +20 -8
  2. package/package.json +2 -2
package/dist/agent.js CHANGED
@@ -86,6 +86,8 @@ class CompilrAgentImpl {
86
86
  agent;
87
87
  abortController;
88
88
  totalUsage = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
89
+ /** External event listener set during run()/stream() — receives ALL agent events including usage */
90
+ externalEventListener;
89
91
  /** Meta-tools fallback handler (set when capabilities.enabled) */
90
92
  _metaToolsFallback;
91
93
  constructor(config) {
@@ -257,13 +259,16 @@ class CompilrAgentImpl {
257
259
  includeDefaults: guardrailsConfig.includeDefaults,
258
260
  },
259
261
  delegation: config?.delegation,
262
+ usage: { enabled: true },
260
263
  onEvent: (event) => {
261
- // Track usage from events
264
+ // Track usage internally
262
265
  if (event.type === 'usage_recorded') {
263
266
  this.totalUsage.inputTokens += event.tokens.inputTokens;
264
267
  this.totalUsage.outputTokens += event.tokens.outputTokens;
265
268
  this.totalUsage.totalTokens += event.tokens.inputTokens + event.tokens.outputTokens;
266
269
  }
270
+ // Forward ALL events to external listener (if set via run/stream)
271
+ this.externalEventListener?.(event);
267
272
  },
268
273
  });
269
274
  // Register tools
@@ -274,13 +279,20 @@ class CompilrAgentImpl {
274
279
  }
275
280
  }
276
281
  async run(message, options) {
277
- const result = await this.agent.run(message, {
278
- signal: options?.signal ?? this.abortController.signal,
279
- maxIterations: options?.maxIterations,
280
- onEvent: options?.onEvent,
281
- toolFilter: options?.toolFilter,
282
- });
283
- return toRunResult(result);
282
+ // Set external listener so constructor's onEvent can forward events
283
+ this.externalEventListener = options?.onEvent;
284
+ try {
285
+ const result = await this.agent.run(message, {
286
+ signal: options?.signal ?? this.abortController.signal,
287
+ maxIterations: options?.maxIterations,
288
+ onEvent: options?.onEvent,
289
+ toolFilter: options?.toolFilter,
290
+ });
291
+ return toRunResult(result);
292
+ }
293
+ finally {
294
+ this.externalEventListener = undefined;
295
+ }
284
296
  }
285
297
  async *stream(message, options) {
286
298
  const events = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilr-dev/sdk",
3
- "version": "0.7.12",
3
+ "version": "0.7.14",
4
4
  "description": "Universal agent runtime for building AI-powered applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "devDependencies": {
70
70
  "@anthropic-ai/sdk": "^0.78.0",
71
- "@compilr-dev/agents": "^0.3.27",
71
+ "@compilr-dev/agents": "^0.3.28",
72
72
  "@compilr-dev/agents-coding": "^1.0.2",
73
73
  "@eslint/js": "^9.39.1",
74
74
  "@opentelemetry/api": "^1.9.0",