lalph 0.3.95 → 0.3.96
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/cli.mjs +1571 -1558
- package/package.json +2 -2
- package/src/Clanka.ts +5 -1
package/dist/cli.mjs
CHANGED
|
@@ -28,9 +28,9 @@ import { StringDecoder } from "node:string_decoder";
|
|
|
28
28
|
import TreeSitter from "tree-sitter";
|
|
29
29
|
import TreeSitterJavaScript from "tree-sitter-javascript";
|
|
30
30
|
import TreeSitterTypeScript from "tree-sitter-typescript";
|
|
31
|
-
import Sqlite from "better-sqlite3";
|
|
32
31
|
import process$1 from "node:process";
|
|
33
32
|
import tty from "node:tty";
|
|
33
|
+
import Sqlite from "better-sqlite3";
|
|
34
34
|
//#region \0rolldown/runtime.js
|
|
35
35
|
var __create = Object.create;
|
|
36
36
|
var __defProp = Object.defineProperty;
|
|
@@ -181683,7 +181683,7 @@ var ji = Bt, Ii = Object.assign(Qe, { sync: Bt }), zi = Ut, Bi = Object.assign(e
|
|
|
181683
181683
|
});
|
|
181684
181684
|
Ze.glob = Ze;
|
|
181685
181685
|
//#endregion
|
|
181686
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
181686
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/ApplyPatch.js
|
|
181687
181687
|
/**
|
|
181688
181688
|
* @since 1.0.0
|
|
181689
181689
|
*/
|
|
@@ -196556,7 +196556,7 @@ var StreamableHTTPClientTransport = class {
|
|
|
196556
196556
|
}
|
|
196557
196557
|
};
|
|
196558
196558
|
//#endregion
|
|
196559
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
196559
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/McpClient.js
|
|
196560
196560
|
/**
|
|
196561
196561
|
* @since 1.0.0
|
|
196562
196562
|
*/
|
|
@@ -196601,7 +196601,7 @@ const layer$13 = effect$1(McpClient, gen(function* () {
|
|
|
196601
196601
|
});
|
|
196602
196602
|
}));
|
|
196603
196603
|
//#endregion
|
|
196604
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
196604
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/ExaSearch.js
|
|
196605
196605
|
/**
|
|
196606
196606
|
* @since 1.0.0
|
|
196607
196607
|
*/
|
|
@@ -211551,7 +211551,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin$1(((exports) => {
|
|
|
211551
211551
|
exports.impl = impl;
|
|
211552
211552
|
}));
|
|
211553
211553
|
//#endregion
|
|
211554
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
211554
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/WebToMarkdown.js
|
|
211555
211555
|
/**
|
|
211556
211556
|
* @since 1.0.0
|
|
211557
211557
|
*/
|
|
@@ -214690,1385 +214690,7 @@ function isEmptyParamsRecord(indexSignature) {
|
|
|
214690
214690
|
return indexSignature.parameter === string$3 && isNever(indexSignature.type);
|
|
214691
214691
|
}
|
|
214692
214692
|
//#endregion
|
|
214693
|
-
//#region node_modules/.pnpm/effect@4.0.0-beta.
|
|
214694
|
-
/**
|
|
214695
|
-
* @since 4.0.0
|
|
214696
|
-
* @category Type IDs
|
|
214697
|
-
*/
|
|
214698
|
-
const TypeId$4 = "~effect/schema/VariantSchema";
|
|
214699
|
-
const cacheSymbol = /* @__PURE__ */ Symbol.for(`${TypeId$4}/cache`);
|
|
214700
|
-
/**
|
|
214701
|
-
* @since 4.0.0
|
|
214702
|
-
* @category guards
|
|
214703
|
-
*/
|
|
214704
|
-
const isStruct = (u) => hasProperty(u, TypeId$4);
|
|
214705
|
-
const FieldTypeId = "~effect/schema/VariantSchema/Field";
|
|
214706
|
-
/**
|
|
214707
|
-
* @since 4.0.0
|
|
214708
|
-
* @category guards
|
|
214709
|
-
*/
|
|
214710
|
-
const isField = (u) => hasProperty(u, FieldTypeId);
|
|
214711
|
-
const extract$1 = /* @__PURE__ */ dual((args) => isStruct(args[0]), (self, variant, options) => {
|
|
214712
|
-
const cache = self[cacheSymbol] ?? (self[cacheSymbol] = {});
|
|
214713
|
-
const cacheKey = options?.isDefault === true ? "__default" : variant;
|
|
214714
|
-
if (cache[cacheKey] !== void 0) return cache[cacheKey];
|
|
214715
|
-
const fields = {};
|
|
214716
|
-
for (const key of Object.keys(self[TypeId$4])) {
|
|
214717
|
-
const value = self[TypeId$4][key];
|
|
214718
|
-
if ("~effect/schema/VariantSchema" in value) if (options?.isDefault === true && isSchema(value)) fields[key] = value;
|
|
214719
|
-
else fields[key] = extract$1(value, variant);
|
|
214720
|
-
else if (FieldTypeId in value) {
|
|
214721
|
-
if (variant in value.schemas) fields[key] = value.schemas[variant];
|
|
214722
|
-
} else fields[key] = value;
|
|
214723
|
-
}
|
|
214724
|
-
return cache[cacheKey] = Struct$2(fields);
|
|
214725
|
-
});
|
|
214726
|
-
/**
|
|
214727
|
-
* @since 4.0.0
|
|
214728
|
-
* @category constructors
|
|
214729
|
-
*/
|
|
214730
|
-
const make$12 = (options) => {
|
|
214731
|
-
function Class(identifier) {
|
|
214732
|
-
return function(fields, annotations) {
|
|
214733
|
-
const variantStruct = Struct$1(fields);
|
|
214734
|
-
const schema = extract$1(variantStruct, options.defaultVariant, { isDefault: true });
|
|
214735
|
-
const SClass = Class$2;
|
|
214736
|
-
class Base extends SClass(identifier)(schema.fields, annotations) {
|
|
214737
|
-
static [TypeId$4] = fields;
|
|
214738
|
-
}
|
|
214739
|
-
for (const variant of options.variants) Object.defineProperty(Base, variant, { value: extract$1(variantStruct, variant).annotate({
|
|
214740
|
-
id: `${identifier}.${variant}`,
|
|
214741
|
-
title: `${identifier}.${variant}`
|
|
214742
|
-
}) });
|
|
214743
|
-
return Base;
|
|
214744
|
-
};
|
|
214745
|
-
}
|
|
214746
|
-
function FieldOnly(keys) {
|
|
214747
|
-
return function(schema) {
|
|
214748
|
-
const obj = {};
|
|
214749
|
-
for (const key of keys) obj[key] = schema;
|
|
214750
|
-
return Field$1(obj);
|
|
214751
|
-
};
|
|
214752
|
-
}
|
|
214753
|
-
function FieldExcept(keys) {
|
|
214754
|
-
return function(schema) {
|
|
214755
|
-
const obj = {};
|
|
214756
|
-
for (const variant of options.variants) if (!keys.includes(variant)) obj[variant] = schema;
|
|
214757
|
-
return Field$1(obj);
|
|
214758
|
-
};
|
|
214759
|
-
}
|
|
214760
|
-
function UnionVariants(members) {
|
|
214761
|
-
return Union$1(members, options.variants);
|
|
214762
|
-
}
|
|
214763
|
-
return {
|
|
214764
|
-
Struct: Struct$1,
|
|
214765
|
-
Field: Field$1,
|
|
214766
|
-
FieldOnly,
|
|
214767
|
-
FieldExcept,
|
|
214768
|
-
Class,
|
|
214769
|
-
Union: UnionVariants,
|
|
214770
|
-
fieldEvolve: dual(2, (self, f) => {
|
|
214771
|
-
return Field$1(evolve((isField(self) ? self : Field$1(Object.fromEntries(options.variants.map((variant) => [variant, self])))).schemas, f));
|
|
214772
|
-
}),
|
|
214773
|
-
extract: dual(2, (self, variant) => extract$1(self, variant, { isDefault: variant === options.defaultVariant }))
|
|
214774
|
-
};
|
|
214775
|
-
};
|
|
214776
|
-
const StructProto = { pipe() {
|
|
214777
|
-
return pipeArguments(this, arguments);
|
|
214778
|
-
} };
|
|
214779
|
-
const Struct$1 = (fields) => {
|
|
214780
|
-
const self = Object.create(StructProto);
|
|
214781
|
-
self[TypeId$4] = fields;
|
|
214782
|
-
return self;
|
|
214783
|
-
};
|
|
214784
|
-
const FieldProto = {
|
|
214785
|
-
[FieldTypeId]: FieldTypeId,
|
|
214786
|
-
pipe() {
|
|
214787
|
-
return pipeArguments(this, arguments);
|
|
214788
|
-
}
|
|
214789
|
-
};
|
|
214790
|
-
const Field$1 = (schemas) => {
|
|
214791
|
-
const self = Object.create(FieldProto);
|
|
214792
|
-
self.schemas = schemas;
|
|
214793
|
-
return self;
|
|
214794
|
-
};
|
|
214795
|
-
const Union$1 = (members, variants) => {
|
|
214796
|
-
const VariantUnion = Union$2(members.filter((member) => isSchema(member)));
|
|
214797
|
-
for (const variant of variants) Object.defineProperty(VariantUnion, variant, { value: Union$2(members.map((member) => extract$1(member, variant))) });
|
|
214798
|
-
return VariantUnion;
|
|
214799
|
-
};
|
|
214800
|
-
//#endregion
|
|
214801
|
-
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/schema/Model.js
|
|
214802
|
-
const { Class, Field, FieldExcept, FieldOnly, Struct, Union, extract, fieldEvolve } = /* @__PURE__ */ make$12({
|
|
214803
|
-
variants: [
|
|
214804
|
-
"select",
|
|
214805
|
-
"insert",
|
|
214806
|
-
"update",
|
|
214807
|
-
"json",
|
|
214808
|
-
"jsonCreate",
|
|
214809
|
-
"jsonUpdate"
|
|
214810
|
-
],
|
|
214811
|
-
defaultVariant: "select"
|
|
214812
|
-
});
|
|
214813
|
-
/**
|
|
214814
|
-
* A field that represents a column that is generated by the database.
|
|
214815
|
-
*
|
|
214816
|
-
* It is available for selection and update, but not for insertion.
|
|
214817
|
-
*
|
|
214818
|
-
* @since 4.0.0
|
|
214819
|
-
* @category generated
|
|
214820
|
-
*/
|
|
214821
|
-
const Generated = (schema) => Field({
|
|
214822
|
-
select: schema,
|
|
214823
|
-
update: schema,
|
|
214824
|
-
json: schema
|
|
214825
|
-
});
|
|
214826
|
-
//#endregion
|
|
214827
|
-
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/sql/SqlError.js
|
|
214828
|
-
/**
|
|
214829
|
-
* @since 4.0.0
|
|
214830
|
-
*/
|
|
214831
|
-
const TypeId$3 = "~effect/sql/SqlError";
|
|
214832
|
-
/**
|
|
214833
|
-
* @since 4.0.0
|
|
214834
|
-
*/
|
|
214835
|
-
var SqlError = class extends TaggedErrorClass("effect/sql/SqlError")("SqlError", {
|
|
214836
|
-
cause: Defect,
|
|
214837
|
-
message: /* @__PURE__ */ optional$3(String$1)
|
|
214838
|
-
}) {
|
|
214839
|
-
/**
|
|
214840
|
-
* @since 4.0.0
|
|
214841
|
-
*/
|
|
214842
|
-
[TypeId$3] = TypeId$3;
|
|
214843
|
-
};
|
|
214844
|
-
/**
|
|
214845
|
-
* @since 4.0.0
|
|
214846
|
-
*/
|
|
214847
|
-
var ResultLengthMismatch = class extends TaggedErrorClass("effect/sql/ResultLengthMismatch")("ResultLengthMismatch", {
|
|
214848
|
-
expected: Number$1,
|
|
214849
|
-
actual: Number$1
|
|
214850
|
-
}) {
|
|
214851
|
-
/**
|
|
214852
|
-
* @since 4.0.0
|
|
214853
|
-
*/
|
|
214854
|
-
[TypeId$3] = TypeId$3;
|
|
214855
|
-
/**
|
|
214856
|
-
* @since 4.0.0
|
|
214857
|
-
*/
|
|
214858
|
-
get message() {
|
|
214859
|
-
return `Expected ${this.expected} results but got ${this.actual}`;
|
|
214860
|
-
}
|
|
214861
|
-
};
|
|
214862
|
-
//#endregion
|
|
214863
|
-
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/sql/SqlResolver.js
|
|
214864
|
-
/**
|
|
214865
|
-
* @since 4.0.0
|
|
214866
|
-
*/
|
|
214867
|
-
const SqlRequestProto = {
|
|
214868
|
-
...Class$3.prototype,
|
|
214869
|
-
[symbol$5](that) {
|
|
214870
|
-
return equals$2(this.payload, that.payload);
|
|
214871
|
-
},
|
|
214872
|
-
[symbol$6]() {
|
|
214873
|
-
return hash(this.payload);
|
|
214874
|
-
}
|
|
214875
|
-
};
|
|
214876
|
-
/**
|
|
214877
|
-
* @since 4.0.0
|
|
214878
|
-
* @category requests
|
|
214879
|
-
*/
|
|
214880
|
-
const request$1 = function() {
|
|
214881
|
-
if (arguments.length === 1) {
|
|
214882
|
-
const resolver = arguments[0];
|
|
214883
|
-
return (payload) => request$2(SqlRequest(payload), resolver);
|
|
214884
|
-
}
|
|
214885
|
-
return request$2(SqlRequest(arguments[0]), arguments[1]);
|
|
214886
|
-
};
|
|
214887
|
-
/**
|
|
214888
|
-
* @since 4.0.0
|
|
214889
|
-
* @category requests
|
|
214890
|
-
*/
|
|
214891
|
-
const SqlRequest = (payload) => {
|
|
214892
|
-
const self = Object.create(SqlRequestProto);
|
|
214893
|
-
self.payload = payload;
|
|
214894
|
-
return self;
|
|
214895
|
-
};
|
|
214896
|
-
/**
|
|
214897
|
-
* Create a resolver for a sql query with a request schema and a result schema.
|
|
214898
|
-
*
|
|
214899
|
-
* The request schema is used to validate the input of the query.
|
|
214900
|
-
* The result schema is used to validate the output of the query.
|
|
214901
|
-
*
|
|
214902
|
-
* Results are mapped to the requests in order, so the length of the results must match the length of the requests.
|
|
214903
|
-
*
|
|
214904
|
-
* @since 4.0.0
|
|
214905
|
-
* @category resolvers
|
|
214906
|
-
*/
|
|
214907
|
-
const ordered = (options) => {
|
|
214908
|
-
const decodeArray = decodeUnknownEffect(Array$1(options.Result));
|
|
214909
|
-
return makeGrouped({
|
|
214910
|
-
key: transactionKey,
|
|
214911
|
-
resolver: fnUntraced(function* (entries) {
|
|
214912
|
-
const inputs = yield* partitionRequests(entries, options.Request);
|
|
214913
|
-
const results = yield* options.execute(inputs).pipe(provideServices$2(entries[0].services));
|
|
214914
|
-
if (results.length !== inputs.length) return yield* new ResultLengthMismatch({
|
|
214915
|
-
expected: inputs.length,
|
|
214916
|
-
actual: results.length
|
|
214917
|
-
});
|
|
214918
|
-
const decodedResults = yield* decodeArray(results).pipe(provideServices$2(entries[0].services));
|
|
214919
|
-
for (let i = 0; i < entries.length; i++) entries[i].completeUnsafe(succeed$6(decodedResults[i]));
|
|
214920
|
-
})
|
|
214921
|
-
});
|
|
214922
|
-
};
|
|
214923
|
-
/**
|
|
214924
|
-
* Create a resolver that resolves results by id.
|
|
214925
|
-
*
|
|
214926
|
-
* @since 4.0.0
|
|
214927
|
-
* @category resolvers
|
|
214928
|
-
*/
|
|
214929
|
-
const findById = (options) => {
|
|
214930
|
-
const decodeResults = decodeUnknownEffect(Array$1(options.Result));
|
|
214931
|
-
return makeGrouped({
|
|
214932
|
-
key(entry) {
|
|
214933
|
-
const conn = entry.services.mapUnsafe.get(TransactionConnection.key);
|
|
214934
|
-
if (!conn) return void 0;
|
|
214935
|
-
return byReferenceUnsafe(conn);
|
|
214936
|
-
},
|
|
214937
|
-
resolver: fnUntraced(function* (entries) {
|
|
214938
|
-
const [inputs, idMap] = yield* partitionRequestsById(entries, options.Id);
|
|
214939
|
-
const results = yield* options.execute(inputs).pipe(provideServices$2(entries[0].services));
|
|
214940
|
-
const decodedResults = yield* decodeResults(results).pipe(provideServices$2(entries[0].services));
|
|
214941
|
-
for (let i = 0; i < decodedResults.length; i++) {
|
|
214942
|
-
const result = decodedResults[i];
|
|
214943
|
-
const id = options.ResultId(result, results[i]);
|
|
214944
|
-
const request = get$13(idMap, id);
|
|
214945
|
-
if (request._tag === "None") continue;
|
|
214946
|
-
remove$5(idMap, id);
|
|
214947
|
-
request.value.completeUnsafe(succeed$6(result));
|
|
214948
|
-
}
|
|
214949
|
-
if (isEmpty$3(idMap)) return;
|
|
214950
|
-
forEach$2(idMap, (request) => {
|
|
214951
|
-
request.completeUnsafe(constNoSuchElement);
|
|
214952
|
-
});
|
|
214953
|
-
})
|
|
214954
|
-
});
|
|
214955
|
-
};
|
|
214956
|
-
const void_ = (options) => makeGrouped({
|
|
214957
|
-
key: transactionKey,
|
|
214958
|
-
resolver: fnUntraced(function* (entries) {
|
|
214959
|
-
const inputs = yield* partitionRequests(entries, options.Request);
|
|
214960
|
-
yield* options.execute(inputs).pipe(provideServices$2(entries[0].services));
|
|
214961
|
-
for (let i = 0; i < entries.length; i++) entries[i].completeUnsafe(void_$3);
|
|
214962
|
-
})
|
|
214963
|
-
});
|
|
214964
|
-
const constNoSuchElement = /* @__PURE__ */ fail$8(/* @__PURE__ */ new NoSuchElementError());
|
|
214965
|
-
const partitionRequests = function* (requests, schema) {
|
|
214966
|
-
const len = requests.length;
|
|
214967
|
-
const inputs = empty$17();
|
|
214968
|
-
let entry;
|
|
214969
|
-
const encode = encodeEffect(schema);
|
|
214970
|
-
const handle = matchCauseEager({
|
|
214971
|
-
onFailure(cause) {
|
|
214972
|
-
entry.completeUnsafe(failCause$4(cause));
|
|
214973
|
-
},
|
|
214974
|
-
onSuccess(value) {
|
|
214975
|
-
inputs.push(value);
|
|
214976
|
-
}
|
|
214977
|
-
});
|
|
214978
|
-
for (let i = 0; i < len; i++) {
|
|
214979
|
-
entry = requests[i];
|
|
214980
|
-
yield provideServices$2(handle(encode(entry.request.payload)), entry.services);
|
|
214981
|
-
}
|
|
214982
|
-
return inputs;
|
|
214983
|
-
};
|
|
214984
|
-
const partitionRequestsById = function* (requests, schema) {
|
|
214985
|
-
const len = requests.length;
|
|
214986
|
-
const inputs = empty$17();
|
|
214987
|
-
const byIdMap = empty$11();
|
|
214988
|
-
let entry;
|
|
214989
|
-
const encode = encodeEffect(schema);
|
|
214990
|
-
const handle = matchCauseEager({
|
|
214991
|
-
onFailure(cause) {
|
|
214992
|
-
entry.completeUnsafe(failCause$4(cause));
|
|
214993
|
-
},
|
|
214994
|
-
onSuccess(value) {
|
|
214995
|
-
inputs.push(value);
|
|
214996
|
-
}
|
|
214997
|
-
});
|
|
214998
|
-
for (let i = 0; i < len; i++) {
|
|
214999
|
-
entry = requests[i];
|
|
215000
|
-
yield provideServices$2(handle(encode(entry.request.payload)), entry.services);
|
|
215001
|
-
set$8(byIdMap, entry.request.payload, entry);
|
|
215002
|
-
}
|
|
215003
|
-
return [inputs, byIdMap];
|
|
215004
|
-
};
|
|
215005
|
-
function transactionKey(entry) {
|
|
215006
|
-
const conn = entry.services.mapUnsafe.get(TransactionConnection.key);
|
|
215007
|
-
if (!conn) return void 0;
|
|
215008
|
-
return byReferenceUnsafe(conn);
|
|
215009
|
-
}
|
|
215010
|
-
//#endregion
|
|
215011
|
-
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/sql/SqlSchema.js
|
|
215012
|
-
/**
|
|
215013
|
-
* Run a sql query with a request schema and a result schema.
|
|
215014
|
-
*
|
|
215015
|
-
* @since 4.0.0
|
|
215016
|
-
* @category constructor
|
|
215017
|
-
*/
|
|
215018
|
-
const findAll = (options) => {
|
|
215019
|
-
const encodeRequest = encodeEffect(options.Request);
|
|
215020
|
-
const decode = decodeUnknownEffect(mutable(Array$1(options.Result)));
|
|
215021
|
-
return (request) => flatMap$4(flatMap$4(encodeRequest(request), options.execute), decode);
|
|
215022
|
-
};
|
|
215023
|
-
//#endregion
|
|
215024
|
-
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/sql/SqlModel.js
|
|
215025
|
-
/**
|
|
215026
|
-
* Create some simple data loaders from a model.
|
|
215027
|
-
*
|
|
215028
|
-
* @since 4.0.0
|
|
215029
|
-
* @category repository
|
|
215030
|
-
*/
|
|
215031
|
-
const makeDataLoaders = (Model, options) => gen(function* () {
|
|
215032
|
-
const sql = yield* SqlClient;
|
|
215033
|
-
const idSchema = Model.fields[options.idColumn];
|
|
215034
|
-
const idColumn = options.idColumn;
|
|
215035
|
-
const setMaxBatchSize = options.maxBatchSize ? batchN(options.maxBatchSize) : identity;
|
|
215036
|
-
const insertExecute = request$1(ordered({
|
|
215037
|
-
Request: Model.insert,
|
|
215038
|
-
Result: Model,
|
|
215039
|
-
execute: (request) => sql.onDialectOrElse({
|
|
215040
|
-
mysql: () => forEach$4(request, (request) => sql`insert into ${sql(options.tableName)} ${sql.insert(request)};
|
|
215041
|
-
select * from ${sql(options.tableName)} where ${sql(idColumn)} = LAST_INSERT_ID();`.unprepared.pipe(map$9(([, results]) => results[0])), { concurrency: 10 }),
|
|
215042
|
-
orElse: () => sql`insert into ${sql(options.tableName)} ${sql.insert(request).returning("*")}`
|
|
215043
|
-
})
|
|
215044
|
-
}).pipe(setDelay(options.window), setMaxBatchSize, withSpan(`${options.spanPrefix}.insertResolver`)));
|
|
215045
|
-
const insert = (insert) => insertExecute(insert).pipe(catchTag$1("ResultLengthMismatch", die$2), withSpan$1(`${options.spanPrefix}.insert`, {}, { captureStackTrace: false }));
|
|
215046
|
-
const insertVoidExecute = request$1(void_({
|
|
215047
|
-
Request: Model.insert,
|
|
215048
|
-
execute: (request) => sql`insert into ${sql(options.tableName)} ${sql.insert(request)}`
|
|
215049
|
-
}).pipe(setDelay(options.window), setMaxBatchSize, withSpan(`${options.spanPrefix}.insertVoidResolver`)));
|
|
215050
|
-
const insertVoid = (insert) => insertVoidExecute(insert).pipe(withSpan$1(`${options.spanPrefix}.insertVoid`, {}, { captureStackTrace: false }));
|
|
215051
|
-
const findByIdExecute = request$1(findById({
|
|
215052
|
-
Id: idSchema,
|
|
215053
|
-
Result: Model,
|
|
215054
|
-
ResultId(request) {
|
|
215055
|
-
return request[idColumn];
|
|
215056
|
-
},
|
|
215057
|
-
execute: (ids) => sql`select * from ${sql(options.tableName)} where ${sql.in(idColumn, ids)}`
|
|
215058
|
-
}).pipe(setDelay(options.window), setMaxBatchSize, withSpan(`${options.spanPrefix}.findByIdResolver`)));
|
|
215059
|
-
const findById$1 = (id) => findByIdExecute(id).pipe(withSpan$1(`${options.spanPrefix}.findById`, { attributes: { id } }, { captureStackTrace: false }));
|
|
215060
|
-
const deleteExecute = request$1(void_({
|
|
215061
|
-
Request: idSchema,
|
|
215062
|
-
execute: (ids) => sql`delete from ${sql(options.tableName)} where ${sql.in(idColumn, ids)}`
|
|
215063
|
-
}).pipe(setDelay(options.window), setMaxBatchSize, withSpan(`${options.spanPrefix}.deleteResolver`)));
|
|
215064
|
-
const delete_ = (id) => deleteExecute(id).pipe(withSpan$1(`${options.spanPrefix}.delete`, { attributes: { id } }, { captureStackTrace: false }));
|
|
215065
|
-
return {
|
|
215066
|
-
insert,
|
|
215067
|
-
insertVoid,
|
|
215068
|
-
findById: findById$1,
|
|
215069
|
-
delete: delete_
|
|
215070
|
-
};
|
|
215071
|
-
});
|
|
215072
|
-
//#endregion
|
|
215073
|
-
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/ai/EmbeddingModel.js
|
|
215074
|
-
/**
|
|
215075
|
-
* The `EmbeddingModel` module provides provider-agnostic text embedding capabilities.
|
|
215076
|
-
*
|
|
215077
|
-
* @example
|
|
215078
|
-
* ```ts
|
|
215079
|
-
* import { Effect } from "effect"
|
|
215080
|
-
* import { EmbeddingModel } from "effect/unstable/ai"
|
|
215081
|
-
*
|
|
215082
|
-
* const program = Effect.gen(function*() {
|
|
215083
|
-
* const model = yield* EmbeddingModel.EmbeddingModel
|
|
215084
|
-
* return yield* model.embed("hello world")
|
|
215085
|
-
* })
|
|
215086
|
-
* ```
|
|
215087
|
-
*
|
|
215088
|
-
* @since 4.0.0
|
|
215089
|
-
*/
|
|
215090
|
-
/**
|
|
215091
|
-
* Service tag for embedding model operations.
|
|
215092
|
-
*
|
|
215093
|
-
* @since 4.0.0
|
|
215094
|
-
* @category services
|
|
215095
|
-
*/
|
|
215096
|
-
var EmbeddingModel = class extends Service$1()("effect/unstable/ai/EmbeddingModel") {};
|
|
215097
|
-
/**
|
|
215098
|
-
* Service tag that provides the current embedding dimensions.
|
|
215099
|
-
*
|
|
215100
|
-
* @since 4.0.0
|
|
215101
|
-
* @category services
|
|
215102
|
-
*/
|
|
215103
|
-
var Dimensions = class extends Service$1()("effect/unstable/ai/EmbeddingModel/Dimensions") {};
|
|
215104
|
-
/**
|
|
215105
|
-
* Token usage metadata for embedding operations.
|
|
215106
|
-
*
|
|
215107
|
-
* @since 4.0.0
|
|
215108
|
-
* @category models
|
|
215109
|
-
*/
|
|
215110
|
-
var EmbeddingUsage = class extends Class$2("effect/ai/EmbeddingModel/EmbeddingUsage")({ inputTokens: /* @__PURE__ */ UndefinedOr(Finite) }) {};
|
|
215111
|
-
/**
|
|
215112
|
-
* Response for a single embedding request.
|
|
215113
|
-
*
|
|
215114
|
-
* @since 4.0.0
|
|
215115
|
-
* @category models
|
|
215116
|
-
*/
|
|
215117
|
-
var EmbedResponse = class extends Class$2("effect/ai/EmbeddingModel/EmbedResponse")({ vector: /* @__PURE__ */ Array$1(Finite) }) {};
|
|
215118
|
-
/**
|
|
215119
|
-
* Response for multiple embeddings.
|
|
215120
|
-
*
|
|
215121
|
-
* @since 4.0.0
|
|
215122
|
-
* @category models
|
|
215123
|
-
*/
|
|
215124
|
-
var EmbedManyResponse = class extends Class$2("effect/ai/EmbeddingModel/EmbedManyResponse")({
|
|
215125
|
-
embeddings: /* @__PURE__ */ Array$1(EmbedResponse),
|
|
215126
|
-
usage: EmbeddingUsage
|
|
215127
|
-
}) {};
|
|
215128
|
-
/**
|
|
215129
|
-
* Tagged request used by request resolvers for embedding operations.
|
|
215130
|
-
*
|
|
215131
|
-
* @since 4.0.0
|
|
215132
|
-
* @category constructors
|
|
215133
|
-
*/
|
|
215134
|
-
var EmbeddingRequest = class extends TaggedClass$1("EmbeddingRequest") {};
|
|
215135
|
-
const invalidProviderResponse = (description) => make$15({
|
|
215136
|
-
module: "EmbeddingModel",
|
|
215137
|
-
method: "embedMany",
|
|
215138
|
-
reason: new InvalidOutputError({ description })
|
|
215139
|
-
});
|
|
215140
|
-
/**
|
|
215141
|
-
* Creates an EmbeddingModel service from a provider embedMany implementation.
|
|
215142
|
-
*
|
|
215143
|
-
* @since 4.0.0
|
|
215144
|
-
* @category constructors
|
|
215145
|
-
*/
|
|
215146
|
-
const make$11 = /* @__PURE__ */ fnUntraced(function* (params) {
|
|
215147
|
-
const resolver = make$47((entries) => flatMap$4(params.embedMany({ inputs: entries.map((entry) => entry.request.input) }), (response) => map$9(mapProviderResults(entries.length, response.results), (embeddings) => {
|
|
215148
|
-
for (let i = 0; i < entries.length; i++) entries[i].completeUnsafe(succeed$6(embeddings[i]));
|
|
215149
|
-
}))).pipe(withSpan("EmbeddingModel.resolver"));
|
|
215150
|
-
return EmbeddingModel.of({
|
|
215151
|
-
resolver,
|
|
215152
|
-
embed: (input) => request$2(new EmbeddingRequest({ input }), resolver).pipe(withSpan$1("EmbeddingModel.embed")),
|
|
215153
|
-
embedMany: (input) => (input.length === 0 ? succeed$3(new EmbedManyResponse({
|
|
215154
|
-
embeddings: [],
|
|
215155
|
-
usage: new EmbeddingUsage({ inputTokens: void 0 })
|
|
215156
|
-
})) : params.embedMany({ inputs: input }).pipe(flatMap$4((response) => mapProviderResults(input.length, response.results).pipe(map$9((embeddings) => new EmbedManyResponse({
|
|
215157
|
-
embeddings,
|
|
215158
|
-
usage: new EmbeddingUsage({ inputTokens: response.usage.inputTokens })
|
|
215159
|
-
})))))).pipe(withSpan$1("EmbeddingModel.embedMany"))
|
|
215160
|
-
});
|
|
215161
|
-
});
|
|
215162
|
-
const mapProviderResults = (inputLength, results) => {
|
|
215163
|
-
const embeddings = new Array(inputLength);
|
|
215164
|
-
if (results.length !== inputLength) return fail$6(invalidProviderResponse(`Provider returned ${results.length} embeddings but expected ${inputLength}`));
|
|
215165
|
-
for (let i = 0; i < results.length; i++) {
|
|
215166
|
-
const vector = results[i];
|
|
215167
|
-
embeddings[i] = new EmbedResponse({ vector });
|
|
215168
|
-
}
|
|
215169
|
-
return succeed$3(embeddings);
|
|
215170
|
-
};
|
|
215171
|
-
//#endregion
|
|
215172
|
-
//#region node_modules/.pnpm/clanka@0.2.21_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_09288369fd42a7055df614a5b619d2f6/node_modules/clanka/dist/ChunkRepo.js
|
|
215173
|
-
/**
|
|
215174
|
-
* @since 1.0.0
|
|
215175
|
-
* @category Models
|
|
215176
|
-
*/
|
|
215177
|
-
const ChunkId = Number$1.pipe(brand("ChunkRepo/ChunkId"));
|
|
215178
|
-
/**
|
|
215179
|
-
* @since 1.0.0
|
|
215180
|
-
* @category Models
|
|
215181
|
-
*/
|
|
215182
|
-
const SyncId = String$1.pipe(brand("ChunkRepo/SyncId"));
|
|
215183
|
-
/**
|
|
215184
|
-
* @since 1.0.0
|
|
215185
|
-
* @category Models
|
|
215186
|
-
*/
|
|
215187
|
-
const Float32ArraySchema = instanceOf(Float32Array);
|
|
215188
|
-
/**
|
|
215189
|
-
* @since 1.0.0
|
|
215190
|
-
* @category Models
|
|
215191
|
-
*/
|
|
215192
|
-
const Float32ArrayFromArray = Array$1(Number$1).pipe(decodeTo(Float32ArraySchema, transform$3({
|
|
215193
|
-
decode: (arr) => new Float32Array(arr),
|
|
215194
|
-
encode: (array) => Array.from(array)
|
|
215195
|
-
})));
|
|
215196
|
-
/**
|
|
215197
|
-
* @since 1.0.0
|
|
215198
|
-
* @category Models
|
|
215199
|
-
*/
|
|
215200
|
-
const Float32ArrayField = Field({
|
|
215201
|
-
insert: Float32ArraySchema,
|
|
215202
|
-
update: Float32ArraySchema,
|
|
215203
|
-
jsonCreate: Float32ArrayFromArray,
|
|
215204
|
-
jsonUpdate: Float32ArrayFromArray
|
|
215205
|
-
});
|
|
215206
|
-
/**
|
|
215207
|
-
* @since 1.0.0
|
|
215208
|
-
* @category Models
|
|
215209
|
-
*/
|
|
215210
|
-
var Chunk = class extends Class("Chunk")({
|
|
215211
|
-
id: Generated(ChunkId),
|
|
215212
|
-
path: String$1,
|
|
215213
|
-
content: String$1,
|
|
215214
|
-
hash: String$1,
|
|
215215
|
-
vector: Float32ArrayField,
|
|
215216
|
-
syncId: SyncId
|
|
215217
|
-
}) {};
|
|
215218
|
-
/**
|
|
215219
|
-
* @since 1.0.0
|
|
215220
|
-
* @category Services
|
|
215221
|
-
*/
|
|
215222
|
-
var ChunkRepo = class extends Service$1()("clanka/ChunkRepo") {};
|
|
215223
|
-
/**
|
|
215224
|
-
* @since 1.0.0
|
|
215225
|
-
* @category Errors
|
|
215226
|
-
*/
|
|
215227
|
-
var ChunkRepoError = class extends TaggedErrorClass()("ChunkRepoError", { reason: Union$2([SqlError]) }) {
|
|
215228
|
-
cause = this.reason;
|
|
215229
|
-
message = this.reason.message;
|
|
215230
|
-
};
|
|
215231
|
-
/**
|
|
215232
|
-
* @since 1.0.0
|
|
215233
|
-
* @category Layers
|
|
215234
|
-
*/
|
|
215235
|
-
const layer$10 = effect$1(ChunkRepo, gen(function* () {
|
|
215236
|
-
const sql = yield* SqlClient;
|
|
215237
|
-
const dimensions = yield* Dimensions;
|
|
215238
|
-
const loaders = yield* makeDataLoaders(Chunk, {
|
|
215239
|
-
tableName: "chunks",
|
|
215240
|
-
idColumn: "id",
|
|
215241
|
-
window: 10,
|
|
215242
|
-
spanPrefix: "ChunkRepo"
|
|
215243
|
-
});
|
|
215244
|
-
let needsQuantization = true;
|
|
215245
|
-
const maybeQuantize = gen(function* () {
|
|
215246
|
-
if (!needsQuantization) return;
|
|
215247
|
-
needsQuantization = false;
|
|
215248
|
-
yield* sql`select vector_init('chunks', 'vector', 'type=FLOAT32,dimension=${sql.literal(String(dimensions))}')`;
|
|
215249
|
-
yield* sql`select vector_quantize('chunks', 'vector')`;
|
|
215250
|
-
}).pipe(mapError$2((reason) => new ChunkRepoError({ reason })));
|
|
215251
|
-
yield* forkScoped(maybeQuantize);
|
|
215252
|
-
const search = findAll({
|
|
215253
|
-
Request: Struct$2({
|
|
215254
|
-
vector: Float32ArraySchema,
|
|
215255
|
-
limit: Number$1
|
|
215256
|
-
}),
|
|
215257
|
-
Result: Chunk,
|
|
215258
|
-
execute: ({ vector, limit }) => sql`
|
|
215259
|
-
select chunks.id, chunks.path, chunks.content, chunks.hash, chunks.syncId
|
|
215260
|
-
from chunks
|
|
215261
|
-
JOIN vector_quantize_scan('chunks', 'vector', ${vector}, CAST(${limit} AS INTEGER)) AS v
|
|
215262
|
-
ON chunks.id = v.rowid
|
|
215263
|
-
`
|
|
215264
|
-
});
|
|
215265
|
-
const exists = findById({
|
|
215266
|
-
Id: String$1,
|
|
215267
|
-
Result: Struct$2({
|
|
215268
|
-
id: ChunkId,
|
|
215269
|
-
hash: String$1
|
|
215270
|
-
}),
|
|
215271
|
-
ResultId(result) {
|
|
215272
|
-
return result.hash;
|
|
215273
|
-
},
|
|
215274
|
-
execute: (hashes) => sql`select id, hash from chunks where ${sql.in("hash", hashes)}`
|
|
215275
|
-
}).pipe(setDelay(5));
|
|
215276
|
-
return ChunkRepo.of({
|
|
215277
|
-
insert: (insert) => {
|
|
215278
|
-
needsQuantization = true;
|
|
215279
|
-
return loaders.insert(insert).pipe(catchTags$1({
|
|
215280
|
-
SqlError: (reason) => fail$6(new ChunkRepoError({ reason })),
|
|
215281
|
-
SchemaError: die$2
|
|
215282
|
-
}));
|
|
215283
|
-
},
|
|
215284
|
-
findById: (id) => loaders.findById(id).pipe(catchTags$1({ SchemaError: die$2 })),
|
|
215285
|
-
exists: (hash) => request$1(hash, exists).pipe(map$9((result) => result.id), catchNoSuchElement, catchTags$1({
|
|
215286
|
-
SqlError: (reason) => fail$6(new ChunkRepoError({ reason })),
|
|
215287
|
-
SchemaError: die$2
|
|
215288
|
-
})),
|
|
215289
|
-
search: fn("ChunkRepo.search")(function* (options) {
|
|
215290
|
-
yield* maybeQuantize;
|
|
215291
|
-
return yield* search(options).pipe(catchTags$1({
|
|
215292
|
-
SqlError: (reason) => fail$6(new ChunkRepoError({ reason })),
|
|
215293
|
-
SchemaError: die$2
|
|
215294
|
-
}));
|
|
215295
|
-
}),
|
|
215296
|
-
quantize: maybeQuantize,
|
|
215297
|
-
setSyncId: (chunkId, syncId) => sql`update chunks set syncId = ${syncId} where id = ${chunkId}`.pipe(mapError$2((reason) => new ChunkRepoError({ reason }))),
|
|
215298
|
-
deleteByPath: (path) => sql`delete from chunks where path = ${path}`.pipe(mapError$2((reason) => new ChunkRepoError({ reason }))),
|
|
215299
|
-
deleteForSyncId: (syncId) => sql`delete from chunks where syncId != ${syncId}`.pipe(mapError$2((reason) => new ChunkRepoError({ reason })))
|
|
215300
|
-
});
|
|
215301
|
-
}));
|
|
215302
|
-
//#endregion
|
|
215303
|
-
//#region node_modules/.pnpm/clanka@0.2.21_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_09288369fd42a7055df614a5b619d2f6/node_modules/clanka/dist/CodeChunker.js
|
|
215304
|
-
/**
|
|
215305
|
-
* @since 1.0.0
|
|
215306
|
-
*/
|
|
215307
|
-
/**
|
|
215308
|
-
* @since 1.0.0
|
|
215309
|
-
* @category Services
|
|
215310
|
-
*/
|
|
215311
|
-
var CodeChunker = class extends Service$1()("clanka/CodeChunker") {};
|
|
215312
|
-
const sourceExtensions = new Set([
|
|
215313
|
-
"c",
|
|
215314
|
-
"cc",
|
|
215315
|
-
"cpp",
|
|
215316
|
-
"cs",
|
|
215317
|
-
"css",
|
|
215318
|
-
"cts",
|
|
215319
|
-
"cxx",
|
|
215320
|
-
"go",
|
|
215321
|
-
"gql",
|
|
215322
|
-
"graphql",
|
|
215323
|
-
"h",
|
|
215324
|
-
"hpp",
|
|
215325
|
-
"html",
|
|
215326
|
-
"ini",
|
|
215327
|
-
"java",
|
|
215328
|
-
"js",
|
|
215329
|
-
"jsx",
|
|
215330
|
-
"kt",
|
|
215331
|
-
"kts",
|
|
215332
|
-
"less",
|
|
215333
|
-
"lua",
|
|
215334
|
-
"mjs",
|
|
215335
|
-
"mts",
|
|
215336
|
-
"php",
|
|
215337
|
-
"py",
|
|
215338
|
-
"rb",
|
|
215339
|
-
"rs",
|
|
215340
|
-
"sass",
|
|
215341
|
-
"scala",
|
|
215342
|
-
"scss",
|
|
215343
|
-
"sh",
|
|
215344
|
-
"sql",
|
|
215345
|
-
"svelte",
|
|
215346
|
-
"swift",
|
|
215347
|
-
"ts",
|
|
215348
|
-
"tsx",
|
|
215349
|
-
"vue",
|
|
215350
|
-
"xml",
|
|
215351
|
-
"zsh"
|
|
215352
|
-
]);
|
|
215353
|
-
const documentationExtensions = new Set([
|
|
215354
|
-
"adoc",
|
|
215355
|
-
"asciidoc",
|
|
215356
|
-
"md",
|
|
215357
|
-
"mdx",
|
|
215358
|
-
"rst",
|
|
215359
|
-
"txt"
|
|
215360
|
-
]);
|
|
215361
|
-
const ignoredDirectories = new Set([
|
|
215362
|
-
".git",
|
|
215363
|
-
".next",
|
|
215364
|
-
".nuxt",
|
|
215365
|
-
".svelte-kit",
|
|
215366
|
-
".turbo",
|
|
215367
|
-
"build",
|
|
215368
|
-
"coverage",
|
|
215369
|
-
"dist",
|
|
215370
|
-
"node_modules",
|
|
215371
|
-
"target"
|
|
215372
|
-
]);
|
|
215373
|
-
const normalizePath$1 = (path) => path.replace(/\\/g, "/");
|
|
215374
|
-
const normalizeText = (content) => content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
215375
|
-
const meaningfulLinePattern = /[^\s\p{P}]/u;
|
|
215376
|
-
const isMeaningfulLine = (line) => meaningfulLinePattern.test(line);
|
|
215377
|
-
const languageByExtension = new Map([
|
|
215378
|
-
["js", TreeSitterJavaScript],
|
|
215379
|
-
["jsx", TreeSitterJavaScript],
|
|
215380
|
-
["ts", TreeSitterTypeScript.typescript],
|
|
215381
|
-
["tsx", TreeSitterTypeScript.tsx]
|
|
215382
|
-
]);
|
|
215383
|
-
/**
|
|
215384
|
-
* @since 1.0.0
|
|
215385
|
-
* @category Predicates
|
|
215386
|
-
*/
|
|
215387
|
-
const isProbablyMinified = (content) => {
|
|
215388
|
-
const normalized = normalizeText(content);
|
|
215389
|
-
if (normalized.length < 2e3) return false;
|
|
215390
|
-
const lines = normalized.split("\n");
|
|
215391
|
-
if (lines.length <= 2) return true;
|
|
215392
|
-
let longLines = 0;
|
|
215393
|
-
for (const line of lines) if (line.length >= 300) longLines++;
|
|
215394
|
-
return lines.length <= 20 && longLines / lines.length >= .8;
|
|
215395
|
-
};
|
|
215396
|
-
/**
|
|
215397
|
-
* @since 1.0.0
|
|
215398
|
-
* @category Predicates
|
|
215399
|
-
*/
|
|
215400
|
-
const isMeaningfulFile = (path) => {
|
|
215401
|
-
const parts = normalizePath$1(path).toLowerCase().split("/");
|
|
215402
|
-
const fileName = parts.at(-1);
|
|
215403
|
-
if (fileName === void 0 || fileName.length === 0) return false;
|
|
215404
|
-
if (parts.some((part) => ignoredDirectories.has(part))) return false;
|
|
215405
|
-
if (/\.min\.(?:css|js)$/i.test(fileName)) return false;
|
|
215406
|
-
const extensionIndex = fileName.lastIndexOf(".");
|
|
215407
|
-
if (extensionIndex === -1) return false;
|
|
215408
|
-
const extension = fileName.slice(extensionIndex + 1);
|
|
215409
|
-
return sourceExtensions.has(extension) || documentationExtensions.has(extension);
|
|
215410
|
-
};
|
|
215411
|
-
const resolveChunkSettings = (options) => {
|
|
215412
|
-
const chunkSize = Math.max(1, options.chunkSize);
|
|
215413
|
-
return {
|
|
215414
|
-
chunkSize,
|
|
215415
|
-
chunkOverlap: Math.max(0, Math.min(chunkSize - 1, options.chunkOverlap)),
|
|
215416
|
-
chunkMaxCharacters: options.chunkMaxCharacters !== void 0 && Number.isFinite(options.chunkMaxCharacters) ? Math.max(1, Math.floor(options.chunkMaxCharacters)) : Number.POSITIVE_INFINITY
|
|
215417
|
-
};
|
|
215418
|
-
};
|
|
215419
|
-
const getPathExtension = (path) => {
|
|
215420
|
-
const fileName = path.split("/").at(-1);
|
|
215421
|
-
if (fileName === void 0) return;
|
|
215422
|
-
const extensionIndex = fileName.lastIndexOf(".");
|
|
215423
|
-
if (extensionIndex === -1) return;
|
|
215424
|
-
return fileName.slice(extensionIndex + 1).toLowerCase();
|
|
215425
|
-
};
|
|
215426
|
-
const resolveAstLanguage = (path) => {
|
|
215427
|
-
const extension = getPathExtension(path);
|
|
215428
|
-
if (extension === void 0) return;
|
|
215429
|
-
return languageByExtension.get(extension);
|
|
215430
|
-
};
|
|
215431
|
-
const lineRangeFromNode = (node) => {
|
|
215432
|
-
const startLine = node.startPosition.row + 1;
|
|
215433
|
-
return {
|
|
215434
|
-
startLine,
|
|
215435
|
-
endLine: Math.max(startLine, node.endPosition.row + 1)
|
|
215436
|
-
};
|
|
215437
|
-
};
|
|
215438
|
-
const hasOnlyWhitespaceLines = (lines, startLine, endLine) => {
|
|
215439
|
-
if (startLine > endLine) return true;
|
|
215440
|
-
for (let lineIndex = startLine; lineIndex <= endLine; lineIndex++) if ((lines[lineIndex - 1] ?? "").trim().length > 0) return false;
|
|
215441
|
-
return true;
|
|
215442
|
-
};
|
|
215443
|
-
const lineRangeWithLeadingComments = (node, siblings, nodeIndex, lines) => {
|
|
215444
|
-
const baseRange = lineRangeFromNode(node);
|
|
215445
|
-
let startLine = baseRange.startLine;
|
|
215446
|
-
for (let index = nodeIndex - 1; index >= 0; index--) {
|
|
215447
|
-
const sibling = siblings[index];
|
|
215448
|
-
if (sibling.type !== "comment") break;
|
|
215449
|
-
const commentRange = lineRangeFromNode(sibling);
|
|
215450
|
-
if (!hasOnlyWhitespaceLines(lines, commentRange.endLine + 1, startLine - 1)) break;
|
|
215451
|
-
startLine = commentRange.startLine;
|
|
215452
|
-
}
|
|
215453
|
-
return {
|
|
215454
|
-
startLine,
|
|
215455
|
-
endLine: baseRange.endLine
|
|
215456
|
-
};
|
|
215457
|
-
};
|
|
215458
|
-
const normalizeLineRange = (range, lineCount) => {
|
|
215459
|
-
const startLine = Math.max(1, Math.min(lineCount, range.startLine));
|
|
215460
|
-
const endLine = Math.max(1, Math.min(lineCount, range.endLine));
|
|
215461
|
-
if (endLine < startLine) return;
|
|
215462
|
-
return {
|
|
215463
|
-
startLine,
|
|
215464
|
-
endLine
|
|
215465
|
-
};
|
|
215466
|
-
};
|
|
215467
|
-
const lineLengthPrefixSums = (lines) => {
|
|
215468
|
-
const sums = [0];
|
|
215469
|
-
for (let index = 0; index < lines.length; index++) sums.push(sums[index] + lines[index].length);
|
|
215470
|
-
return sums;
|
|
215471
|
-
};
|
|
215472
|
-
const lineRangeCharacterLength = (prefixSums, range) => prefixSums[range.endLine] - prefixSums[range.startLine - 1] + (range.endLine - range.startLine);
|
|
215473
|
-
const resolveSegmentEndLine = (options) => {
|
|
215474
|
-
if (options.settings.chunkMaxCharacters === Number.POSITIVE_INFINITY) return options.maxEndLine;
|
|
215475
|
-
let endLine = options.maxEndLine;
|
|
215476
|
-
while (endLine > options.startLine && lineRangeCharacterLength(options.prefixSums, {
|
|
215477
|
-
startLine: options.startLine,
|
|
215478
|
-
endLine
|
|
215479
|
-
}) > options.settings.chunkMaxCharacters) endLine--;
|
|
215480
|
-
return endLine;
|
|
215481
|
-
};
|
|
215482
|
-
const splitRange = (range, settings, prefixSums) => {
|
|
215483
|
-
if (range.endLine - range.startLine + 1 <= settings.chunkSize && lineRangeCharacterLength(prefixSums, range) <= settings.chunkMaxCharacters) return [range];
|
|
215484
|
-
const out = [];
|
|
215485
|
-
for (let startLine = range.startLine; startLine <= range.endLine;) {
|
|
215486
|
-
const maxEndLine = Math.min(range.endLine, startLine + settings.chunkSize - 1);
|
|
215487
|
-
const endLine = resolveSegmentEndLine({
|
|
215488
|
-
startLine,
|
|
215489
|
-
maxEndLine,
|
|
215490
|
-
settings,
|
|
215491
|
-
prefixSums
|
|
215492
|
-
});
|
|
215493
|
-
out.push({
|
|
215494
|
-
startLine,
|
|
215495
|
-
endLine
|
|
215496
|
-
});
|
|
215497
|
-
if (endLine >= range.endLine) break;
|
|
215498
|
-
startLine = Math.max(startLine + 1, endLine - settings.chunkOverlap + 1);
|
|
215499
|
-
}
|
|
215500
|
-
return out;
|
|
215501
|
-
};
|
|
215502
|
-
const nodeText = (node) => {
|
|
215503
|
-
if (node === null) return;
|
|
215504
|
-
const value = node.text.trim().replace(/\s+/g, " ");
|
|
215505
|
-
return value.length === 0 ? void 0 : value;
|
|
215506
|
-
};
|
|
215507
|
-
const nodeFieldText = (node, fieldName) => nodeText(node.childForFieldName(fieldName));
|
|
215508
|
-
const isNamespaceNode = (node) => node.type === "internal_module" || node.type === "module";
|
|
215509
|
-
const unwrapDeclarationNode = (node) => {
|
|
215510
|
-
let current = node;
|
|
215511
|
-
while (true) {
|
|
215512
|
-
if (current.type === "export_statement") {
|
|
215513
|
-
const declaration = current.childForFieldName("declaration") ?? current.namedChildren[0];
|
|
215514
|
-
if (declaration === void 0) return current;
|
|
215515
|
-
current = declaration;
|
|
215516
|
-
continue;
|
|
215517
|
-
}
|
|
215518
|
-
if (current.type === "ambient_declaration") {
|
|
215519
|
-
const declaration = current.namedChildren.find((child) => child.type.endsWith("_declaration") || isNamespaceNode(child));
|
|
215520
|
-
if (declaration === void 0) return current;
|
|
215521
|
-
current = declaration;
|
|
215522
|
-
continue;
|
|
215523
|
-
}
|
|
215524
|
-
return current;
|
|
215525
|
-
}
|
|
215526
|
-
};
|
|
215527
|
-
const variableDeclarators = (node) => node.namedChildren.filter((child) => child.type === "variable_declarator");
|
|
215528
|
-
const variableTypeFromDeclarator = (node) => {
|
|
215529
|
-
const value = node.childForFieldName("value");
|
|
215530
|
-
if (value !== null && value.type.includes("function")) return "function";
|
|
215531
|
-
return "variable";
|
|
215532
|
-
};
|
|
215533
|
-
const variableTypeFromDeclaration = (node) => {
|
|
215534
|
-
if (variableDeclarators(node).some((declarator) => variableTypeFromDeclarator(declarator) === "function")) return "function";
|
|
215535
|
-
return "variable";
|
|
215536
|
-
};
|
|
215537
|
-
const chunkTypeFromNode = (node) => {
|
|
215538
|
-
switch (node.type) {
|
|
215539
|
-
case "class_declaration": return "class";
|
|
215540
|
-
case "enum_declaration": return "enum";
|
|
215541
|
-
case "function_declaration":
|
|
215542
|
-
case "generator_function_declaration": return "function";
|
|
215543
|
-
case "internal_module":
|
|
215544
|
-
case "module": return "namespace";
|
|
215545
|
-
case "interface_declaration": return "interface";
|
|
215546
|
-
case "generator_method_definition":
|
|
215547
|
-
case "method_definition": return "method";
|
|
215548
|
-
case "type_alias_declaration": return "type-alias";
|
|
215549
|
-
case "lexical_declaration":
|
|
215550
|
-
case "variable_declaration": return variableTypeFromDeclaration(node);
|
|
215551
|
-
case "variable_declarator": return variableTypeFromDeclarator(node);
|
|
215552
|
-
default: return;
|
|
215553
|
-
}
|
|
215554
|
-
};
|
|
215555
|
-
const variableNamesFromDeclaration = (node) => {
|
|
215556
|
-
const names = variableDeclarators(node).map((declarator) => nodeFieldText(declarator, "name")).filter((name) => name !== void 0);
|
|
215557
|
-
if (names.length === 0) return;
|
|
215558
|
-
return names.join(", ");
|
|
215559
|
-
};
|
|
215560
|
-
const nameFromNode = (node) => {
|
|
215561
|
-
switch (node.type) {
|
|
215562
|
-
case "class_declaration":
|
|
215563
|
-
case "enum_declaration":
|
|
215564
|
-
case "function_declaration":
|
|
215565
|
-
case "generator_function_declaration":
|
|
215566
|
-
case "internal_module":
|
|
215567
|
-
case "interface_declaration":
|
|
215568
|
-
case "module":
|
|
215569
|
-
case "generator_method_definition":
|
|
215570
|
-
case "method_definition":
|
|
215571
|
-
case "type_alias_declaration":
|
|
215572
|
-
case "variable_declarator": return nodeFieldText(node, "name");
|
|
215573
|
-
case "lexical_declaration":
|
|
215574
|
-
case "variable_declaration": return variableNamesFromDeclaration(node);
|
|
215575
|
-
default: return;
|
|
215576
|
-
}
|
|
215577
|
-
};
|
|
215578
|
-
const formatParent = (type, name) => {
|
|
215579
|
-
if (type === void 0 && name === void 0) return;
|
|
215580
|
-
if (type === void 0) return name;
|
|
215581
|
-
if (name === void 0) return type;
|
|
215582
|
-
return type + " " + name;
|
|
215583
|
-
};
|
|
215584
|
-
const collectClassMethodRanges = (classNode, parent, lines) => {
|
|
215585
|
-
const body = classNode.childForFieldName("body");
|
|
215586
|
-
if (body === null) return [];
|
|
215587
|
-
const out = [];
|
|
215588
|
-
for (let index = 0; index < body.namedChildren.length; index++) {
|
|
215589
|
-
const child = body.namedChildren[index];
|
|
215590
|
-
if (!child.type.includes("method")) continue;
|
|
215591
|
-
out.push({
|
|
215592
|
-
...lineRangeWithLeadingComments(child, body.namedChildren, index, lines),
|
|
215593
|
-
name: nameFromNode(child),
|
|
215594
|
-
type: chunkTypeFromNode(child),
|
|
215595
|
-
parent
|
|
215596
|
-
});
|
|
215597
|
-
}
|
|
215598
|
-
return out;
|
|
215599
|
-
};
|
|
215600
|
-
const collectAstRanges = (path, content, lines) => {
|
|
215601
|
-
const language = resolveAstLanguage(path);
|
|
215602
|
-
if (language === void 0) return [];
|
|
215603
|
-
try {
|
|
215604
|
-
const parser = new TreeSitter();
|
|
215605
|
-
parser.setLanguage(language);
|
|
215606
|
-
const tree = parser.parse(content, void 0, { bufferSize: 1024 * 1024 });
|
|
215607
|
-
const collectDeclarationRanges = (siblings, parent) => {
|
|
215608
|
-
const out = [];
|
|
215609
|
-
for (let index = 0; index < siblings.length; index++) {
|
|
215610
|
-
const sibling = siblings[index];
|
|
215611
|
-
if (sibling.type === "comment" || sibling.type.includes("import")) continue;
|
|
215612
|
-
const declarationNode = unwrapDeclarationNode(sibling);
|
|
215613
|
-
const type = chunkTypeFromNode(declarationNode);
|
|
215614
|
-
const name = nameFromNode(declarationNode);
|
|
215615
|
-
if (type === void 0 && name === void 0) continue;
|
|
215616
|
-
out.push({
|
|
215617
|
-
...lineRangeWithLeadingComments(sibling, siblings, index, lines),
|
|
215618
|
-
name,
|
|
215619
|
-
type,
|
|
215620
|
-
parent
|
|
215621
|
-
});
|
|
215622
|
-
if (declarationNode.type === "class_declaration") out.push(...collectClassMethodRanges(declarationNode, formatParent(type, name), lines));
|
|
215623
|
-
if (isNamespaceNode(declarationNode)) {
|
|
215624
|
-
const body = declarationNode.childForFieldName("body");
|
|
215625
|
-
if (body !== null) out.push(...collectDeclarationRanges(body.namedChildren, formatParent(type, name)));
|
|
215626
|
-
}
|
|
215627
|
-
}
|
|
215628
|
-
return out;
|
|
215629
|
-
};
|
|
215630
|
-
return collectDeclarationRanges(tree.rootNode.namedChildren, void 0);
|
|
215631
|
-
} catch {
|
|
215632
|
-
return [];
|
|
215633
|
-
}
|
|
215634
|
-
};
|
|
215635
|
-
const chunksFromRanges = (path, lines, ranges, settings) => {
|
|
215636
|
-
const hasMethodChildRange = (classRange) => {
|
|
215637
|
-
const parent = formatParent("class", classRange.name);
|
|
215638
|
-
return ranges.some((range) => range.type === "method" && range.parent === parent && range.startLine >= classRange.startLine && range.endLine <= classRange.endLine);
|
|
215639
|
-
};
|
|
215640
|
-
const out = [];
|
|
215641
|
-
const seen = /* @__PURE__ */ new Set();
|
|
215642
|
-
const prefixSums = lineLengthPrefixSums(lines);
|
|
215643
|
-
for (const range of ranges) {
|
|
215644
|
-
const normalizedRange = normalizeLineRange(range, lines.length);
|
|
215645
|
-
if (normalizedRange === void 0) continue;
|
|
215646
|
-
const allSegments = splitRange(normalizedRange, settings, prefixSums);
|
|
215647
|
-
const segments = range.type === "class" && allSegments.length > 1 && hasMethodChildRange({
|
|
215648
|
-
...normalizedRange,
|
|
215649
|
-
name: range.name
|
|
215650
|
-
}) ? [allSegments[0]] : allSegments;
|
|
215651
|
-
for (const segment of segments) {
|
|
215652
|
-
const key = String(segment.startLine) + ":" + String(segment.endLine) + ":" + (range.name ?? "") + ":" + (range.type ?? "") + ":" + (range.parent ?? "");
|
|
215653
|
-
if (seen.has(key)) continue;
|
|
215654
|
-
seen.add(key);
|
|
215655
|
-
const chunkLines = lines.slice(segment.startLine - 1, segment.endLine);
|
|
215656
|
-
if (!chunkLines.some(isMeaningfulLine)) continue;
|
|
215657
|
-
out.push({
|
|
215658
|
-
path,
|
|
215659
|
-
startLine: segment.startLine,
|
|
215660
|
-
endLine: segment.endLine,
|
|
215661
|
-
name: range.name,
|
|
215662
|
-
type: range.type,
|
|
215663
|
-
parent: range.parent,
|
|
215664
|
-
content: chunkLines.join("\n")
|
|
215665
|
-
});
|
|
215666
|
-
}
|
|
215667
|
-
}
|
|
215668
|
-
return out.toSorted((left, right) => left.startLine - right.startLine || left.endLine - right.endLine || (left.name ?? "").localeCompare(right.name ?? ""));
|
|
215669
|
-
};
|
|
215670
|
-
const chunkWithLineWindows = (path, lines, settings) => {
|
|
215671
|
-
const out = [];
|
|
215672
|
-
const prefixSums = lineLengthPrefixSums(lines);
|
|
215673
|
-
for (let index = 0; index < lines.length;) {
|
|
215674
|
-
if (!isMeaningfulLine(lines[index])) {
|
|
215675
|
-
index++;
|
|
215676
|
-
continue;
|
|
215677
|
-
}
|
|
215678
|
-
const startLine = index + 1;
|
|
215679
|
-
const endLine = resolveSegmentEndLine({
|
|
215680
|
-
startLine,
|
|
215681
|
-
maxEndLine: Math.min(lines.length, startLine + settings.chunkSize - 1),
|
|
215682
|
-
settings,
|
|
215683
|
-
prefixSums
|
|
215684
|
-
});
|
|
215685
|
-
const chunkLines = lines.slice(startLine - 1, endLine);
|
|
215686
|
-
out.push({
|
|
215687
|
-
path,
|
|
215688
|
-
startLine,
|
|
215689
|
-
endLine,
|
|
215690
|
-
name: void 0,
|
|
215691
|
-
type: void 0,
|
|
215692
|
-
parent: void 0,
|
|
215693
|
-
content: chunkLines.join("\n")
|
|
215694
|
-
});
|
|
215695
|
-
if (endLine >= lines.length) break;
|
|
215696
|
-
index = Math.max(startLine + 1, endLine - settings.chunkOverlap + 1) - 1;
|
|
215697
|
-
}
|
|
215698
|
-
return out;
|
|
215699
|
-
};
|
|
215700
|
-
/**
|
|
215701
|
-
* @since 1.0.0
|
|
215702
|
-
* @category Constructors
|
|
215703
|
-
*/
|
|
215704
|
-
const chunkFileContent = (path, content, options) => {
|
|
215705
|
-
if (content.trim().length === 0 || isProbablyMinified(content)) return [];
|
|
215706
|
-
const normalizedPath = normalizePath$1(path);
|
|
215707
|
-
const normalizedContent = normalizeText(content);
|
|
215708
|
-
const lines = normalizedContent.split("\n");
|
|
215709
|
-
if (lines.at(-1) === "") lines.pop();
|
|
215710
|
-
if (lines.length === 0) return [];
|
|
215711
|
-
const settings = resolveChunkSettings(options);
|
|
215712
|
-
const astRanges = collectAstRanges(normalizedPath, normalizedContent, lines);
|
|
215713
|
-
if (astRanges.length > 0) {
|
|
215714
|
-
const astChunks = chunksFromRanges(normalizedPath, lines, astRanges, settings);
|
|
215715
|
-
if (astChunks.length > 0) return astChunks;
|
|
215716
|
-
}
|
|
215717
|
-
return chunkWithLineWindows(normalizedPath, lines, settings);
|
|
215718
|
-
};
|
|
215719
|
-
/**
|
|
215720
|
-
* @since 1.0.0
|
|
215721
|
-
* @category Layers
|
|
215722
|
-
*/
|
|
215723
|
-
const layer$9 = effect$1(CodeChunker, gen(function* () {
|
|
215724
|
-
const spawner = yield* ChildProcessSpawner;
|
|
215725
|
-
const fs = yield* FileSystem;
|
|
215726
|
-
const pathService = yield* Path$1;
|
|
215727
|
-
const listFiles = fn("CodeChunker.listFiles")(function* (options) {
|
|
215728
|
-
const root = pathService.resolve(options.root);
|
|
215729
|
-
const maxFileSize = options.maxFileSize ?? "1M";
|
|
215730
|
-
return yield* pipe$1(spawner.streamLines(make$45("rg", [
|
|
215731
|
-
"--files",
|
|
215732
|
-
"--hidden",
|
|
215733
|
-
"--max-filesize",
|
|
215734
|
-
maxFileSize,
|
|
215735
|
-
"--glob",
|
|
215736
|
-
"!.git"
|
|
215737
|
-
], {
|
|
215738
|
-
cwd: root,
|
|
215739
|
-
stdin: "ignore"
|
|
215740
|
-
})), runCollect, map$9(fromIterable$5), map$9((entries) => entries.map((entry) => normalizePath$1(entry.trim())).filter((entry) => entry.length > 0 && isMeaningfulFile(entry)).sort((left, right) => left.localeCompare(right))), orDie$2);
|
|
215741
|
-
});
|
|
215742
|
-
const chunkFile = fn("CodeChunker.chunkFile")(function* (options) {
|
|
215743
|
-
const root = pathService.resolve(options.root);
|
|
215744
|
-
const absolutePath = pathService.resolve(root, options.path);
|
|
215745
|
-
const path = normalizePath$1(pathService.relative(root, absolutePath));
|
|
215746
|
-
if (path.length === 0 || path === ".." || path.startsWith("../") || !isMeaningfulFile(path)) return [];
|
|
215747
|
-
return yield* pipe$1(fs.readFileString(absolutePath), map$9((content) => chunkFileContent(path, content, options)), catch_$2(() => succeed$3([])));
|
|
215748
|
-
});
|
|
215749
|
-
const chunkFiles = (options) => fromArray(options.paths).pipe(flatMap$2((path) => pipe$1(chunkFile({
|
|
215750
|
-
root: options.root,
|
|
215751
|
-
path,
|
|
215752
|
-
chunkSize: options.chunkSize,
|
|
215753
|
-
chunkOverlap: options.chunkOverlap,
|
|
215754
|
-
...options.chunkMaxCharacters === void 0 ? {} : { chunkMaxCharacters: options.chunkMaxCharacters }
|
|
215755
|
-
}), fromArrayEffect), { concurrency: 5 }));
|
|
215756
|
-
const chunkCodebase = fnUntraced(function* (options) {
|
|
215757
|
-
const root = pathService.resolve(options.root);
|
|
215758
|
-
return chunkFiles({
|
|
215759
|
-
root,
|
|
215760
|
-
paths: yield* listFiles({
|
|
215761
|
-
root,
|
|
215762
|
-
...options.maxFileSize === void 0 ? {} : { maxFileSize: options.maxFileSize }
|
|
215763
|
-
}),
|
|
215764
|
-
chunkSize: options.chunkSize,
|
|
215765
|
-
chunkOverlap: options.chunkOverlap,
|
|
215766
|
-
...options.chunkMaxCharacters === void 0 ? {} : { chunkMaxCharacters: options.chunkMaxCharacters }
|
|
215767
|
-
});
|
|
215768
|
-
}, unwrap);
|
|
215769
|
-
return CodeChunker.of({
|
|
215770
|
-
listFiles,
|
|
215771
|
-
chunkFile,
|
|
215772
|
-
chunkFiles,
|
|
215773
|
-
chunkCodebase
|
|
215774
|
-
});
|
|
215775
|
-
}));
|
|
215776
|
-
//#endregion
|
|
215777
|
-
//#region node_modules/.pnpm/@effect+sql-sqlite-node@4.0.0-beta.36_effect@4.0.0-beta.36/node_modules/@effect/sql-sqlite-node/dist/SqliteClient.js
|
|
215778
|
-
/**
|
|
215779
|
-
* @since 1.0.0
|
|
215780
|
-
*/
|
|
215781
|
-
const ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
215782
|
-
/**
|
|
215783
|
-
* @category type ids
|
|
215784
|
-
* @since 1.0.0
|
|
215785
|
-
*/
|
|
215786
|
-
const TypeId$2 = "~@effect/sql-sqlite-node/SqliteClient";
|
|
215787
|
-
/**
|
|
215788
|
-
* @category tags
|
|
215789
|
-
* @since 1.0.0
|
|
215790
|
-
*/
|
|
215791
|
-
const SqliteClient = /* @__PURE__ */ Service$1("@effect/sql-sqlite-node/SqliteClient");
|
|
215792
|
-
/**
|
|
215793
|
-
* @category constructor
|
|
215794
|
-
* @since 1.0.0
|
|
215795
|
-
*/
|
|
215796
|
-
const make$10 = (options) => gen(function* () {
|
|
215797
|
-
const compiler = makeCompilerSqlite(options.transformQueryNames);
|
|
215798
|
-
const transformRows = options.transformResultNames ? defaultTransforms(options.transformResultNames).array : void 0;
|
|
215799
|
-
const makeConnection = gen(function* () {
|
|
215800
|
-
const scope$3 = yield* scope;
|
|
215801
|
-
const db = new Sqlite(options.filename, { readonly: options.readonly ?? false });
|
|
215802
|
-
yield* addFinalizer$1(scope$3, sync(() => db.close()));
|
|
215803
|
-
if (options.disableWAL !== true) db.pragma("journal_mode = WAL");
|
|
215804
|
-
const prepareCache = yield* make$57({
|
|
215805
|
-
capacity: options.prepareCacheSize ?? 200,
|
|
215806
|
-
timeToLive: options.prepareCacheTTL ?? minutes(10),
|
|
215807
|
-
lookup: (sql) => try_({
|
|
215808
|
-
try: () => db.prepare(sql),
|
|
215809
|
-
catch: (cause) => new SqlError({
|
|
215810
|
-
cause,
|
|
215811
|
-
message: "Failed to prepare statement "
|
|
215812
|
-
})
|
|
215813
|
-
})
|
|
215814
|
-
});
|
|
215815
|
-
const runStatement = (statement, params, raw) => withFiber((fiber) => {
|
|
215816
|
-
if (get$15(fiber.services, SafeIntegers)) statement.safeIntegers(true);
|
|
215817
|
-
try {
|
|
215818
|
-
if (statement.reader) return succeed$3(statement.all(...params));
|
|
215819
|
-
const result = statement.run(...params);
|
|
215820
|
-
return succeed$3(raw ? result : []);
|
|
215821
|
-
} catch (cause) {
|
|
215822
|
-
return fail$6(new SqlError({
|
|
215823
|
-
cause,
|
|
215824
|
-
message: "Failed to execute statement"
|
|
215825
|
-
}));
|
|
215826
|
-
}
|
|
215827
|
-
});
|
|
215828
|
-
const run = (sql, params, raw = false) => flatMap$4(get$7(prepareCache, sql), (s) => runStatement(s, params, raw));
|
|
215829
|
-
const runValues = (sql, params) => acquireUseRelease(get$7(prepareCache, sql), (statement) => try_({
|
|
215830
|
-
try: () => {
|
|
215831
|
-
if (statement.reader) {
|
|
215832
|
-
statement.raw(true);
|
|
215833
|
-
return statement.all(...params);
|
|
215834
|
-
}
|
|
215835
|
-
statement.run(...params);
|
|
215836
|
-
return [];
|
|
215837
|
-
},
|
|
215838
|
-
catch: (cause) => new SqlError({
|
|
215839
|
-
cause,
|
|
215840
|
-
message: "Failed to execute statement"
|
|
215841
|
-
})
|
|
215842
|
-
}), (statement) => sync(() => statement.reader && statement.raw(false)));
|
|
215843
|
-
return identity({
|
|
215844
|
-
execute(sql, params, transformRows) {
|
|
215845
|
-
return transformRows ? map$9(run(sql, params), transformRows) : run(sql, params);
|
|
215846
|
-
},
|
|
215847
|
-
executeRaw(sql, params) {
|
|
215848
|
-
return run(sql, params, true);
|
|
215849
|
-
},
|
|
215850
|
-
executeValues(sql, params) {
|
|
215851
|
-
return runValues(sql, params);
|
|
215852
|
-
},
|
|
215853
|
-
executeUnprepared(sql, params, transformRows) {
|
|
215854
|
-
const effect = runStatement(db.prepare(sql), params ?? [], false);
|
|
215855
|
-
return transformRows ? map$9(effect, transformRows) : effect;
|
|
215856
|
-
},
|
|
215857
|
-
executeStream(_sql, _params) {
|
|
215858
|
-
return die("executeStream not implemented");
|
|
215859
|
-
},
|
|
215860
|
-
export: try_({
|
|
215861
|
-
try: () => db.serialize(),
|
|
215862
|
-
catch: (cause) => new SqlError({
|
|
215863
|
-
cause,
|
|
215864
|
-
message: "Failed to export database"
|
|
215865
|
-
})
|
|
215866
|
-
}),
|
|
215867
|
-
backup(destination) {
|
|
215868
|
-
return tryPromise({
|
|
215869
|
-
try: () => db.backup(destination),
|
|
215870
|
-
catch: (cause) => new SqlError({
|
|
215871
|
-
cause,
|
|
215872
|
-
message: "Failed to backup database"
|
|
215873
|
-
})
|
|
215874
|
-
});
|
|
215875
|
-
},
|
|
215876
|
-
loadExtension(path) {
|
|
215877
|
-
return try_({
|
|
215878
|
-
try: () => db.loadExtension(path),
|
|
215879
|
-
catch: (cause) => new SqlError({
|
|
215880
|
-
cause,
|
|
215881
|
-
message: "Failed to load extension"
|
|
215882
|
-
})
|
|
215883
|
-
});
|
|
215884
|
-
}
|
|
215885
|
-
});
|
|
215886
|
-
});
|
|
215887
|
-
const semaphore = yield* make$72(1);
|
|
215888
|
-
const connection = yield* makeConnection;
|
|
215889
|
-
const acquirer = semaphore.withPermits(1)(succeed$3(connection));
|
|
215890
|
-
const transactionAcquirer = uninterruptibleMask((restore) => {
|
|
215891
|
-
const scope = getUnsafe$4(getCurrent().services, Scope);
|
|
215892
|
-
return as$1(tap$1(restore(semaphore.take(1)), () => addFinalizer$1(scope, semaphore.release(1))), connection);
|
|
215893
|
-
});
|
|
215894
|
-
return Object.assign(yield* make$49({
|
|
215895
|
-
acquirer,
|
|
215896
|
-
compiler,
|
|
215897
|
-
transactionAcquirer,
|
|
215898
|
-
spanAttributes: [...options.spanAttributes ? Object.entries(options.spanAttributes) : [], [ATTR_DB_SYSTEM_NAME, "sqlite"]],
|
|
215899
|
-
transformRows
|
|
215900
|
-
}), {
|
|
215901
|
-
[TypeId$2]: TypeId$2,
|
|
215902
|
-
config: options,
|
|
215903
|
-
export: flatMap$4(acquirer, (_) => _.export),
|
|
215904
|
-
backup: (destination) => flatMap$4(acquirer, (_) => _.backup(destination)),
|
|
215905
|
-
loadExtension: (path) => flatMap$4(acquirer, (_) => _.loadExtension(path))
|
|
215906
|
-
});
|
|
215907
|
-
});
|
|
215908
|
-
/**
|
|
215909
|
-
* @category layers
|
|
215910
|
-
* @since 1.0.0
|
|
215911
|
-
*/
|
|
215912
|
-
const layer$8 = (config) => effectServices(map$9(make$10(config), (client) => make$87(SqliteClient, client).pipe(add$3(SqlClient, client)))).pipe(provide$3(layer$32));
|
|
215913
|
-
//#endregion
|
|
215914
|
-
//#region node_modules/.pnpm/@effect+sql-sqlite-node@4.0.0-beta.36_effect@4.0.0-beta.36/node_modules/@effect/sql-sqlite-node/dist/SqliteMigrator.js
|
|
215915
|
-
/**
|
|
215916
|
-
* @category constructor
|
|
215917
|
-
* @since 1.0.0
|
|
215918
|
-
*/
|
|
215919
|
-
const run$1 = /* @__PURE__ */ make$25({});
|
|
215920
|
-
/**
|
|
215921
|
-
* @category constructor
|
|
215922
|
-
* @since 1.0.0
|
|
215923
|
-
*/
|
|
215924
|
-
const layer$7 = (options) => effectDiscard(run$1(options));
|
|
215925
|
-
//#endregion
|
|
215926
|
-
//#region node_modules/.pnpm/clanka@0.2.21_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_09288369fd42a7055df614a5b619d2f6/node_modules/clanka/dist/internal/sqlite-vector.js
|
|
215927
|
-
/**
|
|
215928
|
-
* Binary extension for each platform
|
|
215929
|
-
*/
|
|
215930
|
-
const PLATFORM_EXTENSIONS = {
|
|
215931
|
-
darwin: ".dylib",
|
|
215932
|
-
linux: ".so",
|
|
215933
|
-
win32: ".dll"
|
|
215934
|
-
};
|
|
215935
|
-
/**
|
|
215936
|
-
* Detects if the system uses musl libc (Alpine Linux, etc.)
|
|
215937
|
-
* Uses multiple detection strategies for reliability
|
|
215938
|
-
*/
|
|
215939
|
-
function isMusl() {
|
|
215940
|
-
if (platform() !== "linux") return false;
|
|
215941
|
-
for (const file of [
|
|
215942
|
-
"/lib/ld-musl-x86_64.so.1",
|
|
215943
|
-
"/lib/ld-musl-aarch64.so.1",
|
|
215944
|
-
"/lib/ld-musl-armhf.so.1"
|
|
215945
|
-
]) if (existsSync(file)) return true;
|
|
215946
|
-
try {
|
|
215947
|
-
if (execSync("ldd --version 2>&1", {
|
|
215948
|
-
encoding: "utf-8",
|
|
215949
|
-
stdio: [
|
|
215950
|
-
"pipe",
|
|
215951
|
-
"pipe",
|
|
215952
|
-
"pipe"
|
|
215953
|
-
]
|
|
215954
|
-
}).includes("musl")) return true;
|
|
215955
|
-
} catch {}
|
|
215956
|
-
try {
|
|
215957
|
-
if (existsSync("/etc/os-release")) {
|
|
215958
|
-
const osRelease = readFileSync("/etc/os-release", "utf-8");
|
|
215959
|
-
if (osRelease.includes("Alpine") || osRelease.includes("musl")) return true;
|
|
215960
|
-
}
|
|
215961
|
-
} catch {}
|
|
215962
|
-
try {
|
|
215963
|
-
if ((process.report?.getReport?.())?.header?.glibcVersionRuntime === "") return true;
|
|
215964
|
-
} catch {}
|
|
215965
|
-
return false;
|
|
215966
|
-
}
|
|
215967
|
-
/**
|
|
215968
|
-
* Gets the current platform identifier
|
|
215969
|
-
* @throws {Error} If the platform is unsupported
|
|
215970
|
-
*/
|
|
215971
|
-
function getCurrentPlatform() {
|
|
215972
|
-
const platformName = platform();
|
|
215973
|
-
const archName = arch();
|
|
215974
|
-
if (platformName === "darwin") {
|
|
215975
|
-
if (archName === "arm64") return "darwin-arm64";
|
|
215976
|
-
if (archName === "x64" || archName === "ia32") return "darwin-x86_64";
|
|
215977
|
-
}
|
|
215978
|
-
if (platformName === "linux") {
|
|
215979
|
-
const muslSuffix = isMusl() ? "-musl" : "";
|
|
215980
|
-
if (archName === "arm64") return `linux-arm64${muslSuffix}`;
|
|
215981
|
-
if (archName === "x64" || archName === "ia32") return `linux-x86_64${muslSuffix}`;
|
|
215982
|
-
}
|
|
215983
|
-
if (platformName === "win32") {
|
|
215984
|
-
if (archName === "x64" || archName === "ia32") return "win32-x86_64";
|
|
215985
|
-
}
|
|
215986
|
-
throw new Error(`Unsupported platform: ${platformName}-${archName}. Supported platforms: darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64, win32-x86_64 (with glibc or musl support for Linux)`);
|
|
215987
|
-
}
|
|
215988
|
-
/**
|
|
215989
|
-
* Gets the package name for the current platform
|
|
215990
|
-
*/
|
|
215991
|
-
function getPlatformPackageName() {
|
|
215992
|
-
return `@sqliteai/sqlite-vector-${getCurrentPlatform()}`;
|
|
215993
|
-
}
|
|
215994
|
-
/**
|
|
215995
|
-
* Gets the binary filename for the current platform
|
|
215996
|
-
*/
|
|
215997
|
-
function getBinaryName() {
|
|
215998
|
-
const platformName = platform();
|
|
215999
|
-
const extension = PLATFORM_EXTENSIONS[platformName];
|
|
216000
|
-
if (!extension) throw new Error(`Unknown platform: ${platformName}`);
|
|
216001
|
-
return `vector${extension}`;
|
|
216002
|
-
}
|
|
216003
|
-
/**
|
|
216004
|
-
* Error thrown when the SQLite Vector extension cannot be found
|
|
216005
|
-
*/
|
|
216006
|
-
var ExtensionNotFoundError = class extends Error {
|
|
216007
|
-
constructor(message) {
|
|
216008
|
-
super(message);
|
|
216009
|
-
this.name = "ExtensionNotFoundError";
|
|
216010
|
-
}
|
|
216011
|
-
};
|
|
216012
|
-
/**
|
|
216013
|
-
* Attempts to load the platform-specific package
|
|
216014
|
-
* @returns The path to the extension binary, or null if not found
|
|
216015
|
-
*/
|
|
216016
|
-
function tryLoadPlatformPackage() {
|
|
216017
|
-
try {
|
|
216018
|
-
const packageName = getPlatformPackageName();
|
|
216019
|
-
return import.meta.resolve(packageName).replace(/\/index\.js$/, `/${getBinaryName()}`).replace("file://", "");
|
|
216020
|
-
} catch {}
|
|
216021
|
-
return null;
|
|
216022
|
-
}
|
|
216023
|
-
/**
|
|
216024
|
-
* Gets the absolute path to the SQLite Vector extension binary for the current platform
|
|
216025
|
-
*
|
|
216026
|
-
* @returns Absolute path to the extension binary (.so, .dylib, or .dll)
|
|
216027
|
-
* @throws {ExtensionNotFoundError} If the extension binary cannot be found
|
|
216028
|
-
*
|
|
216029
|
-
* @example
|
|
216030
|
-
* ```typescript
|
|
216031
|
-
* import { getExtensionPath } from '@sqliteai/sqlite-vector';
|
|
216032
|
-
*
|
|
216033
|
-
* const extensionPath = getExtensionPath();
|
|
216034
|
-
* // On macOS ARM64: /path/to/node_modules/@sqliteai/sqlite-vector-darwin-arm64/vector.dylib
|
|
216035
|
-
* ```
|
|
216036
|
-
*/
|
|
216037
|
-
function getExtensionPath() {
|
|
216038
|
-
const platformPath = tryLoadPlatformPackage();
|
|
216039
|
-
if (platformPath) return resolve(platformPath);
|
|
216040
|
-
throw new ExtensionNotFoundError(`SQLite Vector extension not found for platform: ${getCurrentPlatform()}\n\nThe platform-specific package "${getPlatformPackageName()}" is not installed.\nThis usually happens when:\n 1. Your platform is not supported\n 2. npm failed to install optional dependencies\n 3. You're installing with --no-optional flag\n\nTry running: npm install --force`);
|
|
216041
|
-
}
|
|
216042
|
-
//#endregion
|
|
216043
|
-
//#region node_modules/.pnpm/clanka@0.2.21_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_09288369fd42a7055df614a5b619d2f6/node_modules/clanka/dist/Sqlite.js
|
|
216044
|
-
/**
|
|
216045
|
-
* @since 1.0.0
|
|
216046
|
-
*/
|
|
216047
|
-
/**
|
|
216048
|
-
* @since 1.0.0
|
|
216049
|
-
* @category Layers
|
|
216050
|
-
*/
|
|
216051
|
-
const SqliteLayer = (database) => layer$7({ loader: fromRecord({ "0001_create_chunks": gen(function* () {
|
|
216052
|
-
const sql = yield* SqlClient;
|
|
216053
|
-
yield* sql`CREATE TABLE IF NOT EXISTS chunks (
|
|
216054
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
216055
|
-
path TEXT NOT NULL,
|
|
216056
|
-
content TEXT NOT NULL,
|
|
216057
|
-
hash TEXT NOT NULL,
|
|
216058
|
-
vector BLOB NOT NULL,
|
|
216059
|
-
syncId TEXT NOT NULL
|
|
216060
|
-
)`;
|
|
216061
|
-
yield* sql`CREATE INDEX IF NOT EXISTS idx_chunks_hash ON chunks (hash)`;
|
|
216062
|
-
}) }) }).pipe(provide$3(effectDiscard(gen(function* () {
|
|
216063
|
-
yield* (yield* SqliteClient).loadExtension(getExtensionPath());
|
|
216064
|
-
}))), provideMerge(layer$8({ filename: database })), provide$3(effectDiscard(gen(function* () {
|
|
216065
|
-
const fs = yield* FileSystem;
|
|
216066
|
-
const directory = (yield* Path$1).dirname(database);
|
|
216067
|
-
if (directory === ".") return;
|
|
216068
|
-
yield* fs.makeDirectory(directory, { recursive: true });
|
|
216069
|
-
}))));
|
|
216070
|
-
//#endregion
|
|
216071
|
-
//#region node_modules/.pnpm/clanka@0.2.21_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_09288369fd42a7055df614a5b619d2f6/node_modules/clanka/dist/SemanticSearch.js
|
|
214693
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/SemanticSearch/Service.js
|
|
216072
214694
|
/**
|
|
216073
214695
|
* @since 1.0.0
|
|
216074
214696
|
*/
|
|
@@ -216077,124 +214699,6 @@ const SqliteLayer = (database) => layer$7({ loader: fromRecord({ "0001_create_ch
|
|
|
216077
214699
|
* @category Services
|
|
216078
214700
|
*/
|
|
216079
214701
|
var SemanticSearch = class extends Service$1()("clanka/SemanticSearch/SemanticSearch") {};
|
|
216080
|
-
const normalizePath = (path) => path.replace(/\\/g, "/");
|
|
216081
|
-
const resolveChunkConfig = (options) => ({
|
|
216082
|
-
chunkSize: 30,
|
|
216083
|
-
chunkOverlap: 0,
|
|
216084
|
-
chunkMaxCharacters: options.chunkMaxCharacters ?? 1e4
|
|
216085
|
-
});
|
|
216086
|
-
const makeEmbeddingResolver = (resolver, options) => resolver.pipe(setDelay(options.embeddingRequestDelay ?? millis(50)), batchN(options.embeddingBatchSize ?? 500));
|
|
216087
|
-
const chunkEmbeddingInput = (chunk) => {
|
|
216088
|
-
const headerLines = ["---", "file: " + chunk.path];
|
|
216089
|
-
if (chunk.name !== void 0) headerLines.push("name: " + chunk.name);
|
|
216090
|
-
if (chunk.type !== void 0) headerLines.push("type: " + chunk.type);
|
|
216091
|
-
if (chunk.parent !== void 0) headerLines.push("parent: " + chunk.parent);
|
|
216092
|
-
headerLines.push("---");
|
|
216093
|
-
const contentLines = chunk.content.split("\n");
|
|
216094
|
-
let contentWithLines = "";
|
|
216095
|
-
for (let i = 0; i < contentLines.length; i++) {
|
|
216096
|
-
if (i > 0) contentWithLines += "\n";
|
|
216097
|
-
contentWithLines += `${chunk.startLine + i}: ${contentLines[i]}`;
|
|
216098
|
-
}
|
|
216099
|
-
return headerLines.join("\n") + "\n\n" + contentWithLines;
|
|
216100
|
-
};
|
|
216101
|
-
const hashChunkInput = (input) => createHash("sha256").update(input).digest("hex");
|
|
216102
|
-
/**
|
|
216103
|
-
* @since 1.0.0
|
|
216104
|
-
* @category Layers
|
|
216105
|
-
*/
|
|
216106
|
-
const layer$6 = (options) => effect$1(SemanticSearch, gen(function* () {
|
|
216107
|
-
const chunker = yield* CodeChunker;
|
|
216108
|
-
const repo = yield* ChunkRepo;
|
|
216109
|
-
const embeddings = yield* EmbeddingModel;
|
|
216110
|
-
const pathService = yield* Path$1;
|
|
216111
|
-
const root = pathService.resolve(options.directory);
|
|
216112
|
-
const resolver = makeEmbeddingResolver(embeddings.resolver, options);
|
|
216113
|
-
const concurrency = options.concurrency ?? 2e3;
|
|
216114
|
-
const chunkConfig = resolveChunkConfig(options);
|
|
216115
|
-
const indexHandle = yield* make$56();
|
|
216116
|
-
const console = yield* Console$1;
|
|
216117
|
-
const resolveIndexedPath = (path) => {
|
|
216118
|
-
const absolutePath = pathService.resolve(root, path);
|
|
216119
|
-
const relativePath = normalizePath(pathService.relative(root, absolutePath));
|
|
216120
|
-
if (relativePath.length === 0 || relativePath === ".." || relativePath.startsWith("../")) return none$4();
|
|
216121
|
-
return some$2(relativePath);
|
|
216122
|
-
};
|
|
216123
|
-
const processChunk = fnUntraced(function* (options) {
|
|
216124
|
-
const input = chunkEmbeddingInput(options.chunk);
|
|
216125
|
-
const hash = hashChunkInput(input);
|
|
216126
|
-
if (options.checkExisting) {
|
|
216127
|
-
const id = yield* repo.exists(hash);
|
|
216128
|
-
if (isSome(id)) {
|
|
216129
|
-
yield* repo.setSyncId(id.value, options.syncId);
|
|
216130
|
-
return;
|
|
216131
|
-
}
|
|
216132
|
-
}
|
|
216133
|
-
const result = yield* request$2(new EmbeddingRequest({ input }), resolver);
|
|
216134
|
-
const vector = new Float32Array(result.vector);
|
|
216135
|
-
yield* repo.insert(Chunk.insert.makeUnsafe({
|
|
216136
|
-
path: options.chunk.path,
|
|
216137
|
-
hash,
|
|
216138
|
-
content: input,
|
|
216139
|
-
vector,
|
|
216140
|
-
syncId: options.syncId
|
|
216141
|
-
}));
|
|
216142
|
-
}, ignore$1({
|
|
216143
|
-
log: "Warn",
|
|
216144
|
-
message: "Failed to process chunk for embedding"
|
|
216145
|
-
}), (effect, options) => annotateLogs(effect, { chunk: `${options.chunk.path}/${options.chunk.startLine}` }));
|
|
216146
|
-
const runIndex = run$4(indexHandle, gen(function* () {
|
|
216147
|
-
const syncId = SyncId.makeUnsafe(crypto.randomUUID());
|
|
216148
|
-
yield* logInfo("Starting SemanticSearch index");
|
|
216149
|
-
yield* pipe$1(chunker.chunkCodebase({
|
|
216150
|
-
root,
|
|
216151
|
-
...chunkConfig
|
|
216152
|
-
}), tap((chunk) => processChunk({
|
|
216153
|
-
chunk,
|
|
216154
|
-
syncId,
|
|
216155
|
-
checkExisting: true
|
|
216156
|
-
}), { concurrency }), runDrain);
|
|
216157
|
-
yield* repo.deleteForSyncId(syncId);
|
|
216158
|
-
yield* logInfo("Finished SemanticSearch index");
|
|
216159
|
-
}).pipe(withSpan$1("SemanticSearch.index"), withLogSpan("SemanticSearch.index"), provideService$2(Console$1, console)), { onlyIfMissing: true });
|
|
216160
|
-
const initialIndex = yield* runIndex;
|
|
216161
|
-
yield* runIndex.pipe(delay(minutes(3)), forever, forkScoped);
|
|
216162
|
-
return SemanticSearch.of({
|
|
216163
|
-
search: fn("SemanticSearch.search")(function* (options) {
|
|
216164
|
-
yield* join$2(initialIndex);
|
|
216165
|
-
yield* annotateCurrentSpan(options);
|
|
216166
|
-
const { vector } = yield* embeddings.embed(options.query);
|
|
216167
|
-
return (yield* repo.search({
|
|
216168
|
-
vector: new Float32Array(vector),
|
|
216169
|
-
limit: options.limit
|
|
216170
|
-
})).map((r) => r.content).join("\n\n");
|
|
216171
|
-
}, orDie$2),
|
|
216172
|
-
updateFile: fn("SemanticSearch.updateFile")(function* (path) {
|
|
216173
|
-
yield* join$2(initialIndex);
|
|
216174
|
-
const indexedPath = resolveIndexedPath(path);
|
|
216175
|
-
if (isNone(indexedPath)) return;
|
|
216176
|
-
yield* repo.deleteByPath(indexedPath.value);
|
|
216177
|
-
const chunks = yield* chunker.chunkFile({
|
|
216178
|
-
root,
|
|
216179
|
-
path: indexedPath.value,
|
|
216180
|
-
...chunkConfig
|
|
216181
|
-
});
|
|
216182
|
-
if (chunks.length === 0) return;
|
|
216183
|
-
const syncId = SyncId.makeUnsafe(crypto.randomUUID());
|
|
216184
|
-
yield* pipe$1(fromArray(chunks), tap((chunk) => processChunk({
|
|
216185
|
-
chunk,
|
|
216186
|
-
syncId,
|
|
216187
|
-
checkExisting: false
|
|
216188
|
-
}), { concurrency }), runDrain);
|
|
216189
|
-
}, orDie$2),
|
|
216190
|
-
removeFile: fn("SemanticSearch.removeFile")(function* (path) {
|
|
216191
|
-
yield* join$2(initialIndex);
|
|
216192
|
-
const indexedPath = resolveIndexedPath(path);
|
|
216193
|
-
if (isNone(indexedPath)) return;
|
|
216194
|
-
yield* repo.deleteByPath(indexedPath.value);
|
|
216195
|
-
}, orDie$2)
|
|
216196
|
-
});
|
|
216197
|
-
})).pipe(provide$3([layer$9, layer$10.pipe(provide$3(SqliteLayer(options.database ?? ".clanka/search.sqlite")))]));
|
|
216198
214702
|
/**
|
|
216199
214703
|
* @since 1.0.0
|
|
216200
214704
|
* @category Utils
|
|
@@ -216212,7 +214716,7 @@ const maybeRemoveFile = (path) => serviceOption(SemanticSearch).pipe(flatMap$4(m
|
|
|
216212
214716
|
onSome: (service) => service.removeFile(path)
|
|
216213
214717
|
})));
|
|
216214
214718
|
//#endregion
|
|
216215
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
214719
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/AgentTools.js
|
|
216216
214720
|
/**
|
|
216217
214721
|
* @since 1.0.0
|
|
216218
214722
|
*/
|
|
@@ -216563,7 +215067,7 @@ const AgentToolHandlers = AgentToolHandlersNoDeps.pipe(provide$3([layer$12, laye
|
|
|
216563
215067
|
AgentToolHandlersNoDeps.pipe(provide$3([mock(ExaSearch)({}), mock(WebToMarkdown)({})]));
|
|
216564
215068
|
var ApplyPatchError = class extends TaggedClass$2("ApplyPatchError") {};
|
|
216565
215069
|
//#endregion
|
|
216566
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
215070
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/TypeBuilder.js
|
|
216567
215071
|
const resolveDocumentation = resolveAt("documentation");
|
|
216568
215072
|
const identifierPattern = /^[$A-Z_a-z][$0-9A-Z_a-z]*$/u;
|
|
216569
215073
|
const Precedence = {
|
|
@@ -216836,7 +215340,7 @@ const render = (schema, options) => {
|
|
|
216836
215340
|
return printNode({ text: documentation === void 0 ? rendered.text : `${renderJsDoc(documentation, 0, printerOptions)}${printerOptions.newLine}${rendered.text}` }, printerOptions);
|
|
216837
215341
|
};
|
|
216838
215342
|
//#endregion
|
|
216839
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
215343
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/ToolkitRenderer.js
|
|
216840
215344
|
/**
|
|
216841
215345
|
* @since 1.0.0
|
|
216842
215346
|
*/
|
|
@@ -216858,7 +215362,7 @@ declare function ${name}(${params}): Promise<${render(tool.successSchema)}>`);
|
|
|
216858
215362
|
}) });
|
|
216859
215363
|
};
|
|
216860
215364
|
//#endregion
|
|
216861
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
215365
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/ScriptPreprocessing.js
|
|
216862
215366
|
const isIdentifierChar = (char) => char !== void 0 && /[A-Za-z0-9_$]/.test(char);
|
|
216863
215367
|
const isIdentifierStartChar = (char) => char !== void 0 && /[A-Za-z_$]/.test(char);
|
|
216864
215368
|
const hasIdentifierBoundary = (text, index, length) => !isIdentifierChar(text[index - 1]) && !isIdentifierChar(text[index + length]);
|
|
@@ -217307,7 +215811,7 @@ const fixAssignedTemplatesForToolCalls = (script) => {
|
|
|
217307
215811
|
};
|
|
217308
215812
|
const preprocessScript = (script) => fixAssignedTemplatesForToolCalls(["applyPatch", "taskComplete"].reduce((current, functionName) => fixCallTemplateArgument(current, functionName), fixTargetCallObjectPropertyTemplates(script)));
|
|
217309
215813
|
//#endregion
|
|
217310
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
215814
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/AgentExecutor.js
|
|
217311
215815
|
/**
|
|
217312
215816
|
* @since 1.0.0
|
|
217313
215817
|
*/
|
|
@@ -217492,7 +215996,7 @@ var QueueWriteStream = class extends Writable {
|
|
|
217492
215996
|
}
|
|
217493
215997
|
};
|
|
217494
215998
|
//#endregion
|
|
217495
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
215999
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/ScriptExtraction.js
|
|
217496
216000
|
const stripWrappingCodeFence = (script) => {
|
|
217497
216001
|
const lines = script.split(/\r?\n/);
|
|
217498
216002
|
if (lines.length < 2) return script;
|
|
@@ -217792,14 +216296,14 @@ const Message$1 = /* @__PURE__ */ Union$2([
|
|
|
217792
216296
|
content: Array$1(Union$2([ToolResultPart, ToolApprovalResponsePart]))
|
|
217793
216297
|
}).annotate({ identifier: "ToolMessage" })
|
|
217794
216298
|
]);
|
|
217795
|
-
const TypeId$
|
|
216299
|
+
const TypeId$4 = "~effect/unstable/ai/Prompt";
|
|
217796
216300
|
/**
|
|
217797
216301
|
* Type guard to check if a value is a Prompt.
|
|
217798
216302
|
*
|
|
217799
216303
|
* @since 4.0.0
|
|
217800
216304
|
* @category guards
|
|
217801
216305
|
*/
|
|
217802
|
-
const isPrompt = (u) => hasProperty(u, TypeId$
|
|
216306
|
+
const isPrompt = (u) => hasProperty(u, TypeId$4);
|
|
217803
216307
|
const $Prompt = /* @__PURE__ */ declare((u) => isPrompt(u), { identifier: "Prompt" });
|
|
217804
216308
|
/**
|
|
217805
216309
|
* Describes a schema that represents a `Prompt` instance.
|
|
@@ -217818,7 +216322,7 @@ const Prompt$1 = /* @__PURE__ */ Struct$2({ content: Array$1(toEncoded(Message$1
|
|
|
217818
216322
|
})
|
|
217819
216323
|
})));
|
|
217820
216324
|
const Proto = {
|
|
217821
|
-
[TypeId$
|
|
216325
|
+
[TypeId$4]: TypeId$4,
|
|
217822
216326
|
pipe() {
|
|
217823
216327
|
return pipeArguments(this, arguments);
|
|
217824
216328
|
}
|
|
@@ -217867,7 +216371,7 @@ const empty = /* @__PURE__ */ makePrompt([]);
|
|
|
217867
216371
|
* @since 4.0.0
|
|
217868
216372
|
* @category constructors
|
|
217869
216373
|
*/
|
|
217870
|
-
const make$
|
|
216374
|
+
const make$12 = (input) => {
|
|
217871
216375
|
if (typeof input === "string") return makePrompt([makeMessage("user", { content: [makePart("text", { text: input })] })]);
|
|
217872
216376
|
if (isIterable(input)) return makePrompt(decodeMessagesSync(fromIterable$5(input), { errors: "all" }));
|
|
217873
216377
|
return input;
|
|
@@ -218016,7 +216520,7 @@ const fromResponseParts = (parts) => {
|
|
|
218016
216520
|
* @category combinators
|
|
218017
216521
|
*/
|
|
218018
216522
|
const concat = /* @__PURE__ */ dual(2, (self, input) => {
|
|
218019
|
-
const other = make$
|
|
216523
|
+
const other = make$12(input);
|
|
218020
216524
|
if (self.content.length === 0) return other;
|
|
218021
216525
|
if (other.content.length === 0) return self;
|
|
218022
216526
|
return fromMessages([...self.content, ...other.content]);
|
|
@@ -218150,7 +216654,7 @@ var ResponseIdTracker = class extends Service$1()("effect/ai/ResponseIdTracker")
|
|
|
218150
216654
|
* @since 4.0.0
|
|
218151
216655
|
* @category constructors
|
|
218152
216656
|
*/
|
|
218153
|
-
const make$
|
|
216657
|
+
const make$11 = /* @__PURE__ */ sync(() => {
|
|
218154
216658
|
const sentParts = /* @__PURE__ */ new Map();
|
|
218155
216659
|
const none = () => {
|
|
218156
216660
|
sentParts.clear();
|
|
@@ -218487,7 +216991,7 @@ var GenerateObjectResponse = class extends GenerateTextResponse {
|
|
|
218487
216991
|
* @since 4.0.0
|
|
218488
216992
|
* @category constructors
|
|
218489
216993
|
*/
|
|
218490
|
-
const make$
|
|
216994
|
+
const make$10 = /* @__PURE__ */ fnUntraced(function* (params) {
|
|
218491
216995
|
const codecTransformer = params.codecTransformer ?? defaultCodecTransformer;
|
|
218492
216996
|
const parentSpanTransformer = yield* serviceOption(CurrentSpanTransformer);
|
|
218493
216997
|
const getSpanTransformer = serviceOption(CurrentSpanTransformer).pipe(map$9(orElse$1(() => parentSpanTransformer)));
|
|
@@ -218498,7 +217002,7 @@ const make$7 = /* @__PURE__ */ fnUntraced(function* (params) {
|
|
|
218498
217002
|
} }, fnUntraced(function* (span) {
|
|
218499
217003
|
const spanTransformer = yield* getSpanTransformer;
|
|
218500
217004
|
const providerOptions = {
|
|
218501
|
-
prompt: make$
|
|
217005
|
+
prompt: make$12(options.prompt),
|
|
218502
217006
|
tools: [],
|
|
218503
217007
|
toolChoice: "none",
|
|
218504
217008
|
responseFormat: { type: "text" },
|
|
@@ -218523,7 +217027,7 @@ const make$7 = /* @__PURE__ */ fnUntraced(function* (params) {
|
|
|
218523
217027
|
} }, fnUntraced(function* (span) {
|
|
218524
217028
|
const spanTransformer = yield* getSpanTransformer;
|
|
218525
217029
|
const providerOptions = {
|
|
218526
|
-
prompt: make$
|
|
217030
|
+
prompt: make$12(options.prompt),
|
|
218527
217031
|
tools: [],
|
|
218528
217032
|
toolChoice: "none",
|
|
218529
217033
|
responseFormat: {
|
|
@@ -218558,7 +217062,7 @@ const make$7 = /* @__PURE__ */ fnUntraced(function* (params) {
|
|
|
218558
217062
|
toolChoice: options.toolChoice
|
|
218559
217063
|
} });
|
|
218560
217064
|
const providerOptions = {
|
|
218561
|
-
prompt: make$
|
|
217065
|
+
prompt: make$12(options.prompt),
|
|
218562
217066
|
tools: [],
|
|
218563
217067
|
toolChoice: "none",
|
|
218564
217068
|
responseFormat: { type: "text" },
|
|
@@ -219041,7 +217545,7 @@ const applySpanTransformer = (transformer, response, options) => {
|
|
|
219041
217545
|
});
|
|
219042
217546
|
};
|
|
219043
217547
|
//#endregion
|
|
219044
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
217548
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/Agent.js
|
|
219045
217549
|
/**
|
|
219046
217550
|
* @since 1.0.0
|
|
219047
217551
|
*/
|
|
@@ -219049,7 +217553,7 @@ const applySpanTransformer = (transformer, response, options) => {
|
|
|
219049
217553
|
* @since 1.0.0
|
|
219050
217554
|
* @category Models
|
|
219051
217555
|
*/
|
|
219052
|
-
const TypeId = "~clanka/Agent";
|
|
217556
|
+
const TypeId$3 = "~clanka/Agent";
|
|
219053
217557
|
/**
|
|
219054
217558
|
* @since 1.0.0
|
|
219055
217559
|
* @category Service
|
|
@@ -219059,7 +217563,7 @@ const Agent = Service$1("clanka/Agent");
|
|
|
219059
217563
|
* @since 1.0.0
|
|
219060
217564
|
* @category Constructors
|
|
219061
217565
|
*/
|
|
219062
|
-
const make$
|
|
217566
|
+
const make$9 = gen(function* () {
|
|
219063
217567
|
const executor = yield* AgentExecutor;
|
|
219064
217568
|
const singleTool = yield* SingleTools.asEffect().pipe(provide$1(SingleToolHandlers));
|
|
219065
217569
|
const capabilities = yield* executor.capabilities;
|
|
@@ -219123,7 +217627,7 @@ ${content}
|
|
|
219123
217627
|
let id = agentCounter++;
|
|
219124
217628
|
const stream = spawn({
|
|
219125
217629
|
agentId: id,
|
|
219126
|
-
prompt: make$
|
|
217630
|
+
prompt: make$12(prompt),
|
|
219127
217631
|
system: opts.system,
|
|
219128
217632
|
disableHistory: true
|
|
219129
217633
|
});
|
|
@@ -219295,10 +217799,10 @@ ${content}
|
|
|
219295
217799
|
}, unwrap);
|
|
219296
217800
|
const sendLock = makeUnsafe$9(1);
|
|
219297
217801
|
return Agent.of({
|
|
219298
|
-
[TypeId]: TypeId,
|
|
217802
|
+
[TypeId$3]: TypeId$3,
|
|
219299
217803
|
send: (options) => spawn({
|
|
219300
217804
|
agentId: agentCounter++,
|
|
219301
|
-
prompt: make$
|
|
217805
|
+
prompt: make$12(options.prompt),
|
|
219302
217806
|
system: options.system
|
|
219303
217807
|
}).pipe(broadcast({
|
|
219304
217808
|
capacity: "unbounded",
|
|
@@ -219384,14 +217888,14 @@ const SingleToolHandlers = SingleTools.toLayer({ execute: fnUntraced(function* (
|
|
|
219384
217888
|
* @since 1.0.0
|
|
219385
217889
|
* @category Layers
|
|
219386
217890
|
*/
|
|
219387
|
-
const layer$
|
|
217891
|
+
const layer$10 = effect$1(Agent, make$9);
|
|
219388
217892
|
/**
|
|
219389
217893
|
* Create an Agent layer that uses a local AgentExecutor.
|
|
219390
217894
|
*
|
|
219391
217895
|
* @since 1.0.0
|
|
219392
217896
|
* @category Layers
|
|
219393
217897
|
*/
|
|
219394
|
-
const layerLocal = (options) => layer$
|
|
217898
|
+
const layerLocal = (options) => layer$10.pipe(provide$3(layerLocal$1(options)));
|
|
219395
217899
|
/**
|
|
219396
217900
|
* @since 1.0.0
|
|
219397
217901
|
* @category Subagent model
|
|
@@ -226476,7 +224980,7 @@ const ListThreadItemsMethod200 = ThreadItemListResource;
|
|
|
226476
224980
|
const GetThreadMethod200 = ThreadResource;
|
|
226477
224981
|
const DeleteThreadMethod200 = DeletedThreadResource;
|
|
226478
224982
|
const ListThreadsMethod200 = ThreadListResource;
|
|
226479
|
-
const make$
|
|
224983
|
+
const make$8 = (httpClient, options = {}) => {
|
|
226480
224984
|
const unexpectedStatus = (response) => flatMap$4(orElseSucceed(response.json, () => "Unexpected status code"), (description) => fail$6(new HttpClientError({ reason: new StatusCodeError({
|
|
226481
224985
|
request: response.request,
|
|
226482
224986
|
response,
|
|
@@ -228034,12 +226538,12 @@ const RedactedOpenAiHeaders$1 = {
|
|
|
228034
226538
|
* @since 1.0.0
|
|
228035
226539
|
* @category constructors
|
|
228036
226540
|
*/
|
|
228037
|
-
const make$
|
|
226541
|
+
const make$7 = /* @__PURE__ */ fnUntraced(function* (options) {
|
|
228038
226542
|
const baseClient = yield* HttpClient;
|
|
228039
226543
|
const apiUrl = options.apiUrl ?? "https://api.openai.com/v1";
|
|
228040
226544
|
const httpClient = baseClient.pipe(mapRequest(flow(prependUrl(apiUrl), options.apiKey ? bearerToken(value$2(options.apiKey)) : identity, options.organizationId ? setHeader(RedactedOpenAiHeaders$1.OpenAiOrganization, value$2(options.organizationId)) : identity, options.projectId ? setHeader(RedactedOpenAiHeaders$1.OpenAiProject, value$2(options.projectId)) : identity, acceptJson)), options.transformClient ? options.transformClient : identity);
|
|
228041
226545
|
const httpClientOk = filterStatusOk(httpClient);
|
|
228042
|
-
const client = make$
|
|
226546
|
+
const client = make$8(httpClient, { transformClient: fnUntraced(function* (client) {
|
|
228043
226547
|
const config = yield* OpenAiConfig$1.getOrUndefined;
|
|
228044
226548
|
if (isNotUndefined(config?.transformClient)) return config.transformClient(client);
|
|
228045
226549
|
return client;
|
|
@@ -228083,7 +226587,7 @@ const make$4 = /* @__PURE__ */ fnUntraced(function* (options) {
|
|
|
228083
226587
|
* @since 1.0.0
|
|
228084
226588
|
* @category layers
|
|
228085
226589
|
*/
|
|
228086
|
-
const layer$
|
|
226590
|
+
const layer$9 = (options) => effect$1(OpenAiClient$1, make$7(options));
|
|
228087
226591
|
/**
|
|
228088
226592
|
* @since 1.0.0
|
|
228089
226593
|
* @category Websocket mode
|
|
@@ -228091,7 +226595,7 @@ const layer$4 = (options) => effect$1(OpenAiClient$1, make$4(options));
|
|
|
228091
226595
|
var OpenAiSocket = class extends Service$1()("@effect/ai-openai/OpenAiClient/OpenAiSocket") {};
|
|
228092
226596
|
const makeSocket = /* @__PURE__ */ gen(function* () {
|
|
228093
226597
|
const client = yield* OpenAiClient$1;
|
|
228094
|
-
const tracker = yield* make$
|
|
226598
|
+
const tracker = yield* make$11;
|
|
228095
226599
|
const request = yield* orDie$2(client.client.httpClient.preprocess(post("/responses")));
|
|
228096
226600
|
const socket = yield* makeWebSocket(request.url.replace(/^http/, "ws")).pipe(updateService(WebSocketConstructor, (f) => (url) => f(url, { headers: request.headers })));
|
|
228097
226601
|
const queueRef = yield* make$68({
|
|
@@ -228225,6 +226729,105 @@ const decodeEvent = /* @__PURE__ */ decodeUnknownSync(/* @__PURE__ */ fromJsonSt
|
|
|
228225
226729
|
*/
|
|
228226
226730
|
const layerWebSocketMode = /* @__PURE__ */ effectServices(makeSocket);
|
|
228227
226731
|
//#endregion
|
|
226732
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/ai/EmbeddingModel.js
|
|
226733
|
+
/**
|
|
226734
|
+
* The `EmbeddingModel` module provides provider-agnostic text embedding capabilities.
|
|
226735
|
+
*
|
|
226736
|
+
* @example
|
|
226737
|
+
* ```ts
|
|
226738
|
+
* import { Effect } from "effect"
|
|
226739
|
+
* import { EmbeddingModel } from "effect/unstable/ai"
|
|
226740
|
+
*
|
|
226741
|
+
* const program = Effect.gen(function*() {
|
|
226742
|
+
* const model = yield* EmbeddingModel.EmbeddingModel
|
|
226743
|
+
* return yield* model.embed("hello world")
|
|
226744
|
+
* })
|
|
226745
|
+
* ```
|
|
226746
|
+
*
|
|
226747
|
+
* @since 4.0.0
|
|
226748
|
+
*/
|
|
226749
|
+
/**
|
|
226750
|
+
* Service tag for embedding model operations.
|
|
226751
|
+
*
|
|
226752
|
+
* @since 4.0.0
|
|
226753
|
+
* @category services
|
|
226754
|
+
*/
|
|
226755
|
+
var EmbeddingModel = class extends Service$1()("effect/unstable/ai/EmbeddingModel") {};
|
|
226756
|
+
/**
|
|
226757
|
+
* Service tag that provides the current embedding dimensions.
|
|
226758
|
+
*
|
|
226759
|
+
* @since 4.0.0
|
|
226760
|
+
* @category services
|
|
226761
|
+
*/
|
|
226762
|
+
var Dimensions = class extends Service$1()("effect/unstable/ai/EmbeddingModel/Dimensions") {};
|
|
226763
|
+
/**
|
|
226764
|
+
* Token usage metadata for embedding operations.
|
|
226765
|
+
*
|
|
226766
|
+
* @since 4.0.0
|
|
226767
|
+
* @category models
|
|
226768
|
+
*/
|
|
226769
|
+
var EmbeddingUsage = class extends Class$2("effect/ai/EmbeddingModel/EmbeddingUsage")({ inputTokens: /* @__PURE__ */ UndefinedOr(Finite) }) {};
|
|
226770
|
+
/**
|
|
226771
|
+
* Response for a single embedding request.
|
|
226772
|
+
*
|
|
226773
|
+
* @since 4.0.0
|
|
226774
|
+
* @category models
|
|
226775
|
+
*/
|
|
226776
|
+
var EmbedResponse = class extends Class$2("effect/ai/EmbeddingModel/EmbedResponse")({ vector: /* @__PURE__ */ Array$1(Finite) }) {};
|
|
226777
|
+
/**
|
|
226778
|
+
* Response for multiple embeddings.
|
|
226779
|
+
*
|
|
226780
|
+
* @since 4.0.0
|
|
226781
|
+
* @category models
|
|
226782
|
+
*/
|
|
226783
|
+
var EmbedManyResponse = class extends Class$2("effect/ai/EmbeddingModel/EmbedManyResponse")({
|
|
226784
|
+
embeddings: /* @__PURE__ */ Array$1(EmbedResponse),
|
|
226785
|
+
usage: EmbeddingUsage
|
|
226786
|
+
}) {};
|
|
226787
|
+
/**
|
|
226788
|
+
* Tagged request used by request resolvers for embedding operations.
|
|
226789
|
+
*
|
|
226790
|
+
* @since 4.0.0
|
|
226791
|
+
* @category constructors
|
|
226792
|
+
*/
|
|
226793
|
+
var EmbeddingRequest = class extends TaggedClass$1("EmbeddingRequest") {};
|
|
226794
|
+
const invalidProviderResponse = (description) => make$15({
|
|
226795
|
+
module: "EmbeddingModel",
|
|
226796
|
+
method: "embedMany",
|
|
226797
|
+
reason: new InvalidOutputError({ description })
|
|
226798
|
+
});
|
|
226799
|
+
/**
|
|
226800
|
+
* Creates an EmbeddingModel service from a provider embedMany implementation.
|
|
226801
|
+
*
|
|
226802
|
+
* @since 4.0.0
|
|
226803
|
+
* @category constructors
|
|
226804
|
+
*/
|
|
226805
|
+
const make$6 = /* @__PURE__ */ fnUntraced(function* (params) {
|
|
226806
|
+
const resolver = make$47((entries) => flatMap$4(params.embedMany({ inputs: entries.map((entry) => entry.request.input) }), (response) => map$9(mapProviderResults(entries.length, response.results), (embeddings) => {
|
|
226807
|
+
for (let i = 0; i < entries.length; i++) entries[i].completeUnsafe(succeed$6(embeddings[i]));
|
|
226808
|
+
}))).pipe(withSpan("EmbeddingModel.resolver"));
|
|
226809
|
+
return EmbeddingModel.of({
|
|
226810
|
+
resolver,
|
|
226811
|
+
embed: (input) => request$2(new EmbeddingRequest({ input }), resolver).pipe(withSpan$1("EmbeddingModel.embed")),
|
|
226812
|
+
embedMany: (input) => (input.length === 0 ? succeed$3(new EmbedManyResponse({
|
|
226813
|
+
embeddings: [],
|
|
226814
|
+
usage: new EmbeddingUsage({ inputTokens: void 0 })
|
|
226815
|
+
})) : params.embedMany({ inputs: input }).pipe(flatMap$4((response) => mapProviderResults(input.length, response.results).pipe(map$9((embeddings) => new EmbedManyResponse({
|
|
226816
|
+
embeddings,
|
|
226817
|
+
usage: new EmbeddingUsage({ inputTokens: response.usage.inputTokens })
|
|
226818
|
+
})))))).pipe(withSpan$1("EmbeddingModel.embedMany"))
|
|
226819
|
+
});
|
|
226820
|
+
});
|
|
226821
|
+
const mapProviderResults = (inputLength, results) => {
|
|
226822
|
+
const embeddings = new Array(inputLength);
|
|
226823
|
+
if (results.length !== inputLength) return fail$6(invalidProviderResponse(`Provider returned ${results.length} embeddings but expected ${inputLength}`));
|
|
226824
|
+
for (let i = 0; i < results.length; i++) {
|
|
226825
|
+
const vector = results[i];
|
|
226826
|
+
embeddings[i] = new EmbedResponse({ vector });
|
|
226827
|
+
}
|
|
226828
|
+
return succeed$3(embeddings);
|
|
226829
|
+
};
|
|
226830
|
+
//#endregion
|
|
228228
226831
|
//#region node_modules/.pnpm/@effect+ai-openai@4.0.0-beta.36_effect@4.0.0-beta.36/node_modules/@effect/ai-openai/dist/OpenAiEmbeddingModel.js
|
|
228229
226832
|
/**
|
|
228230
226833
|
* OpenAI Embedding Model implementation.
|
|
@@ -228244,7 +226847,7 @@ var Config$2 = class extends Service$1()("@effect/ai-openai/OpenAiEmbeddingModel
|
|
|
228244
226847
|
* @since 1.0.0
|
|
228245
226848
|
* @category constructors
|
|
228246
226849
|
*/
|
|
228247
|
-
const model$1 = (model, options) => make$16("openai", model, merge$6(layer$
|
|
226850
|
+
const model$1 = (model, options) => make$16("openai", model, merge$6(layer$8({
|
|
228248
226851
|
model,
|
|
228249
226852
|
config: {
|
|
228250
226853
|
...options.config,
|
|
@@ -228257,7 +226860,7 @@ const model$1 = (model, options) => make$16("openai", model, merge$6(layer$3({
|
|
|
228257
226860
|
* @since 1.0.0
|
|
228258
226861
|
* @category constructors
|
|
228259
226862
|
*/
|
|
228260
|
-
const make$
|
|
226863
|
+
const make$5 = /* @__PURE__ */ fnUntraced(function* ({ model, config: providerConfig }) {
|
|
228261
226864
|
const client = yield* OpenAiClient$1;
|
|
228262
226865
|
const makeConfig = gen(function* () {
|
|
228263
226866
|
const services$5 = yield* services();
|
|
@@ -228267,7 +226870,7 @@ const make$3 = /* @__PURE__ */ fnUntraced(function* ({ model, config: providerCo
|
|
|
228267
226870
|
...services$5.mapUnsafe.get(Config$2.key)
|
|
228268
226871
|
};
|
|
228269
226872
|
});
|
|
228270
|
-
return yield* make$
|
|
226873
|
+
return yield* make$6({ embedMany: fnUntraced(function* ({ inputs }) {
|
|
228271
226874
|
const config = yield* makeConfig;
|
|
228272
226875
|
const response = yield* client.createEmbedding({
|
|
228273
226876
|
...config,
|
|
@@ -228282,7 +226885,7 @@ const make$3 = /* @__PURE__ */ fnUntraced(function* ({ model, config: providerCo
|
|
|
228282
226885
|
* @since 1.0.0
|
|
228283
226886
|
* @category layers
|
|
228284
226887
|
*/
|
|
228285
|
-
const layer$
|
|
226888
|
+
const layer$8 = (options) => effect$1(EmbeddingModel, make$5(options));
|
|
228286
226889
|
const mapProviderResponse = (inputLength, response) => {
|
|
228287
226890
|
if (response.data.length !== inputLength) return fail$6(invalidOutput("Provider returned " + response.data.length + " embeddings but expected " + inputLength));
|
|
228288
226891
|
const results = new Array(inputLength);
|
|
@@ -228681,7 +227284,7 @@ var Config$1 = class extends Service$1()("@effect/ai-openai/OpenAiLanguageModel/
|
|
|
228681
227284
|
* @since 1.0.0
|
|
228682
227285
|
* @category constructors
|
|
228683
227286
|
*/
|
|
228684
|
-
const make$
|
|
227287
|
+
const make$4 = /* @__PURE__ */ fnUntraced(function* ({ model, config: providerConfig }) {
|
|
228685
227288
|
const client = yield* OpenAiClient$1;
|
|
228686
227289
|
const makeConfig = gen(function* () {
|
|
228687
227290
|
const services$4 = yield* services();
|
|
@@ -228722,7 +227325,7 @@ const make$2 = /* @__PURE__ */ fnUntraced(function* ({ model, config: providerCo
|
|
|
228722
227325
|
...options.previousResponseId ? { previous_response_id: options.previousResponseId } : void 0
|
|
228723
227326
|
};
|
|
228724
227327
|
});
|
|
228725
|
-
return yield* make$
|
|
227328
|
+
return yield* make$10({
|
|
228726
227329
|
codecTransformer: toCodecOpenAI,
|
|
228727
227330
|
generateText: fnUntraced(function* (options) {
|
|
228728
227331
|
const config = yield* makeConfig;
|
|
@@ -228771,7 +227374,7 @@ const make$2 = /* @__PURE__ */ fnUntraced(function* ({ model, config: providerCo
|
|
|
228771
227374
|
* @since 1.0.0
|
|
228772
227375
|
* @category layers
|
|
228773
227376
|
*/
|
|
228774
|
-
const layer$
|
|
227377
|
+
const layer$7 = (options) => effect$1(LanguageModel, make$4(options));
|
|
228775
227378
|
/**
|
|
228776
227379
|
* Provides config overrides for OpenAI language model operations.
|
|
228777
227380
|
*
|
|
@@ -230425,7 +229028,7 @@ const transformToolCallParams = /* @__PURE__ */ fnUntraced(function* (tools, too
|
|
|
230425
229028
|
})));
|
|
230426
229029
|
});
|
|
230427
229030
|
//#endregion
|
|
230428
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
229031
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/CodexAuth.js
|
|
230429
229032
|
/**
|
|
230430
229033
|
* @since 1.0.0
|
|
230431
229034
|
*/
|
|
@@ -230645,7 +229248,7 @@ var CodexAuth = class CodexAuth extends Service$1()("clanka/CodexAuth") {
|
|
|
230645
229248
|
static layerClient = this.layerClientNoDeps.pipe(provide$3(CodexAuth.layer));
|
|
230646
229249
|
};
|
|
230647
229250
|
//#endregion
|
|
230648
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
229251
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/Codex.js
|
|
230649
229252
|
/**
|
|
230650
229253
|
* @since 1.0.0
|
|
230651
229254
|
*/
|
|
@@ -230653,13 +229256,13 @@ var CodexAuth = class CodexAuth extends Service$1()("clanka/CodexAuth") {
|
|
|
230653
229256
|
* @since 1.0.0
|
|
230654
229257
|
* @category Layers
|
|
230655
229258
|
*/
|
|
230656
|
-
const layerClient$1 = layer$
|
|
229259
|
+
const layerClient$1 = layer$9({ apiUrl: "https://chatgpt.com/backend-api/codex" }).pipe(provide$3(CodexAuth.layerClient));
|
|
230657
229260
|
/**
|
|
230658
229261
|
* @since 1.0.0
|
|
230659
229262
|
* @category Layers
|
|
230660
229263
|
*/
|
|
230661
229264
|
const modelWebSocket = (model, options) => make$16("openai", model, layerModel(model, options).pipe(merge$6(fresh(layerWebSocketMode))));
|
|
230662
|
-
const layerModel = (model, options) => layer$
|
|
229265
|
+
const layerModel = (model, options) => layer$7({
|
|
230663
229266
|
model,
|
|
230664
229267
|
config: {
|
|
230665
229268
|
...omit$2(options ?? {}, ["reasoning"]),
|
|
@@ -230671,6 +229274,480 @@ const layerModel = (model, options) => layer$2({
|
|
|
230671
229274
|
}
|
|
230672
229275
|
}).pipe(merge$6(AgentModelConfig.layer({ systemPromptTransform: (system, effect) => withConfigOverride(effect, { instructions: system }) })));
|
|
230673
229276
|
//#endregion
|
|
229277
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/CodeChunker.js
|
|
229278
|
+
/**
|
|
229279
|
+
* @since 1.0.0
|
|
229280
|
+
*/
|
|
229281
|
+
/**
|
|
229282
|
+
* @since 1.0.0
|
|
229283
|
+
* @category Services
|
|
229284
|
+
*/
|
|
229285
|
+
var CodeChunker = class extends Service$1()("clanka/CodeChunker") {};
|
|
229286
|
+
const sourceExtensions = new Set([
|
|
229287
|
+
"c",
|
|
229288
|
+
"cc",
|
|
229289
|
+
"cpp",
|
|
229290
|
+
"cs",
|
|
229291
|
+
"css",
|
|
229292
|
+
"cts",
|
|
229293
|
+
"cxx",
|
|
229294
|
+
"go",
|
|
229295
|
+
"gql",
|
|
229296
|
+
"graphql",
|
|
229297
|
+
"h",
|
|
229298
|
+
"hpp",
|
|
229299
|
+
"html",
|
|
229300
|
+
"ini",
|
|
229301
|
+
"java",
|
|
229302
|
+
"js",
|
|
229303
|
+
"jsx",
|
|
229304
|
+
"kt",
|
|
229305
|
+
"kts",
|
|
229306
|
+
"less",
|
|
229307
|
+
"lua",
|
|
229308
|
+
"mjs",
|
|
229309
|
+
"mts",
|
|
229310
|
+
"php",
|
|
229311
|
+
"py",
|
|
229312
|
+
"rb",
|
|
229313
|
+
"rs",
|
|
229314
|
+
"sass",
|
|
229315
|
+
"scala",
|
|
229316
|
+
"scss",
|
|
229317
|
+
"sh",
|
|
229318
|
+
"sql",
|
|
229319
|
+
"svelte",
|
|
229320
|
+
"swift",
|
|
229321
|
+
"ts",
|
|
229322
|
+
"tsx",
|
|
229323
|
+
"vue",
|
|
229324
|
+
"xml",
|
|
229325
|
+
"zsh"
|
|
229326
|
+
]);
|
|
229327
|
+
const documentationExtensions = new Set([
|
|
229328
|
+
"adoc",
|
|
229329
|
+
"asciidoc",
|
|
229330
|
+
"md",
|
|
229331
|
+
"mdx",
|
|
229332
|
+
"rst",
|
|
229333
|
+
"txt"
|
|
229334
|
+
]);
|
|
229335
|
+
const ignoredDirectories = new Set([
|
|
229336
|
+
".git",
|
|
229337
|
+
".next",
|
|
229338
|
+
".nuxt",
|
|
229339
|
+
".svelte-kit",
|
|
229340
|
+
".turbo",
|
|
229341
|
+
"build",
|
|
229342
|
+
"coverage",
|
|
229343
|
+
"dist",
|
|
229344
|
+
"node_modules",
|
|
229345
|
+
"target"
|
|
229346
|
+
]);
|
|
229347
|
+
const normalizePath$1 = (path) => path.replace(/\\/g, "/");
|
|
229348
|
+
const normalizeText = (content) => content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
229349
|
+
const meaningfulLinePattern = /[^\s\p{P}]/u;
|
|
229350
|
+
const isMeaningfulLine = (line) => meaningfulLinePattern.test(line);
|
|
229351
|
+
const languageByExtension = new Map([
|
|
229352
|
+
["js", TreeSitterJavaScript],
|
|
229353
|
+
["jsx", TreeSitterJavaScript],
|
|
229354
|
+
["ts", TreeSitterTypeScript.typescript],
|
|
229355
|
+
["tsx", TreeSitterTypeScript.tsx]
|
|
229356
|
+
]);
|
|
229357
|
+
/**
|
|
229358
|
+
* @since 1.0.0
|
|
229359
|
+
* @category Predicates
|
|
229360
|
+
*/
|
|
229361
|
+
const isProbablyMinified = (content) => {
|
|
229362
|
+
const normalized = normalizeText(content);
|
|
229363
|
+
if (normalized.length < 2e3) return false;
|
|
229364
|
+
const lines = normalized.split("\n");
|
|
229365
|
+
if (lines.length <= 2) return true;
|
|
229366
|
+
let longLines = 0;
|
|
229367
|
+
for (const line of lines) if (line.length >= 300) longLines++;
|
|
229368
|
+
return lines.length <= 20 && longLines / lines.length >= .8;
|
|
229369
|
+
};
|
|
229370
|
+
/**
|
|
229371
|
+
* @since 1.0.0
|
|
229372
|
+
* @category Predicates
|
|
229373
|
+
*/
|
|
229374
|
+
const isMeaningfulFile = (path) => {
|
|
229375
|
+
const parts = normalizePath$1(path).toLowerCase().split("/");
|
|
229376
|
+
const fileName = parts.at(-1);
|
|
229377
|
+
if (fileName === void 0 || fileName.length === 0) return false;
|
|
229378
|
+
if (parts.some((part) => ignoredDirectories.has(part))) return false;
|
|
229379
|
+
if (/\.min\.(?:css|js)$/i.test(fileName)) return false;
|
|
229380
|
+
const extensionIndex = fileName.lastIndexOf(".");
|
|
229381
|
+
if (extensionIndex === -1) return false;
|
|
229382
|
+
const extension = fileName.slice(extensionIndex + 1);
|
|
229383
|
+
return sourceExtensions.has(extension) || documentationExtensions.has(extension);
|
|
229384
|
+
};
|
|
229385
|
+
const resolveChunkSettings = (options) => {
|
|
229386
|
+
const chunkSize = Math.max(1, options.chunkSize);
|
|
229387
|
+
return {
|
|
229388
|
+
chunkSize,
|
|
229389
|
+
chunkOverlap: Math.max(0, Math.min(chunkSize - 1, options.chunkOverlap)),
|
|
229390
|
+
chunkMaxCharacters: options.chunkMaxCharacters !== void 0 && Number.isFinite(options.chunkMaxCharacters) ? Math.max(1, Math.floor(options.chunkMaxCharacters)) : Number.POSITIVE_INFINITY
|
|
229391
|
+
};
|
|
229392
|
+
};
|
|
229393
|
+
const getPathExtension = (path) => {
|
|
229394
|
+
const fileName = path.split("/").at(-1);
|
|
229395
|
+
if (fileName === void 0) return;
|
|
229396
|
+
const extensionIndex = fileName.lastIndexOf(".");
|
|
229397
|
+
if (extensionIndex === -1) return;
|
|
229398
|
+
return fileName.slice(extensionIndex + 1).toLowerCase();
|
|
229399
|
+
};
|
|
229400
|
+
const resolveAstLanguage = (path) => {
|
|
229401
|
+
const extension = getPathExtension(path);
|
|
229402
|
+
if (extension === void 0) return;
|
|
229403
|
+
return languageByExtension.get(extension);
|
|
229404
|
+
};
|
|
229405
|
+
const lineRangeFromNode = (node) => {
|
|
229406
|
+
const startLine = node.startPosition.row + 1;
|
|
229407
|
+
return {
|
|
229408
|
+
startLine,
|
|
229409
|
+
endLine: Math.max(startLine, node.endPosition.row + 1)
|
|
229410
|
+
};
|
|
229411
|
+
};
|
|
229412
|
+
const hasOnlyWhitespaceLines = (lines, startLine, endLine) => {
|
|
229413
|
+
if (startLine > endLine) return true;
|
|
229414
|
+
for (let lineIndex = startLine; lineIndex <= endLine; lineIndex++) if ((lines[lineIndex - 1] ?? "").trim().length > 0) return false;
|
|
229415
|
+
return true;
|
|
229416
|
+
};
|
|
229417
|
+
const lineRangeWithLeadingComments = (node, siblings, nodeIndex, lines) => {
|
|
229418
|
+
const baseRange = lineRangeFromNode(node);
|
|
229419
|
+
let startLine = baseRange.startLine;
|
|
229420
|
+
for (let index = nodeIndex - 1; index >= 0; index--) {
|
|
229421
|
+
const sibling = siblings[index];
|
|
229422
|
+
if (sibling.type !== "comment") break;
|
|
229423
|
+
const commentRange = lineRangeFromNode(sibling);
|
|
229424
|
+
if (!hasOnlyWhitespaceLines(lines, commentRange.endLine + 1, startLine - 1)) break;
|
|
229425
|
+
startLine = commentRange.startLine;
|
|
229426
|
+
}
|
|
229427
|
+
return {
|
|
229428
|
+
startLine,
|
|
229429
|
+
endLine: baseRange.endLine
|
|
229430
|
+
};
|
|
229431
|
+
};
|
|
229432
|
+
const normalizeLineRange = (range, lineCount) => {
|
|
229433
|
+
const startLine = Math.max(1, Math.min(lineCount, range.startLine));
|
|
229434
|
+
const endLine = Math.max(1, Math.min(lineCount, range.endLine));
|
|
229435
|
+
if (endLine < startLine) return;
|
|
229436
|
+
return {
|
|
229437
|
+
startLine,
|
|
229438
|
+
endLine
|
|
229439
|
+
};
|
|
229440
|
+
};
|
|
229441
|
+
const lineLengthPrefixSums = (lines) => {
|
|
229442
|
+
const sums = [0];
|
|
229443
|
+
for (let index = 0; index < lines.length; index++) sums.push(sums[index] + lines[index].length);
|
|
229444
|
+
return sums;
|
|
229445
|
+
};
|
|
229446
|
+
const lineRangeCharacterLength = (prefixSums, range) => prefixSums[range.endLine] - prefixSums[range.startLine - 1] + (range.endLine - range.startLine);
|
|
229447
|
+
const resolveSegmentEndLine = (options) => {
|
|
229448
|
+
if (options.settings.chunkMaxCharacters === Number.POSITIVE_INFINITY) return options.maxEndLine;
|
|
229449
|
+
let endLine = options.maxEndLine;
|
|
229450
|
+
while (endLine > options.startLine && lineRangeCharacterLength(options.prefixSums, {
|
|
229451
|
+
startLine: options.startLine,
|
|
229452
|
+
endLine
|
|
229453
|
+
}) > options.settings.chunkMaxCharacters) endLine--;
|
|
229454
|
+
return endLine;
|
|
229455
|
+
};
|
|
229456
|
+
const splitRange = (range, settings, prefixSums) => {
|
|
229457
|
+
if (range.endLine - range.startLine + 1 <= settings.chunkSize && lineRangeCharacterLength(prefixSums, range) <= settings.chunkMaxCharacters) return [range];
|
|
229458
|
+
const out = [];
|
|
229459
|
+
for (let startLine = range.startLine; startLine <= range.endLine;) {
|
|
229460
|
+
const maxEndLine = Math.min(range.endLine, startLine + settings.chunkSize - 1);
|
|
229461
|
+
const endLine = resolveSegmentEndLine({
|
|
229462
|
+
startLine,
|
|
229463
|
+
maxEndLine,
|
|
229464
|
+
settings,
|
|
229465
|
+
prefixSums
|
|
229466
|
+
});
|
|
229467
|
+
out.push({
|
|
229468
|
+
startLine,
|
|
229469
|
+
endLine
|
|
229470
|
+
});
|
|
229471
|
+
if (endLine >= range.endLine) break;
|
|
229472
|
+
startLine = Math.max(startLine + 1, endLine - settings.chunkOverlap + 1);
|
|
229473
|
+
}
|
|
229474
|
+
return out;
|
|
229475
|
+
};
|
|
229476
|
+
const nodeText = (node) => {
|
|
229477
|
+
if (node === null) return;
|
|
229478
|
+
const value = node.text.trim().replace(/\s+/g, " ");
|
|
229479
|
+
return value.length === 0 ? void 0 : value;
|
|
229480
|
+
};
|
|
229481
|
+
const nodeFieldText = (node, fieldName) => nodeText(node.childForFieldName(fieldName));
|
|
229482
|
+
const isNamespaceNode = (node) => node.type === "internal_module" || node.type === "module";
|
|
229483
|
+
const unwrapDeclarationNode = (node) => {
|
|
229484
|
+
let current = node;
|
|
229485
|
+
while (true) {
|
|
229486
|
+
if (current.type === "export_statement") {
|
|
229487
|
+
const declaration = current.childForFieldName("declaration") ?? current.namedChildren[0];
|
|
229488
|
+
if (declaration === void 0) return current;
|
|
229489
|
+
current = declaration;
|
|
229490
|
+
continue;
|
|
229491
|
+
}
|
|
229492
|
+
if (current.type === "ambient_declaration") {
|
|
229493
|
+
const declaration = current.namedChildren.find((child) => child.type.endsWith("_declaration") || isNamespaceNode(child));
|
|
229494
|
+
if (declaration === void 0) return current;
|
|
229495
|
+
current = declaration;
|
|
229496
|
+
continue;
|
|
229497
|
+
}
|
|
229498
|
+
return current;
|
|
229499
|
+
}
|
|
229500
|
+
};
|
|
229501
|
+
const variableDeclarators = (node) => node.namedChildren.filter((child) => child.type === "variable_declarator");
|
|
229502
|
+
const variableTypeFromDeclarator = (node) => {
|
|
229503
|
+
const value = node.childForFieldName("value");
|
|
229504
|
+
if (value !== null && value.type.includes("function")) return "function";
|
|
229505
|
+
return "variable";
|
|
229506
|
+
};
|
|
229507
|
+
const variableTypeFromDeclaration = (node) => {
|
|
229508
|
+
if (variableDeclarators(node).some((declarator) => variableTypeFromDeclarator(declarator) === "function")) return "function";
|
|
229509
|
+
return "variable";
|
|
229510
|
+
};
|
|
229511
|
+
const chunkTypeFromNode = (node) => {
|
|
229512
|
+
switch (node.type) {
|
|
229513
|
+
case "class_declaration": return "class";
|
|
229514
|
+
case "enum_declaration": return "enum";
|
|
229515
|
+
case "function_declaration":
|
|
229516
|
+
case "generator_function_declaration": return "function";
|
|
229517
|
+
case "internal_module":
|
|
229518
|
+
case "module": return "namespace";
|
|
229519
|
+
case "interface_declaration": return "interface";
|
|
229520
|
+
case "generator_method_definition":
|
|
229521
|
+
case "method_definition": return "method";
|
|
229522
|
+
case "type_alias_declaration": return "type-alias";
|
|
229523
|
+
case "lexical_declaration":
|
|
229524
|
+
case "variable_declaration": return variableTypeFromDeclaration(node);
|
|
229525
|
+
case "variable_declarator": return variableTypeFromDeclarator(node);
|
|
229526
|
+
default: return;
|
|
229527
|
+
}
|
|
229528
|
+
};
|
|
229529
|
+
const variableNamesFromDeclaration = (node) => {
|
|
229530
|
+
const names = variableDeclarators(node).map((declarator) => nodeFieldText(declarator, "name")).filter((name) => name !== void 0);
|
|
229531
|
+
if (names.length === 0) return;
|
|
229532
|
+
return names.join(", ");
|
|
229533
|
+
};
|
|
229534
|
+
const nameFromNode = (node) => {
|
|
229535
|
+
switch (node.type) {
|
|
229536
|
+
case "class_declaration":
|
|
229537
|
+
case "enum_declaration":
|
|
229538
|
+
case "function_declaration":
|
|
229539
|
+
case "generator_function_declaration":
|
|
229540
|
+
case "internal_module":
|
|
229541
|
+
case "interface_declaration":
|
|
229542
|
+
case "module":
|
|
229543
|
+
case "generator_method_definition":
|
|
229544
|
+
case "method_definition":
|
|
229545
|
+
case "type_alias_declaration":
|
|
229546
|
+
case "variable_declarator": return nodeFieldText(node, "name");
|
|
229547
|
+
case "lexical_declaration":
|
|
229548
|
+
case "variable_declaration": return variableNamesFromDeclaration(node);
|
|
229549
|
+
default: return;
|
|
229550
|
+
}
|
|
229551
|
+
};
|
|
229552
|
+
const formatParent = (type, name) => {
|
|
229553
|
+
if (type === void 0 && name === void 0) return;
|
|
229554
|
+
if (type === void 0) return name;
|
|
229555
|
+
if (name === void 0) return type;
|
|
229556
|
+
return type + " " + name;
|
|
229557
|
+
};
|
|
229558
|
+
const collectClassMethodRanges = (classNode, parent, lines) => {
|
|
229559
|
+
const body = classNode.childForFieldName("body");
|
|
229560
|
+
if (body === null) return [];
|
|
229561
|
+
const out = [];
|
|
229562
|
+
for (let index = 0; index < body.namedChildren.length; index++) {
|
|
229563
|
+
const child = body.namedChildren[index];
|
|
229564
|
+
if (!child.type.includes("method")) continue;
|
|
229565
|
+
out.push({
|
|
229566
|
+
...lineRangeWithLeadingComments(child, body.namedChildren, index, lines),
|
|
229567
|
+
name: nameFromNode(child),
|
|
229568
|
+
type: chunkTypeFromNode(child),
|
|
229569
|
+
parent
|
|
229570
|
+
});
|
|
229571
|
+
}
|
|
229572
|
+
return out;
|
|
229573
|
+
};
|
|
229574
|
+
const collectAstRanges = (path, content, lines) => {
|
|
229575
|
+
const language = resolveAstLanguage(path);
|
|
229576
|
+
if (language === void 0) return [];
|
|
229577
|
+
try {
|
|
229578
|
+
const parser = new TreeSitter();
|
|
229579
|
+
parser.setLanguage(language);
|
|
229580
|
+
const tree = parser.parse(content, void 0, { bufferSize: 1024 * 1024 });
|
|
229581
|
+
const collectDeclarationRanges = (siblings, parent) => {
|
|
229582
|
+
const out = [];
|
|
229583
|
+
for (let index = 0; index < siblings.length; index++) {
|
|
229584
|
+
const sibling = siblings[index];
|
|
229585
|
+
if (sibling.type === "comment" || sibling.type.includes("import")) continue;
|
|
229586
|
+
const declarationNode = unwrapDeclarationNode(sibling);
|
|
229587
|
+
const type = chunkTypeFromNode(declarationNode);
|
|
229588
|
+
const name = nameFromNode(declarationNode);
|
|
229589
|
+
if (type === void 0 && name === void 0) continue;
|
|
229590
|
+
out.push({
|
|
229591
|
+
...lineRangeWithLeadingComments(sibling, siblings, index, lines),
|
|
229592
|
+
name,
|
|
229593
|
+
type,
|
|
229594
|
+
parent
|
|
229595
|
+
});
|
|
229596
|
+
if (declarationNode.type === "class_declaration") out.push(...collectClassMethodRanges(declarationNode, formatParent(type, name), lines));
|
|
229597
|
+
if (isNamespaceNode(declarationNode)) {
|
|
229598
|
+
const body = declarationNode.childForFieldName("body");
|
|
229599
|
+
if (body !== null) out.push(...collectDeclarationRanges(body.namedChildren, formatParent(type, name)));
|
|
229600
|
+
}
|
|
229601
|
+
}
|
|
229602
|
+
return out;
|
|
229603
|
+
};
|
|
229604
|
+
return collectDeclarationRanges(tree.rootNode.namedChildren, void 0);
|
|
229605
|
+
} catch {
|
|
229606
|
+
return [];
|
|
229607
|
+
}
|
|
229608
|
+
};
|
|
229609
|
+
const chunksFromRanges = (path, lines, ranges, settings) => {
|
|
229610
|
+
const hasMethodChildRange = (classRange) => {
|
|
229611
|
+
const parent = formatParent("class", classRange.name);
|
|
229612
|
+
return ranges.some((range) => range.type === "method" && range.parent === parent && range.startLine >= classRange.startLine && range.endLine <= classRange.endLine);
|
|
229613
|
+
};
|
|
229614
|
+
const out = [];
|
|
229615
|
+
const seen = /* @__PURE__ */ new Set();
|
|
229616
|
+
const prefixSums = lineLengthPrefixSums(lines);
|
|
229617
|
+
for (const range of ranges) {
|
|
229618
|
+
const normalizedRange = normalizeLineRange(range, lines.length);
|
|
229619
|
+
if (normalizedRange === void 0) continue;
|
|
229620
|
+
const allSegments = splitRange(normalizedRange, settings, prefixSums);
|
|
229621
|
+
const segments = range.type === "class" && allSegments.length > 1 && hasMethodChildRange({
|
|
229622
|
+
...normalizedRange,
|
|
229623
|
+
name: range.name
|
|
229624
|
+
}) ? [allSegments[0]] : allSegments;
|
|
229625
|
+
for (const segment of segments) {
|
|
229626
|
+
const key = String(segment.startLine) + ":" + String(segment.endLine) + ":" + (range.name ?? "") + ":" + (range.type ?? "") + ":" + (range.parent ?? "");
|
|
229627
|
+
if (seen.has(key)) continue;
|
|
229628
|
+
seen.add(key);
|
|
229629
|
+
const chunkLines = lines.slice(segment.startLine - 1, segment.endLine);
|
|
229630
|
+
if (!chunkLines.some(isMeaningfulLine)) continue;
|
|
229631
|
+
out.push({
|
|
229632
|
+
path,
|
|
229633
|
+
startLine: segment.startLine,
|
|
229634
|
+
endLine: segment.endLine,
|
|
229635
|
+
name: range.name,
|
|
229636
|
+
type: range.type,
|
|
229637
|
+
parent: range.parent,
|
|
229638
|
+
content: chunkLines.join("\n")
|
|
229639
|
+
});
|
|
229640
|
+
}
|
|
229641
|
+
}
|
|
229642
|
+
return out.toSorted((left, right) => left.startLine - right.startLine || left.endLine - right.endLine || (left.name ?? "").localeCompare(right.name ?? ""));
|
|
229643
|
+
};
|
|
229644
|
+
const chunkWithLineWindows = (path, lines, settings) => {
|
|
229645
|
+
const out = [];
|
|
229646
|
+
const prefixSums = lineLengthPrefixSums(lines);
|
|
229647
|
+
for (let index = 0; index < lines.length;) {
|
|
229648
|
+
if (!isMeaningfulLine(lines[index])) {
|
|
229649
|
+
index++;
|
|
229650
|
+
continue;
|
|
229651
|
+
}
|
|
229652
|
+
const startLine = index + 1;
|
|
229653
|
+
const endLine = resolveSegmentEndLine({
|
|
229654
|
+
startLine,
|
|
229655
|
+
maxEndLine: Math.min(lines.length, startLine + settings.chunkSize - 1),
|
|
229656
|
+
settings,
|
|
229657
|
+
prefixSums
|
|
229658
|
+
});
|
|
229659
|
+
const chunkLines = lines.slice(startLine - 1, endLine);
|
|
229660
|
+
out.push({
|
|
229661
|
+
path,
|
|
229662
|
+
startLine,
|
|
229663
|
+
endLine,
|
|
229664
|
+
name: void 0,
|
|
229665
|
+
type: void 0,
|
|
229666
|
+
parent: void 0,
|
|
229667
|
+
content: chunkLines.join("\n")
|
|
229668
|
+
});
|
|
229669
|
+
if (endLine >= lines.length) break;
|
|
229670
|
+
index = Math.max(startLine + 1, endLine - settings.chunkOverlap + 1) - 1;
|
|
229671
|
+
}
|
|
229672
|
+
return out;
|
|
229673
|
+
};
|
|
229674
|
+
/**
|
|
229675
|
+
* @since 1.0.0
|
|
229676
|
+
* @category Constructors
|
|
229677
|
+
*/
|
|
229678
|
+
const chunkFileContent = (path, content, options) => {
|
|
229679
|
+
if (content.trim().length === 0 || isProbablyMinified(content)) return [];
|
|
229680
|
+
const normalizedPath = normalizePath$1(path);
|
|
229681
|
+
const normalizedContent = normalizeText(content);
|
|
229682
|
+
const lines = normalizedContent.split("\n");
|
|
229683
|
+
if (lines.at(-1) === "") lines.pop();
|
|
229684
|
+
if (lines.length === 0) return [];
|
|
229685
|
+
const settings = resolveChunkSettings(options);
|
|
229686
|
+
const astRanges = collectAstRanges(normalizedPath, normalizedContent, lines);
|
|
229687
|
+
if (astRanges.length > 0) {
|
|
229688
|
+
const astChunks = chunksFromRanges(normalizedPath, lines, astRanges, settings);
|
|
229689
|
+
if (astChunks.length > 0) return astChunks;
|
|
229690
|
+
}
|
|
229691
|
+
return chunkWithLineWindows(normalizedPath, lines, settings);
|
|
229692
|
+
};
|
|
229693
|
+
/**
|
|
229694
|
+
* @since 1.0.0
|
|
229695
|
+
* @category Layers
|
|
229696
|
+
*/
|
|
229697
|
+
const layer$6 = effect$1(CodeChunker, gen(function* () {
|
|
229698
|
+
const spawner = yield* ChildProcessSpawner;
|
|
229699
|
+
const fs = yield* FileSystem;
|
|
229700
|
+
const pathService = yield* Path$1;
|
|
229701
|
+
const listFiles = fn("CodeChunker.listFiles")(function* (options) {
|
|
229702
|
+
const root = pathService.resolve(options.root);
|
|
229703
|
+
const maxFileSize = options.maxFileSize ?? "1M";
|
|
229704
|
+
return yield* pipe$1(spawner.streamLines(make$45("rg", [
|
|
229705
|
+
"--files",
|
|
229706
|
+
"--hidden",
|
|
229707
|
+
"--max-filesize",
|
|
229708
|
+
maxFileSize,
|
|
229709
|
+
"--glob",
|
|
229710
|
+
"!.git"
|
|
229711
|
+
], {
|
|
229712
|
+
cwd: root,
|
|
229713
|
+
stdin: "ignore"
|
|
229714
|
+
})), runCollect, map$9(fromIterable$5), map$9((entries) => entries.map((entry) => normalizePath$1(entry.trim())).filter((entry) => entry.length > 0 && isMeaningfulFile(entry)).sort((left, right) => left.localeCompare(right))), orDie$2);
|
|
229715
|
+
});
|
|
229716
|
+
const chunkFile = fn("CodeChunker.chunkFile")(function* (options) {
|
|
229717
|
+
const root = pathService.resolve(options.root);
|
|
229718
|
+
const absolutePath = pathService.resolve(root, options.path);
|
|
229719
|
+
const path = normalizePath$1(pathService.relative(root, absolutePath));
|
|
229720
|
+
if (path.length === 0 || path === ".." || path.startsWith("../") || !isMeaningfulFile(path)) return [];
|
|
229721
|
+
return yield* pipe$1(fs.readFileString(absolutePath), map$9((content) => chunkFileContent(path, content, options)), catch_$2(() => succeed$3([])));
|
|
229722
|
+
});
|
|
229723
|
+
const chunkFiles = (options) => fromArray(options.paths).pipe(flatMap$2((path) => pipe$1(chunkFile({
|
|
229724
|
+
root: options.root,
|
|
229725
|
+
path,
|
|
229726
|
+
chunkSize: options.chunkSize,
|
|
229727
|
+
chunkOverlap: options.chunkOverlap,
|
|
229728
|
+
...options.chunkMaxCharacters === void 0 ? {} : { chunkMaxCharacters: options.chunkMaxCharacters }
|
|
229729
|
+
}), fromArrayEffect), { concurrency: 5 }));
|
|
229730
|
+
const chunkCodebase = fnUntraced(function* (options) {
|
|
229731
|
+
const root = pathService.resolve(options.root);
|
|
229732
|
+
return chunkFiles({
|
|
229733
|
+
root,
|
|
229734
|
+
paths: yield* listFiles({
|
|
229735
|
+
root,
|
|
229736
|
+
...options.maxFileSize === void 0 ? {} : { maxFileSize: options.maxFileSize }
|
|
229737
|
+
}),
|
|
229738
|
+
chunkSize: options.chunkSize,
|
|
229739
|
+
chunkOverlap: options.chunkOverlap,
|
|
229740
|
+
...options.chunkMaxCharacters === void 0 ? {} : { chunkMaxCharacters: options.chunkMaxCharacters }
|
|
229741
|
+
});
|
|
229742
|
+
}, unwrap);
|
|
229743
|
+
return CodeChunker.of({
|
|
229744
|
+
listFiles,
|
|
229745
|
+
chunkFile,
|
|
229746
|
+
chunkFiles,
|
|
229747
|
+
chunkCodebase
|
|
229748
|
+
});
|
|
229749
|
+
}));
|
|
229750
|
+
//#endregion
|
|
230674
229751
|
//#region node_modules/.pnpm/@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36/node_modules/@effect/ai-openai-compat/dist/internal/errors.js
|
|
230675
229752
|
/** @internal */
|
|
230676
229753
|
const OpenAiErrorBody = /* @__PURE__ */ Struct$2({ error: /* @__PURE__ */ Struct$2({
|
|
@@ -230911,7 +229988,7 @@ const RedactedOpenAiHeaders = {
|
|
|
230911
229988
|
* @since 1.0.0
|
|
230912
229989
|
* @category constructors
|
|
230913
229990
|
*/
|
|
230914
|
-
const make$
|
|
229991
|
+
const make$3 = /* @__PURE__ */ fnUntraced(function* (options) {
|
|
230915
229992
|
const httpClient = (yield* HttpClient).pipe(mapRequest((request) => request.pipe(prependUrl(options.apiUrl ?? "https://api.openai.com/v1"), options.apiKey !== void 0 ? bearerToken(value$2(options.apiKey)) : identity, options.organizationId !== void 0 ? setHeader(RedactedOpenAiHeaders.OpenAiOrganization, value$2(options.organizationId)) : identity, options.projectId !== void 0 ? setHeader(RedactedOpenAiHeaders.OpenAiProject, value$2(options.projectId)) : identity, acceptJson)), options.transformClient !== void 0 ? options.transformClient : identity);
|
|
230916
229993
|
const resolveHttpClient = map$9(OpenAiConfig.getOrUndefined, (config) => config?.transformClient !== void 0 ? config.transformClient(httpClient) : httpClient);
|
|
230917
229994
|
const decodeResponse = schemaBodyJson(ChatCompletionResponse);
|
|
@@ -230949,7 +230026,7 @@ const make$1 = /* @__PURE__ */ fnUntraced(function* (options) {
|
|
|
230949
230026
|
* @since 1.0.0
|
|
230950
230027
|
* @category layers
|
|
230951
230028
|
*/
|
|
230952
|
-
const layer$
|
|
230029
|
+
const layer$5 = (options) => effect$1(OpenAiClient, make$3(options));
|
|
230953
230030
|
const CreateEmbeddingResponseSchema = /* @__PURE__ */ Struct$2({
|
|
230954
230031
|
data: /* @__PURE__ */ Array$1(/* @__PURE__ */ Struct$2({
|
|
230955
230032
|
embedding: /* @__PURE__ */ Union$2([/* @__PURE__ */ Array$1(Number$1), String$1]),
|
|
@@ -231097,7 +230174,7 @@ var Config = class extends Service$1()("@effect/ai-openai-compat/OpenAiLanguageM
|
|
|
231097
230174
|
* @since 1.0.0
|
|
231098
230175
|
* @category constructors
|
|
231099
230176
|
*/
|
|
231100
|
-
const make = /* @__PURE__ */ fnUntraced(function* ({ model, config: providerConfig }) {
|
|
230177
|
+
const make$2 = /* @__PURE__ */ fnUntraced(function* ({ model, config: providerConfig }) {
|
|
231101
230178
|
const client = yield* OpenAiClient;
|
|
231102
230179
|
const makeConfig = gen(function* () {
|
|
231103
230180
|
const services$3 = yield* services();
|
|
@@ -231137,7 +230214,7 @@ const make = /* @__PURE__ */ fnUntraced(function* ({ model, config: providerConf
|
|
|
231137
230214
|
...toolChoice !== void 0 ? { tool_choice: toolChoice } : void 0
|
|
231138
230215
|
});
|
|
231139
230216
|
});
|
|
231140
|
-
return yield* make$
|
|
230217
|
+
return yield* make$10({
|
|
231141
230218
|
codecTransformer: toCodecOpenAI,
|
|
231142
230219
|
generateText: fnUntraced(function* (options) {
|
|
231143
230220
|
const config = yield* makeConfig;
|
|
@@ -231183,7 +230260,7 @@ const make = /* @__PURE__ */ fnUntraced(function* ({ model, config: providerConf
|
|
|
231183
230260
|
* @since 1.0.0
|
|
231184
230261
|
* @category layers
|
|
231185
230262
|
*/
|
|
231186
|
-
const layer = (options) => effect$1(LanguageModel, make(options));
|
|
230263
|
+
const layer$4 = (options) => effect$1(LanguageModel, make$2(options));
|
|
231187
230264
|
const getSystemMessageMode = (model) => model.startsWith("o") || model.startsWith("gpt-5") || model.startsWith("codex-") || model.startsWith("computer-use") ? "developer" : "system";
|
|
231188
230265
|
const prepareMessages = /* @__PURE__ */ fnUntraced(function* ({ config, options, capabilities, include, toolNameMapper }) {
|
|
231189
230266
|
const hasConversation = isNotNullish(config.conversation);
|
|
@@ -231957,7 +231034,7 @@ const getUsageDetailNumber = (details, field) => {
|
|
|
231957
231034
|
return typeof value === "number" ? value : void 0;
|
|
231958
231035
|
};
|
|
231959
231036
|
//#endregion
|
|
231960
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
231037
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/CopilotAuth.js
|
|
231961
231038
|
/**
|
|
231962
231039
|
* @since 1.0.0
|
|
231963
231040
|
*/
|
|
@@ -232148,7 +231225,7 @@ var GithubCopilotAuth = class GithubCopilotAuth extends Service$1()("clanka/Gith
|
|
|
232148
231225
|
static layerClient = this.layerClientNoDeps.pipe(provide$3(GithubCopilotAuth.layer));
|
|
232149
231226
|
};
|
|
232150
231227
|
//#endregion
|
|
232151
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
231228
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/Copilot.js
|
|
232152
231229
|
/**
|
|
232153
231230
|
* @since 1.0.0
|
|
232154
231231
|
*/
|
|
@@ -232156,12 +231233,12 @@ var GithubCopilotAuth = class GithubCopilotAuth extends Service$1()("clanka/Gith
|
|
|
232156
231233
|
* @since 1.0.0
|
|
232157
231234
|
* @category Layers
|
|
232158
231235
|
*/
|
|
232159
|
-
const layerClient = layer$
|
|
231236
|
+
const layerClient = layer$5({ apiUrl: API_URL }).pipe(provide$3(GithubCopilotAuth.layerClient));
|
|
232160
231237
|
/**
|
|
232161
231238
|
* @since 1.0.0
|
|
232162
231239
|
* @category Layers
|
|
232163
231240
|
*/
|
|
232164
|
-
const model = (model, options) => make$16("openai", model, merge$6(layer({
|
|
231241
|
+
const model = (model, options) => make$16("openai", model, merge$6(layer$4({
|
|
232165
231242
|
model,
|
|
232166
231243
|
config: omit$2(options ?? {}, ["systemPromptTransform"])
|
|
232167
231244
|
}), AgentModelConfig.layer({ systemPromptTransform: options?.systemPromptTransform })));
|
|
@@ -232568,7 +231645,7 @@ Object.defineProperties(createChalk.prototype, styles);
|
|
|
232568
231645
|
const chalk = createChalk();
|
|
232569
231646
|
createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
232570
231647
|
//#endregion
|
|
232571
|
-
//#region node_modules/.pnpm/clanka@0.2.
|
|
231648
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/OutputFormatter.js
|
|
232572
231649
|
/**
|
|
232573
231650
|
* @since 1.0.0
|
|
232574
231651
|
*/
|
|
@@ -232642,7 +231719,7 @@ var Muxer = class extends Service$1()("clanka/OutputFormatter/Muxer") {};
|
|
|
232642
231719
|
* @category Muxer
|
|
232643
231720
|
*/
|
|
232644
231721
|
const layerMuxer = (formatter) => effect$1(Muxer, gen(function* () {
|
|
232645
|
-
const scope$
|
|
231722
|
+
const scope$3 = yield* scope;
|
|
232646
231723
|
const output = yield* unbounded$1();
|
|
232647
231724
|
let agentCount = 0;
|
|
232648
231725
|
let currentAgentId = null;
|
|
@@ -232668,12 +231745,948 @@ const layerMuxer = (formatter) => effect$1(Muxer, gen(function* () {
|
|
|
232668
231745
|
if (currentAgentId !== id) return void_$2;
|
|
232669
231746
|
currentAgentId = null;
|
|
232670
231747
|
return semaphore.release(1);
|
|
232671
|
-
}), forkIn(scope$
|
|
231748
|
+
}), forkIn(scope$3), asVoid);
|
|
232672
231749
|
},
|
|
232673
231750
|
output: fromPubSub(output)
|
|
232674
231751
|
});
|
|
232675
231752
|
}));
|
|
232676
231753
|
//#endregion
|
|
231754
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/schema/VariantSchema.js
|
|
231755
|
+
/**
|
|
231756
|
+
* @since 4.0.0
|
|
231757
|
+
* @category Type IDs
|
|
231758
|
+
*/
|
|
231759
|
+
const TypeId$2 = "~effect/schema/VariantSchema";
|
|
231760
|
+
const cacheSymbol = /* @__PURE__ */ Symbol.for(`${TypeId$2}/cache`);
|
|
231761
|
+
/**
|
|
231762
|
+
* @since 4.0.0
|
|
231763
|
+
* @category guards
|
|
231764
|
+
*/
|
|
231765
|
+
const isStruct = (u) => hasProperty(u, TypeId$2);
|
|
231766
|
+
const FieldTypeId = "~effect/schema/VariantSchema/Field";
|
|
231767
|
+
/**
|
|
231768
|
+
* @since 4.0.0
|
|
231769
|
+
* @category guards
|
|
231770
|
+
*/
|
|
231771
|
+
const isField = (u) => hasProperty(u, FieldTypeId);
|
|
231772
|
+
const extract$1 = /* @__PURE__ */ dual((args) => isStruct(args[0]), (self, variant, options) => {
|
|
231773
|
+
const cache = self[cacheSymbol] ?? (self[cacheSymbol] = {});
|
|
231774
|
+
const cacheKey = options?.isDefault === true ? "__default" : variant;
|
|
231775
|
+
if (cache[cacheKey] !== void 0) return cache[cacheKey];
|
|
231776
|
+
const fields = {};
|
|
231777
|
+
for (const key of Object.keys(self[TypeId$2])) {
|
|
231778
|
+
const value = self[TypeId$2][key];
|
|
231779
|
+
if ("~effect/schema/VariantSchema" in value) if (options?.isDefault === true && isSchema(value)) fields[key] = value;
|
|
231780
|
+
else fields[key] = extract$1(value, variant);
|
|
231781
|
+
else if (FieldTypeId in value) {
|
|
231782
|
+
if (variant in value.schemas) fields[key] = value.schemas[variant];
|
|
231783
|
+
} else fields[key] = value;
|
|
231784
|
+
}
|
|
231785
|
+
return cache[cacheKey] = Struct$2(fields);
|
|
231786
|
+
});
|
|
231787
|
+
/**
|
|
231788
|
+
* @since 4.0.0
|
|
231789
|
+
* @category constructors
|
|
231790
|
+
*/
|
|
231791
|
+
const make$1 = (options) => {
|
|
231792
|
+
function Class(identifier) {
|
|
231793
|
+
return function(fields, annotations) {
|
|
231794
|
+
const variantStruct = Struct$1(fields);
|
|
231795
|
+
const schema = extract$1(variantStruct, options.defaultVariant, { isDefault: true });
|
|
231796
|
+
const SClass = Class$2;
|
|
231797
|
+
class Base extends SClass(identifier)(schema.fields, annotations) {
|
|
231798
|
+
static [TypeId$2] = fields;
|
|
231799
|
+
}
|
|
231800
|
+
for (const variant of options.variants) Object.defineProperty(Base, variant, { value: extract$1(variantStruct, variant).annotate({
|
|
231801
|
+
id: `${identifier}.${variant}`,
|
|
231802
|
+
title: `${identifier}.${variant}`
|
|
231803
|
+
}) });
|
|
231804
|
+
return Base;
|
|
231805
|
+
};
|
|
231806
|
+
}
|
|
231807
|
+
function FieldOnly(keys) {
|
|
231808
|
+
return function(schema) {
|
|
231809
|
+
const obj = {};
|
|
231810
|
+
for (const key of keys) obj[key] = schema;
|
|
231811
|
+
return Field$1(obj);
|
|
231812
|
+
};
|
|
231813
|
+
}
|
|
231814
|
+
function FieldExcept(keys) {
|
|
231815
|
+
return function(schema) {
|
|
231816
|
+
const obj = {};
|
|
231817
|
+
for (const variant of options.variants) if (!keys.includes(variant)) obj[variant] = schema;
|
|
231818
|
+
return Field$1(obj);
|
|
231819
|
+
};
|
|
231820
|
+
}
|
|
231821
|
+
function UnionVariants(members) {
|
|
231822
|
+
return Union$1(members, options.variants);
|
|
231823
|
+
}
|
|
231824
|
+
return {
|
|
231825
|
+
Struct: Struct$1,
|
|
231826
|
+
Field: Field$1,
|
|
231827
|
+
FieldOnly,
|
|
231828
|
+
FieldExcept,
|
|
231829
|
+
Class,
|
|
231830
|
+
Union: UnionVariants,
|
|
231831
|
+
fieldEvolve: dual(2, (self, f) => {
|
|
231832
|
+
return Field$1(evolve((isField(self) ? self : Field$1(Object.fromEntries(options.variants.map((variant) => [variant, self])))).schemas, f));
|
|
231833
|
+
}),
|
|
231834
|
+
extract: dual(2, (self, variant) => extract$1(self, variant, { isDefault: variant === options.defaultVariant }))
|
|
231835
|
+
};
|
|
231836
|
+
};
|
|
231837
|
+
const StructProto = { pipe() {
|
|
231838
|
+
return pipeArguments(this, arguments);
|
|
231839
|
+
} };
|
|
231840
|
+
const Struct$1 = (fields) => {
|
|
231841
|
+
const self = Object.create(StructProto);
|
|
231842
|
+
self[TypeId$2] = fields;
|
|
231843
|
+
return self;
|
|
231844
|
+
};
|
|
231845
|
+
const FieldProto = {
|
|
231846
|
+
[FieldTypeId]: FieldTypeId,
|
|
231847
|
+
pipe() {
|
|
231848
|
+
return pipeArguments(this, arguments);
|
|
231849
|
+
}
|
|
231850
|
+
};
|
|
231851
|
+
const Field$1 = (schemas) => {
|
|
231852
|
+
const self = Object.create(FieldProto);
|
|
231853
|
+
self.schemas = schemas;
|
|
231854
|
+
return self;
|
|
231855
|
+
};
|
|
231856
|
+
const Union$1 = (members, variants) => {
|
|
231857
|
+
const VariantUnion = Union$2(members.filter((member) => isSchema(member)));
|
|
231858
|
+
for (const variant of variants) Object.defineProperty(VariantUnion, variant, { value: Union$2(members.map((member) => extract$1(member, variant))) });
|
|
231859
|
+
return VariantUnion;
|
|
231860
|
+
};
|
|
231861
|
+
//#endregion
|
|
231862
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/schema/Model.js
|
|
231863
|
+
const { Class, Field, FieldExcept, FieldOnly, Struct, Union, extract, fieldEvolve } = /* @__PURE__ */ make$1({
|
|
231864
|
+
variants: [
|
|
231865
|
+
"select",
|
|
231866
|
+
"insert",
|
|
231867
|
+
"update",
|
|
231868
|
+
"json",
|
|
231869
|
+
"jsonCreate",
|
|
231870
|
+
"jsonUpdate"
|
|
231871
|
+
],
|
|
231872
|
+
defaultVariant: "select"
|
|
231873
|
+
});
|
|
231874
|
+
/**
|
|
231875
|
+
* A field that represents a column that is generated by the database.
|
|
231876
|
+
*
|
|
231877
|
+
* It is available for selection and update, but not for insertion.
|
|
231878
|
+
*
|
|
231879
|
+
* @since 4.0.0
|
|
231880
|
+
* @category generated
|
|
231881
|
+
*/
|
|
231882
|
+
const Generated = (schema) => Field({
|
|
231883
|
+
select: schema,
|
|
231884
|
+
update: schema,
|
|
231885
|
+
json: schema
|
|
231886
|
+
});
|
|
231887
|
+
//#endregion
|
|
231888
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/sql/SqlError.js
|
|
231889
|
+
/**
|
|
231890
|
+
* @since 4.0.0
|
|
231891
|
+
*/
|
|
231892
|
+
const TypeId$1 = "~effect/sql/SqlError";
|
|
231893
|
+
/**
|
|
231894
|
+
* @since 4.0.0
|
|
231895
|
+
*/
|
|
231896
|
+
var SqlError = class extends TaggedErrorClass("effect/sql/SqlError")("SqlError", {
|
|
231897
|
+
cause: Defect,
|
|
231898
|
+
message: /* @__PURE__ */ optional$3(String$1)
|
|
231899
|
+
}) {
|
|
231900
|
+
/**
|
|
231901
|
+
* @since 4.0.0
|
|
231902
|
+
*/
|
|
231903
|
+
[TypeId$1] = TypeId$1;
|
|
231904
|
+
};
|
|
231905
|
+
/**
|
|
231906
|
+
* @since 4.0.0
|
|
231907
|
+
*/
|
|
231908
|
+
var ResultLengthMismatch = class extends TaggedErrorClass("effect/sql/ResultLengthMismatch")("ResultLengthMismatch", {
|
|
231909
|
+
expected: Number$1,
|
|
231910
|
+
actual: Number$1
|
|
231911
|
+
}) {
|
|
231912
|
+
/**
|
|
231913
|
+
* @since 4.0.0
|
|
231914
|
+
*/
|
|
231915
|
+
[TypeId$1] = TypeId$1;
|
|
231916
|
+
/**
|
|
231917
|
+
* @since 4.0.0
|
|
231918
|
+
*/
|
|
231919
|
+
get message() {
|
|
231920
|
+
return `Expected ${this.expected} results but got ${this.actual}`;
|
|
231921
|
+
}
|
|
231922
|
+
};
|
|
231923
|
+
//#endregion
|
|
231924
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/sql/SqlResolver.js
|
|
231925
|
+
/**
|
|
231926
|
+
* @since 4.0.0
|
|
231927
|
+
*/
|
|
231928
|
+
const SqlRequestProto = {
|
|
231929
|
+
...Class$3.prototype,
|
|
231930
|
+
[symbol$5](that) {
|
|
231931
|
+
return equals$2(this.payload, that.payload);
|
|
231932
|
+
},
|
|
231933
|
+
[symbol$6]() {
|
|
231934
|
+
return hash(this.payload);
|
|
231935
|
+
}
|
|
231936
|
+
};
|
|
231937
|
+
/**
|
|
231938
|
+
* @since 4.0.0
|
|
231939
|
+
* @category requests
|
|
231940
|
+
*/
|
|
231941
|
+
const request$1 = function() {
|
|
231942
|
+
if (arguments.length === 1) {
|
|
231943
|
+
const resolver = arguments[0];
|
|
231944
|
+
return (payload) => request$2(SqlRequest(payload), resolver);
|
|
231945
|
+
}
|
|
231946
|
+
return request$2(SqlRequest(arguments[0]), arguments[1]);
|
|
231947
|
+
};
|
|
231948
|
+
/**
|
|
231949
|
+
* @since 4.0.0
|
|
231950
|
+
* @category requests
|
|
231951
|
+
*/
|
|
231952
|
+
const SqlRequest = (payload) => {
|
|
231953
|
+
const self = Object.create(SqlRequestProto);
|
|
231954
|
+
self.payload = payload;
|
|
231955
|
+
return self;
|
|
231956
|
+
};
|
|
231957
|
+
/**
|
|
231958
|
+
* Create a resolver for a sql query with a request schema and a result schema.
|
|
231959
|
+
*
|
|
231960
|
+
* The request schema is used to validate the input of the query.
|
|
231961
|
+
* The result schema is used to validate the output of the query.
|
|
231962
|
+
*
|
|
231963
|
+
* Results are mapped to the requests in order, so the length of the results must match the length of the requests.
|
|
231964
|
+
*
|
|
231965
|
+
* @since 4.0.0
|
|
231966
|
+
* @category resolvers
|
|
231967
|
+
*/
|
|
231968
|
+
const ordered = (options) => {
|
|
231969
|
+
const decodeArray = decodeUnknownEffect(Array$1(options.Result));
|
|
231970
|
+
return makeGrouped({
|
|
231971
|
+
key: transactionKey,
|
|
231972
|
+
resolver: fnUntraced(function* (entries) {
|
|
231973
|
+
const inputs = yield* partitionRequests(entries, options.Request);
|
|
231974
|
+
const results = yield* options.execute(inputs).pipe(provideServices$2(entries[0].services));
|
|
231975
|
+
if (results.length !== inputs.length) return yield* new ResultLengthMismatch({
|
|
231976
|
+
expected: inputs.length,
|
|
231977
|
+
actual: results.length
|
|
231978
|
+
});
|
|
231979
|
+
const decodedResults = yield* decodeArray(results).pipe(provideServices$2(entries[0].services));
|
|
231980
|
+
for (let i = 0; i < entries.length; i++) entries[i].completeUnsafe(succeed$6(decodedResults[i]));
|
|
231981
|
+
})
|
|
231982
|
+
});
|
|
231983
|
+
};
|
|
231984
|
+
/**
|
|
231985
|
+
* Create a resolver that resolves results by id.
|
|
231986
|
+
*
|
|
231987
|
+
* @since 4.0.0
|
|
231988
|
+
* @category resolvers
|
|
231989
|
+
*/
|
|
231990
|
+
const findById = (options) => {
|
|
231991
|
+
const decodeResults = decodeUnknownEffect(Array$1(options.Result));
|
|
231992
|
+
return makeGrouped({
|
|
231993
|
+
key(entry) {
|
|
231994
|
+
const conn = entry.services.mapUnsafe.get(TransactionConnection.key);
|
|
231995
|
+
if (!conn) return void 0;
|
|
231996
|
+
return byReferenceUnsafe(conn);
|
|
231997
|
+
},
|
|
231998
|
+
resolver: fnUntraced(function* (entries) {
|
|
231999
|
+
const [inputs, idMap] = yield* partitionRequestsById(entries, options.Id);
|
|
232000
|
+
const results = yield* options.execute(inputs).pipe(provideServices$2(entries[0].services));
|
|
232001
|
+
const decodedResults = yield* decodeResults(results).pipe(provideServices$2(entries[0].services));
|
|
232002
|
+
for (let i = 0; i < decodedResults.length; i++) {
|
|
232003
|
+
const result = decodedResults[i];
|
|
232004
|
+
const id = options.ResultId(result, results[i]);
|
|
232005
|
+
const request = get$13(idMap, id);
|
|
232006
|
+
if (request._tag === "None") continue;
|
|
232007
|
+
remove$5(idMap, id);
|
|
232008
|
+
request.value.completeUnsafe(succeed$6(result));
|
|
232009
|
+
}
|
|
232010
|
+
if (isEmpty$3(idMap)) return;
|
|
232011
|
+
forEach$2(idMap, (request) => {
|
|
232012
|
+
request.completeUnsafe(constNoSuchElement);
|
|
232013
|
+
});
|
|
232014
|
+
})
|
|
232015
|
+
});
|
|
232016
|
+
};
|
|
232017
|
+
const void_ = (options) => makeGrouped({
|
|
232018
|
+
key: transactionKey,
|
|
232019
|
+
resolver: fnUntraced(function* (entries) {
|
|
232020
|
+
const inputs = yield* partitionRequests(entries, options.Request);
|
|
232021
|
+
yield* options.execute(inputs).pipe(provideServices$2(entries[0].services));
|
|
232022
|
+
for (let i = 0; i < entries.length; i++) entries[i].completeUnsafe(void_$3);
|
|
232023
|
+
})
|
|
232024
|
+
});
|
|
232025
|
+
const constNoSuchElement = /* @__PURE__ */ fail$8(/* @__PURE__ */ new NoSuchElementError());
|
|
232026
|
+
const partitionRequests = function* (requests, schema) {
|
|
232027
|
+
const len = requests.length;
|
|
232028
|
+
const inputs = empty$17();
|
|
232029
|
+
let entry;
|
|
232030
|
+
const encode = encodeEffect(schema);
|
|
232031
|
+
const handle = matchCauseEager({
|
|
232032
|
+
onFailure(cause) {
|
|
232033
|
+
entry.completeUnsafe(failCause$4(cause));
|
|
232034
|
+
},
|
|
232035
|
+
onSuccess(value) {
|
|
232036
|
+
inputs.push(value);
|
|
232037
|
+
}
|
|
232038
|
+
});
|
|
232039
|
+
for (let i = 0; i < len; i++) {
|
|
232040
|
+
entry = requests[i];
|
|
232041
|
+
yield provideServices$2(handle(encode(entry.request.payload)), entry.services);
|
|
232042
|
+
}
|
|
232043
|
+
return inputs;
|
|
232044
|
+
};
|
|
232045
|
+
const partitionRequestsById = function* (requests, schema) {
|
|
232046
|
+
const len = requests.length;
|
|
232047
|
+
const inputs = empty$17();
|
|
232048
|
+
const byIdMap = empty$11();
|
|
232049
|
+
let entry;
|
|
232050
|
+
const encode = encodeEffect(schema);
|
|
232051
|
+
const handle = matchCauseEager({
|
|
232052
|
+
onFailure(cause) {
|
|
232053
|
+
entry.completeUnsafe(failCause$4(cause));
|
|
232054
|
+
},
|
|
232055
|
+
onSuccess(value) {
|
|
232056
|
+
inputs.push(value);
|
|
232057
|
+
}
|
|
232058
|
+
});
|
|
232059
|
+
for (let i = 0; i < len; i++) {
|
|
232060
|
+
entry = requests[i];
|
|
232061
|
+
yield provideServices$2(handle(encode(entry.request.payload)), entry.services);
|
|
232062
|
+
set$8(byIdMap, entry.request.payload, entry);
|
|
232063
|
+
}
|
|
232064
|
+
return [inputs, byIdMap];
|
|
232065
|
+
};
|
|
232066
|
+
function transactionKey(entry) {
|
|
232067
|
+
const conn = entry.services.mapUnsafe.get(TransactionConnection.key);
|
|
232068
|
+
if (!conn) return void 0;
|
|
232069
|
+
return byReferenceUnsafe(conn);
|
|
232070
|
+
}
|
|
232071
|
+
//#endregion
|
|
232072
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/sql/SqlSchema.js
|
|
232073
|
+
/**
|
|
232074
|
+
* Run a sql query with a request schema and a result schema.
|
|
232075
|
+
*
|
|
232076
|
+
* @since 4.0.0
|
|
232077
|
+
* @category constructor
|
|
232078
|
+
*/
|
|
232079
|
+
const findAll = (options) => {
|
|
232080
|
+
const encodeRequest = encodeEffect(options.Request);
|
|
232081
|
+
const decode = decodeUnknownEffect(mutable(Array$1(options.Result)));
|
|
232082
|
+
return (request) => flatMap$4(flatMap$4(encodeRequest(request), options.execute), decode);
|
|
232083
|
+
};
|
|
232084
|
+
//#endregion
|
|
232085
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.36/node_modules/effect/dist/unstable/sql/SqlModel.js
|
|
232086
|
+
/**
|
|
232087
|
+
* Create some simple data loaders from a model.
|
|
232088
|
+
*
|
|
232089
|
+
* @since 4.0.0
|
|
232090
|
+
* @category repository
|
|
232091
|
+
*/
|
|
232092
|
+
const makeDataLoaders = (Model, options) => gen(function* () {
|
|
232093
|
+
const sql = yield* SqlClient;
|
|
232094
|
+
const idSchema = Model.fields[options.idColumn];
|
|
232095
|
+
const idColumn = options.idColumn;
|
|
232096
|
+
const setMaxBatchSize = options.maxBatchSize ? batchN(options.maxBatchSize) : identity;
|
|
232097
|
+
const insertExecute = request$1(ordered({
|
|
232098
|
+
Request: Model.insert,
|
|
232099
|
+
Result: Model,
|
|
232100
|
+
execute: (request) => sql.onDialectOrElse({
|
|
232101
|
+
mysql: () => forEach$4(request, (request) => sql`insert into ${sql(options.tableName)} ${sql.insert(request)};
|
|
232102
|
+
select * from ${sql(options.tableName)} where ${sql(idColumn)} = LAST_INSERT_ID();`.unprepared.pipe(map$9(([, results]) => results[0])), { concurrency: 10 }),
|
|
232103
|
+
orElse: () => sql`insert into ${sql(options.tableName)} ${sql.insert(request).returning("*")}`
|
|
232104
|
+
})
|
|
232105
|
+
}).pipe(setDelay(options.window), setMaxBatchSize, withSpan(`${options.spanPrefix}.insertResolver`)));
|
|
232106
|
+
const insert = (insert) => insertExecute(insert).pipe(catchTag$1("ResultLengthMismatch", die$2), withSpan$1(`${options.spanPrefix}.insert`, {}, { captureStackTrace: false }));
|
|
232107
|
+
const insertVoidExecute = request$1(void_({
|
|
232108
|
+
Request: Model.insert,
|
|
232109
|
+
execute: (request) => sql`insert into ${sql(options.tableName)} ${sql.insert(request)}`
|
|
232110
|
+
}).pipe(setDelay(options.window), setMaxBatchSize, withSpan(`${options.spanPrefix}.insertVoidResolver`)));
|
|
232111
|
+
const insertVoid = (insert) => insertVoidExecute(insert).pipe(withSpan$1(`${options.spanPrefix}.insertVoid`, {}, { captureStackTrace: false }));
|
|
232112
|
+
const findByIdExecute = request$1(findById({
|
|
232113
|
+
Id: idSchema,
|
|
232114
|
+
Result: Model,
|
|
232115
|
+
ResultId(request) {
|
|
232116
|
+
return request[idColumn];
|
|
232117
|
+
},
|
|
232118
|
+
execute: (ids) => sql`select * from ${sql(options.tableName)} where ${sql.in(idColumn, ids)}`
|
|
232119
|
+
}).pipe(setDelay(options.window), setMaxBatchSize, withSpan(`${options.spanPrefix}.findByIdResolver`)));
|
|
232120
|
+
const findById$1 = (id) => findByIdExecute(id).pipe(withSpan$1(`${options.spanPrefix}.findById`, { attributes: { id } }, { captureStackTrace: false }));
|
|
232121
|
+
const deleteExecute = request$1(void_({
|
|
232122
|
+
Request: idSchema,
|
|
232123
|
+
execute: (ids) => sql`delete from ${sql(options.tableName)} where ${sql.in(idColumn, ids)}`
|
|
232124
|
+
}).pipe(setDelay(options.window), setMaxBatchSize, withSpan(`${options.spanPrefix}.deleteResolver`)));
|
|
232125
|
+
const delete_ = (id) => deleteExecute(id).pipe(withSpan$1(`${options.spanPrefix}.delete`, { attributes: { id } }, { captureStackTrace: false }));
|
|
232126
|
+
return {
|
|
232127
|
+
insert,
|
|
232128
|
+
insertVoid,
|
|
232129
|
+
findById: findById$1,
|
|
232130
|
+
delete: delete_
|
|
232131
|
+
};
|
|
232132
|
+
});
|
|
232133
|
+
//#endregion
|
|
232134
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/ChunkRepo.js
|
|
232135
|
+
/**
|
|
232136
|
+
* @since 1.0.0
|
|
232137
|
+
* @category Models
|
|
232138
|
+
*/
|
|
232139
|
+
const ChunkId = Number$1.pipe(brand("ChunkRepo/ChunkId"));
|
|
232140
|
+
/**
|
|
232141
|
+
* @since 1.0.0
|
|
232142
|
+
* @category Models
|
|
232143
|
+
*/
|
|
232144
|
+
const SyncId = String$1.pipe(brand("ChunkRepo/SyncId"));
|
|
232145
|
+
/**
|
|
232146
|
+
* @since 1.0.0
|
|
232147
|
+
* @category Models
|
|
232148
|
+
*/
|
|
232149
|
+
const Float32ArraySchema = instanceOf(Float32Array);
|
|
232150
|
+
/**
|
|
232151
|
+
* @since 1.0.0
|
|
232152
|
+
* @category Models
|
|
232153
|
+
*/
|
|
232154
|
+
const Float32ArrayFromArray = Array$1(Number$1).pipe(decodeTo(Float32ArraySchema, transform$3({
|
|
232155
|
+
decode: (arr) => new Float32Array(arr),
|
|
232156
|
+
encode: (array) => Array.from(array)
|
|
232157
|
+
})));
|
|
232158
|
+
/**
|
|
232159
|
+
* @since 1.0.0
|
|
232160
|
+
* @category Models
|
|
232161
|
+
*/
|
|
232162
|
+
const Float32ArrayField = Field({
|
|
232163
|
+
insert: Float32ArraySchema,
|
|
232164
|
+
update: Float32ArraySchema,
|
|
232165
|
+
jsonCreate: Float32ArrayFromArray,
|
|
232166
|
+
jsonUpdate: Float32ArrayFromArray
|
|
232167
|
+
});
|
|
232168
|
+
/**
|
|
232169
|
+
* @since 1.0.0
|
|
232170
|
+
* @category Models
|
|
232171
|
+
*/
|
|
232172
|
+
var Chunk = class extends Class("Chunk")({
|
|
232173
|
+
id: Generated(ChunkId),
|
|
232174
|
+
path: String$1,
|
|
232175
|
+
content: String$1,
|
|
232176
|
+
hash: String$1,
|
|
232177
|
+
vector: Float32ArrayField,
|
|
232178
|
+
syncId: SyncId
|
|
232179
|
+
}) {};
|
|
232180
|
+
/**
|
|
232181
|
+
* @since 1.0.0
|
|
232182
|
+
* @category Services
|
|
232183
|
+
*/
|
|
232184
|
+
var ChunkRepo = class extends Service$1()("clanka/ChunkRepo") {};
|
|
232185
|
+
/**
|
|
232186
|
+
* @since 1.0.0
|
|
232187
|
+
* @category Errors
|
|
232188
|
+
*/
|
|
232189
|
+
var ChunkRepoError = class extends TaggedErrorClass()("ChunkRepoError", { reason: Union$2([SqlError]) }) {
|
|
232190
|
+
cause = this.reason;
|
|
232191
|
+
message = this.reason.message;
|
|
232192
|
+
};
|
|
232193
|
+
/**
|
|
232194
|
+
* @since 1.0.0
|
|
232195
|
+
* @category Layers
|
|
232196
|
+
*/
|
|
232197
|
+
const layer$3 = effect$1(ChunkRepo, gen(function* () {
|
|
232198
|
+
const sql = yield* SqlClient;
|
|
232199
|
+
const dimensions = yield* Dimensions;
|
|
232200
|
+
const loaders = yield* makeDataLoaders(Chunk, {
|
|
232201
|
+
tableName: "chunks",
|
|
232202
|
+
idColumn: "id",
|
|
232203
|
+
window: 10,
|
|
232204
|
+
spanPrefix: "ChunkRepo"
|
|
232205
|
+
});
|
|
232206
|
+
let needsQuantization = true;
|
|
232207
|
+
const maybeQuantize = gen(function* () {
|
|
232208
|
+
if (!needsQuantization) return;
|
|
232209
|
+
needsQuantization = false;
|
|
232210
|
+
yield* sql`select vector_init('chunks', 'vector', 'type=FLOAT32,dimension=${sql.literal(String(dimensions))}')`;
|
|
232211
|
+
yield* sql`select vector_quantize('chunks', 'vector')`;
|
|
232212
|
+
}).pipe(mapError$2((reason) => new ChunkRepoError({ reason })));
|
|
232213
|
+
yield* forkScoped(maybeQuantize);
|
|
232214
|
+
const search = findAll({
|
|
232215
|
+
Request: Struct$2({
|
|
232216
|
+
vector: Float32ArraySchema,
|
|
232217
|
+
limit: Number$1
|
|
232218
|
+
}),
|
|
232219
|
+
Result: Chunk,
|
|
232220
|
+
execute: ({ vector, limit }) => sql`
|
|
232221
|
+
select chunks.id, chunks.path, chunks.content, chunks.hash, chunks.syncId
|
|
232222
|
+
from chunks
|
|
232223
|
+
JOIN vector_quantize_scan('chunks', 'vector', ${vector}, CAST(${limit} AS INTEGER)) AS v
|
|
232224
|
+
ON chunks.id = v.rowid
|
|
232225
|
+
`
|
|
232226
|
+
});
|
|
232227
|
+
const exists = findById({
|
|
232228
|
+
Id: String$1,
|
|
232229
|
+
Result: Struct$2({
|
|
232230
|
+
id: ChunkId,
|
|
232231
|
+
hash: String$1
|
|
232232
|
+
}),
|
|
232233
|
+
ResultId(result) {
|
|
232234
|
+
return result.hash;
|
|
232235
|
+
},
|
|
232236
|
+
execute: (hashes) => sql`select id, hash from chunks where ${sql.in("hash", hashes)}`
|
|
232237
|
+
}).pipe(setDelay(5));
|
|
232238
|
+
return ChunkRepo.of({
|
|
232239
|
+
insert: (insert) => {
|
|
232240
|
+
needsQuantization = true;
|
|
232241
|
+
return loaders.insert(insert).pipe(catchTags$1({
|
|
232242
|
+
SqlError: (reason) => fail$6(new ChunkRepoError({ reason })),
|
|
232243
|
+
SchemaError: die$2
|
|
232244
|
+
}));
|
|
232245
|
+
},
|
|
232246
|
+
findById: (id) => loaders.findById(id).pipe(catchTags$1({ SchemaError: die$2 })),
|
|
232247
|
+
exists: (hash) => request$1(hash, exists).pipe(map$9((result) => result.id), catchNoSuchElement, catchTags$1({
|
|
232248
|
+
SqlError: (reason) => fail$6(new ChunkRepoError({ reason })),
|
|
232249
|
+
SchemaError: die$2
|
|
232250
|
+
})),
|
|
232251
|
+
search: fn("ChunkRepo.search")(function* (options) {
|
|
232252
|
+
yield* maybeQuantize;
|
|
232253
|
+
return yield* search(options).pipe(catchTags$1({
|
|
232254
|
+
SqlError: (reason) => fail$6(new ChunkRepoError({ reason })),
|
|
232255
|
+
SchemaError: die$2
|
|
232256
|
+
}));
|
|
232257
|
+
}),
|
|
232258
|
+
quantize: maybeQuantize,
|
|
232259
|
+
setSyncId: (chunkId, syncId) => sql`update chunks set syncId = ${syncId} where id = ${chunkId}`.pipe(mapError$2((reason) => new ChunkRepoError({ reason }))),
|
|
232260
|
+
deleteByPath: (path) => sql`delete from chunks where path = ${path}`.pipe(mapError$2((reason) => new ChunkRepoError({ reason }))),
|
|
232261
|
+
deleteForSyncId: (syncId) => sql`delete from chunks where syncId != ${syncId}`.pipe(mapError$2((reason) => new ChunkRepoError({ reason })))
|
|
232262
|
+
});
|
|
232263
|
+
}));
|
|
232264
|
+
//#endregion
|
|
232265
|
+
//#region node_modules/.pnpm/@effect+sql-sqlite-node@4.0.0-beta.36_effect@4.0.0-beta.36/node_modules/@effect/sql-sqlite-node/dist/SqliteClient.js
|
|
232266
|
+
/**
|
|
232267
|
+
* @since 1.0.0
|
|
232268
|
+
*/
|
|
232269
|
+
const ATTR_DB_SYSTEM_NAME = "db.system.name";
|
|
232270
|
+
/**
|
|
232271
|
+
* @category type ids
|
|
232272
|
+
* @since 1.0.0
|
|
232273
|
+
*/
|
|
232274
|
+
const TypeId = "~@effect/sql-sqlite-node/SqliteClient";
|
|
232275
|
+
/**
|
|
232276
|
+
* @category tags
|
|
232277
|
+
* @since 1.0.0
|
|
232278
|
+
*/
|
|
232279
|
+
const SqliteClient = /* @__PURE__ */ Service$1("@effect/sql-sqlite-node/SqliteClient");
|
|
232280
|
+
/**
|
|
232281
|
+
* @category constructor
|
|
232282
|
+
* @since 1.0.0
|
|
232283
|
+
*/
|
|
232284
|
+
const make = (options) => gen(function* () {
|
|
232285
|
+
const compiler = makeCompilerSqlite(options.transformQueryNames);
|
|
232286
|
+
const transformRows = options.transformResultNames ? defaultTransforms(options.transformResultNames).array : void 0;
|
|
232287
|
+
const makeConnection = gen(function* () {
|
|
232288
|
+
const scope$2 = yield* scope;
|
|
232289
|
+
const db = new Sqlite(options.filename, { readonly: options.readonly ?? false });
|
|
232290
|
+
yield* addFinalizer$1(scope$2, sync(() => db.close()));
|
|
232291
|
+
if (options.disableWAL !== true) db.pragma("journal_mode = WAL");
|
|
232292
|
+
const prepareCache = yield* make$57({
|
|
232293
|
+
capacity: options.prepareCacheSize ?? 200,
|
|
232294
|
+
timeToLive: options.prepareCacheTTL ?? minutes(10),
|
|
232295
|
+
lookup: (sql) => try_({
|
|
232296
|
+
try: () => db.prepare(sql),
|
|
232297
|
+
catch: (cause) => new SqlError({
|
|
232298
|
+
cause,
|
|
232299
|
+
message: "Failed to prepare statement "
|
|
232300
|
+
})
|
|
232301
|
+
})
|
|
232302
|
+
});
|
|
232303
|
+
const runStatement = (statement, params, raw) => withFiber((fiber) => {
|
|
232304
|
+
if (get$15(fiber.services, SafeIntegers)) statement.safeIntegers(true);
|
|
232305
|
+
try {
|
|
232306
|
+
if (statement.reader) return succeed$3(statement.all(...params));
|
|
232307
|
+
const result = statement.run(...params);
|
|
232308
|
+
return succeed$3(raw ? result : []);
|
|
232309
|
+
} catch (cause) {
|
|
232310
|
+
return fail$6(new SqlError({
|
|
232311
|
+
cause,
|
|
232312
|
+
message: "Failed to execute statement"
|
|
232313
|
+
}));
|
|
232314
|
+
}
|
|
232315
|
+
});
|
|
232316
|
+
const run = (sql, params, raw = false) => flatMap$4(get$7(prepareCache, sql), (s) => runStatement(s, params, raw));
|
|
232317
|
+
const runValues = (sql, params) => acquireUseRelease(get$7(prepareCache, sql), (statement) => try_({
|
|
232318
|
+
try: () => {
|
|
232319
|
+
if (statement.reader) {
|
|
232320
|
+
statement.raw(true);
|
|
232321
|
+
return statement.all(...params);
|
|
232322
|
+
}
|
|
232323
|
+
statement.run(...params);
|
|
232324
|
+
return [];
|
|
232325
|
+
},
|
|
232326
|
+
catch: (cause) => new SqlError({
|
|
232327
|
+
cause,
|
|
232328
|
+
message: "Failed to execute statement"
|
|
232329
|
+
})
|
|
232330
|
+
}), (statement) => sync(() => statement.reader && statement.raw(false)));
|
|
232331
|
+
return identity({
|
|
232332
|
+
execute(sql, params, transformRows) {
|
|
232333
|
+
return transformRows ? map$9(run(sql, params), transformRows) : run(sql, params);
|
|
232334
|
+
},
|
|
232335
|
+
executeRaw(sql, params) {
|
|
232336
|
+
return run(sql, params, true);
|
|
232337
|
+
},
|
|
232338
|
+
executeValues(sql, params) {
|
|
232339
|
+
return runValues(sql, params);
|
|
232340
|
+
},
|
|
232341
|
+
executeUnprepared(sql, params, transformRows) {
|
|
232342
|
+
const effect = runStatement(db.prepare(sql), params ?? [], false);
|
|
232343
|
+
return transformRows ? map$9(effect, transformRows) : effect;
|
|
232344
|
+
},
|
|
232345
|
+
executeStream(_sql, _params) {
|
|
232346
|
+
return die("executeStream not implemented");
|
|
232347
|
+
},
|
|
232348
|
+
export: try_({
|
|
232349
|
+
try: () => db.serialize(),
|
|
232350
|
+
catch: (cause) => new SqlError({
|
|
232351
|
+
cause,
|
|
232352
|
+
message: "Failed to export database"
|
|
232353
|
+
})
|
|
232354
|
+
}),
|
|
232355
|
+
backup(destination) {
|
|
232356
|
+
return tryPromise({
|
|
232357
|
+
try: () => db.backup(destination),
|
|
232358
|
+
catch: (cause) => new SqlError({
|
|
232359
|
+
cause,
|
|
232360
|
+
message: "Failed to backup database"
|
|
232361
|
+
})
|
|
232362
|
+
});
|
|
232363
|
+
},
|
|
232364
|
+
loadExtension(path) {
|
|
232365
|
+
return try_({
|
|
232366
|
+
try: () => db.loadExtension(path),
|
|
232367
|
+
catch: (cause) => new SqlError({
|
|
232368
|
+
cause,
|
|
232369
|
+
message: "Failed to load extension"
|
|
232370
|
+
})
|
|
232371
|
+
});
|
|
232372
|
+
}
|
|
232373
|
+
});
|
|
232374
|
+
});
|
|
232375
|
+
const semaphore = yield* make$72(1);
|
|
232376
|
+
const connection = yield* makeConnection;
|
|
232377
|
+
const acquirer = semaphore.withPermits(1)(succeed$3(connection));
|
|
232378
|
+
const transactionAcquirer = uninterruptibleMask((restore) => {
|
|
232379
|
+
const scope = getUnsafe$4(getCurrent().services, Scope);
|
|
232380
|
+
return as$1(tap$1(restore(semaphore.take(1)), () => addFinalizer$1(scope, semaphore.release(1))), connection);
|
|
232381
|
+
});
|
|
232382
|
+
return Object.assign(yield* make$49({
|
|
232383
|
+
acquirer,
|
|
232384
|
+
compiler,
|
|
232385
|
+
transactionAcquirer,
|
|
232386
|
+
spanAttributes: [...options.spanAttributes ? Object.entries(options.spanAttributes) : [], [ATTR_DB_SYSTEM_NAME, "sqlite"]],
|
|
232387
|
+
transformRows
|
|
232388
|
+
}), {
|
|
232389
|
+
[TypeId]: TypeId,
|
|
232390
|
+
config: options,
|
|
232391
|
+
export: flatMap$4(acquirer, (_) => _.export),
|
|
232392
|
+
backup: (destination) => flatMap$4(acquirer, (_) => _.backup(destination)),
|
|
232393
|
+
loadExtension: (path) => flatMap$4(acquirer, (_) => _.loadExtension(path))
|
|
232394
|
+
});
|
|
232395
|
+
});
|
|
232396
|
+
/**
|
|
232397
|
+
* @category layers
|
|
232398
|
+
* @since 1.0.0
|
|
232399
|
+
*/
|
|
232400
|
+
const layer$2 = (config) => effectServices(map$9(make(config), (client) => make$87(SqliteClient, client).pipe(add$3(SqlClient, client)))).pipe(provide$3(layer$32));
|
|
232401
|
+
//#endregion
|
|
232402
|
+
//#region node_modules/.pnpm/@effect+sql-sqlite-node@4.0.0-beta.36_effect@4.0.0-beta.36/node_modules/@effect/sql-sqlite-node/dist/SqliteMigrator.js
|
|
232403
|
+
/**
|
|
232404
|
+
* @category constructor
|
|
232405
|
+
* @since 1.0.0
|
|
232406
|
+
*/
|
|
232407
|
+
const run$1 = /* @__PURE__ */ make$25({});
|
|
232408
|
+
/**
|
|
232409
|
+
* @category constructor
|
|
232410
|
+
* @since 1.0.0
|
|
232411
|
+
*/
|
|
232412
|
+
const layer$1 = (options) => effectDiscard(run$1(options));
|
|
232413
|
+
//#endregion
|
|
232414
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/internal/sqlite-vector.js
|
|
232415
|
+
/**
|
|
232416
|
+
* Binary extension for each platform
|
|
232417
|
+
*/
|
|
232418
|
+
const PLATFORM_EXTENSIONS = {
|
|
232419
|
+
darwin: ".dylib",
|
|
232420
|
+
linux: ".so",
|
|
232421
|
+
win32: ".dll"
|
|
232422
|
+
};
|
|
232423
|
+
/**
|
|
232424
|
+
* Detects if the system uses musl libc (Alpine Linux, etc.)
|
|
232425
|
+
* Uses multiple detection strategies for reliability
|
|
232426
|
+
*/
|
|
232427
|
+
function isMusl() {
|
|
232428
|
+
if (platform() !== "linux") return false;
|
|
232429
|
+
for (const file of [
|
|
232430
|
+
"/lib/ld-musl-x86_64.so.1",
|
|
232431
|
+
"/lib/ld-musl-aarch64.so.1",
|
|
232432
|
+
"/lib/ld-musl-armhf.so.1"
|
|
232433
|
+
]) if (existsSync(file)) return true;
|
|
232434
|
+
try {
|
|
232435
|
+
if (execSync("ldd --version 2>&1", {
|
|
232436
|
+
encoding: "utf-8",
|
|
232437
|
+
stdio: [
|
|
232438
|
+
"pipe",
|
|
232439
|
+
"pipe",
|
|
232440
|
+
"pipe"
|
|
232441
|
+
]
|
|
232442
|
+
}).includes("musl")) return true;
|
|
232443
|
+
} catch {}
|
|
232444
|
+
try {
|
|
232445
|
+
if (existsSync("/etc/os-release")) {
|
|
232446
|
+
const osRelease = readFileSync("/etc/os-release", "utf-8");
|
|
232447
|
+
if (osRelease.includes("Alpine") || osRelease.includes("musl")) return true;
|
|
232448
|
+
}
|
|
232449
|
+
} catch {}
|
|
232450
|
+
try {
|
|
232451
|
+
if ((process.report?.getReport?.())?.header?.glibcVersionRuntime === "") return true;
|
|
232452
|
+
} catch {}
|
|
232453
|
+
return false;
|
|
232454
|
+
}
|
|
232455
|
+
/**
|
|
232456
|
+
* Gets the current platform identifier
|
|
232457
|
+
* @throws {Error} If the platform is unsupported
|
|
232458
|
+
*/
|
|
232459
|
+
function getCurrentPlatform() {
|
|
232460
|
+
const platformName = platform();
|
|
232461
|
+
const archName = arch();
|
|
232462
|
+
if (platformName === "darwin") {
|
|
232463
|
+
if (archName === "arm64") return "darwin-arm64";
|
|
232464
|
+
if (archName === "x64" || archName === "ia32") return "darwin-x86_64";
|
|
232465
|
+
}
|
|
232466
|
+
if (platformName === "linux") {
|
|
232467
|
+
const muslSuffix = isMusl() ? "-musl" : "";
|
|
232468
|
+
if (archName === "arm64") return `linux-arm64${muslSuffix}`;
|
|
232469
|
+
if (archName === "x64" || archName === "ia32") return `linux-x86_64${muslSuffix}`;
|
|
232470
|
+
}
|
|
232471
|
+
if (platformName === "win32") {
|
|
232472
|
+
if (archName === "x64" || archName === "ia32") return "win32-x86_64";
|
|
232473
|
+
}
|
|
232474
|
+
throw new Error(`Unsupported platform: ${platformName}-${archName}. Supported platforms: darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64, win32-x86_64 (with glibc or musl support for Linux)`);
|
|
232475
|
+
}
|
|
232476
|
+
/**
|
|
232477
|
+
* Gets the package name for the current platform
|
|
232478
|
+
*/
|
|
232479
|
+
function getPlatformPackageName() {
|
|
232480
|
+
return `@sqliteai/sqlite-vector-${getCurrentPlatform()}`;
|
|
232481
|
+
}
|
|
232482
|
+
/**
|
|
232483
|
+
* Gets the binary filename for the current platform
|
|
232484
|
+
*/
|
|
232485
|
+
function getBinaryName() {
|
|
232486
|
+
const platformName = platform();
|
|
232487
|
+
const extension = PLATFORM_EXTENSIONS[platformName];
|
|
232488
|
+
if (!extension) throw new Error(`Unknown platform: ${platformName}`);
|
|
232489
|
+
return `vector${extension}`;
|
|
232490
|
+
}
|
|
232491
|
+
/**
|
|
232492
|
+
* Error thrown when the SQLite Vector extension cannot be found
|
|
232493
|
+
*/
|
|
232494
|
+
var ExtensionNotFoundError = class extends Error {
|
|
232495
|
+
constructor(message) {
|
|
232496
|
+
super(message);
|
|
232497
|
+
this.name = "ExtensionNotFoundError";
|
|
232498
|
+
}
|
|
232499
|
+
};
|
|
232500
|
+
/**
|
|
232501
|
+
* Attempts to load the platform-specific package
|
|
232502
|
+
* @returns The path to the extension binary, or null if not found
|
|
232503
|
+
*/
|
|
232504
|
+
function tryLoadPlatformPackage() {
|
|
232505
|
+
try {
|
|
232506
|
+
const packageName = getPlatformPackageName();
|
|
232507
|
+
return import.meta.resolve(packageName).replace(/\/index\.js$/, `/${getBinaryName()}`).replace("file://", "");
|
|
232508
|
+
} catch {}
|
|
232509
|
+
return null;
|
|
232510
|
+
}
|
|
232511
|
+
/**
|
|
232512
|
+
* Gets the absolute path to the SQLite Vector extension binary for the current platform
|
|
232513
|
+
*
|
|
232514
|
+
* @returns Absolute path to the extension binary (.so, .dylib, or .dll)
|
|
232515
|
+
* @throws {ExtensionNotFoundError} If the extension binary cannot be found
|
|
232516
|
+
*
|
|
232517
|
+
* @example
|
|
232518
|
+
* ```typescript
|
|
232519
|
+
* import { getExtensionPath } from '@sqliteai/sqlite-vector';
|
|
232520
|
+
*
|
|
232521
|
+
* const extensionPath = getExtensionPath();
|
|
232522
|
+
* // On macOS ARM64: /path/to/node_modules/@sqliteai/sqlite-vector-darwin-arm64/vector.dylib
|
|
232523
|
+
* ```
|
|
232524
|
+
*/
|
|
232525
|
+
function getExtensionPath() {
|
|
232526
|
+
const platformPath = tryLoadPlatformPackage();
|
|
232527
|
+
if (platformPath) return resolve(platformPath);
|
|
232528
|
+
throw new ExtensionNotFoundError(`SQLite Vector extension not found for platform: ${getCurrentPlatform()}\n\nThe platform-specific package "${getPlatformPackageName()}" is not installed.\nThis usually happens when:\n 1. Your platform is not supported\n 2. npm failed to install optional dependencies\n 3. You're installing with --no-optional flag\n\nTry running: npm install --force`);
|
|
232529
|
+
}
|
|
232530
|
+
//#endregion
|
|
232531
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/Sqlite.js
|
|
232532
|
+
/**
|
|
232533
|
+
* @since 1.0.0
|
|
232534
|
+
*/
|
|
232535
|
+
/**
|
|
232536
|
+
* @since 1.0.0
|
|
232537
|
+
* @category Layers
|
|
232538
|
+
*/
|
|
232539
|
+
const SqliteLayer = (database) => layer$1({ loader: fromRecord({ "0001_create_chunks": gen(function* () {
|
|
232540
|
+
const sql = yield* SqlClient;
|
|
232541
|
+
yield* sql`CREATE TABLE IF NOT EXISTS chunks (
|
|
232542
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
232543
|
+
path TEXT NOT NULL,
|
|
232544
|
+
content TEXT NOT NULL,
|
|
232545
|
+
hash TEXT NOT NULL,
|
|
232546
|
+
vector BLOB NOT NULL,
|
|
232547
|
+
syncId TEXT NOT NULL
|
|
232548
|
+
)`;
|
|
232549
|
+
yield* sql`CREATE INDEX IF NOT EXISTS idx_chunks_hash ON chunks (hash)`;
|
|
232550
|
+
}) }) }).pipe(provide$3(effectDiscard(gen(function* () {
|
|
232551
|
+
yield* (yield* SqliteClient).loadExtension(getExtensionPath());
|
|
232552
|
+
}))), provideMerge(layer$2({ filename: database })), provide$3(effectDiscard(gen(function* () {
|
|
232553
|
+
const fs = yield* FileSystem;
|
|
232554
|
+
const directory = (yield* Path$1).dirname(database);
|
|
232555
|
+
if (directory === ".") return;
|
|
232556
|
+
yield* fs.makeDirectory(directory, { recursive: true });
|
|
232557
|
+
}))));
|
|
232558
|
+
//#endregion
|
|
232559
|
+
//#region node_modules/.pnpm/clanka@0.2.25_@effect+ai-openai-compat@4.0.0-beta.36_effect@4.0.0-beta.36__@effect+ai-o_7e66a3c8cbea5282674885bea99d757a/node_modules/clanka/dist/SemanticSearch.js
|
|
232560
|
+
/**
|
|
232561
|
+
* @since 1.0.0
|
|
232562
|
+
*/
|
|
232563
|
+
var SemanticSearch_exports = /* @__PURE__ */ __exportAll({
|
|
232564
|
+
SemanticSearch: () => SemanticSearch,
|
|
232565
|
+
chunkEmbeddingInput: () => chunkEmbeddingInput,
|
|
232566
|
+
layer: () => layer,
|
|
232567
|
+
makeEmbeddingResolver: () => makeEmbeddingResolver,
|
|
232568
|
+
maybeRemoveFile: () => maybeRemoveFile,
|
|
232569
|
+
maybeUpdateFile: () => maybeUpdateFile
|
|
232570
|
+
});
|
|
232571
|
+
const normalizePath = (path) => path.replace(/\\/g, "/");
|
|
232572
|
+
const resolveChunkConfig = (options) => ({
|
|
232573
|
+
chunkSize: 30,
|
|
232574
|
+
chunkOverlap: 0,
|
|
232575
|
+
chunkMaxCharacters: options.chunkMaxCharacters ?? 1e4
|
|
232576
|
+
});
|
|
232577
|
+
const makeEmbeddingResolver = (resolver, options) => resolver.pipe(setDelay(options.embeddingRequestDelay ?? millis(50)), batchN(options.embeddingBatchSize ?? 300));
|
|
232578
|
+
const chunkEmbeddingInput = (chunk) => {
|
|
232579
|
+
const headerLines = ["---", "file: " + chunk.path];
|
|
232580
|
+
if (chunk.name !== void 0) headerLines.push("name: " + chunk.name);
|
|
232581
|
+
if (chunk.type !== void 0) headerLines.push("type: " + chunk.type);
|
|
232582
|
+
if (chunk.parent !== void 0) headerLines.push("parent: " + chunk.parent);
|
|
232583
|
+
headerLines.push("---");
|
|
232584
|
+
const contentLines = chunk.content.split("\n");
|
|
232585
|
+
let contentWithLines = "";
|
|
232586
|
+
for (let i = 0; i < contentLines.length; i++) {
|
|
232587
|
+
if (i > 0) contentWithLines += "\n";
|
|
232588
|
+
contentWithLines += `${chunk.startLine + i}: ${contentLines[i]}`;
|
|
232589
|
+
}
|
|
232590
|
+
return headerLines.join("\n") + "\n\n" + contentWithLines;
|
|
232591
|
+
};
|
|
232592
|
+
const hashChunkInput = (input) => createHash("sha256").update(input).digest("hex");
|
|
232593
|
+
/**
|
|
232594
|
+
* @since 1.0.0
|
|
232595
|
+
* @category Layers
|
|
232596
|
+
*/
|
|
232597
|
+
const layer = (options) => effect$1(SemanticSearch, gen(function* () {
|
|
232598
|
+
const chunker = yield* CodeChunker;
|
|
232599
|
+
const repo = yield* ChunkRepo;
|
|
232600
|
+
const embeddings = yield* EmbeddingModel;
|
|
232601
|
+
const pathService = yield* Path$1;
|
|
232602
|
+
const root = pathService.resolve(options.directory);
|
|
232603
|
+
const resolver = makeEmbeddingResolver(embeddings.resolver, options);
|
|
232604
|
+
const concurrency = options.concurrency ?? 2e3;
|
|
232605
|
+
const chunkConfig = resolveChunkConfig(options);
|
|
232606
|
+
const indexHandle = yield* make$56();
|
|
232607
|
+
const console = yield* Console$1;
|
|
232608
|
+
const resolveIndexedPath = (path) => {
|
|
232609
|
+
const absolutePath = pathService.resolve(root, path);
|
|
232610
|
+
const relativePath = normalizePath(pathService.relative(root, absolutePath));
|
|
232611
|
+
if (relativePath.length === 0 || relativePath === ".." || relativePath.startsWith("../")) return none$4();
|
|
232612
|
+
return some$2(relativePath);
|
|
232613
|
+
};
|
|
232614
|
+
const processChunk = fnUntraced(function* (options) {
|
|
232615
|
+
const input = chunkEmbeddingInput(options.chunk);
|
|
232616
|
+
const hash = hashChunkInput(input);
|
|
232617
|
+
if (options.checkExisting) {
|
|
232618
|
+
const id = yield* repo.exists(hash);
|
|
232619
|
+
if (isSome(id)) {
|
|
232620
|
+
yield* repo.setSyncId(id.value, options.syncId);
|
|
232621
|
+
return;
|
|
232622
|
+
}
|
|
232623
|
+
}
|
|
232624
|
+
const result = yield* request$2(new EmbeddingRequest({ input }), resolver);
|
|
232625
|
+
const vector = new Float32Array(result.vector);
|
|
232626
|
+
yield* repo.insert(Chunk.insert.makeUnsafe({
|
|
232627
|
+
path: options.chunk.path,
|
|
232628
|
+
hash,
|
|
232629
|
+
content: input,
|
|
232630
|
+
vector,
|
|
232631
|
+
syncId: options.syncId
|
|
232632
|
+
}));
|
|
232633
|
+
}, ignore$1({
|
|
232634
|
+
log: "Warn",
|
|
232635
|
+
message: "Failed to process chunk for embedding"
|
|
232636
|
+
}), (effect, options) => annotateLogs(effect, { chunk: `${options.chunk.path}/${options.chunk.startLine}` }));
|
|
232637
|
+
const runIndex = run$4(indexHandle, gen(function* () {
|
|
232638
|
+
const syncId = SyncId.makeUnsafe(crypto.randomUUID());
|
|
232639
|
+
yield* logInfo("Starting SemanticSearch index");
|
|
232640
|
+
yield* pipe$1(chunker.chunkCodebase({
|
|
232641
|
+
root,
|
|
232642
|
+
...chunkConfig
|
|
232643
|
+
}), tap((chunk) => processChunk({
|
|
232644
|
+
chunk,
|
|
232645
|
+
syncId,
|
|
232646
|
+
checkExisting: true
|
|
232647
|
+
}), { concurrency }), runDrain);
|
|
232648
|
+
yield* repo.deleteForSyncId(syncId);
|
|
232649
|
+
yield* logInfo("Finished SemanticSearch index");
|
|
232650
|
+
}).pipe(withSpan$1("SemanticSearch.index"), withLogSpan("SemanticSearch.index"), provideService$2(Console$1, console)), { onlyIfMissing: true });
|
|
232651
|
+
const initialIndex = yield* runIndex;
|
|
232652
|
+
yield* runIndex.pipe(delay(minutes(3)), forever, forkScoped);
|
|
232653
|
+
return SemanticSearch.of({
|
|
232654
|
+
search: fn("SemanticSearch.search")(function* (options) {
|
|
232655
|
+
yield* join$2(initialIndex);
|
|
232656
|
+
yield* annotateCurrentSpan(options);
|
|
232657
|
+
const { vector } = yield* embeddings.embed(options.query);
|
|
232658
|
+
return (yield* repo.search({
|
|
232659
|
+
vector: new Float32Array(vector),
|
|
232660
|
+
limit: options.limit
|
|
232661
|
+
})).map((r) => r.content).join("\n\n");
|
|
232662
|
+
}, orDie$2),
|
|
232663
|
+
updateFile: fn("SemanticSearch.updateFile")(function* (path) {
|
|
232664
|
+
yield* join$2(initialIndex);
|
|
232665
|
+
const indexedPath = resolveIndexedPath(path);
|
|
232666
|
+
if (isNone(indexedPath)) return;
|
|
232667
|
+
yield* repo.deleteByPath(indexedPath.value);
|
|
232668
|
+
const chunks = yield* chunker.chunkFile({
|
|
232669
|
+
root,
|
|
232670
|
+
path: indexedPath.value,
|
|
232671
|
+
...chunkConfig
|
|
232672
|
+
});
|
|
232673
|
+
if (chunks.length === 0) return;
|
|
232674
|
+
const syncId = SyncId.makeUnsafe(crypto.randomUUID());
|
|
232675
|
+
yield* pipe$1(fromArray(chunks), tap((chunk) => processChunk({
|
|
232676
|
+
chunk,
|
|
232677
|
+
syncId,
|
|
232678
|
+
checkExisting: false
|
|
232679
|
+
}), { concurrency }), runDrain);
|
|
232680
|
+
}, orDie$2),
|
|
232681
|
+
removeFile: fn("SemanticSearch.removeFile")(function* (path) {
|
|
232682
|
+
yield* join$2(initialIndex);
|
|
232683
|
+
const indexedPath = resolveIndexedPath(path);
|
|
232684
|
+
if (isNone(indexedPath)) return;
|
|
232685
|
+
yield* repo.deleteByPath(indexedPath.value);
|
|
232686
|
+
}, orDie$2)
|
|
232687
|
+
});
|
|
232688
|
+
})).pipe(provide$3([layer$6, layer$3.pipe(provide$3(SqliteLayer(options.database ?? ".clanka/search.sqlite")))]));
|
|
232689
|
+
//#endregion
|
|
232677
232690
|
//#region src/ClankaModels.ts
|
|
232678
232691
|
const ModelServices = layerUndici.pipe(merge$6(layerKvs));
|
|
232679
232692
|
const Reasoning = Literals([
|
|
@@ -241251,10 +241264,10 @@ const SemanticSearchLayer = unwrap$3(gen(function* () {
|
|
|
241251
241264
|
const pathService = yield* Path$1;
|
|
241252
241265
|
const apiKey = yield* redacted("LALPH_OPENAI_API_KEY").pipe(option);
|
|
241253
241266
|
if (isNone(apiKey)) return empty$15;
|
|
241254
|
-
return layer
|
|
241267
|
+
return (yield* promise(() => Promise.resolve().then(() => SemanticSearch_exports))).layer({
|
|
241255
241268
|
directory: worktree.directory,
|
|
241256
241269
|
database: pathService.join(worktree.directory, ".lalph", "shared", "search.sqlite")
|
|
241257
|
-
}).pipe(orDie$3, provide$3(model$1("text-embedding-3-small", { dimensions: 1536 })), provide$3(layer$
|
|
241270
|
+
}).pipe(orDie$3, provide$3(model$1("text-embedding-3-small", { dimensions: 1536 })), provide$3(layer$9({ apiKey: apiKey.value }).pipe(provide$3(layerUndici))), tapCause$1((cause) => logWarning(`Failed to create SemanticSearch layer`, cause)), catchCause$2(() => empty$15));
|
|
241258
241271
|
}).pipe(orDie$2));
|
|
241259
241272
|
const runClanka = fnUntraced(function* (options) {
|
|
241260
241273
|
const muxer = yield* Muxer;
|
|
@@ -241297,7 +241310,7 @@ const agentWorker = fnUntraced(function* (options) {
|
|
|
241297
241310
|
system: options.system,
|
|
241298
241311
|
prompt: match$10(options.research, {
|
|
241299
241312
|
onNone: () => options.prompt,
|
|
241300
|
-
onSome: (research) => make$
|
|
241313
|
+
onSome: (research) => make$12([{
|
|
241301
241314
|
role: "user",
|
|
241302
241315
|
content: options.prompt
|
|
241303
241316
|
}, {
|
|
@@ -242292,7 +242305,7 @@ const commandEdit = make$58("edit").pipe(withDescription("Open the selected proj
|
|
|
242292
242305
|
const commandSource = make$58("source").pipe(withDescription("Select the issue source to use (e.g. GitHub Issues or Linear). This applies to all projects."), withHandler(() => selectIssueSource), provide(Settings.layer));
|
|
242293
242306
|
//#endregion
|
|
242294
242307
|
//#region package.json
|
|
242295
|
-
var version = "0.3.
|
|
242308
|
+
var version = "0.3.96";
|
|
242296
242309
|
//#endregion
|
|
242297
242310
|
//#region src/commands/projects/ls.ts
|
|
242298
242311
|
const commandProjectsLs = make$58("ls").pipe(withDescription("List configured projects and how they run (enabled state, concurrency, branch, git flow, review agent)."), withHandler(fnUntraced(function* () {
|