@vellumai/assistant 0.9.0-dev.202606181324.0804a69 → 0.9.0-dev.202606181513.fd39213
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/node_modules/@vellumai/gateway-client/src/admission-policy-contract.ts +4 -9
- package/package.json +1 -1
- package/src/__tests__/cancel-clears-processing.test.ts +22 -19
- package/src/__tests__/conversation-agent-loop.test.ts +48 -41
- package/src/__tests__/media-stream-server-integration.test.ts +317 -13
- package/src/__tests__/relay-server.test.ts +285 -0
- package/src/__tests__/twilio-routes.test.ts +81 -1
- package/src/calls/__tests__/channel-admission-reader.test.ts +132 -0
- package/src/calls/__tests__/relay-setup-router.test.ts +350 -0
- package/src/calls/channel-admission-reader.ts +104 -0
- package/src/calls/media-stream-server.ts +84 -2
- package/src/calls/relay-server.ts +66 -0
- package/src/calls/relay-setup-router.ts +77 -0
- package/src/calls/twilio-routes.ts +17 -8
- package/src/daemon/conversation-agent-loop.ts +122 -56
- package/src/daemon/conversation.ts +7 -0
- package/src/daemon/handlers/conversations.ts +6 -8
- package/src/runtime/routes/inbound-stages/admission-policy.test.ts +4 -2
- package/src/telemetry/usage-telemetry-reporter.test.ts +59 -13
- package/src/telemetry/usage-telemetry-reporter.ts +28 -16
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests for UsageTelemetryReporter.
|
|
3
3
|
*
|
|
4
|
-
* Covers
|
|
5
|
-
*
|
|
4
|
+
* Covers the authenticated send path (and the skip behavior when credentials
|
|
5
|
+
* are absent or the platform is disabled), watermark advancement, error
|
|
6
|
+
* handling, batch recursion, device ID resolution, and payload shape.
|
|
6
7
|
*/
|
|
7
8
|
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
8
9
|
|
|
@@ -303,7 +304,8 @@ beforeEach(() => {
|
|
|
303
304
|
getDb().delete(authFallbackEvents).run();
|
|
304
305
|
getDb().delete(toolInvocations).run();
|
|
305
306
|
getDb().delete(skillLoadedEvents).run();
|
|
306
|
-
|
|
307
|
+
delete process.env.VELLUM_DISABLE_PLATFORM;
|
|
308
|
+
delete process.env.IS_PLATFORM;
|
|
307
309
|
mockGetPlatformBaseUrl.mockReset();
|
|
308
310
|
mockGetDeviceId.mockReset();
|
|
309
311
|
mockGetDeviceId.mockReturnValue("test-device-id");
|
|
@@ -320,10 +322,23 @@ beforeEach(() => {
|
|
|
320
322
|
Promise.resolve(new Response('{"accepted":0}', { status: 200 })),
|
|
321
323
|
);
|
|
322
324
|
globalThis.fetch = mockFetch as unknown as typeof fetch;
|
|
325
|
+
|
|
326
|
+
// Default to an authenticated client whose fetch delegates to the mockFetch
|
|
327
|
+
// spy, so the existing payload/body assertions keep working. The reporter
|
|
328
|
+
// sends authenticated-only; tests that exercise the no-credentials path
|
|
329
|
+
// override this with `mockPlatformClient = null`.
|
|
330
|
+
mockPlatformClient = {
|
|
331
|
+
baseUrl: "https://test.vellum.ai",
|
|
332
|
+
assistantApiKey: "test-key",
|
|
333
|
+
platformAssistantId: "asst-123",
|
|
334
|
+
fetch: (path: string, init?: RequestInit) => mockFetch(path, init),
|
|
335
|
+
};
|
|
323
336
|
});
|
|
324
337
|
|
|
325
338
|
afterEach(() => {
|
|
326
339
|
globalThis.fetch = originalFetch;
|
|
340
|
+
delete process.env.VELLUM_DISABLE_PLATFORM;
|
|
341
|
+
delete process.env.IS_PLATFORM;
|
|
327
342
|
});
|
|
328
343
|
|
|
329
344
|
// ---------------------------------------------------------------------------
|
|
@@ -354,26 +369,57 @@ describe("UsageTelemetryReporter", () => {
|
|
|
354
369
|
expect(mockFetch).not.toHaveBeenCalled();
|
|
355
370
|
});
|
|
356
371
|
|
|
357
|
-
test("
|
|
372
|
+
test("flush is skipped when no platform credentials are available", async () => {
|
|
373
|
+
// Authenticated-only: with no client, nothing is sent and the watermark is
|
|
374
|
+
// left intact so the backlog ships once credentials resolve.
|
|
358
375
|
mockPlatformClient = null;
|
|
359
|
-
mockGetPlatformBaseUrl.mockReturnValue("https://platform.test.ai");
|
|
360
376
|
|
|
361
377
|
const events = [makeUsageEvent()];
|
|
362
378
|
mockQueryUnreportedUsageEvents.mockReturnValue(events);
|
|
363
|
-
|
|
364
|
-
|
|
379
|
+
|
|
380
|
+
const reporter = new UsageTelemetryReporter();
|
|
381
|
+
await reporter.flush();
|
|
382
|
+
|
|
383
|
+
expect(mockFetch).not.toHaveBeenCalled();
|
|
384
|
+
const watermarkCalls = mockSetMemoryCheckpoint.mock.calls.filter(
|
|
385
|
+
(c) => c[0] === "telemetry:usage:last_reported_at",
|
|
365
386
|
);
|
|
387
|
+
expect(watermarkCalls.length).toBe(0);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
test("flush is skipped when VELLUM_DISABLE_PLATFORM is set in local mode", async () => {
|
|
391
|
+
// The platform-disabled toggle suppresses the send. Unlike the opt-out
|
|
392
|
+
// branch, watermarks are NOT advanced, so the backlog ships once the flag
|
|
393
|
+
// is cleared.
|
|
394
|
+
process.env.VELLUM_DISABLE_PLATFORM = "true";
|
|
395
|
+
|
|
396
|
+
const events = [makeUsageEvent()];
|
|
397
|
+
mockQueryUnreportedUsageEvents.mockReturnValue(events);
|
|
398
|
+
|
|
399
|
+
const reporter = new UsageTelemetryReporter();
|
|
400
|
+
// Construction initializes the absent tool_executed watermark; clear that
|
|
401
|
+
// call so the assertion below covers only the flush.
|
|
402
|
+
mockSetMemoryCheckpoint.mockClear();
|
|
403
|
+
await reporter.flush();
|
|
404
|
+
|
|
405
|
+
expect(mockFetch).not.toHaveBeenCalled();
|
|
406
|
+
expect(mockSetMemoryCheckpoint).not.toHaveBeenCalled();
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test("VELLUM_DISABLE_PLATFORM is ignored when IS_PLATFORM is set (managed mode)", async () => {
|
|
410
|
+
// Platform-managed assistants always connect to the platform; an inherited
|
|
411
|
+
// VELLUM_DISABLE_PLATFORM must not suppress telemetry for them (matches
|
|
412
|
+
// arePlatformFeaturesEnabled / VellumPlatformClient.create()).
|
|
413
|
+
process.env.IS_PLATFORM = "true";
|
|
414
|
+
process.env.VELLUM_DISABLE_PLATFORM = "true";
|
|
415
|
+
|
|
416
|
+
const events = [makeUsageEvent()];
|
|
417
|
+
mockQueryUnreportedUsageEvents.mockReturnValue(events);
|
|
366
418
|
|
|
367
419
|
const reporter = new UsageTelemetryReporter();
|
|
368
420
|
await reporter.flush();
|
|
369
421
|
|
|
370
422
|
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
371
|
-
const [url, opts] = mockFetch.mock.calls[0] as [string, RequestInit];
|
|
372
|
-
expect(url).toStartWith("https://platform.test.ai");
|
|
373
|
-
expect(url).toEndWith("/telemetry/ingest/");
|
|
374
|
-
const headers = opts.headers as Record<string, string>;
|
|
375
|
-
expect(headers["Content-Type"]).toBe("application/json");
|
|
376
|
-
expect(headers["X-Telemetry-Token"]).toBeUndefined();
|
|
377
423
|
});
|
|
378
424
|
|
|
379
425
|
test("watermark advances on successful upload", async () => {
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* Periodically flushes LLM usage events and turn events (user messages) from
|
|
5
5
|
* the local SQLite database and POSTs them to the platform telemetry endpoint.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Authenticated-only: events are sent via the managed proxy context
|
|
8
|
+
* (Api-Key header). When no platform credentials are available, or when
|
|
9
|
+
* platform features are disabled (VELLUM_DISABLE_PLATFORM in local mode), the
|
|
10
|
+
* flush is skipped and retried next cycle.
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
import {
|
|
13
|
-
getPlatformBaseUrl,
|
|
14
14
|
getPlatformOrganizationId,
|
|
15
15
|
getPlatformUserId,
|
|
16
16
|
} from "../config/env.js";
|
|
@@ -27,6 +27,7 @@ import { queryUnreportedSkillLoadedEvents } from "../memory/skill-loaded-events-
|
|
|
27
27
|
import { queryUnreportedToolExecutedEvents } from "../memory/tool-executed-events-store.js";
|
|
28
28
|
import { queryUnreportedTurnEvents } from "../memory/turn-events-store.js";
|
|
29
29
|
import { VellumPlatformClient } from "../platform/client.js";
|
|
30
|
+
import { arePlatformFeaturesEnabled } from "../platform/feature-gate.js";
|
|
30
31
|
import type { UsageAttributionProfileSource } from "../usage/types.js";
|
|
31
32
|
import { getDeviceId } from "../util/device-id.js";
|
|
32
33
|
import { getLogger } from "../util/logger.js";
|
|
@@ -162,7 +163,8 @@ export class UsageTelemetryReporter {
|
|
|
162
163
|
// Delay the first flush to allow the credential infrastructure (CES
|
|
163
164
|
// handshake) to complete. Without this delay, VellumPlatformClient.create()
|
|
164
165
|
// returns null because the credential backend hasn't resolved yet, causing
|
|
165
|
-
//
|
|
166
|
+
// the initial flush to be skipped (we send authenticated-only); the
|
|
167
|
+
// delay lets credentials resolve so the first flush can actually ship.
|
|
166
168
|
this.initialFlushTimer = setTimeout(() => {
|
|
167
169
|
this.initialFlushTimer = null;
|
|
168
170
|
this.flush().catch((err) => {
|
|
@@ -237,6 +239,15 @@ export class UsageTelemetryReporter {
|
|
|
237
239
|
return;
|
|
238
240
|
}
|
|
239
241
|
|
|
242
|
+
// Skip when platform features are disabled (VELLUM_DISABLE_PLATFORM in
|
|
243
|
+
// local mode; the flag is ignored when IS_PLATFORM is set, matching
|
|
244
|
+
// VellumPlatformClient.create()). Unlike the opt-out branch above,
|
|
245
|
+
// watermarks are NOT advanced: this is a deployment/local-mode toggle
|
|
246
|
+
// (not a privacy opt-out), so the unsent backlog ships once it's cleared.
|
|
247
|
+
if (!arePlatformFeaturesEnabled()) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
240
251
|
// Read usage watermark (compound cursor: createdAt + id)
|
|
241
252
|
const watermark = Number(
|
|
242
253
|
getMemoryCheckpoint(CHECKPOINT_KEY_WATERMARK) ?? "0",
|
|
@@ -343,12 +354,19 @@ export class UsageTelemetryReporter {
|
|
|
343
354
|
)
|
|
344
355
|
return;
|
|
345
356
|
|
|
346
|
-
// Resolve auth context
|
|
347
|
-
//
|
|
357
|
+
// Resolve auth context. We send authenticated-only: if no platform
|
|
358
|
+
// credentials are available yet, skip without advancing watermarks so the
|
|
359
|
+
// backlog ships on a later cycle once credentials resolve.
|
|
348
360
|
const client = await VellumPlatformClient.create();
|
|
361
|
+
if (!client) {
|
|
362
|
+
log.debug(
|
|
363
|
+
{ pendingEventCount: events.length + turnEvents.length },
|
|
364
|
+
"Telemetry flush: no platform credentials — skipping, will retry next cycle",
|
|
365
|
+
);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
349
368
|
log.debug(
|
|
350
369
|
{
|
|
351
|
-
authenticated: !!client,
|
|
352
370
|
usageCount: events.length,
|
|
353
371
|
turnCount: turnEvents.length,
|
|
354
372
|
lifecycleCount: lifecycleEvents.length,
|
|
@@ -588,18 +606,12 @@ export class UsageTelemetryReporter {
|
|
|
588
606
|
body: JSON.stringify(payload),
|
|
589
607
|
};
|
|
590
608
|
|
|
591
|
-
|
|
592
|
-
if (client) {
|
|
593
|
-
resp = await client.fetch(TELEMETRY_PATH, fetchInit);
|
|
594
|
-
} else {
|
|
595
|
-
const url = `${getPlatformBaseUrl()}${TELEMETRY_PATH}`;
|
|
596
|
-
resp = await fetch(url, fetchInit);
|
|
597
|
-
}
|
|
609
|
+
const resp = await client.fetch(TELEMETRY_PATH, fetchInit);
|
|
598
610
|
|
|
599
611
|
if (!resp.ok) {
|
|
600
612
|
const body = await resp.text();
|
|
601
613
|
log.warn(
|
|
602
|
-
{ status: resp.status,
|
|
614
|
+
{ status: resp.status, body },
|
|
603
615
|
"Usage telemetry POST failed — will retry next cycle",
|
|
604
616
|
);
|
|
605
617
|
return;
|