thinkwell 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +207 -279
- package/dist/agent.js.map +1 -1
- package/dist/build.js +44 -98
- package/dist/cli/build.js +92 -227
- package/dist/cli/bundle.js +570 -1136
- package/dist/cli/check.js +125 -214
- package/dist/cli/commands.js +63 -177
- package/dist/cli/compiler-host.js +81 -190
- package/dist/cli/dependency-check.js +125 -269
- package/dist/cli/dependency-errors.js +12 -84
- package/dist/cli/fmt.js +1 -13
- package/dist/cli/init-command.js +21 -68
- package/dist/cli/init.js +90 -220
- package/dist/cli/loader.js +95 -361
- package/dist/cli/new-command.js +25 -73
- package/dist/cli/package-manager.js +50 -117
- package/dist/cli/schema.js +89 -245
- package/dist/cli/workspace.js +92 -226
- package/dist/connectors/index.js +1 -7
- package/dist/generated/features.d.ts +5 -0
- package/dist/generated/features.d.ts.map +1 -0
- package/dist/generated/features.js +4 -0
- package/dist/generated/features.js.map +1 -0
- package/dist/index.js +0 -5
- package/dist/schema.js +3 -36
- package/dist/session.js +50 -82
- package/dist/think-builder.d.ts.map +1 -1
- package/dist/think-builder.js +269 -370
- package/dist/think-builder.js.map +1 -1
- package/dist/thought-event.d.ts +1 -0
- package/dist/thought-event.d.ts.map +1 -1
- package/dist/thought-event.js +0 -1
- package/dist/thought-stream.js +60 -96
- package/dist-pkg/acp.cjs +13385 -1876
- package/dist-pkg/cli-build.cjs +171 -369
- package/dist-pkg/cli-bundle.cjs +289 -690
- package/dist-pkg/cli-check.cjs +202 -415
- package/dist-pkg/cli-dependency-check.cjs +39 -82
- package/dist-pkg/cli-dependency-errors.cjs +9 -41
- package/dist-pkg/cli-loader.cjs +90 -173
- package/dist-pkg/protocol.cjs +2 -8
- package/dist-pkg/thinkwell.cjs +876 -1842
- package/package.json +7 -6
package/dist-pkg/cli-loader.cjs
CHANGED
|
@@ -238623,61 +238623,49 @@ var import_node_fs = require("node:fs");
|
|
|
238623
238623
|
var import_ts_json_schema_generator = __toESM(require_dist(), 1);
|
|
238624
238624
|
function findTsConfig(startDir) {
|
|
238625
238625
|
let dir = startDir;
|
|
238626
|
-
|
|
238626
|
+
for (; ; ) {
|
|
238627
238627
|
const configPath = (0, import_node_path.join)(dir, "tsconfig.json");
|
|
238628
|
-
if ((0, import_node_fs.existsSync)(configPath))
|
|
238628
|
+
if ((0, import_node_fs.existsSync)(configPath))
|
|
238629
238629
|
return configPath;
|
|
238630
|
-
}
|
|
238631
238630
|
const parent = (0, import_node_path.dirname)(dir);
|
|
238632
|
-
if (parent === dir)
|
|
238633
|
-
return
|
|
238634
|
-
}
|
|
238631
|
+
if (parent === dir)
|
|
238632
|
+
return;
|
|
238635
238633
|
dir = parent;
|
|
238636
238634
|
}
|
|
238637
238635
|
}
|
|
238638
238636
|
__name(findTsConfig, "findTsConfig");
|
|
238639
238637
|
function inlineRefs(obj, definitions) {
|
|
238640
|
-
if (obj === null || typeof obj
|
|
238638
|
+
if (obj === null || typeof obj != "object")
|
|
238641
238639
|
return obj;
|
|
238642
|
-
|
|
238643
|
-
if (Array.isArray(obj)) {
|
|
238640
|
+
if (Array.isArray(obj))
|
|
238644
238641
|
return obj.map((item) => inlineRefs(item, definitions));
|
|
238645
|
-
}
|
|
238646
238642
|
const record = obj;
|
|
238647
|
-
if (typeof record
|
|
238648
|
-
const
|
|
238649
|
-
|
|
238650
|
-
if (match && definitions[match[1]]) {
|
|
238643
|
+
if (typeof record.$ref == "string") {
|
|
238644
|
+
const match = record.$ref.match(/^#\/definitions\/(.+)$/);
|
|
238645
|
+
if (match && definitions[match[1]])
|
|
238651
238646
|
return inlineRefs(definitions[match[1]], definitions);
|
|
238652
|
-
}
|
|
238653
238647
|
}
|
|
238654
238648
|
const result = {};
|
|
238655
|
-
for (const [key2, value] of Object.entries(record))
|
|
238649
|
+
for (const [key2, value] of Object.entries(record))
|
|
238656
238650
|
result[key2] = inlineRefs(value, definitions);
|
|
238657
|
-
}
|
|
238658
238651
|
return result;
|
|
238659
238652
|
}
|
|
238660
238653
|
__name(inlineRefs, "inlineRefs");
|
|
238661
238654
|
function cleanSchema(typeName, schema) {
|
|
238662
238655
|
const definitions = schema.definitions || {};
|
|
238663
238656
|
let result = definitions[typeName] || schema;
|
|
238664
|
-
result = inlineRefs(result, definitions)
|
|
238665
|
-
if (typeof result === "object" && result !== null) {
|
|
238657
|
+
if (result = inlineRefs(result, definitions), typeof result == "object" && result !== null) {
|
|
238666
238658
|
const cleaned = { ...result };
|
|
238667
|
-
delete cleaned
|
|
238668
|
-
delete cleaned["definitions"];
|
|
238669
|
-
return cleaned;
|
|
238659
|
+
return delete cleaned.$schema, delete cleaned.definitions, cleaned;
|
|
238670
238660
|
}
|
|
238671
238661
|
return result;
|
|
238672
238662
|
}
|
|
238673
238663
|
__name(cleanSchema, "cleanSchema");
|
|
238674
238664
|
function generateSchemas(filePath, typeNames) {
|
|
238675
238665
|
const schemas = /* @__PURE__ */ new Map();
|
|
238676
|
-
if (typeNames.length === 0)
|
|
238666
|
+
if (typeNames.length === 0)
|
|
238677
238667
|
return schemas;
|
|
238678
|
-
|
|
238679
|
-
const configPath = findTsConfig((0, import_node_path.dirname)(filePath));
|
|
238680
|
-
const generator = (0, import_ts_json_schema_generator.createGenerator)({
|
|
238668
|
+
const configPath = findTsConfig((0, import_node_path.dirname)(filePath)), generator = (0, import_ts_json_schema_generator.createGenerator)({
|
|
238681
238669
|
path: filePath,
|
|
238682
238670
|
...configPath && { tsconfig: configPath },
|
|
238683
238671
|
skipTypeCheck: true,
|
|
@@ -238694,8 +238682,7 @@ __name(generateSchemas, "generateSchemas");
|
|
|
238694
238682
|
// dist/cli/schema.js
|
|
238695
238683
|
var JSONSCHEMA_TAG = "JSONSchema";
|
|
238696
238684
|
function hasJsDocTag(node, tagName) {
|
|
238697
|
-
|
|
238698
|
-
return jsDocNodes.some((tag) => tag.tagName.text === tagName);
|
|
238685
|
+
return import_typescript.default.getJSDocTags(node).some((tag) => tag.tagName.text === tagName);
|
|
238699
238686
|
}
|
|
238700
238687
|
__name(hasJsDocTag, "hasJsDocTag");
|
|
238701
238688
|
function findMarkedTypes(path, source) {
|
|
@@ -238705,48 +238692,36 @@ function findMarkedTypes(path, source) {
|
|
|
238705
238692
|
import_typescript.default.ScriptTarget.Latest,
|
|
238706
238693
|
true
|
|
238707
238694
|
// setParentNodes - needed for JSDoc traversal
|
|
238708
|
-
);
|
|
238709
|
-
|
|
238710
|
-
|
|
238711
|
-
|
|
238712
|
-
if (
|
|
238713
|
-
const
|
|
238714
|
-
|
|
238715
|
-
|
|
238716
|
-
|
|
238717
|
-
|
|
238718
|
-
|
|
238719
|
-
|
|
238720
|
-
|
|
238721
|
-
|
|
238722
|
-
|
|
238723
|
-
|
|
238724
|
-
|
|
238725
|
-
|
|
238726
|
-
|
|
238727
|
-
node,
|
|
238728
|
-
startPosition: node.getStart(),
|
|
238729
|
-
endPosition: node.getEnd(),
|
|
238730
|
-
line: line + 1,
|
|
238731
|
-
column: character + 1,
|
|
238732
|
-
declarationLength,
|
|
238733
|
-
isExported
|
|
238734
|
-
});
|
|
238735
|
-
}
|
|
238695
|
+
), results = [];
|
|
238696
|
+
return import_typescript.default.forEachChild(sourceFile, /* @__PURE__ */ __name(function visit(node) {
|
|
238697
|
+
if ((import_typescript.default.isInterfaceDeclaration(node) || import_typescript.default.isTypeAliasDeclaration(node) || import_typescript.default.isEnumDeclaration(node) || import_typescript.default.isClassDeclaration(node)) && hasJsDocTag(node, JSONSCHEMA_TAG)) {
|
|
238698
|
+
const name = node.name?.text;
|
|
238699
|
+
if (name) {
|
|
238700
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
238701
|
+
let keyword = "interface";
|
|
238702
|
+
import_typescript.default.isTypeAliasDeclaration(node) ? keyword = "type" : import_typescript.default.isEnumDeclaration(node) ? keyword = "enum" : import_typescript.default.isClassDeclaration(node) && (keyword = "class");
|
|
238703
|
+
const declarationLength = keyword.length + 1 + name.length, isExported = node.modifiers?.some((m) => m.kind === import_typescript.default.SyntaxKind.ExportKeyword) ?? false;
|
|
238704
|
+
results.push({
|
|
238705
|
+
name,
|
|
238706
|
+
node,
|
|
238707
|
+
startPosition: node.getStart(),
|
|
238708
|
+
endPosition: node.getEnd(),
|
|
238709
|
+
line: line + 1,
|
|
238710
|
+
column: character + 1,
|
|
238711
|
+
declarationLength,
|
|
238712
|
+
isExported
|
|
238713
|
+
});
|
|
238736
238714
|
}
|
|
238737
238715
|
}
|
|
238738
238716
|
import_typescript.default.forEachChild(node, visit);
|
|
238739
|
-
}, "visit"));
|
|
238740
|
-
return results;
|
|
238717
|
+
}, "visit")), results;
|
|
238741
238718
|
}
|
|
238742
238719
|
__name(findMarkedTypes, "findMarkedTypes");
|
|
238743
238720
|
function resolveGenerateSchemas(projectDir) {
|
|
238744
238721
|
if (projectDir) {
|
|
238745
|
-
const
|
|
238746
|
-
|
|
238747
|
-
if (typeof buildMod.generateSchemas === "function") {
|
|
238722
|
+
const buildMod = (0, import_node_module.createRequire)((0, import_node_path2.join)(projectDir, "package.json"))("thinkwell/build");
|
|
238723
|
+
if (typeof buildMod.generateSchemas == "function")
|
|
238748
238724
|
return buildMod.generateSchemas;
|
|
238749
|
-
}
|
|
238750
238725
|
throw new Error(`thinkwell/build resolved from ${projectDir} but does not export generateSchemas. This may indicate a version mismatch \u2014 try updating the thinkwell dependency.`);
|
|
238751
238726
|
}
|
|
238752
238727
|
return generateSchemas;
|
|
@@ -238754,18 +238729,14 @@ function resolveGenerateSchemas(projectDir) {
|
|
|
238754
238729
|
__name(resolveGenerateSchemas, "resolveGenerateSchemas");
|
|
238755
238730
|
function generateSchemas2(path, types, sourceCode, projectDir) {
|
|
238756
238731
|
const schemas = /* @__PURE__ */ new Map();
|
|
238757
|
-
if (types.length === 0)
|
|
238732
|
+
if (types.length === 0)
|
|
238758
238733
|
return schemas;
|
|
238759
|
-
}
|
|
238760
238734
|
const buildGenerateSchemas = resolveGenerateSchemas(projectDir);
|
|
238761
238735
|
for (const typeInfo of types) {
|
|
238762
238736
|
const { name, line, column } = typeInfo;
|
|
238763
238737
|
try {
|
|
238764
|
-
const
|
|
238765
|
-
|
|
238766
|
-
if (schema) {
|
|
238767
|
-
schemas.set(name, schema);
|
|
238768
|
-
}
|
|
238738
|
+
const schema = buildGenerateSchemas(path, [name]).get(name);
|
|
238739
|
+
schema && schemas.set(name, schema);
|
|
238769
238740
|
} catch (error) {
|
|
238770
238741
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
238771
238742
|
throw new Error(`Failed to generate schema for type '${name}' at ${path}:${line}:${column}
|
|
@@ -238778,27 +238749,27 @@ function generateSchemas2(path, types, sourceCode, projectDir) {
|
|
|
238778
238749
|
__name(generateSchemas2, "generateSchemas");
|
|
238779
238750
|
var ACP_NAMESPACE = "$$__thinkwell__acp__$$";
|
|
238780
238751
|
function generateNamespace(name, schema, isExported) {
|
|
238781
|
-
const schemaJson = JSON.stringify(schema, null, 2).split(
|
|
238782
|
-
|
|
238752
|
+
const schemaJson = JSON.stringify(schema, null, 2).split(`
|
|
238753
|
+
`).map((line, i) => i === 0 ? line : " " + line).join(`
|
|
238754
|
+
`);
|
|
238783
238755
|
return [
|
|
238784
|
-
`${
|
|
238756
|
+
`${isExported ? "export " : ""}namespace ${name} {`,
|
|
238785
238757
|
` export const Schema: ${ACP_NAMESPACE}.SchemaProvider<${name}> = {`,
|
|
238786
238758
|
` toJsonSchema: () => (${schemaJson}) as ${ACP_NAMESPACE}.JsonSchema,`,
|
|
238787
|
-
|
|
238788
|
-
|
|
238789
|
-
].join(
|
|
238759
|
+
" };",
|
|
238760
|
+
"}"
|
|
238761
|
+
].join(`
|
|
238762
|
+
`);
|
|
238790
238763
|
}
|
|
238791
238764
|
__name(generateNamespace, "generateNamespace");
|
|
238792
238765
|
function generateInsertions(types, schemas) {
|
|
238793
238766
|
const insertions = [];
|
|
238794
238767
|
for (const { name, endPosition, isExported } of types) {
|
|
238795
238768
|
const schema = schemas.get(name);
|
|
238796
|
-
|
|
238797
|
-
continue;
|
|
238798
|
-
}
|
|
238799
|
-
insertions.push({
|
|
238769
|
+
schema && insertions.push({
|
|
238800
238770
|
position: endPosition,
|
|
238801
|
-
code:
|
|
238771
|
+
code: `
|
|
238772
|
+
` + generateNamespace(name, schema, isExported)
|
|
238802
238773
|
});
|
|
238803
238774
|
}
|
|
238804
238775
|
return insertions.sort((a, b) => b.position - a.position);
|
|
@@ -238810,9 +238781,8 @@ function generateSchemaImport() {
|
|
|
238810
238781
|
__name(generateSchemaImport, "generateSchemaImport");
|
|
238811
238782
|
function applyInsertions(source, insertions) {
|
|
238812
238783
|
let result = source;
|
|
238813
|
-
for (const { position, code } of insertions)
|
|
238784
|
+
for (const { position, code } of insertions)
|
|
238814
238785
|
result = result.slice(0, position) + code + result.slice(position);
|
|
238815
|
-
}
|
|
238816
238786
|
return result;
|
|
238817
238787
|
}
|
|
238818
238788
|
__name(applyInsertions, "applyInsertions");
|
|
@@ -238821,18 +238791,15 @@ function hasJsonSchemaMarkers(source) {
|
|
|
238821
238791
|
}
|
|
238822
238792
|
__name(hasJsonSchemaMarkers, "hasJsonSchemaMarkers");
|
|
238823
238793
|
function transformJsonSchemas(path, source, projectDir) {
|
|
238824
|
-
if (!hasJsonSchemaMarkers(source))
|
|
238794
|
+
if (!hasJsonSchemaMarkers(source))
|
|
238825
238795
|
return source;
|
|
238826
|
-
}
|
|
238827
238796
|
const markedTypes = findMarkedTypes(path, source);
|
|
238828
|
-
if (markedTypes.length === 0)
|
|
238797
|
+
if (markedTypes.length === 0)
|
|
238829
238798
|
return source;
|
|
238830
|
-
|
|
238831
|
-
const schemas = generateSchemas2(path, markedTypes, source, projectDir);
|
|
238832
|
-
const insertions = generateInsertions(markedTypes, schemas);
|
|
238799
|
+
const schemas = generateSchemas2(path, markedTypes, source, projectDir), insertions = generateInsertions(markedTypes, schemas);
|
|
238833
238800
|
let modifiedSource = applyInsertions(source, insertions);
|
|
238834
|
-
modifiedSource = generateSchemaImport() +
|
|
238835
|
-
|
|
238801
|
+
return modifiedSource = generateSchemaImport() + `
|
|
238802
|
+
` + modifiedSource, modifiedSource;
|
|
238836
238803
|
}
|
|
238837
238804
|
__name(transformJsonSchemas, "transformJsonSchemas");
|
|
238838
238805
|
|
|
@@ -238842,7 +238809,7 @@ function initializeBundledRegistry(modules) {
|
|
|
238842
238809
|
global.__bundled__ = modules;
|
|
238843
238810
|
}
|
|
238844
238811
|
__name(initializeBundledRegistry, "initializeBundledRegistry");
|
|
238845
|
-
var __projectDir
|
|
238812
|
+
var __projectDir;
|
|
238846
238813
|
function setExplicitConfig(projectDir) {
|
|
238847
238814
|
__projectDir = projectDir;
|
|
238848
238815
|
}
|
|
@@ -238853,44 +238820,31 @@ function isBundledPackage(moduleName) {
|
|
|
238853
238820
|
__name(isBundledPackage, "isBundledPackage");
|
|
238854
238821
|
function extractShebang(source) {
|
|
238855
238822
|
if (source.startsWith("#!")) {
|
|
238856
|
-
const newlineIndex = source.indexOf(
|
|
238857
|
-
|
|
238858
|
-
|
|
238859
|
-
}
|
|
238860
|
-
return [source, ""];
|
|
238823
|
+
const newlineIndex = source.indexOf(`
|
|
238824
|
+
`);
|
|
238825
|
+
return newlineIndex !== -1 ? [source.slice(0, newlineIndex + 1), source.slice(newlineIndex + 1)] : [source, ""];
|
|
238861
238826
|
}
|
|
238862
238827
|
return ["", source];
|
|
238863
238828
|
}
|
|
238864
238829
|
__name(extractShebang, "extractShebang");
|
|
238865
238830
|
function transformVirtualImports(source) {
|
|
238866
238831
|
const importPattern = /import\s+\{([^}]+)\}\s+from\s+['"](@thinkwell\/(?:acp|protocol)|thinkwell)['"]/g;
|
|
238867
|
-
source = source.replace(importPattern, (_2, imports, packageName) => {
|
|
238868
|
-
const cleanImports = imports.trim();
|
|
238869
|
-
return `const {${cleanImports}} = global.__bundled__["${packageName}"]`;
|
|
238870
|
-
});
|
|
238832
|
+
source = source.replace(importPattern, (_2, imports, packageName) => `const {${imports.trim()}} = global.__bundled__["${packageName}"]`);
|
|
238871
238833
|
const defaultImportPattern = /import\s+(\w+)\s+from\s+['"](@thinkwell\/(?:acp|protocol)|thinkwell)['"]/g;
|
|
238872
|
-
source = source.replace(defaultImportPattern, (_2, importName, packageName) => {
|
|
238873
|
-
return `const ${importName} = global.__bundled__["${packageName}"].default || global.__bundled__["${packageName}"]`;
|
|
238874
|
-
});
|
|
238834
|
+
source = source.replace(defaultImportPattern, (_2, importName, packageName) => `const ${importName} = global.__bundled__["${packageName}"].default || global.__bundled__["${packageName}"]`);
|
|
238875
238835
|
const namespaceImportPattern = /import\s+\*\s+as\s+(\w+)\s+from\s+['"](@thinkwell\/(?:acp|protocol)|thinkwell)['"]/g;
|
|
238876
|
-
source = source.replace(namespaceImportPattern, (_2, importName, packageName) => {
|
|
238877
|
-
return `const ${importName} = global.__bundled__["${packageName}"]`;
|
|
238878
|
-
});
|
|
238836
|
+
source = source.replace(namespaceImportPattern, (_2, importName, packageName) => `const ${importName} = global.__bundled__["${packageName}"]`);
|
|
238879
238837
|
const typeImportPattern = /import\s+type\s+\{[^}]+\}\s+from\s+['"](@thinkwell\/(?:acp|protocol)|thinkwell)['"]\s*;?/g;
|
|
238880
|
-
source = source.replace(typeImportPattern, "");
|
|
238881
|
-
return source;
|
|
238838
|
+
return source = source.replace(typeImportPattern, ""), source;
|
|
238882
238839
|
}
|
|
238883
238840
|
__name(transformVirtualImports, "transformVirtualImports");
|
|
238884
238841
|
function createCustomRequire(scriptPath) {
|
|
238885
|
-
const scriptDir = (0, import_node_path3.dirname)(scriptPath);
|
|
238886
|
-
const nodeModulesPath = (0, import_node_path3.join)(scriptDir, "node_modules");
|
|
238887
|
-
const baseRequire = (0, import_node_module2.createRequire)(scriptPath);
|
|
238842
|
+
const scriptDir = (0, import_node_path3.dirname)(scriptPath), nodeModulesPath = (0, import_node_path3.join)(scriptDir, "node_modules"), baseRequire = (0, import_node_module2.createRequire)(scriptPath);
|
|
238888
238843
|
function customRequire(moduleName) {
|
|
238889
238844
|
if (!__projectDir && global.__bundled__ && isBundledPackage(moduleName)) {
|
|
238890
238845
|
const bundled = global.__bundled__[moduleName];
|
|
238891
|
-
if (bundled)
|
|
238846
|
+
if (bundled)
|
|
238892
238847
|
return bundled;
|
|
238893
|
-
}
|
|
238894
238848
|
}
|
|
238895
238849
|
try {
|
|
238896
238850
|
const resolved = baseRequire.resolve(moduleName, {
|
|
@@ -238902,32 +238856,20 @@ function createCustomRequire(scriptPath) {
|
|
|
238902
238856
|
}
|
|
238903
238857
|
}
|
|
238904
238858
|
__name(customRequire, "customRequire");
|
|
238905
|
-
customRequire.resolve = ((id, options) => {
|
|
238906
|
-
if (!__projectDir && global.__bundled__ && isBundledPackage(id))
|
|
238859
|
+
return customRequire.resolve = ((id, options) => {
|
|
238860
|
+
if (!__projectDir && global.__bundled__ && isBundledPackage(id))
|
|
238907
238861
|
return `/__bundled__/${id}`;
|
|
238908
|
-
}
|
|
238909
238862
|
const paths = options?.paths ?? [scriptDir, nodeModulesPath];
|
|
238910
238863
|
try {
|
|
238911
238864
|
return baseRequire.resolve(id, { paths });
|
|
238912
238865
|
} catch {
|
|
238913
238866
|
return baseRequire.resolve(id, options);
|
|
238914
238867
|
}
|
|
238915
|
-
});
|
|
238916
|
-
customRequire.resolve.paths = baseRequire.resolve.paths;
|
|
238917
|
-
customRequire.cache = baseRequire.cache;
|
|
238918
|
-
customRequire.extensions = baseRequire.extensions;
|
|
238919
|
-
customRequire.main = baseRequire.main;
|
|
238920
|
-
return customRequire;
|
|
238868
|
+
}), customRequire.resolve.paths = baseRequire.resolve.paths, customRequire.cache = baseRequire.cache, customRequire.extensions = baseRequire.extensions, customRequire.main = baseRequire.main, customRequire;
|
|
238921
238869
|
}
|
|
238922
238870
|
__name(createCustomRequire, "createCustomRequire");
|
|
238923
238871
|
function needsTransformation(source) {
|
|
238924
|
-
|
|
238925
|
-
return true;
|
|
238926
|
-
}
|
|
238927
|
-
if (!__projectDir && /from\s+['"](?:thinkwell|@thinkwell\/(?:acp|protocol))['"]/.test(source)) {
|
|
238928
|
-
return true;
|
|
238929
|
-
}
|
|
238930
|
-
return false;
|
|
238872
|
+
return !!(hasJsonSchemaMarkers(source) || !__projectDir && /from\s+['"](?:thinkwell|@thinkwell\/(?:acp|protocol))['"]/.test(source));
|
|
238931
238873
|
}
|
|
238932
238874
|
__name(needsTransformation, "needsTransformation");
|
|
238933
238875
|
function randomId() {
|
|
@@ -238936,58 +238878,35 @@ function randomId() {
|
|
|
238936
238878
|
__name(randomId, "randomId");
|
|
238937
238879
|
function rewriteJsToTsExtensions(originalPath, source) {
|
|
238938
238880
|
const scriptDir = (0, import_node_path3.dirname)(originalPath);
|
|
238939
|
-
source = source.replace(/(from\s+['"])(\.\.?\/[^'"]*?)\.js(['"])/g, (match, prefix, specifierBase, suffix) => {
|
|
238881
|
+
return source = source.replace(/(from\s+['"])(\.\.?\/[^'"]*?)\.js(['"])/g, (match, prefix, specifierBase, suffix) => {
|
|
238940
238882
|
const tsPath = (0, import_node_path3.resolve)(scriptDir, `${specifierBase}.ts`);
|
|
238941
|
-
|
|
238942
|
-
|
|
238943
|
-
}
|
|
238944
|
-
return match;
|
|
238945
|
-
});
|
|
238946
|
-
source = source.replace(/(import\s*\(\s*['"])(\.\.?\/[^'"]*?)\.js(['"]\s*\))/g, (match, prefix, specifierBase, suffix) => {
|
|
238883
|
+
return (0, import_node_fs2.existsSync)(tsPath) ? `${prefix}${specifierBase}.ts${suffix}` : match;
|
|
238884
|
+
}), source = source.replace(/(import\s*\(\s*['"])(\.\.?\/[^'"]*?)\.js(['"]\s*\))/g, (match, prefix, specifierBase, suffix) => {
|
|
238947
238885
|
const tsPath = (0, import_node_path3.resolve)(scriptDir, `${specifierBase}.ts`);
|
|
238948
|
-
|
|
238949
|
-
|
|
238950
|
-
}
|
|
238951
|
-
return match;
|
|
238952
|
-
});
|
|
238953
|
-
return source;
|
|
238886
|
+
return (0, import_node_fs2.existsSync)(tsPath) ? `${prefix}${specifierBase}.ts${suffix}` : match;
|
|
238887
|
+
}), source;
|
|
238954
238888
|
}
|
|
238955
238889
|
__name(rewriteJsToTsExtensions, "rewriteJsToTsExtensions");
|
|
238956
238890
|
function generateImportMetaPatch(originalPath) {
|
|
238957
|
-
const fileUrl = `file://${originalPath}
|
|
238958
|
-
const originalDir = (0, import_node_path3.dirname)(originalPath);
|
|
238959
|
-
const originalFilename = originalPath;
|
|
238960
|
-
const escape = /* @__PURE__ */ __name((s) => s.replace(/\\/g, "\\\\").replace(/'/g, "\\'"), "escape");
|
|
238891
|
+
const fileUrl = `file://${originalPath}`, originalDir = (0, import_node_path3.dirname)(originalPath), originalFilename = originalPath, escape = /* @__PURE__ */ __name((s) => s.replace(/\\/g, "\\\\").replace(/'/g, "\\'"), "escape");
|
|
238961
238892
|
return [
|
|
238962
238893
|
`Object.defineProperty(import.meta, 'url', { value: '${escape(fileUrl)}', writable: false, configurable: true });`,
|
|
238963
238894
|
`Object.defineProperty(import.meta, 'dirname', { value: '${escape(originalDir)}', writable: false, configurable: true });`,
|
|
238964
238895
|
`Object.defineProperty(import.meta, 'filename', { value: '${escape(originalFilename)}', writable: false, configurable: true });`,
|
|
238965
238896
|
""
|
|
238966
|
-
].join(
|
|
238897
|
+
].join(`
|
|
238898
|
+
`);
|
|
238967
238899
|
}
|
|
238968
238900
|
__name(generateImportMetaPatch, "generateImportMetaPatch");
|
|
238969
238901
|
function loadScript(scriptPath) {
|
|
238970
|
-
const absolutePath = (0, import_node_path3.isAbsolute)(scriptPath) ? scriptPath : (0, import_node_path3.resolve)(process.cwd(), scriptPath);
|
|
238971
|
-
|
|
238972
|
-
|
|
238973
|
-
if (!needsTransformation(sourceWithoutShebang)) {
|
|
238974
|
-
const baseRequire = (0, import_node_module2.createRequire)(absolutePath);
|
|
238975
|
-
return baseRequire(absolutePath);
|
|
238976
|
-
}
|
|
238902
|
+
const absolutePath = (0, import_node_path3.isAbsolute)(scriptPath) ? scriptPath : (0, import_node_path3.resolve)(process.cwd(), scriptPath), rawSource = (0, import_node_fs2.readFileSync)(absolutePath, "utf-8"), [, sourceWithoutShebang] = extractShebang(rawSource);
|
|
238903
|
+
if (!needsTransformation(sourceWithoutShebang))
|
|
238904
|
+
return (0, import_node_module2.createRequire)(absolutePath)(absolutePath);
|
|
238977
238905
|
let source = transformJsonSchemas(absolutePath, sourceWithoutShebang, __projectDir);
|
|
238978
|
-
|
|
238979
|
-
|
|
238980
|
-
}
|
|
238981
|
-
source = rewriteJsToTsExtensions(absolutePath, source);
|
|
238982
|
-
source = generateImportMetaPatch(absolutePath) + source;
|
|
238983
|
-
const ext = absolutePath.endsWith(".ts") ? ".ts" : ".js";
|
|
238984
|
-
const scriptDir = (0, import_node_path3.dirname)(absolutePath);
|
|
238985
|
-
const tempFile = (0, import_node_path3.join)(scriptDir, `.thinkwell-${(0, import_node_path3.basename)(absolutePath, ext)}-${randomId()}${ext}`);
|
|
238906
|
+
__projectDir || (source = transformVirtualImports(source)), source = rewriteJsToTsExtensions(absolutePath, source), source = generateImportMetaPatch(absolutePath) + source;
|
|
238907
|
+
const ext = absolutePath.endsWith(".ts") ? ".ts" : ".js", scriptDir = (0, import_node_path3.dirname)(absolutePath), tempFile = (0, import_node_path3.join)(scriptDir, `.thinkwell-${(0, import_node_path3.basename)(absolutePath, ext)}-${randomId()}${ext}`);
|
|
238986
238908
|
try {
|
|
238987
|
-
(0, import_node_fs2.writeFileSync)(tempFile, source, "utf-8");
|
|
238988
|
-
const baseRequire = (0, import_node_module2.createRequire)(absolutePath);
|
|
238989
|
-
const result = baseRequire(tempFile);
|
|
238990
|
-
return result;
|
|
238909
|
+
return (0, import_node_fs2.writeFileSync)(tempFile, source, "utf-8"), (0, import_node_module2.createRequire)(absolutePath)(tempFile);
|
|
238991
238910
|
} finally {
|
|
238992
238911
|
try {
|
|
238993
238912
|
(0, import_node_fs2.rmSync)(tempFile);
|
|
@@ -239001,24 +238920,22 @@ async function runScript(scriptPath, args = []) {
|
|
|
239001
238920
|
process.argv = [process.execPath, scriptPath, ...args];
|
|
239002
238921
|
try {
|
|
239003
238922
|
const exports2 = loadScript(scriptPath);
|
|
239004
|
-
if (exports2 && typeof exports2
|
|
238923
|
+
if (exports2 && typeof exports2 == "object") {
|
|
239005
238924
|
const mod = exports2;
|
|
239006
|
-
if (typeof mod.default
|
|
238925
|
+
if (typeof mod.default == "function") {
|
|
239007
238926
|
await mod.default();
|
|
239008
238927
|
return;
|
|
239009
238928
|
}
|
|
239010
|
-
if (typeof mod.main
|
|
238929
|
+
if (typeof mod.main == "function") {
|
|
239011
238930
|
await mod.main();
|
|
239012
238931
|
return;
|
|
239013
238932
|
}
|
|
239014
|
-
if (typeof mod.run
|
|
238933
|
+
if (typeof mod.run == "function") {
|
|
239015
238934
|
await mod.run();
|
|
239016
238935
|
return;
|
|
239017
238936
|
}
|
|
239018
238937
|
}
|
|
239019
|
-
|
|
239020
|
-
await exports2();
|
|
239021
|
-
}
|
|
238938
|
+
typeof exports2 == "function" && await exports2();
|
|
239022
238939
|
} finally {
|
|
239023
238940
|
process.argv = originalArgv;
|
|
239024
238941
|
}
|
package/dist-pkg/protocol.cjs
CHANGED
|
@@ -77,18 +77,12 @@ var JsonRpcErrorCodes = {
|
|
|
77
77
|
};
|
|
78
78
|
function createRequest(id, method, params) {
|
|
79
79
|
const request = { jsonrpc: "2.0", id, method };
|
|
80
|
-
|
|
81
|
-
request.params = params;
|
|
82
|
-
}
|
|
83
|
-
return request;
|
|
80
|
+
return params !== void 0 && (request.params = params), request;
|
|
84
81
|
}
|
|
85
82
|
__name(createRequest, "createRequest");
|
|
86
83
|
function createNotification(method, params) {
|
|
87
84
|
const notification = { jsonrpc: "2.0", method };
|
|
88
|
-
|
|
89
|
-
notification.params = params;
|
|
90
|
-
}
|
|
91
|
-
return notification;
|
|
85
|
+
return params !== void 0 && (notification.params = params), notification;
|
|
92
86
|
}
|
|
93
87
|
__name(createNotification, "createNotification");
|
|
94
88
|
function createSuccessResponse(id, result) {
|