@absolutejs/voice 0.0.22-beta.415 → 0.0.22-beta.417

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/dist/index.d.ts CHANGED
@@ -206,6 +206,6 @@ export type { PlivoInboundMessage, PlivoMediaStreamBridge, PlivoMediaStreamBridg
206
206
  export type { VoiceTelephonyCarrierMatrix, VoiceTelephonyCarrierMatrixEntry, VoiceTelephonyCarrierMatrixInput, VoiceTelephonyCarrierMatrixOptions, VoiceTelephonyCarrierMatrixRoutesOptions, VoiceTelephonyCarrierMatrixStatus } from './telephony/matrix';
207
207
  export { shapeTelephonyAssistantText } from './telephony/response';
208
208
  export type { TelephonyResponseShapeMode, TelephonyResponseShapeOptions } from './telephony/response';
209
- export { buildVoiceProofPack, buildVoiceProofPackFromObservabilityExport, createVoiceProofPackStaleWhileRefreshSource, createVoiceProofPackArtifacts, createVoiceProofPackOperationsRecordSection, createVoiceProofPackProductionReadinessSection, createVoiceProofPackProviderSloSection, createVoiceProofPackRoutes, createVoiceProofPackSupportBundleSection, renderVoiceProofPackMarkdown, writeVoiceProofPack } from './proofPack';
210
- export type { VoiceProofPack, VoiceProofPackEvidence, VoiceProofPackInput, VoiceProofPackRoutesOptions, VoiceProofPackSection, VoiceProofPackSourceValue, VoiceProofPackStatus, VoiceProofPackStaleWhileRefreshSourceOptions, VoiceProofPackWriteResult } from './proofPack';
209
+ export { buildVoiceProofPack, buildVoiceProofPackFromObservabilityExport, createVoiceProofPackBuildContext, createVoiceProofPackStaleWhileRefreshSource, createVoiceProofPackArtifacts, createVoiceProofPackOperationsRecordSection, createVoiceProofPackProductionReadinessSection, createVoiceProofPackProviderSloSection, createVoiceProofPackRoutes, createVoiceProofPackSupportBundleSection, renderVoiceProofPackMarkdown, writeVoiceProofPack } from './proofPack';
210
+ export type { VoiceProofPack, VoiceProofPackBuildContext, VoiceProofPackBuildContextOptions, VoiceProofPackBuildTiming, VoiceProofPackEvidence, VoiceProofPackInput, VoiceProofPackRefreshState, VoiceProofPackRefreshStatus, VoiceProofPackRoutesOptions, VoiceProofPackSection, VoiceProofPackSourceValue, VoiceProofPackStatus, VoiceProofPackStaleWhileRefreshSource, VoiceProofPackStaleWhileRefreshSourceOptions, VoiceProofPackWriteResult } from './proofPack';
211
211
  export * from './types';
package/dist/index.js CHANGED
@@ -39952,10 +39952,15 @@ import { Elysia as Elysia66 } from "elysia";
39952
39952
  import { mkdir as mkdir5 } from "fs/promises";
39953
39953
  import { dirname as dirname3, join as join4 } from "path";
39954
39954
  var toGeneratedAt = (value) => value === undefined ? new Date().toISOString() : typeof value === "number" ? new Date(value).toISOString() : value;
39955
- var getProofPackGeneratedAtMs = (proofPack) => {
39956
- const generatedAt = buildVoiceProofPack(proofPack).generatedAt;
39955
+ var getProofPackMetadata = (proofPack) => {
39956
+ const built = buildVoiceProofPack(proofPack);
39957
+ const generatedAt = built.generatedAt;
39957
39958
  const generatedAtMs = Date.parse(generatedAt);
39958
- return Number.isFinite(generatedAtMs) ? generatedAtMs : 0;
39959
+ return {
39960
+ generatedAt,
39961
+ generatedAtMs: Number.isFinite(generatedAtMs) ? generatedAtMs : 0,
39962
+ runId: built.runId
39963
+ };
39959
39964
  };
39960
39965
  var summarizeProofPackSections = (sections) => {
39961
39966
  let pass = 0;
@@ -39976,6 +39981,48 @@ var summarizeProofPackSections = (sections) => {
39976
39981
  }
39977
39982
  return { fail, pass, sections: sections.length, warn };
39978
39983
  };
39984
+ var createVoiceProofPackBuildContext = (options = {}) => {
39985
+ const now = options.now ?? Date.now;
39986
+ const cachedValues = new Map;
39987
+ const timings = [];
39988
+ const time = async (label, run) => {
39989
+ const startedAt = now();
39990
+ try {
39991
+ return await run();
39992
+ } finally {
39993
+ const endedAt = now();
39994
+ const timing = {
39995
+ durationMs: Math.max(0, endedAt - startedAt),
39996
+ endedAt,
39997
+ label,
39998
+ startedAt
39999
+ };
40000
+ timings.push(timing);
40001
+ options.onTiming?.(timing);
40002
+ }
40003
+ };
40004
+ const cache = (key, loader) => {
40005
+ const cached = cachedValues.get(key);
40006
+ if (cached) {
40007
+ return cached;
40008
+ }
40009
+ const value = Promise.resolve(loader());
40010
+ cachedValues.set(key, value);
40011
+ return value;
40012
+ };
40013
+ return {
40014
+ cache,
40015
+ clear: (key) => {
40016
+ if (key === undefined) {
40017
+ cachedValues.clear();
40018
+ return;
40019
+ }
40020
+ cachedValues.delete(key);
40021
+ },
40022
+ getTimings: () => [...timings],
40023
+ time
40024
+ };
40025
+ };
39979
40026
  var toProofPackStatus = (status) => {
39980
40027
  if (status === "fail" || status === "failed") {
39981
40028
  return "fail";
@@ -40172,29 +40219,93 @@ var createVoiceProofPackStaleWhileRefreshSource = (options) => {
40172
40219
  const maxAgeMs = options.maxAgeMs ?? 5 * 60000;
40173
40220
  const now = options.now ?? Date.now;
40174
40221
  let refreshPromise;
40222
+ let status = {
40223
+ maxAgeMs,
40224
+ refreshing: false,
40225
+ state: "missing"
40226
+ };
40227
+ const updateStatusFromProofPack = (proofPack, refreshing = Boolean(refreshPromise)) => {
40228
+ const metadata = getProofPackMetadata(proofPack);
40229
+ const ageMs = Math.max(0, now() - metadata.generatedAtMs);
40230
+ status = {
40231
+ ageMs,
40232
+ generatedAt: metadata.generatedAt,
40233
+ lastRefreshCompletedAt: status.lastRefreshCompletedAt,
40234
+ lastRefreshStartedAt: status.lastRefreshStartedAt,
40235
+ maxAgeMs,
40236
+ refreshing,
40237
+ runId: metadata.runId,
40238
+ state: refreshing ? "refreshing" : ageMs <= maxAgeMs ? "fresh" : "stale"
40239
+ };
40240
+ return { ageMs, metadata };
40241
+ };
40175
40242
  const refresh = async () => {
40176
40243
  const refreshed = await options.refresh();
40177
- return refreshed ?? options.read();
40244
+ const proofPack = refreshed ?? await options.read();
40245
+ updateStatusFromProofPack(proofPack, false);
40246
+ status = {
40247
+ ...status,
40248
+ lastRefreshCompletedAt: now(),
40249
+ lastRefreshStartedAt: status.lastRefreshStartedAt,
40250
+ refreshing: false,
40251
+ state: "fresh"
40252
+ };
40253
+ return proofPack;
40178
40254
  };
40179
40255
  const startRefresh = () => {
40256
+ if (!refreshPromise) {
40257
+ status = {
40258
+ ...status,
40259
+ lastRefreshStartedAt: now(),
40260
+ refreshing: true,
40261
+ state: "refreshing"
40262
+ };
40263
+ }
40180
40264
  refreshPromise ??= refresh().finally(() => {
40181
40265
  refreshPromise = undefined;
40182
40266
  });
40183
40267
  return refreshPromise;
40184
40268
  };
40185
- return async () => {
40269
+ const source = async () => {
40186
40270
  let current;
40187
40271
  try {
40188
40272
  current = await options.read();
40189
- } catch {
40190
- return startRefresh();
40273
+ } catch (error) {
40274
+ status = {
40275
+ ...status,
40276
+ error: error instanceof Error ? error.message : String(error),
40277
+ refreshing: Boolean(refreshPromise),
40278
+ state: refreshPromise ? "refreshing" : "missing"
40279
+ };
40280
+ return startRefresh().catch((refreshError) => {
40281
+ status = {
40282
+ ...status,
40283
+ error: refreshError instanceof Error ? refreshError.message : String(refreshError),
40284
+ lastRefreshCompletedAt: now(),
40285
+ refreshing: false,
40286
+ state: "failed"
40287
+ };
40288
+ throw refreshError;
40289
+ });
40191
40290
  }
40192
- if (now() - getProofPackGeneratedAtMs(current) <= maxAgeMs) {
40291
+ const { ageMs } = updateStatusFromProofPack(current);
40292
+ if (ageMs <= maxAgeMs) {
40193
40293
  return current;
40194
40294
  }
40195
- startRefresh().catch((error) => options.onRefreshError?.(error));
40295
+ startRefresh().catch((error) => {
40296
+ status = {
40297
+ ...status,
40298
+ error: error instanceof Error ? error.message : String(error),
40299
+ lastRefreshCompletedAt: now(),
40300
+ refreshing: false,
40301
+ state: "failed"
40302
+ };
40303
+ options.onRefreshError?.(error);
40304
+ });
40196
40305
  return current;
40197
40306
  };
40307
+ source.getStatus = () => status;
40308
+ return source;
40198
40309
  };
40199
40310
  var buildVoiceProofPackFromObservabilityExport = (report, input = {}) => buildVoiceProofPack({
40200
40311
  ...input,
@@ -40763,6 +40874,7 @@ export {
40763
40874
  createVoiceProofPackProviderSloSection,
40764
40875
  createVoiceProofPackProductionReadinessSection,
40765
40876
  createVoiceProofPackOperationsRecordSection,
40877
+ createVoiceProofPackBuildContext,
40766
40878
  createVoiceProofPackArtifacts,
40767
40879
  createVoiceProofAssertion,
40768
40880
  createVoiceProfileTraceTagger,
@@ -53,6 +53,22 @@ export type VoiceProofPackWriteResult = {
53
53
  markdownPath: string;
54
54
  proofPack: VoiceProofPack;
55
55
  };
56
+ export type VoiceProofPackBuildTiming = {
57
+ durationMs: number;
58
+ endedAt: number;
59
+ label: string;
60
+ startedAt: number;
61
+ };
62
+ export type VoiceProofPackBuildContext = {
63
+ cache: <TValue>(key: string, loader: () => Promise<TValue> | TValue) => Promise<TValue>;
64
+ clear: (key?: string) => void;
65
+ getTimings: () => VoiceProofPackBuildTiming[];
66
+ time: <TValue>(label: string, run: () => Promise<TValue> | TValue) => Promise<TValue>;
67
+ };
68
+ export type VoiceProofPackBuildContextOptions = {
69
+ now?: () => number;
70
+ onTiming?: (timing: VoiceProofPackBuildTiming) => void;
71
+ };
56
72
  export type VoiceProofPackSourceValue = VoiceProofPack | VoiceProofPackInput;
57
73
  export type VoiceProofPackStaleWhileRefreshSourceOptions = {
58
74
  maxAgeMs?: number;
@@ -61,6 +77,21 @@ export type VoiceProofPackStaleWhileRefreshSourceOptions = {
61
77
  read: () => VoiceProofPackSourceValue | Promise<VoiceProofPackSourceValue>;
62
78
  refresh: () => VoiceProofPackSourceValue | void | Promise<VoiceProofPackSourceValue | void>;
63
79
  };
80
+ export type VoiceProofPackRefreshState = 'failed' | 'fresh' | 'missing' | 'refreshing' | 'stale';
81
+ export type VoiceProofPackRefreshStatus = {
82
+ ageMs?: number;
83
+ error?: string;
84
+ generatedAt?: string;
85
+ lastRefreshCompletedAt?: number;
86
+ lastRefreshStartedAt?: number;
87
+ maxAgeMs: number;
88
+ refreshing: boolean;
89
+ runId?: string;
90
+ state: VoiceProofPackRefreshState;
91
+ };
92
+ export type VoiceProofPackStaleWhileRefreshSource = ((...args: []) => Promise<VoiceProofPackSourceValue>) & {
93
+ getStatus: () => VoiceProofPackRefreshStatus;
94
+ };
64
95
  export type VoiceProofPackRoutesOptions = {
65
96
  headers?: HeadersInit;
66
97
  jsonPath?: false | string;
@@ -68,6 +99,7 @@ export type VoiceProofPackRoutesOptions = {
68
99
  name?: string;
69
100
  source: VoiceProofPackSourceValue | (() => VoiceProofPackSourceValue | Promise<VoiceProofPackSourceValue>);
70
101
  };
102
+ export declare const createVoiceProofPackBuildContext: (options?: VoiceProofPackBuildContextOptions) => VoiceProofPackBuildContext;
71
103
  export declare const createVoiceProofPackProviderSloSection: (report: VoiceProviderSloReport, options?: {
72
104
  href?: string;
73
105
  title?: string;
@@ -85,7 +117,7 @@ export declare const createVoiceProofPackSupportBundleSection: (input: {
85
117
  title?: string;
86
118
  }) => VoiceProofPackSection;
87
119
  export declare const buildVoiceProofPack: (input: VoiceProofPackInput | VoiceProofPack) => VoiceProofPack;
88
- export declare const createVoiceProofPackStaleWhileRefreshSource: (options: VoiceProofPackStaleWhileRefreshSourceOptions) => () => Promise<VoiceProofPackSourceValue>;
120
+ export declare const createVoiceProofPackStaleWhileRefreshSource: (options: VoiceProofPackStaleWhileRefreshSourceOptions) => VoiceProofPackStaleWhileRefreshSource;
89
121
  export declare const buildVoiceProofPackFromObservabilityExport: (report: VoiceObservabilityExportReport, input?: Omit<VoiceProofPackInput, "artifacts" | "sections">) => VoiceProofPack;
90
122
  export declare const renderVoiceProofPackMarkdown: (proofPack: VoiceProofPack) => string;
91
123
  export declare const writeVoiceProofPack: (input: VoiceProofPackInput | VoiceProofPack, options?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.415",
3
+ "version": "0.0.22-beta.417",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",