@voltro/ai 0.83.0 → 0.83.1

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.
@@ -1,4 +1,4 @@
1
- import { c as e, o as t, r as n } from "./provider-BsyDya-H.js";
1
+ import { c as e, o as t, r as n } from "./provider-BnemgE4D.js";
2
2
  import { NoObjectGeneratedError as r, Output as i, experimental_transcribe as a, generateObject as o, generateText as s, jsonSchema as c, stepCountIs as l, tool as u, wrapLanguageModel as d } from "ai";
3
3
  import { Context as f, Data as p, Effect as m, JSONSchema as h, Metric as g, MetricBoundaries as ee, Runtime as te, Schema as _, Stream as ne } from "effect";
4
4
  import { and as v, bigint as re, eq as y, generateId as b, gte as ie, id as x, integer as S, isNull as ae, json as C, queryFor as w, registerRetention as oe, retentionTtlMsFromEnv as se, table as T, text as E, timestamp as D } from "@voltro/database";
@@ -376,18 +376,24 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
376
376
  receiptKey: E().maxLength(191).backfill((e) => `aiu-pre-receipt-${String(e.id)}`),
377
377
  calledAt: D().default("now")
378
378
  }).index(["tenantId"]).index(["promptDigest"]).unique("byAiUsageReceipt", ["receiptKey"]), Re = (e) => {
379
- let t = e?.gateway?.cost, n = typeof t == "string" ? t.trim() : void 0, r = typeof t == "number" ? t : n !== void 0 && /^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(n) ? Number(n) : NaN;
380
- return Number.isFinite(r) && r >= 0 ? r : void 0;
381
- }, ze = class extends p.TaggedError("AiUsageReceiptConflict") {
379
+ let t = typeof e == "string" ? e.trim() : void 0, n = typeof e == "number" ? e : t !== void 0 && /^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(t) ? Number(t) : NaN;
380
+ return Number.isFinite(n) && n >= 0 ? n : void 0;
381
+ }, ze = (e) => {
382
+ let t = e?.gateway, n = Re(t?.cost);
383
+ if (n === void 0) return;
384
+ if ((Array.isArray(t?.providerAttempts) ? t.providerAttempts : []).findLast((e) => e?.success === !0)?.credentialType !== "byok") return n;
385
+ let r = Re(t?.marketCost);
386
+ return r === void 0 ? void 0 : n + r;
387
+ }, Be = class extends p.TaggedError("AiUsageReceiptConflict") {
382
388
  get message() {
383
389
  let e = Object.keys(this.recorded).filter((e) => this.recorded[e] !== this.attempted[e]).map((e) => `${e} ${String(this.recorded[e])} → ${String(this.attempted[e])}`);
384
390
  return `AI usage receipt ${this.receiptKey} was recorded again with different values (${e.join(", ")}). A replay of the same paid call has the same values; the row keeps what was recorded first.`;
385
391
  }
386
- }, Be = class extends p.TaggedError("AiUsageLedgerError") {
392
+ }, Ve = class extends p.TaggedError("AiUsageLedgerError") {
387
393
  get message() {
388
394
  return `AI usage receipt ${this.receiptKey} could not be written: ${this.cause instanceof Error ? this.cause.message : String(this.cause)}`;
389
395
  }
390
- }, Ve = (e) => ({
396
+ }, He = (e) => ({
391
397
  tenantId: e.tenantId ?? null,
392
398
  provider: String(e.provider),
393
399
  model: String(e.model),
@@ -395,7 +401,7 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
395
401
  inputTokens: Number(e.inputTokens),
396
402
  outputTokens: Number(e.outputTokens),
397
403
  costMicroUsd: Number(e.costMicroUsd)
398
- }), He = (e, t) => (oe({
404
+ }), Ue = (e, t) => (oe({
399
405
  source: "plugin",
400
406
  table: B,
401
407
  timeColumn: "calledAt",
@@ -428,7 +434,7 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
428
434
  calledAt: t.calledAt ?? /* @__PURE__ */ new Date()
429
435
  }, a = yield* m.tryPromise({
430
436
  try: () => e.insertIgnoreWithOutcome(B, i, { conflictColumns: ["receiptKey"] }),
431
- catch: (e) => new Be({
437
+ catch: (e) => new Ve({
432
438
  receiptKey: String(r),
433
439
  cause: e
434
440
  })
@@ -437,16 +443,16 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
437
443
  ...n,
438
444
  receipt: "recorded"
439
445
  };
440
- let o = Ve(a.row), s = Ve(i);
441
- return Object.keys(o).some((e) => o[e] !== s[e]) ? yield* m.fail(new ze({
446
+ let o = He(a.row), s = He(i);
447
+ return Object.keys(o).some((e) => o[e] !== s[e]) ? yield* m.fail(new Be({
442
448
  receiptKey: String(r),
443
449
  recorded: o,
444
450
  attempted: s
445
451
  })) : {
446
- ...Ue(a.row, n),
452
+ ...We(a.row, n),
447
453
  receipt: "replayed"
448
454
  };
449
- })), Ue = (e, t) => {
455
+ })), We = (e, t) => {
450
456
  let n = Number(e.costMicroUsd) / 1e6;
451
457
  return {
452
458
  ...t,
@@ -455,7 +461,7 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
455
461
  totalCostUsd: n,
456
462
  costSource: e.costSource ?? t.costSource
457
463
  };
458
- }, We = (e, t) => He(e, t).pipe(m.asVoid, m.catchAllCause((e) => m.logError("AI usage NOT booked as recorded — the call itself succeeded and was returned", e).pipe(m.annotateLogs({
464
+ }, Ge = (e, t) => Ue(e, t).pipe(m.asVoid, m.catchAllCause((e) => m.logError("AI usage NOT booked as recorded — the call itself succeeded and was returned", e).pipe(m.annotateLogs({
459
465
  scope: "voltro:ai:usage",
460
466
  provider: t.provider,
461
467
  model: t.model,
@@ -473,55 +479,55 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
473
479
  attempt: t.attempt ?? 0
474
480
  },
475
481
  ...t.actualCostUsd === void 0 ? {} : { actualCostUsd: t.actualCostUsd }
476
- })))), Ge = (e, t = {}) => m.promise(async () => {
482
+ })))), Ke = (e, t = {}) => m.promise(async () => {
477
483
  let n = [
478
484
  ...t.tenantId === void 0 ? [] : [y("tenantId", t.tenantId)],
479
485
  ...t.since === void 0 ? [] : [ie("calledAt", t.since)],
480
486
  ...t.promptDigest === void 0 ? [] : [y("promptDigest", t.promptDigest)]
481
487
  ], r = w(Le), i = n.length === 0 ? r : r.where(n.length === 1 ? n[0] : v(...n));
482
488
  return (await e.query(i.descriptor)).reduce((e, t) => e + (Number(t.costMicroUsd) || 0), 0) / 1e6;
483
- }), Ke = ee.exponential({
489
+ }), qe = ee.exponential({
484
490
  start: .001,
485
491
  factor: 2,
486
492
  count: 16
487
- }), V = g.counter("voltro_ai_calls_total", { description: "Total AI provider calls (generate + stream)." }), qe = g.counter("voltro_ai_call_errors_total", { description: "AI provider calls that errored." }), H = g.histogram("voltro_ai_call_duration_seconds", Ke, "AI provider call duration in seconds."), Je = g.counter("voltro_ai_input_tokens_total", {
493
+ }), V = g.counter("voltro_ai_calls_total", { description: "Total AI provider calls (generate + stream)." }), Je = g.counter("voltro_ai_call_errors_total", { description: "AI provider calls that errored." }), H = g.histogram("voltro_ai_call_duration_seconds", qe, "AI provider call duration in seconds."), Ye = g.counter("voltro_ai_input_tokens_total", {
488
494
  description: "Total prompt (input) tokens across AI calls.",
489
495
  incremental: !0
490
- }), Ye = g.counter("voltro_ai_output_tokens_total", {
496
+ }), Xe = g.counter("voltro_ai_output_tokens_total", {
491
497
  description: "Total completion (output) tokens across AI calls.",
492
498
  incremental: !0
493
- }), Xe = g.counter("voltro_ai_cost_microusd_total", {
499
+ }), Ze = g.counter("voltro_ai_cost_microusd_total", {
494
500
  description: "Total estimated AI spend in micro-USD (USD × 1e6).",
495
501
  incremental: !0
496
502
  }), U = (e, t) => ({
497
503
  provider: e.name,
498
504
  model: e.model ?? e.name,
499
505
  operation: t
500
- }), W = (e, t, n) => e.pipe(m.tagMetrics("provider", t.provider), m.tagMetrics("model", t.model), m.tagMetrics("operation", t.operation), m.tagMetrics("status", n)), Ze = (e, t) => {
506
+ }), W = (e, t, n) => e.pipe(m.tagMetrics("provider", t.provider), m.tagMetrics("model", t.model), m.tagMetrics("operation", t.operation), m.tagMetrics("status", n)), Qe = (e, t) => {
501
507
  let n = t.inputTokens ?? 0, r = t.outputTokens ?? 0, i = z({
502
508
  inputTokens: n,
503
509
  outputTokens: r
504
510
  }, { model: e.model }), a = Math.round(i.totalCostUsd * 1e6);
505
511
  return m.all([
506
- W(g.incrementBy(Je, n), e, "ok"),
507
- W(g.incrementBy(Ye, r), e, "ok"),
508
- W(g.incrementBy(Xe, a), e, "ok")
512
+ W(g.incrementBy(Ye, n), e, "ok"),
513
+ W(g.incrementBy(Xe, r), e, "ok"),
514
+ W(g.incrementBy(Ze, a), e, "ok")
509
515
  ], { discard: !0 });
510
516
  }, G = (e, t, n) => m.gen(function* () {
511
517
  let r = yield* m.clockWith((e) => e.currentTimeMillis);
512
- return yield* n.pipe(m.tap((n) => Ze(e, t(n))), m.tap(() => W(g.increment(V), e, "ok").pipe(m.zipRight(m.clockWith((e) => e.currentTimeMillis).pipe(m.flatMap((t) => W(g.update(H, (t - r) / 1e3), e, "ok")))))), m.tapError(() => W(g.increment(V), e, "error").pipe(m.zipRight(W(g.increment(qe), e, "error")), m.zipRight(m.clockWith((e) => e.currentTimeMillis).pipe(m.flatMap((t) => W(g.update(H, (t - r) / 1e3), e, "error")))))), m.withSpan("voltro.ai.call", { attributes: {
518
+ return yield* n.pipe(m.tap((n) => Qe(e, t(n))), m.tap(() => W(g.increment(V), e, "ok").pipe(m.zipRight(m.clockWith((e) => e.currentTimeMillis).pipe(m.flatMap((t) => W(g.update(H, (t - r) / 1e3), e, "ok")))))), m.tapError(() => W(g.increment(V), e, "error").pipe(m.zipRight(W(g.increment(Je), e, "error")), m.zipRight(m.clockWith((e) => e.currentTimeMillis).pipe(m.flatMap((t) => W(g.update(H, (t - r) / 1e3), e, "error")))))), m.withSpan("voltro.ai.call", { attributes: {
513
519
  "ai.provider": e.provider,
514
520
  "ai.model": e.model,
515
521
  "ai.operation": e.operation
516
522
  } }));
517
- }), Qe = (e, t) => {
523
+ }), $e = (e, t) => {
518
524
  let n = Date.now();
519
- return t.pipe(ne.tap((t) => t._tag === "done" ? W(g.increment(V), e, "ok").pipe(m.zipRight(W(g.update(H, (Date.now() - n) / 1e3), e, "ok")), m.zipRight(Ze(e, t.usage ?? {}))) : t._tag === "error" ? W(g.increment(V), e, "error").pipe(m.zipRight(W(g.increment(qe), e, "error")), m.zipRight(W(g.update(H, (Date.now() - n) / 1e3), e, "error"))) : m.void), ne.withSpan("voltro.ai.call", { attributes: {
525
+ return t.pipe(ne.tap((t) => t._tag === "done" ? W(g.increment(V), e, "ok").pipe(m.zipRight(W(g.update(H, (Date.now() - n) / 1e3), e, "ok")), m.zipRight(Qe(e, t.usage ?? {}))) : t._tag === "error" ? W(g.increment(V), e, "error").pipe(m.zipRight(W(g.increment(Je), e, "error")), m.zipRight(W(g.update(H, (Date.now() - n) / 1e3), e, "error"))) : m.void), ne.withSpan("voltro.ai.call", { attributes: {
520
526
  "ai.provider": e.provider,
521
527
  "ai.model": e.model,
522
528
  "ai.operation": e.operation
523
529
  } }));
524
- }, $e = (e) => {
530
+ }, et = (e) => {
525
531
  let t = structuredClone(e), n = {
526
532
  strict: !0,
527
533
  strictTypes: !1,
@@ -539,13 +545,13 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
539
545
  success: !1,
540
546
  error: /* @__PURE__ */ Error("model output does not satisfy the declared JSON Schema")
541
547
  } });
542
- }, et = _.Number.pipe(_.int(), _.nonNegative(), _.lessThanOrEqualTo(2 ** 53 - 1)), tt = _.Struct({
548
+ }, tt = _.Number.pipe(_.int(), _.nonNegative(), _.lessThanOrEqualTo(2 ** 53 - 1)), nt = _.Struct({
543
549
  provider: _.String,
544
550
  model: _.String,
545
551
  usage: _.Struct({
546
- inputTokens: _.optional(et),
547
- outputTokens: _.optional(et),
548
- totalTokens: _.optional(et),
552
+ inputTokens: _.optional(tt),
553
+ outputTokens: _.optional(tt),
554
+ totalTokens: _.optional(tt),
549
555
  completeness: _.Literal("complete", "partial", "unknown")
550
556
  }),
551
557
  cost: _.Union(_.Struct({
@@ -556,12 +562,12 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
556
562
  status: _.Literal("unknown"),
557
563
  source: _.Literal("unreported")
558
564
  }))
559
- }), nt = (e) => typeof e == "number" && Number.isSafeInteger(e) && e >= 0 ? e : void 0, K = (e, t, n, r) => {
560
- let i = typeof n == "object" && n ? n : {}, a = nt("inputTokens" in i ? i.inputTokens : void 0), o = nt("outputTokens" in i ? i.outputTokens : void 0), s = nt("totalTokens" in i ? i.totalTokens : void 0), c = [
565
+ }), rt = (e) => typeof e == "number" && Number.isSafeInteger(e) && e >= 0 ? e : void 0, K = (e, t, n, r) => {
566
+ let i = typeof n == "object" && n ? n : {}, a = rt("inputTokens" in i ? i.inputTokens : void 0), o = rt("outputTokens" in i ? i.outputTokens : void 0), s = rt("totalTokens" in i ? i.totalTokens : void 0), c = [
561
567
  a,
562
568
  o,
563
569
  s
564
- ].filter((e) => e !== void 0).length, l = Re(r);
570
+ ].filter((e) => e !== void 0).length, l = ze(r);
565
571
  return {
566
572
  provider: e,
567
573
  model: t,
@@ -580,7 +586,7 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
580
586
  usd: l
581
587
  }
582
588
  };
583
- }, rt = (e, t) => {
589
+ }, it = (e, t) => {
584
590
  let n = [];
585
591
  return {
586
592
  model: d({
@@ -625,9 +631,9 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
625
631
  }, q = class extends _.TaggedError()("AiError", {
626
632
  reason: _.Literal("generation", "decode"),
627
633
  message: _.String,
628
- evidence: _.optional(tt)
634
+ evidence: _.optional(nt)
629
635
  }) {}, J = (e, t = {}) => {
630
- let n = String(e?.message ?? e), r = it(e), i = new q({
636
+ let n = String(e?.message ?? e), r = at(e), i = new q({
631
637
  reason: "generation",
632
638
  message: `${t.prefix === void 0 ? "" : `${t.prefix}: `}${n}${r.length > 0 ? ` (${r.join(" <- ")})` : ""}`,
633
639
  ...t.evidence === void 0 ? {} : { evidence: t.evidence }
@@ -638,17 +644,17 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
638
644
  configurable: !0,
639
645
  writable: !0
640
646
  }), i;
641
- }, it = (e) => {
647
+ }, at = (e) => {
642
648
  let t = [], n = e;
643
649
  for (let e = 0; e < 8 && typeof n == "object" && n; e++) {
644
650
  let e = n;
645
651
  typeof e.code == "string" && e.code.length > 0 && !t.includes(e.code) && t.push(e.code), n = typeof e.lastError == "object" && e.lastError !== null ? e.lastError : e.cause;
646
652
  }
647
653
  return t;
648
- }, at = (e, t, n) => {
654
+ }, ot = (e, t, n) => {
649
655
  let r = [e, ...t ?? []], i = (e) => n(r[e]).pipe(m.catchTag("AiError", (t) => t.reason === "generation" && e + 1 < r.length ? i(e + 1) : m.fail(t)));
650
656
  return i(0);
651
- }, ot = (e) => m.gen(function* () {
657
+ }, st = (e) => m.gen(function* () {
652
658
  let r = e.messages === void 0 ? e.prompt === void 0 ? void 0 : { prompt: e.prompt } : { messages: [...e.messages] };
653
659
  if (r === void 0 || e.prompt !== void 0 && e.messages !== void 0) return yield* m.fail(new q({
654
660
  reason: "generation",
@@ -660,7 +666,7 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
660
666
  ...e.abortSignal === void 0 ? {} : { abortSignal: e.abortSignal },
661
667
  runtime: i
662
668
  });
663
- return yield* at(e.provider ?? n(), e.fallbacks, (n) => G(U(n, "generateText"), (e) => e.usage, m.tryPromise({
669
+ return yield* ot(e.provider ?? n(), e.fallbacks, (n) => G(U(n, "generateText"), (e) => e.usage, m.tryPromise({
664
670
  try: async () => {
665
671
  let i = t(n), o = await s({
666
672
  model: i,
@@ -688,7 +694,7 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
688
694
  },
689
695
  catch: (e) => J(e)
690
696
  })));
691
- }), st = (e, t) => m.gen(function* () {
697
+ }), ct = (e, t) => m.gen(function* () {
692
698
  let n = h.make(e);
693
699
  if (n?.type !== "object") {
694
700
  let e = n?.anyOf === void 0 ? `type:${JSON.stringify(n?.type ?? null)}` : "anyOf (e.g. Schema.Struct({}) or a union)";
@@ -698,14 +704,14 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
698
704
  }));
699
705
  }
700
706
  return n;
701
- }), ct = (e, t) => st(e, t), lt = (e) => at(e.provider ?? n(), e.fallbacks, (n) => G(U(n, "generateObject"), (e) => e.usage, m.gen(function* () {
707
+ }), lt = (e, t) => ct(e, t), ut = (e) => ot(e.provider ?? n(), e.fallbacks, (n) => G(U(n, "generateObject"), (e) => e.usage, m.gen(function* () {
702
708
  let i = yield* m.try({
703
- try: () => $e(e.jsonSchema),
709
+ try: () => et(e.jsonSchema),
704
710
  catch: () => new q({
705
711
  reason: "decode",
706
712
  message: "generateObjectJson: invalid or unsupported output JSON Schema; no provider call was made"
707
713
  })
708
- }), a = rt(n.name, t(n)), s = a.model, c = yield* m.tryPromise({
714
+ }), a = it(n.name, t(n)), s = a.model, c = yield* m.tryPromise({
709
715
  try: () => o({
710
716
  model: s,
711
717
  schema: i,
@@ -734,9 +740,9 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
734
740
  },
735
741
  providerMetadata: c.providerMetadata
736
742
  };
737
- }))), ut = (e) => m.gen(function* () {
738
- let t = yield* lt({
739
- jsonSchema: yield* st(e.schema, "generateObject"),
743
+ }))), dt = (e) => m.gen(function* () {
744
+ let t = yield* ut({
745
+ jsonSchema: yield* ct(e.schema, "generateObject"),
740
746
  prompt: e.prompt,
741
747
  ...e.system === void 0 ? {} : { system: e.system },
742
748
  ...e.provider === void 0 ? {} : { provider: e.provider },
@@ -753,15 +759,15 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
753
759
  ...t,
754
760
  object: n
755
761
  };
756
- }), dt = (e) => m.gen(function* () {
757
- let a = yield* m.runtime(), o = yield* st(e.schema, "generateObjectWithTools"), u = {
762
+ }), ft = (e) => m.gen(function* () {
763
+ let a = yield* m.runtime(), o = yield* ct(e.schema, "generateObjectWithTools"), u = {
758
764
  store: void 0,
759
765
  ...e.toolContext,
760
766
  ...e.abortSignal === void 0 ? {} : { abortSignal: e.abortSignal },
761
767
  runtime: a
762
768
  }, d = O(e.tools, u);
763
- return yield* at(e.provider ?? n(), e.fallbacks, (n) => G(U(n, "generateObjectWithTools"), (e) => e.usage, m.gen(function* () {
764
- let a = rt(n.name, t(n)), u = a.model, f = yield* m.tryPromise({
769
+ return yield* ot(e.provider ?? n(), e.fallbacks, (n) => G(U(n, "generateObjectWithTools"), (e) => e.usage, m.gen(function* () {
770
+ let a = it(n.name, t(n)), u = a.model, f = yield* m.tryPromise({
765
771
  try: () => s({
766
772
  model: u,
767
773
  prompt: e.prompt,
@@ -805,10 +811,10 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
805
811
  providerMetadata: f.providerMetadata
806
812
  };
807
813
  })));
808
- }), ft = class extends f.Tag("@voltro/AiService")() {}, pt = {
809
- generateText: (e) => ot(e),
810
- generateObject: (e) => ut(e)
811
- }, mt = async (e, t) => {
814
+ }), pt = class extends f.Tag("@voltro/AiService")() {}, mt = {
815
+ generateText: (e) => st(e),
816
+ generateObject: (e) => dt(e)
817
+ }, ht = async (e, t) => {
812
818
  if ("bytes" in e) return {
813
819
  audio: e.bytes,
814
820
  mediaType: e.mediaType
@@ -828,7 +834,7 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
828
834
  audio: n,
829
835
  mediaType: r
830
836
  };
831
- }, ht = (e) => {
837
+ }, gt = (e) => {
832
838
  if (!Array.isArray(e) || e.length === 0) return;
833
839
  let t = [];
834
840
  for (let n of e) {
@@ -843,16 +849,16 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
843
849
  });
844
850
  }
845
851
  return t.length > 0 ? t : void 0;
846
- }, gt = (t) => {
852
+ }, _t = (t) => {
847
853
  let r = t.provider ?? n();
848
854
  return G(U(r, "transcribe"), () => ({}), m.tryPromise({
849
855
  try: async () => {
850
- let { audio: n, mediaType: i } = await mt(t.source, t.resolveRef), o = await a({
856
+ let { audio: n, mediaType: i } = await ht(t.source, t.resolveRef), o = await a({
851
857
  model: e(r),
852
858
  audio: n,
853
859
  ...i === void 0 ? {} : { mediaType: i },
854
860
  ...t.providerOptions === void 0 ? {} : { providerOptions: t.providerOptions }
855
- }), s = t.timestamps === "none" ? void 0 : ht(o.segments);
861
+ }), s = t.timestamps === "none" ? void 0 : gt(o.segments);
856
862
  return {
857
863
  text: o.text,
858
864
  ...o.language === void 0 ? {} : { language: o.language },
@@ -863,31 +869,31 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
863
869
  },
864
870
  catch: (e) => J(e)
865
871
  }));
866
- }, _t = (e) => `sha256:${fe("sha256").update(e).digest("hex").slice(0, 16)}`, vt = class extends _.TaggedError()("PromptRenderError", {
872
+ }, vt = (e) => `sha256:${fe("sha256").update(e).digest("hex").slice(0, 16)}`, yt = class extends _.TaggedError()("PromptRenderError", {
867
873
  promptId: _.String,
868
874
  missing: _.Array(_.String),
869
875
  message: _.String
870
- }) {}, yt = /\{\{\s*([A-Za-z0-9_.]+)\s*\}\}/g, bt = (e) => {
876
+ }) {}, bt = /\{\{\s*([A-Za-z0-9_.]+)\s*\}\}/g, xt = (e) => {
871
877
  let t = /* @__PURE__ */ new Set();
872
- for (let n of e.matchAll(yt)) {
878
+ for (let n of e.matchAll(bt)) {
873
879
  let e = n[1];
874
880
  e !== void 0 && t.add(e);
875
881
  }
876
882
  return [...t];
877
- }, xt = (e, t) => _t(`${e.length}:${e}${(t ?? "").length}:${t ?? ""}`), St = (e) => {
878
- let t = xt(e.template, e.system), n = bt(e.template);
883
+ }, St = (e, t) => vt(`${e.length}:${e}${(t ?? "").length}:${t ?? ""}`), Ct = (e) => {
884
+ let t = St(e.template, e.system), n = xt(e.template);
879
885
  return {
880
886
  ...e,
881
887
  digest: t,
882
888
  variables: n,
883
889
  render: (r = {}) => m.suspend(() => {
884
890
  let i = n.filter((e) => r[e] === void 0);
885
- if (i.length > 0) return m.fail(new vt({
891
+ if (i.length > 0) return m.fail(new yt({
886
892
  promptId: e.id,
887
893
  missing: i,
888
894
  message: `prompt '${e.id}' needs ${i.map((e) => `{{${e}}}`).join(", ")}, which ${i.length === 1 ? "was" : "were"} not supplied.`
889
895
  }));
890
- let a = e.template.replace(yt, (e, t) => String(r[t]));
896
+ let a = e.template.replace(bt, (e, t) => String(r[t]));
891
897
  return m.succeed({
892
898
  promptId: e.id,
893
899
  digest: t,
@@ -898,7 +904,7 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
898
904
  });
899
905
  })
900
906
  };
901
- }, Ct = (e) => typeof e == "object" && !!e && typeof e.prompt == "string" && typeof e.digest == "string" && typeof e.promptId == "string", Y = "_voltro_prompts", X = T(Y, {
907
+ }, wt = (e) => typeof e == "object" && !!e && typeof e.prompt == "string" && typeof e.digest == "string" && typeof e.promptId == "string", Y = "_voltro_prompts", X = T(Y, {
902
908
  id: x({ prefix: "prm" }),
903
909
  promptId: E().maxLength(191),
904
910
  digest: E().maxLength(191),
@@ -909,12 +915,12 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
909
915
  templateChars: S().default(0),
910
916
  firstSeenAt: D().default("now"),
911
917
  lastUsedAt: D().default("now")
912
- }).unique("byPromptsVersion", ["promptId", "digest"]).index(["promptId"]), wt = 8760, Tt = () => {
918
+ }).unique("byPromptsVersion", ["promptId", "digest"]).index(["promptId"]), Tt = 8760, Et = () => {
913
919
  oe({
914
920
  source: "framework",
915
921
  table: Y,
916
922
  timeColumn: "lastUsedAt",
917
- ttlMs: se(process.env.VOLTRO_AI_PROMPTS_TTL_HOURS, wt),
923
+ ttlMs: se(process.env.VOLTRO_AI_PROMPTS_TTL_HOURS, Tt),
918
924
  envVar: "VOLTRO_AI_PROMPTS_TTL_HOURS",
919
925
  label: "ai prompt versions"
920
926
  });
@@ -927,9 +933,9 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
927
933
  system: e.system ?? null,
928
934
  firstSeenAt: e.firstSeenAt ?? null,
929
935
  lastUsedAt: e.lastUsedAt ?? null
930
- }), Et = (e, t) => m.gen(function* () {
931
- Tt();
932
- let n = t.digest ?? St(t).digest;
936
+ }), Dt = (e, t) => m.gen(function* () {
937
+ Et();
938
+ let n = t.digest ?? Ct(t).digest;
933
939
  return yield* m.promise(async () => {
934
940
  let r = (await e.query(w(X).where(v(y("promptId", t.id), y("digest", n))).descriptor))[0];
935
941
  if (r !== void 0) {
@@ -956,10 +962,10 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
956
962
  };
957
963
  return Z(await e.insertIgnore(Y, o, { conflictColumns: ["promptId", "digest"] }) ?? o);
958
964
  });
959
- }), Dt = (e, t) => m.promise(async () => {
965
+ }), Ot = (e, t) => m.promise(async () => {
960
966
  let n = (await e.query(w(X).where(y("digest", t)).descriptor))[0];
961
967
  return n === void 0 ? null : Z(n);
962
- }), Ot = (e, t) => m.promise(async () => [...await e.query(w(X).where(y("promptId", t)).orderBy("revision", "desc").descriptor)].sort((e, t) => (Number(t.revision) || 0) - (Number(e.revision) || 0)).map(Z)), kt = "_voltro_ai_inferences", At = T(kt, {
968
+ }), kt = (e, t) => m.promise(async () => [...await e.query(w(X).where(y("promptId", t)).orderBy("revision", "desc").descriptor)].sort((e, t) => (Number(t.revision) || 0) - (Number(e.revision) || 0)).map(Z)), At = "_voltro_ai_inferences", jt = T(At, {
963
969
  id: x({ prefix: "aiinf" }),
964
970
  tenantId: E().nullable(),
965
971
  executionId: E(),
@@ -1004,17 +1010,17 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
1004
1010
  startedAt: D().nullable(),
1005
1011
  completedAt: D().nullable(),
1006
1012
  durationMs: S().nullable()
1007
- }).index(["status", "enqueuedAt"]).index(["status", "leaseUntil"]).index(["executionId"]).index(["tenantId"]), jt = 3e5, Mt = 4, Q = (e, t) => {
1013
+ }).index(["status", "enqueuedAt"]).index(["status", "leaseUntil"]).index(["executionId"]).index(["tenantId"]), Mt = 3e5, Nt = 4, Q = (e, t) => {
1008
1014
  let n = typeof e == "number" ? e : Number(e);
1009
1015
  return Number.isFinite(n) ? Math.trunc(n) : t;
1010
- }, $ = (e) => e == null ? null : String(e), Nt = (e) => {
1016
+ }, $ = (e) => e == null ? null : String(e), Pt = (e) => {
1011
1017
  if (e instanceof Date) return e;
1012
1018
  if (typeof e == "string" || typeof e == "number") {
1013
1019
  let t = new Date(e);
1014
1020
  return Number.isNaN(t.getTime()) ? null : t;
1015
1021
  }
1016
1022
  return null;
1017
- }, Pt = (e) => ({
1023
+ }, Ft = (e) => ({
1018
1024
  id: String(e.id),
1019
1025
  tenantId: $(e.tenantId),
1020
1026
  executionId: String(e.executionId),
@@ -1036,10 +1042,10 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
1036
1042
  transcription: e.transcription ?? null,
1037
1043
  media: e.media ?? null,
1038
1044
  taskHandle: typeof e.taskHandle == "object" ? e.taskHandle : null,
1039
- taskSubmittedAt: Nt(e.taskSubmittedAt),
1045
+ taskSubmittedAt: Pt(e.taskSubmittedAt),
1040
1046
  attempts: Q(e.attempts, 0),
1041
1047
  fence: Q(e.fence, 0)
1042
- }), Ft = (e) => {
1048
+ }), It = (e) => {
1043
1049
  let t = e.attempts + 1;
1044
1050
  return t >= e.maxAttempts ? {
1045
1051
  kind: "give-up",
@@ -1049,6 +1055,6 @@ var pe = (e, t) => e(t), me = Symbol.for("@voltro/ai/Tool"), he = (e) => ({
1049
1055
  attempts: t,
1050
1056
  delayMs: e.retryAfterMs !== void 0 && e.retryAfterMs > 0 ? e.retryAfterMs : Math.min(e.baseDelayMs * 2 ** (t - 1), e.maxDelayMs)
1051
1057
  };
1052
- }, It = (e) => `voltro.ai.infer:${e}`, Lt = (e, t) => `aiinf_${fe("sha256").update(`${e}\u0000${t}`).digest("hex").slice(0, 40)}`;
1058
+ }, Lt = (e) => `voltro.ai.infer:${e}`, Rt = (e, t) => `aiinf_${fe("sha256").update(`${e}\u0000${t}`).digest("hex").slice(0, 40)}`;
1053
1059
  //#endregion
1054
- export { j as $, tt as A, z as B, J as C, dt as D, lt as E, Be as F, Fe as G, R as H, ze as I, Ne as J, He as K, Me as L, Qe as M, G as N, ot as O, B as P, A as Q, Ge as R, ft as S, ut as T, Pe as U, Re as V, Ie as W, M as X, N as Y, k as Z, Ot as _, Ft as a, he as at, gt as b, Pt as c, vt as d, Ce as et, St as f, xt as g, Dt as h, At as i, O as it, U as j, ct as k, wt as l, _t as m, Mt as n, je as nt, It as o, ge as ot, Ct as p, We as q, jt as r, Ae as rt, Lt as s, _e as st, kt as t, P as tt, Y as u, X as v, pt as w, q as x, Et as y, Le as z };
1060
+ export { j as $, nt as A, z as B, J as C, ft as D, ut as E, Ve as F, Fe as G, R as H, Be as I, Ne as J, Ue as K, Me as L, $e as M, G as N, st as O, B as P, A as Q, Ke as R, pt as S, dt as T, Pe as U, ze as V, Ie as W, M as X, N as Y, k as Z, kt as _, It as a, he as at, _t as b, Ft as c, yt as d, Ce as et, Ct as f, St as g, Ot as h, jt as i, O as it, U as j, lt as k, Tt as l, vt as m, Nt as n, je as nt, Lt as o, ge as ot, wt as p, Ge as q, Mt as r, Ae as rt, Rt as s, _e as st, At as t, P as tt, Y as u, X as v, mt as w, q as x, Dt as y, Le as z };