clanka 0.8.5 → 0.8.6

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,14 +1,14 @@
1
- import { $r as exitHasInterrupts, Aa as getOption, An as NoSuchElementError, Ar as into, At as request$1, B as fn, Bi as fromIterable, Br as isSuccess, Bt as serviceOption, C as catchTags, Ci as succeed$1, Ct as orElseSucceed, D as contextWith, Da as add, Dr as done, Ds as dual, Dt as provideService, E as context, Ea as Service, Et as provideContext, Fi as empty, Fr as fail$1, Fs as pipeArguments, Go as byReferenceUnsafe, Gt as sync, Ha as flatten, Hi as isArrayNonEmpty, Hn as hasInterruptsOnly, Hr as void_$3, Ht as succeed, I as filterOrFail, Ia as merge, Ir as failCause, Ji as map$2, Ko as equals, Kt as tap, L as flatMap, Lt as scope, Ms as pipe, Mt as retry, N as fail, Na as getUnsafe, Nr as makeUnsafe$2, Nt as runFork, O as delay, Oi as updateContext, Or as doneUnsafe, Os as flow, Pa as make$8, Pt as runForkWith, Q as interrupt, Qa as isSome, Qi as sort, Qr as endSpan, Rn as filterInterruptors, Rt as scoped, S as catchTag, Sa as toMillis, So as PipeInspectableProto, Sr as provide, St as orDie, Ta as Reference, Tr as TracerTimingEnabled, U as forEach, Ur as ClockRef, V as fnUntraced, Vr as succeed$2, W as forever, Wa as fromNullishOr, Wt as suspend, X as gen, Xa as isNone, Xo as hash, Xt as tryPromise, Yr as contextWith$1, Z as ignore, Zt as try_, _a as millis, _i as makeSpanUnsafe, _t as onError, a as andThen, ao as some, b as catchNoSuchElement, bi as onExit$1, bn as spaced, br as make$7, c as as, ci as fiberJoin, cn as withLogSpan, cs as isNotNull, di as forkUnsafe, dr as provideMerge, en as uninterruptibleMask, eo as map$1, es as symbol$1, et as isEffect, fa as fromInputUnsafe, g as catchDefect, ga as isZero, gr as addFinalizer, ha as isFinite, ho as make$9, hr as Scope, i as all, ii as fiberInterrupt, in as void_$1, it as logInfo, ja as getOrUndefined, ji as ParentSpan, jo as assignProperty, k as die, ka as get$1, ki as void_$2, ko as withFiber$1, ks as identity, lo as Number$1, m as catchCause, mt as matchCauseEffect, n as acquireUseRelease, no as none, nr as effectContext, o as annotateCurrentSpan, ot as makeSpanScoped, pa as infinity, pn as Class$1, pt as matchCauseEager, q as forkScoped, qo as symbol, qt as tapCause, rn as useSpan, rr as effectDiscard, s as annotateLogs, sn as withFiber, st as map, t as acquireRelease, to as match, tr as effect, ts as hasProperty, tt as logDebug, u as asVoid, un as withSpan, ur as provide$1, ut as mapError, va as minutes, vr as close, vt as onExit, w as catch_, wa as zero, ws as constUndefined, xa as seconds, y as catchIf, yo as Prototype, yt as onExitPrimitive, za as filter, zi as flatMapNullishOr, zr as isFailure } from "./Effect-BEUn4I5E.mjs";
2
- import { $ as tap$1, B as provideService$1, Ft as interruptAs, H as runCollect, It as join$1, Lt as runIn, T as fromQueue, U as runDrain, bt as offerUnsafe, c as die$1, ct as make$11, g as flatMap$1, gt as make$10, ht as failCauseUnsafe, lt as makeUnsafe$3, tt as unwrap, v as fromArray, y as fromArrayEffect } from "./Stream-Cu6P7ZHo.mjs";
3
- import { A as OptionFromNullOr, Cn as transform, D as NullOr, Dt as mutable, F as String$1, Ft as toType, Gn as monotonicTimeNanos, I as Struct$2, In as formatIsoDate, It as withConstructorDefault, J as Union$2, O as Number$2, Ot as optional, Rn as now, S as Natural, St as isSchema, Wn as Clock, Yn as TaggedError$1, Z as brand, _n as transform$1, bn as dateTimeUtcFromInput, c as DateTimeUtcFromDate, d as Defect, i as BooleanFromBit, k as Option, kt as optionalKey, l as DateTimeUtcFromMillis, n as ArraySchema, nt as decodeTo, o as Class$2, ot as encodeEffect, r as Boolean, rt as decodeUnknownEffect, s as DateTimeUtc, u as DateTimeUtcFromString, ut as instanceOf, xn as map$3, yn as transformOptional, z as TaggedError, zn as removeTime, zt as evolve } from "./Schema-CjUGw2Xh.mjs";
4
- import { C as set, D as toPredicate, E as has, S as remove, T as compose, _ as empty$1, a as makeGrouped, b as isEmpty, c as SemanticSearch, d as map$4, f as make$13, g as FileSystem, h as Path, i as batchN, l as maybeRemoveFile, m as Console, n as EmbeddingModel, o as setDelay, p as ChildProcessSpawner, r as EmbeddingRequest, s as withSpan$1, t as Dimensions, u as maybeUpdateFile, v as forEach$1, w as size, x as make$12, y as get$2 } from "./cli.mjs";
1
+ import { $a as getOrUndefined, $n as fromReasons, An as spaced, Ar as Scope, At as request$1, B as fn, Ba as minutes, Br as TracerTimingEnabled, Bt as serviceOption, C as catchTags, Cn as size, Co as match, Ct as orElseSucceed, D as contextWith, Di as forkUnsafe, Do as some, Ds as symbol$1, Dt as provideService, E as context, Er as provideMerge, Et as provideContext, Fr as make$7, Fs as isNotNull, Gi as void_$2, Gr as into, Gt as sync, Hr as done, Ht as succeed, I as filterOrFail, Ia as isFinite, Ja as Service, Jr as makeUnsafe$2, Ka as zero, Kn as combine, Kt as tap, L as flatMap, La as isZero, Li as onExitUnsafe, Lo as make$10, Lr as provide, Lt as scope, Mt as retry, N as fail, Na as fromInputUnsafe, Ni as makeSpanUnsafe, Nr as close, Nt as runFork, O as delay, Os as hasProperty, P as failCause$1, Pa as infinity, Pt as runForkWith, Q as interrupt, Qa as getOption, Qr as failCause, Rt as scoped, S as catchTag, Sn as set, So as map$1, St as orDie, Tr as provide$1, U as forEach$1, Ua as seconds, Ur as doneUnsafe, V as fnUntraced, Vn as NoSuchElementError, Vo as Prototype, W as forever, Wa as toMillis, Wi as updateContext, Wo as PipeInspectableProto, Wt as suspend, X as gen, Xi as has, Xn as filterInterruptors, Xt as tryPromise, Ya as add, Yi as compose, Z as ignore, Za as get$1, Zi as toPredicate, Zr as fail$1, Zs as constUndefined, Zt as try_, _n as forEach, _r as effectContext, _s as equals, _t as onError, a as andThen, aa as flatMapNullishOr, ac as pipe, ai as ClockRef, ar as isFailReason, b as catchNoSuchElement, bi as fiberInterrupt, bn as make$8, bo as isSome, c as as, ca as isArrayNonEmpty, cc as pipeArguments, cn as withLogSpan, cr as makeDieReason, di as contextWith$1, ec as dual, en as uninterruptibleMask, es as withFiber$1, et as isEffect, fo as fromNullishOr, g as catchDefect, gn as empty$1, gr as effect, gs as byReferenceUnsafe, hi as exitHasInterrupts, i as all, ii as void_$3, in as void_$1, io as merge, it as logInfo, jo as Number$1, jr as addFinalizer, k as die, m as catchCause, ma as map$2, mi as endSpan, mn as Class$1, mt as matchCauseEffect, n as acquireUseRelease, nc as identity, ni as isSuccess, no as make$9, ns as assignProperty, o as annotateCurrentSpan, oa as fromIterable, ot as makeSpanScoped, pr as reasonAnnotations, pt as matchCauseEager, q as forkScoped, qa as Reference, qi as ParentSpan, qt as tapCause, ri as succeed$2, rn as useSpan, s as annotateLogs, sn as withFiber, so as filter, st as map, t as acquireRelease, ta as empty, tc as flow, ti as isFailure, to as getUnsafe, tr as hasInterruptsOnly, tt as logDebug, u as asVoid, un as withSpan, uo as flatten, ut as mapError, va as sort, vn as get$2, vo as isNone, vr as effectDiscard, vs as symbol, vt as onExit, w as catch_, wi as fiberJoin, wo as none, xn as remove, xs as hash, y as catchIf, yn as isEmpty, yt as onExitPrimitive, za as millis, zi as succeed$1 } from "./Effect-rADALOOD.mjs";
2
+ import { $ as tap$1, B as provideService$1, Ft as interruptAs, H as runCollect, It as join$1, Lt as runIn, T as fromQueue, U as runDrain, bt as offerUnsafe, c as die$1, ct as make$12, g as flatMap$1, gt as make$11, ht as failCauseUnsafe, lt as makeUnsafe$3, tt as unwrap, v as fromArray, y as fromArrayEffect } from "./Stream-CSLA1_GD.mjs";
3
+ import { A as Option, At as optionalKey, B as TaggedError, Bn as now, C as Natural, Cn as map$3, I as String$1, Kn as Clock, L as Struct$2, Lt as toType, O as NullOr, Ot as mutable, Q as brand, Rn as formatIsoDate, Rt as withConstructorDefault, Sn as dateTimeUtcFromInput, Tn as transform, Vn as removeTime, Vt as evolve, Y as Union$2, Zn as TaggedError$1, c as DateTimeUtcFromDate, d as Defect, dt as instanceOf, i as BooleanFromBit, it as decodeUnknownEffect, j as OptionFromNullOr, k as Number$2, kt as optional, l as DateTimeUtcFromMillis, n as ArraySchema, o as Class$2, qn as monotonicTimeNanos, r as Boolean, rt as decodeTo, s as DateTimeUtc, st as encodeEffect, u as DateTimeUtcFromString, wt as isSchema, xn as transformOptional, yn as transform$1 } from "./Schema-C7NXAOWA.mjs";
4
+ import { a as makeGrouped, c as SemanticSearch, d as map$4, f as make$13, g as FileSystem, h as Path, i as batchN, l as maybeRemoveFile, m as Console, n as EmbeddingModel, o as setDelay, p as ChildProcessSpawner, r as EmbeddingRequest, s as withSpan$1, t as Dimensions, u as maybeUpdateFile } from "./cli.mjs";
5
5
  import { createHash } from "node:crypto";
6
6
  import { DatabaseSync, backup } from "node:sqlite";
7
7
  import TreeSitter from "tree-sitter";
8
8
  import TreeSitterJavaScript from "tree-sitter-javascript";
9
9
  import TreeSitterTypeScript from "tree-sitter-typescript";
10
10
  import { getLoadablePath } from "sqlite-vec";
11
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/reactivity/Reactivity.js
11
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/reactivity/Reactivity.js
12
12
  const TypeId$6 = "~effect/reactivity/Reactivity";
13
13
  const Reactivity = Service("effect/reactivity/Reactivity");
14
14
  const make$6 = sync(() => {
@@ -52,7 +52,7 @@ const make$6 = sync(() => {
52
52
  const query = (keys, effect) => gen(function* () {
53
53
  const services = yield* context();
54
54
  const scope = get$1(services, Scope);
55
- const results = yield* make$10();
55
+ const results = yield* make$11();
56
56
  const runFork = flow(runForkWith(services), runIn(scope));
57
57
  let running = false;
58
58
  let pending = false;
@@ -122,7 +122,7 @@ const keysToHashes = (keys, f) => {
122
122
  }
123
123
  };
124
124
  //#endregion
125
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/SqlError.js
125
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/sql/SqlError.js
126
126
  const TypeId$5 = "~effect/sql/SqlError";
127
127
  const ReasonTypeId = "~effect/sql/SqlError/Reason";
128
128
  const ReasonFields = {
@@ -296,7 +296,7 @@ var ResultLengthMismatch = class extends TaggedError("effect/sql/ResultLengthMis
296
296
  }
297
297
  };
298
298
  //#endregion
299
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/Statement.js
299
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/sql/Statement.js
300
300
  const FragmentTypeId = "~effect/sql/Statement/Fragment";
301
301
  const fragment = (segments) => ({
302
302
  [FragmentTypeId]: FragmentTypeId,
@@ -652,8 +652,27 @@ const defaultTransforms = (transformer, nested = true) => {
652
652
  array
653
653
  };
654
654
  };
655
- const ATTR_DB_OPERATION_NAME = "db.operation.name";
655
+ const spanTarget = (spanAttributes) => {
656
+ const namespace = spanAttribute(spanAttributes, "db.namespace");
657
+ if (isNonEmptyString(namespace)) return namespace;
658
+ const address = spanAttribute(spanAttributes, "server.address");
659
+ if (isNonEmptyString(address)) {
660
+ const port = spanAttribute(spanAttributes, "server.port");
661
+ return port === void 0 ? address : `${address}:${port}`;
662
+ }
663
+ };
664
+ const spanName = (spanAttributes) => {
665
+ const target = spanTarget(spanAttributes);
666
+ if (target !== void 0) return target;
667
+ const system = spanAttribute(spanAttributes, "db.system.name");
668
+ return isNonEmptyString(system) ? system : "sql.execute";
669
+ };
656
670
  const ATTR_DB_QUERY_TEXT = "db.query.text";
671
+ const ATTR_SQL_METHOD = "effect.sql.method";
672
+ const spanAttribute = (spanAttributes, key) => {
673
+ for (let i = spanAttributes.length - 1; i >= 0; i--) if (spanAttributes[i][0] === key) return spanAttributes[i][1];
674
+ };
675
+ const isNonEmptyString = (u) => typeof u === "string" && u.length > 0;
657
676
  const makeUnsafe$1 = (segments, acquirer, compiler, spanAttributes, transformRows, borrower) => {
658
677
  const self = Object.create(StatementProto);
659
678
  self.segments = segments;
@@ -667,13 +686,13 @@ const makeUnsafe$1 = (segments, acquirer, compiler, spanAttributes, transformRow
667
686
  const StatementProto = {
668
687
  [FragmentTypeId]: FragmentTypeId,
669
688
  withConnection(operation, f, withoutTransform = false) {
670
- return useSpan("sql.execute", { kind: "client" }, (span) => this.withConnectionSpan(operation, f, withoutTransform, span));
689
+ return useSpan(spanName(this.spanAttributes), { kind: "client" }, (span) => this.withConnectionSpan(operation, f, withoutTransform, span));
671
690
  },
672
691
  withConnectionSpan(operation, f, withoutTransform, span) {
673
692
  return withStatement(this, span, (statement, fiber) => {
674
693
  const [sql, params] = statement.compile(withoutTransform);
675
694
  for (const [key, value] of this.spanAttributes) span.attribute(key, value);
676
- span.attribute(ATTR_DB_OPERATION_NAME, operation);
695
+ span.attribute(ATTR_SQL_METHOD, operation);
677
696
  span.attribute(ATTR_DB_QUERY_TEXT, sql);
678
697
  const execute = this.borrower === void 0 ? scoped(flatMap(this.acquirer, (_) => f(_, sql, params))) : this.borrower((connection) => f(connection, sql, params));
679
698
  return fiber.cache.tracerEnabled && fiber.getRef(SpanPropagationEnabled) ? provideService(execute, ParentSpan, span) : execute;
@@ -687,10 +706,10 @@ const StatementProto = {
687
706
  },
688
707
  get stream() {
689
708
  const self = this;
690
- return unwrap(flatMap(makeSpanScoped("sql.execute", { kind: "client" }), (span) => withStatement(self, span, (statement, fiber) => {
709
+ return unwrap(flatMap(makeSpanScoped(spanName(self.spanAttributes), { kind: "client" }), (span) => withStatement(self, span, (statement, fiber) => {
691
710
  const [sql, params] = statement.compile();
692
711
  for (const [key, value] of self.spanAttributes) span.attribute(key, value);
693
- span.attribute(ATTR_DB_OPERATION_NAME, "executeStream");
712
+ span.attribute(ATTR_SQL_METHOD, "executeStream");
694
713
  span.attribute(ATTR_DB_QUERY_TEXT, sql);
695
714
  const acquire = map(self.acquirer, (_) => _.executeStream(sql, params, self.transformRows));
696
715
  return fiber.cache.tracerEnabled && fiber.getRef(SpanPropagationEnabled) ? succeed(provideService$1(unwrap(acquire), ParentSpan, span)) : acquire;
@@ -709,7 +728,7 @@ const StatementProto = {
709
728
  ...Prototype({
710
729
  label: "Statement",
711
730
  evaluate(fiber) {
712
- const span = makeSpanUnsafe(fiber, "sql.execute", { kind: "client" });
731
+ const span = makeSpanUnsafe(fiber, spanName(this.spanAttributes), { kind: "client" });
713
732
  const clock = fiber.getRef(Clock);
714
733
  const timingEnabled = fiber.getRef(TracerTimingEnabled);
715
734
  return onExit(this.withConnectionSpan("execute", (connection, sql, params) => connection.execute(sql, params, this.transformRows), false, span), (exit) => endSpan(span, exit, clock, timingEnabled));
@@ -786,7 +805,7 @@ function in_() {
786
805
  }
787
806
  const neverFragment = fragment([literal("1=0")]);
788
807
  //#endregion
789
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/SqlClient.js
808
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/sql/SqlClient.js
790
809
  const TypeId$4 = "~effect/sql/SqlClient";
791
810
  const SqlClient = Service("effect/sql/SqlClient");
792
811
  let clientIdCounter = 0;
@@ -867,9 +886,10 @@ const makeSqliteAcquirers = (options) => {
867
886
  }
868
887
  });
869
888
  });
889
+ const lease = uninterruptibleMask((restore) => flatMap(scope, (scope) => restore(semaphore.take(1)).pipe(andThen(addFinalizer(scope, semaphore.release(1))), andThen(available))));
870
890
  return {
871
- acquirer: semaphore.withPermits(1)(available),
872
- transactionAcquirer: uninterruptibleMask((restore) => flatMap(scope, (scope) => restore(semaphore.take(1)).pipe(andThen(addFinalizer(scope, semaphore.release(1))), andThen(available)))),
891
+ acquirer: lease,
892
+ transactionAcquirer: lease,
873
893
  onCommitFailure: (conn) => tapCause(rollback(conn), (cause) => sync(() => poison(cause)))
874
894
  };
875
895
  };
@@ -878,9 +898,10 @@ const isNoTransactionError = (error) => {
878
898
  const message = typeof cause === "string" ? cause : hasProperty(cause, "message") && typeof cause.message === "string" ? cause.message : "";
879
899
  return /no transaction is active/i.test(message);
880
900
  };
901
+ const failuresToDefects = (cause) => fromReasons(cause.reasons.map((reason) => isFailReason(reason) ? makeDieReason(reason.error).annotate(reasonAnnotations(reason)) : reason));
881
902
  const makeWithTransaction = (options) => {
882
903
  const transactionSemaphore = Service(`effect/sql/SqlClient/TransactionSemaphore/${transactionSemaphoreIdCounter++}`);
883
- return (effect) => uninterruptibleMask((restore) => useSpan("sql.transaction", { kind: "client" }, (span) => withFiber((fiber) => {
904
+ return (effect) => uninterruptibleMask((restore) => useSpan("sql.transaction", { kind: "internal" }, (span) => withFiber((fiber) => {
884
905
  for (const [key, value] of options.spanAttributes) span.attribute(key, value);
885
906
  const services = fiber.context;
886
907
  const clock = fiber.getRef(Clock);
@@ -891,16 +912,18 @@ const makeWithTransaction = (options) => {
891
912
  let effect;
892
913
  if (isSuccess(exit)) {
893
914
  if (id === 0) {
894
- span.event("db.transaction.commit", clock.currentTimeNanosUnsafe());
915
+ span.event("effect.sql.transaction.commit", clock.currentTimeNanosUnsafe());
895
916
  const onCommitFailure = options.onCommitFailure;
896
- effect = orDie(options.commit(conn));
897
- if (onCommitFailure) effect = onError(effect, () => orDie(onCommitFailure(conn)));
917
+ effect = onCommitFailure ? catchCause(options.commit(conn), (commitCause) => matchCauseEffect(onCommitFailure(conn), {
918
+ onFailure: (cleanupCause) => failCause$1(failuresToDefects(combine(commitCause, cleanupCause))),
919
+ onSuccess: () => failCause$1(commitCause)
920
+ })) : options.commit(conn);
898
921
  } else {
899
- span.event("db.transaction.savepoint", clock.currentTimeNanosUnsafe());
922
+ span.event("effect.sql.transaction.savepoint", clock.currentTimeNanosUnsafe());
900
923
  effect = void_$1;
901
924
  }
902
925
  } else {
903
- span.event("db.transaction.rollback", clock.currentTimeNanosUnsafe());
926
+ span.event("effect.sql.transaction.rollback", clock.currentTimeNanosUnsafe());
904
927
  effect = orDie(id > 0 ? options.rollbackSavepoint(conn, id) : options.rollback(conn));
905
928
  }
906
929
  if (id > 0 && options.releaseSavepoint) effect = andThen(effect, orDie(options.releaseSavepoint(conn, id)));
@@ -912,12 +935,12 @@ const makeWithTransaction = (options) => {
912
935
  const TransactionConnection = (clientId) => Service(`effect/sql/SqlClient/TransactionConnection/${clientId}`);
913
936
  const SafeIntegers = Reference("effect/sql/SqlClient/SafeIntegers", { defaultValue: () => false });
914
937
  //#endregion
915
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/Cache.js
938
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/Cache.js
916
939
  const TypeId$3 = "~effect/Cache";
917
940
  const makeWith = (lookup, options) => contextWith$1((context) => {
918
941
  const self = Object.create(Proto$1);
919
942
  self.lookup = (key) => updateContext(lookup(key), (input) => merge(context, input));
920
- self.map = make$12();
943
+ self.map = make$8();
921
944
  self.capacity = options.capacity;
922
945
  self.timeToLive = options.timeToLive ? (exit, key) => fromInputUnsafe(options.timeToLive(exit, key)) : defaultTimeToLive;
923
946
  return succeed$1(self);
@@ -940,7 +963,7 @@ const get = dual(2, (self, key) => withFiber$1((fiber) => {
940
963
  remove(self.map, key);
941
964
  if (!hasExpired(oentry.value, fiber)) {
942
965
  set(self.map, key, oentry.value);
943
- return oentry.value.await();
966
+ return oentry.value.await(fiber);
944
967
  }
945
968
  }
946
969
  const entry = new EntryImpl(fiber, self.lookup(key));
@@ -961,7 +984,7 @@ const get = dual(2, (self, key) => withFiber$1((fiber) => {
961
984
  const exit = entry.fiber.pollUnsafe();
962
985
  if (!skipCache && (exit === void 0 || !exitHasInterrupts(exit))) set(self.map, key, entry);
963
986
  if (Number.isFinite(self.capacity)) checkCapacity(self);
964
- return entry.await();
987
+ return entry.await(fiber);
965
988
  }));
966
989
  var EntryImpl = class {
967
990
  expiresAt;
@@ -973,16 +996,18 @@ var EntryImpl = class {
973
996
  this.awaiters = 0;
974
997
  this.expiresAt = void 0;
975
998
  }
976
- await() {
999
+ await(fiber) {
1000
+ if (fiber === void 0) return withFiber$1((fiber) => this.await(fiber));
977
1001
  const exit = this.fiber.pollUnsafe();
978
1002
  if (exit) return exit;
979
1003
  this.awaiters++;
980
- return onExit$1(fiberJoin(this.fiber), () => {
1004
+ onExitUnsafe(fiber, () => {
981
1005
  this.awaiters--;
982
1006
  if (this.awaiters > 0 || this.fiber.pollUnsafe()) return void_$2;
983
1007
  this.onInterrupt?.();
984
1008
  return fiberInterrupt(this.fiber);
985
1009
  });
1010
+ return fiberJoin(this.fiber);
986
1011
  }
987
1012
  };
988
1013
  const removeEntry = (self, key, entry) => {
@@ -1003,7 +1028,7 @@ const checkCapacity = (self) => {
1003
1028
  }
1004
1029
  };
1005
1030
  //#endregion
1006
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/schema/VariantSchema.js
1031
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/schema/VariantSchema.js
1007
1032
  const TypeId$2 = "~effect/schema/VariantSchema";
1008
1033
  const cacheSymbol = Symbol.for(`${TypeId$2}/cache`);
1009
1034
  const defaultCacheSymbol = Symbol.for(`${TypeId$2}/defaultCache`);
@@ -1108,7 +1133,7 @@ const Union$1 = (members, defaultVariant, variants) => {
1108
1133
  return VariantUnion;
1109
1134
  };
1110
1135
  //#endregion
1111
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/schema/Model.js
1136
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/schema/Model.js
1112
1137
  const { Class, Field, FieldExcept, FieldOnly, Struct, Union, extract, fieldEvolve } = make$3({
1113
1138
  variants: [
1114
1139
  "select",
@@ -1182,7 +1207,7 @@ const DateTimeUpdateFromNumber = Field({
1182
1207
  json: DateTimeUtcFromMillis
1183
1208
  });
1184
1209
  //#endregion
1185
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/SqlResolver.js
1210
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/sql/SqlResolver.js
1186
1211
  const SqlRequestProto = {
1187
1212
  ...Class$1.prototype,
1188
1213
  [symbol](that) {
@@ -1239,7 +1264,7 @@ const findById = (options) => {
1239
1264
  request.value.completeUnsafe(succeed$2(result));
1240
1265
  }
1241
1266
  if (isEmpty(idMap)) return;
1242
- forEach$1(idMap, (request) => {
1267
+ forEach(idMap, (request) => {
1243
1268
  request.completeUnsafe(constNoSuchElement);
1244
1269
  });
1245
1270
  })
@@ -1313,14 +1338,14 @@ function transactionKey(entry) {
1313
1338
  return byReferenceUnsafe(conn);
1314
1339
  }
1315
1340
  //#endregion
1316
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/SqlSchema.js
1341
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/sql/SqlSchema.js
1317
1342
  const findAll = (options) => {
1318
1343
  const encodeRequest = encodeEffect(options.Request);
1319
1344
  const decode = decodeUnknownEffect(mutable(ArraySchema(options.Result)));
1320
1345
  return (request) => flatMap(flatMap(encodeRequest(request), options.execute), decode);
1321
1346
  };
1322
1347
  //#endregion
1323
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/SqlModel.js
1348
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/sql/SqlModel.js
1324
1349
  const makeResolvers = (Model, options) => gen(function* () {
1325
1350
  const sql = yield* SqlClient;
1326
1351
  const idSchema = Model.fields[options.idColumn];
@@ -1333,7 +1358,7 @@ const makeResolvers = (Model, options) => gen(function* () {
1333
1358
  Request: Model.insert,
1334
1359
  Result: Model,
1335
1360
  execute: (request) => sql.onDialectOrElse({
1336
- mysql: () => forEach(request, (request) => sql`insert into ${sql(options.tableName)} ${sql.insert(request)};
1361
+ mysql: () => forEach$1(request, (request) => sql`insert into ${sql(options.tableName)} ${sql.insert(request)};
1337
1362
  select * from ${sql(options.tableName)} where ${withSoftDeleteFilter(sql`${sql(idColumn)} = LAST_INSERT_ID()`)};`.unprepared.pipe(map(([, results]) => results[0])), { concurrency: 10 }),
1338
1363
  orElse: () => sql`insert into ${sql(options.tableName)} ${sql.insert(request).returning("*")}`
1339
1364
  })
@@ -1934,7 +1959,7 @@ const layer$3 = effect(CodeChunker, gen(function* () {
1934
1959
  });
1935
1960
  }));
1936
1961
  //#endregion
1937
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/FiberHandle.js
1962
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/FiberHandle.js
1938
1963
  const TypeId$1 = "~effect/FiberHandle";
1939
1964
  const isFiberHandle = (u) => hasProperty(u, TypeId$1);
1940
1965
  const Proto = {
@@ -1968,16 +1993,17 @@ const setUnsafe = dual((args) => isFiberHandle(args[0]), (self, fiber, options)
1968
1993
  if (self.state._tag === "Closed") {
1969
1994
  fiber.interruptUnsafe(internalFiberId);
1970
1995
  return;
1971
- } else if (self.state.fiber !== void 0) {
1972
- if (self.state.fiber === fiber) return;
1996
+ }
1997
+ const previous = self.state.fiber;
1998
+ if (previous !== void 0) {
1999
+ if (previous === fiber) return;
1973
2000
  else if (options?.onlyIfMissing === true) {
1974
2001
  fiber.interruptUnsafe(internalFiberId);
1975
2002
  return;
1976
2003
  }
1977
- self.state.fiber.interruptUnsafe(internalFiberId);
1978
- self.state.fiber = void 0;
1979
2004
  }
1980
2005
  self.state.fiber = fiber;
2006
+ previous?.interruptUnsafe(internalFiberId);
1981
2007
  fiber.addObserver((exit) => {
1982
2008
  if (self.state._tag === "Open" && fiber === self.state.fiber) self.state.fiber = void 0;
1983
2009
  if (isFailure(exit) && (options?.propagateInterruption === true ? !isInternalInterruption(exit.cause) : !hasInterruptsOnly(exit.cause))) doneUnsafe(self.deferred, exit);
@@ -2004,7 +2030,7 @@ const runImpl = (self, effect, options) => withFiber((parent) => {
2004
2030
  return succeed(fiber);
2005
2031
  });
2006
2032
  //#endregion
2007
- //#region node_modules/.pnpm/@effect+sql-sqlite-node@4.0.1_effect@4.0.1/node_modules/@effect/sql-sqlite-node/dist/SqliteClient.js
2033
+ //#region node_modules/.pnpm/@effect+sql-sqlite-node@4.0.4_effect@4.0.4/node_modules/@effect/sql-sqlite-node/dist/SqliteClient.js
2008
2034
  const ATTR_DB_SYSTEM_NAME = "db.system.name";
2009
2035
  const MAX_BUSY_TIMEOUT = 2147483647;
2010
2036
  const NANOS_PER_MILLI = BigInt(1e6);
@@ -2021,7 +2047,7 @@ const make$1 = (options) => gen(function* () {
2021
2047
  }),
2022
2048
  catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to open database", "connect") })
2023
2049
  }), (db) => sync(() => db.close()));
2024
- db.enableLoadExtension(false);
2050
+ setLoadExtensionEnabled(db, false);
2025
2051
  const busyTimeout = Math.min(MAX_BUSY_TIMEOUT, Math.max(0, Math.round(toMillis(options.busyTimeout ?? seconds(5)))));
2026
2052
  const exec = (sql) => try_({
2027
2053
  try: () => db.exec(sql),
@@ -2124,16 +2150,16 @@ const make$1 = (options) => gen(function* () {
2124
2150
  });
2125
2151
  },
2126
2152
  loadExtension(path) {
2127
- return acquireUseRelease(sync(() => db.enableLoadExtension(true)), () => try_({
2153
+ return acquireUseRelease(sync(() => setLoadExtensionEnabled(db, true)), () => try_({
2128
2154
  try: () => db.loadExtension(path),
2129
2155
  catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to load extension", "loadExtension") })
2130
- }), () => sync(() => db.enableLoadExtension(false)));
2156
+ }), () => sync(() => setLoadExtensionEnabled(db, false)));
2131
2157
  }
2132
2158
  });
2133
2159
  });
2134
2160
  const { acquirer, onCommitFailure, transactionAcquirer } = makeSqliteAcquirers({
2135
2161
  connection: succeed(connection),
2136
- semaphore: yield* make$11(1),
2162
+ semaphore: yield* make$12(1),
2137
2163
  isTransaction: (conn) => conn.isTransaction()
2138
2164
  });
2139
2165
  return Object.assign(yield* make$4({
@@ -2148,11 +2174,11 @@ const make$1 = (options) => gen(function* () {
2148
2174
  }), {
2149
2175
  [TypeId]: TypeId,
2150
2176
  config: options,
2151
- backup: (destination) => flatMap(acquirer, (_) => _.backup(destination)),
2152
- loadExtension: (path) => flatMap(acquirer, (_) => _.loadExtension(path))
2177
+ backup: (destination) => scoped(flatMap(acquirer, (_) => _.backup(destination))),
2178
+ loadExtension: (path) => scoped(flatMap(acquirer, (_) => _.loadExtension(path)))
2153
2179
  });
2154
2180
  });
2155
- const layer$2 = (config) => effectContext(map(make$1(config), (client) => make$8(SqliteClient, client).pipe(add(SqlClient, client)))).pipe(provide$1(layer$5));
2181
+ const layer$2 = (config) => effectContext(map(make$1(config), (client) => make$9(SqliteClient, client).pipe(add(SqlClient, client)))).pipe(provide$1(layer$5));
2156
2182
  const classifyError = (cause, message, operation) => classifySqliteError(sqliteCauseWithErrno(cause), {
2157
2183
  message,
2158
2184
  operation
@@ -2163,8 +2189,11 @@ const sqliteCauseWithErrno = (cause) => {
2163
2189
  if (typeof errcode !== "number") return cause;
2164
2190
  return Object.assign(cause, { errno: errcode });
2165
2191
  };
2192
+ const setLoadExtensionEnabled = (db, enabled) => {
2193
+ if (typeof db.enableLoadExtension === "function") db.enableLoadExtension(enabled);
2194
+ };
2166
2195
  //#endregion
2167
- //#region node_modules/.pnpm/effect@4.0.1/node_modules/effect/dist/sql/Migrator.js
2196
+ //#region node_modules/.pnpm/effect@4.0.4/node_modules/effect/dist/sql/Migrator.js
2168
2197
  var __rewriteRelativeImportExtension = void 0 && (void 0).__rewriteRelativeImportExtension || function(path, preserveJsx) {
2169
2198
  if (typeof path === "string" && /^\.\.?\//.test(path)) return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function(m, tsx, d, ext, cm) {
2170
2199
  return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : d + ext + "." + cm.toLowerCase() + "js";
@@ -2187,11 +2216,11 @@ const make = ({ dumpSchema = () => void_$1 }) => ({ loader, schemaDirectory, tab
2187
2216
  name VARCHAR(255) NOT NULL,
2188
2217
  PRIMARY KEY (migration_id)
2189
2218
  )`,
2190
- pg: () => catch_(sql`select ${table}::regclass`, () => sql`CREATE TABLE ${sql(table)} (
2219
+ pg: () => flatMap(migrationsTableExists(sql, table), (exists) => exists ? void_$1 : asVoid(sql`CREATE TABLE ${sql(table)} (
2191
2220
  migration_id integer primary key,
2192
2221
  created_at timestamp with time zone not null default now(),
2193
2222
  name text not null
2194
- )`),
2223
+ )`).pipe(catch_((error) => flatMap(migrationsTableExists(sql, table), (exists) => exists ? void_$1 : fail(error))))),
2195
2224
  orElse: () => sql`CREATE TABLE IF NOT EXISTS ${sql(table)} (
2196
2225
  migration_id integer PRIMARY KEY NOT NULL,
2197
2226
  created_at datetime NOT NULL DEFAULT current_timestamp,
@@ -2249,7 +2278,7 @@ const make = ({ dumpSchema = () => void_$1 }) => ({ loader, schemaDirectory, tab
2249
2278
  kind: "Locked",
2250
2279
  message: "Migrations already running"
2251
2280
  }) : error));
2252
- yield* forEach(required, ([id, name, effect]) => logDebug(`Running migration`).pipe(flatMap(() => runMigration(id, name, effect)), annotateLogs("migration_id", String(id)), annotateLogs("migration_name", name), withSpan(`Migrator ${id}_${name}`)), { discard: true });
2281
+ yield* forEach$1(required, ([id, name, effect]) => logDebug(`Running migration`).pipe(flatMap(() => runMigration(id, name, effect)), annotateLogs("migration_id", String(id)), annotateLogs("migration_name", name), withSpan(`Migrator ${id}_${name}`)), { discard: true });
2253
2282
  yield* pipe(latestMigration, flatMap(match({
2254
2283
  onNone: () => logDebug(`Migrations complete`),
2255
2284
  onSome: (_) => logDebug(`Migrations complete`).pipe(annotateLogs("latest_migration_id", _.id.toString()), annotateLogs("latest_migration_name", _.name))
@@ -2261,7 +2290,11 @@ const make = ({ dumpSchema = () => void_$1 }) => ({ loader, schemaDirectory, tab
2261
2290
  if (schemaDirectory && completed.length > 0) yield* dumpSchema(`${schemaDirectory}/_schema.sql`, table).pipe(catchCause((cause) => logInfo("Could not dump schema", cause)));
2262
2291
  return completed;
2263
2292
  });
2264
- const migrationOrder = make$9(([a], [b]) => Number$1(a, b));
2293
+ const migrationsTableExists = (sql, table) => {
2294
+ const quotedTable = sql`${sql(table)}`.compile(true)[0];
2295
+ return map(sql`SELECT 1 AS found WHERE to_regclass(${quotedTable}) IS NOT NULL`.withoutTransform, (rows) => rows.length > 0);
2296
+ };
2297
+ const migrationOrder = make$10(([a], [b]) => Number$1(a, b));
2265
2298
  const isConstraintConflict = (error) => error.reason._tag === "ConstraintError" || error.reason._tag === "UniqueViolation";
2266
2299
  const fromRecord = (migrations) => pipe(Object.keys(migrations), flatMapNullishOr((_) => _.match(/^(\d+)_(.+)$/)), map$2(([key, id, name]) => [
2267
2300
  Number(id),
@@ -2269,7 +2302,7 @@ const fromRecord = (migrations) => pipe(Object.keys(migrations), flatMapNullishO
2269
2302
  succeed(migrations[key])
2270
2303
  ]), sort(migrationOrder), succeed);
2271
2304
  //#endregion
2272
- //#region node_modules/.pnpm/@effect+sql-sqlite-node@4.0.1_effect@4.0.1/node_modules/@effect/sql-sqlite-node/dist/SqliteMigrator.js
2305
+ //#region node_modules/.pnpm/@effect+sql-sqlite-node@4.0.4_effect@4.0.4/node_modules/@effect/sql-sqlite-node/dist/SqliteMigrator.js
2273
2306
  const run = make({});
2274
2307
  const layer$1 = (options) => effectDiscard(run(options));
2275
2308
  //#endregion
@@ -2413,4 +2446,4 @@ const layer = (options) => effect(SemanticSearch, gen(function* () {
2413
2446
  //#endregion
2414
2447
  export { SemanticSearch, chunkEmbeddingInput, layer, makeEmbeddingResolver, maybeRemoveFile, maybeUpdateFile };
2415
2448
 
2416
- //# sourceMappingURL=SemanticSearch-CFB73IPb.mjs.map
2449
+ //# sourceMappingURL=SemanticSearch-4Jes3jCl.mjs.map