node-llama-cpp 3.0.0-beta.17 → 3.0.0-beta.19
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/README.md +8 -5
- package/dist/ChatWrapper.js +3 -3
- package/dist/ChatWrapper.js.map +1 -1
- package/dist/apiDocsOverrides.d.ts +1 -0
- package/dist/apiDocsOverrides.js +5 -0
- package/dist/apiDocsOverrides.js.map +1 -0
- package/dist/bindings/AddonTypes.d.ts +1 -0
- package/dist/bindings/Llama.d.ts +6 -0
- package/dist/bindings/Llama.js +11 -0
- package/dist/bindings/Llama.js.map +1 -1
- package/dist/bindings/getLlama.d.ts +6 -2
- package/dist/bindings/getLlama.js +11 -4
- package/dist/bindings/getLlama.js.map +1 -1
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.d.ts +3 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js +27 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js.map +1 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +1 -2
- package/dist/chatWrappers/generic/TemplateChatWrapper.js +1 -2
- package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -1
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +2 -2
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -1
- package/dist/cli/cli.js +5 -3
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/commands/DebugCommand.js +3 -5
- package/dist/cli/commands/DebugCommand.js.map +1 -1
- package/dist/cli/commands/DownloadCommand.d.ts +1 -1
- package/dist/cli/commands/DownloadCommand.js +2 -1
- package/dist/cli/commands/DownloadCommand.js.map +1 -1
- package/dist/cli/commands/PullCommand.d.ts +12 -0
- package/dist/cli/commands/PullCommand.js +109 -0
- package/dist/cli/commands/PullCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +1 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +23 -11
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -1
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +2 -1
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js.map +1 -1
- package/dist/cli/recommendedModels.js +12 -20
- package/dist/cli/recommendedModels.js.map +1 -1
- package/dist/cli/utils/resolveCommandGgufPath.d.ts +3 -1
- package/dist/cli/utils/resolveCommandGgufPath.js +41 -97
- package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -1
- package/dist/cli/utils/resolveModelRecommendationFileOptions.d.ts +2 -2
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js +1 -4
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -1
- package/dist/evaluator/LlamaChat/LlamaChat.d.ts +18 -2
- package/dist/evaluator/LlamaChat/LlamaChat.js +258 -205
- package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -1
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js +1 -2
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +22 -3
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +18 -7
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -1
- package/dist/evaluator/LlamaCompletion.js +2 -2
- package/dist/evaluator/LlamaCompletion.js.map +1 -1
- package/dist/evaluator/LlamaContext/LlamaContext.d.ts +2 -7
- package/dist/evaluator/LlamaContext/LlamaContext.js +12 -12
- package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -1
- package/dist/evaluator/LlamaEmbeddingContext.d.ts +2 -10
- package/dist/evaluator/LlamaEmbeddingContext.js +9 -23
- package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -1
- package/dist/evaluator/LlamaGrammar.d.ts +3 -3
- package/dist/evaluator/LlamaGrammar.js +3 -3
- package/dist/evaluator/LlamaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaJsonSchemaGrammar.js +2 -3
- package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaModel.d.ts +9 -0
- package/dist/evaluator/LlamaModel.js +2 -1
- package/dist/evaluator/LlamaModel.js.map +1 -1
- package/dist/gguf/insights/GgufInsights.js +12 -12
- package/dist/gguf/insights/GgufInsights.js.map +1 -1
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +27 -3
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -1
- package/dist/gguf/parser/parseGguf.js +5 -0
- package/dist/gguf/parser/parseGguf.js.map +1 -1
- package/dist/gguf/readGgufFileInfo.d.ts +5 -2
- package/dist/gguf/readGgufFileInfo.js +38 -10
- package/dist/gguf/readGgufFileInfo.js.map +1 -1
- package/dist/gguf/types/GgufFileInfoTypes.d.ts +32 -0
- package/dist/gguf/types/GgufFileInfoTypes.js.map +1 -1
- package/dist/gguf/utils/getGgufMetadataArchitectureData.js +1 -1
- package/dist/gguf/utils/getGgufMetadataArchitectureData.js.map +1 -1
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.d.ts +2 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js +39 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js.map +1 -0
- package/dist/gguf/utils/resolveSplitGgufParts.d.ts +7 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js +55 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/LlamaText.d.ts +29 -20
- package/dist/utils/LlamaText.js +253 -243
- package/dist/utils/LlamaText.js.map +1 -1
- package/dist/utils/StopGenerationDetector.d.ts +1 -1
- package/dist/utils/StopGenerationDetector.js +2 -0
- package/dist/utils/StopGenerationDetector.js.map +1 -1
- package/dist/utils/TokenStreamRegulator.d.ts +4 -2
- package/dist/utils/TokenStreamRegulator.js +56 -4
- package/dist/utils/TokenStreamRegulator.js.map +1 -1
- package/dist/utils/createModelDownloader.d.ts +99 -0
- package/dist/utils/createModelDownloader.js +226 -0
- package/dist/utils/createModelDownloader.js.map +1 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +18 -8
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -1
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.d.ts +5 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js +11 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +3 -1
- package/dist/utils/gbnfJson/terminals/GbnfArray.js +10 -5
- package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +3 -1
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +9 -4
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +37 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.js +23 -5
- package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +6 -3
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +37 -9
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +5 -4
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js +14 -3
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -1
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.d.ts +10 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js +15 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js.map +1 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.d.ts +2 -1
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +6 -5
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -1
- package/dist/utils/parseTextTemplate.d.ts +2 -2
- package/dist/utils/parseTextTemplate.js +2 -2
- package/dist/utils/runtime.d.ts +4 -0
- package/dist/utils/runtime.js +8 -0
- package/dist/utils/runtime.js.map +1 -0
- package/llama/addon.cpp +18 -7
- package/llama/binariesGithubRelease.json +1 -1
- package/llama/gitRelease.bundle +0 -0
- package/llama/grammars/README.md +1 -1
- package/llama/llama.cpp.info.json +1 -1
- package/llamaBins/linux-arm64/_nlcBuildMetadata.json +1 -1
- package/llamaBins/linux-arm64/llama-addon.node +0 -0
- package/llamaBins/linux-armv7l/_nlcBuildMetadata.json +1 -1
- package/llamaBins/linux-armv7l/llama-addon.node +0 -0
- package/llamaBins/linux-x64/_nlcBuildMetadata.json +1 -1
- package/llamaBins/linux-x64/llama-addon.node +0 -0
- package/llamaBins/linux-x64-cuda/_nlcBuildMetadata.json +1 -1
- package/llamaBins/linux-x64-cuda/llama-addon.node +0 -0
- package/llamaBins/linux-x64-vulkan/_nlcBuildMetadata.json +1 -1
- package/llamaBins/linux-x64-vulkan/llama-addon.node +0 -0
- package/llamaBins/mac-arm64-metal/_nlcBuildMetadata.json +1 -1
- package/llamaBins/mac-arm64-metal/default.metallib +0 -0
- package/llamaBins/mac-arm64-metal/llama-addon.node +0 -0
- package/llamaBins/mac-x64/_nlcBuildMetadata.json +1 -1
- package/llamaBins/mac-x64/llama-addon.node +0 -0
- package/llamaBins/win-arm64/_nlcBuildMetadata.json +1 -1
- package/llamaBins/win-arm64/llama-addon.node +0 -0
- package/llamaBins/win-x64/_nlcBuildMetadata.json +1 -1
- package/llamaBins/win-x64/llama-addon.node +0 -0
- package/llamaBins/win-x64-cuda/_nlcBuildMetadata.json +1 -1
- package/llamaBins/win-x64-cuda/llama-addon.node +0 -0
- package/llamaBins/win-x64-vulkan/_nlcBuildMetadata.json +1 -1
- package/llamaBins/win-x64-vulkan/llama-addon.node +0 -0
- package/package.json +11 -8
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.d.ts +0 -2
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js +0 -9
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GbnfArray.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAGnC,MAAM,OAAO,SAAU,SAAQ,YAAY;IACvB,KAAK,CAAe;
|
|
1
|
+
{"version":3,"file":"GbnfArray.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAGnC,MAAM,OAAO,SAAU,SAAQ,YAAY;IACvB,KAAK,CAAe;IACpB,UAAU,CAAqB;IAE/C,YAAmB,KAAmB,EA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} from "../GbnfGrammarGenerator.js";
|
|
3
|
+
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
|
|
3
4
|
import { GbnfString } from "./GbnfString.js";
|
|
4
5
|
import { GbnfStringValue } from "./GbnfStringValue.js";
|
|
5
6
|
export declare class GbnfObjectMap extends GbnfTerminal {
|
|
@@ -8,10 +9,11 @@ export declare class GbnfObjectMap extends GbnfTerminal {
|
|
|
8
9
|
value: GbnfTerminal;
|
|
9
10
|
required: true;
|
|
10
11
|
}>>;
|
|
12
|
+
readonly scopeState: GbnfJsonScopeState;
|
|
11
13
|
constructor(fields: Array<Readonly<{
|
|
12
14
|
key: GbnfString | GbnfStringValue;
|
|
13
15
|
value: GbnfTerminal;
|
|
14
16
|
required: true;
|
|
15
|
-
}
|
|
17
|
+
}>>, scopeState?: GbnfJsonScopeState);
|
|
16
18
|
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
|
|
17
19
|
}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
|
|
2
3
|
import { GbnfWhitespace } from "./GbnfWhitespace.js";
|
|
3
4
|
import { GbnfGrammar } from "./GbnfGrammar.js";
|
|
4
5
|
export class GbnfObjectMap extends GbnfTerminal {
|
|
5
6
|
fields;
|
|
6
|
-
|
|
7
|
+
scopeState;
|
|
8
|
+
constructor(fields, scopeState = new GbnfJsonScopeState()) {
|
|
7
9
|
super();
|
|
8
10
|
this.fields = fields;
|
|
11
|
+
this.scopeState = scopeState;
|
|
9
12
|
}
|
|
10
13
|
getGrammar(grammarGenerator) {
|
|
11
|
-
const
|
|
14
|
+
const getWhitespaceRuleName = (newScope, newLine) => (newScope
|
|
15
|
+
? new GbnfWhitespace(this.scopeState.getForNewScope(), { newLine }).resolve(grammarGenerator)
|
|
16
|
+
: new GbnfWhitespace(this.scopeState, { newLine }).resolve(grammarGenerator));
|
|
12
17
|
return new GbnfGrammar([
|
|
13
|
-
'"{"',
|
|
18
|
+
'"{"', getWhitespaceRuleName(true, "before"),
|
|
14
19
|
...this.fields.map(({ key, value }, index) => {
|
|
15
20
|
return new GbnfGrammar([
|
|
16
21
|
key.getGrammar(), '":"', "[ ]?", value.resolve(grammarGenerator),
|
|
17
22
|
index < this.fields.length - 1 ? '","' : "",
|
|
18
|
-
|
|
23
|
+
getWhitespaceRuleName(index < this.fields.length - 1, "before")
|
|
19
24
|
]).getGrammar();
|
|
20
25
|
}),
|
|
21
26
|
'"}"'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GbnfObjectMap.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfObjectMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"GbnfObjectMap.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfObjectMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAGlE,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAG7C,MAAM,OAAO,aAAc,SAAQ,YAAY;IAC3B,MAAM,CAA8F;IACpG,UAAU,CAAqB;IAE/C,YACI,MAAmG,EACnG,aAAiC,IAAI,kBAAkB,EAAE;QAEzD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAEM,UAAU,CAAC,gBAAsC;QACpD,MAAM,qBAAqB,GAAG,CAAC,QAAiB,EAAE,OAAmC,EAAE,EAAE,CAAC,CACtF,QAAQ;YACJ,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;YAC3F,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CACjF,CAAC;QAEF,OAAO,IAAI,WAAW,CAAC;YACnB,KAAK,EAAE,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC;YAC5C,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAC,GAAG,EAAE,KAAK,EAAC,EAAE,KAAK,EAAE,EAAE;gBACvC,OAAO,IAAI,WAAW,CAAC;oBACnB,GAAG,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC;oBAChE,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;oBAC3C,qBAAqB,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,QAAQ,CAAC;iBAClE,CAAC,CAAC,UAAU,EAAE,CAAC;YACpB,CAAC,CAAC;YACF,KAAK;SACR,CAAC,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;CACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
|
|
3
|
+
export declare class GbnfRepetition extends GbnfTerminal {
|
|
4
|
+
readonly value: GbnfTerminal;
|
|
5
|
+
readonly minRepetitions: number;
|
|
6
|
+
readonly maxRepetitions: number | null;
|
|
7
|
+
constructor(value: GbnfTerminal, minRepetitions: number, maxRepetitions: number | null);
|
|
8
|
+
getGrammar(grammarGenerator: GbnfGrammarGenerator): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { grammarNoValue } from "./gbnfConsts.js";
|
|
3
|
+
export class GbnfRepetition extends GbnfTerminal {
|
|
4
|
+
value;
|
|
5
|
+
minRepetitions;
|
|
6
|
+
maxRepetitions;
|
|
7
|
+
constructor(value, minRepetitions, maxRepetitions) {
|
|
8
|
+
super();
|
|
9
|
+
this.value = value;
|
|
10
|
+
this.minRepetitions = minRepetitions;
|
|
11
|
+
this.maxRepetitions = maxRepetitions;
|
|
12
|
+
}
|
|
13
|
+
getGrammar(grammarGenerator) {
|
|
14
|
+
const resolvedValue = this.value.resolve(grammarGenerator);
|
|
15
|
+
let grammarStart = "";
|
|
16
|
+
let grammarEnd = "";
|
|
17
|
+
for (let i = 0; i < this.minRepetitions; i++) {
|
|
18
|
+
grammarStart += "(" + resolvedValue + " ";
|
|
19
|
+
grammarEnd += ")";
|
|
20
|
+
}
|
|
21
|
+
if (this.maxRepetitions === Infinity || this.maxRepetitions == null) {
|
|
22
|
+
grammarStart += "(" + resolvedValue + " ";
|
|
23
|
+
grammarEnd += ")*";
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
for (let i = this.minRepetitions + 1; i <= this.maxRepetitions; i++) {
|
|
27
|
+
grammarStart += "(" + resolvedValue + " ";
|
|
28
|
+
grammarEnd += ")?";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const res = grammarStart + grammarEnd;
|
|
32
|
+
if (res === "")
|
|
33
|
+
return grammarNoValue;
|
|
34
|
+
return res;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=GbnfRepetition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GbnfRepetition.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfRepetition.ts"],"names":[],"mappings":"AA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AI,GAAG,KAAK,EAAE;YACV,OAAO,cAAc,CAAC;QAE1B,OAAO,GAAG,CAAC;IACf,CAAC;CACJ"}
|
|
@@ -2,14 +2,32 @@ import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
|
2
2
|
import { reservedRuleNames } from "./gbnfConsts.js";
|
|
3
3
|
export class GbnfString extends GbnfTerminal {
|
|
4
4
|
getGrammar() {
|
|
5
|
-
return
|
|
6
|
-
'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
return [
|
|
6
|
+
'"\\""',
|
|
7
|
+
or([
|
|
8
|
+
negatedCharacterSet([
|
|
9
|
+
'"',
|
|
10
|
+
"\\\\",
|
|
11
|
+
"\\x7F",
|
|
12
|
+
"\\x00-\\x1F"
|
|
13
|
+
]),
|
|
14
|
+
// escape sequences
|
|
15
|
+
'"\\\\" ' + or([
|
|
16
|
+
'["\\\\/bfnrt]',
|
|
17
|
+
'"u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]'
|
|
18
|
+
])
|
|
19
|
+
]) + "*",
|
|
20
|
+
'"\\""'
|
|
21
|
+
].join(" ");
|
|
10
22
|
}
|
|
11
23
|
getRuleName() {
|
|
12
24
|
return reservedRuleNames.string;
|
|
13
25
|
}
|
|
14
26
|
}
|
|
27
|
+
function negatedCharacterSet(characterDefinitions) {
|
|
28
|
+
return "[^" + characterDefinitions.join("") + "]";
|
|
29
|
+
}
|
|
30
|
+
function or(definitions) {
|
|
31
|
+
return "(" + definitions.join(" | ") + ")";
|
|
32
|
+
}
|
|
15
33
|
//# sourceMappingURL=GbnfString.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GbnfString.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAGlD,MAAM,OAAO,UAAW,SAAQ,YAAY;IACjC,UAAU;QACb,OAAO,
|
|
1
|
+
{"version":3,"file":"GbnfString.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAGlD,MAAM,OAAO,UAAW,SAAQ,YAAY;IACjC,UAAU;QACb,OAAO;YACH,OAAO;YACP,EAAE,CAAC;gBACC,mBAAmB,CAAC;oBAChB,GAAG;oBACH,MAAM;oBACN,OAAO;oBACP,aAAa;iBAChB,CAAC;gBAEF,mBAAmB;gBACnB,SAAS,GAAG,EAAE,CAAC;oBACX,eAAe;oBACf,qDAAqD;iBACxD,CAAC;aACL,CAAC,GAAG,GAAG;YACR,OAAO;SACV,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;IAEkB,WAAW;QAC1B,OAAO,iBAAiB,CAAC,MAAM,CAAC;IACpC,CAAC;CACJ;AAED,SAAS,mBAAmB,CAAC,oBAA8B;IACvD,OAAO,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;AACtD,CAAC;AAED,SAAS,EAAE,CAAC,WAAqB;IAC7B,OAAO,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;AAC/C,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
|
+
import { GbnfJsonScopeState } from "../utils/GbnfJsonScopeState.js";
|
|
2
3
|
export declare class GbnfWhitespace extends GbnfTerminal {
|
|
3
|
-
readonly
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
readonly scopeState: GbnfJsonScopeState;
|
|
5
|
+
readonly newLine: "before" | "after" | false;
|
|
6
|
+
constructor(scopeState: GbnfJsonScopeState, { newLine }?: {
|
|
7
|
+
newLine?: "before" | "after" | false;
|
|
8
|
+
space?: boolean;
|
|
6
9
|
});
|
|
7
10
|
getGrammar(): string;
|
|
8
11
|
protected getRuleName(): string;
|
|
@@ -1,20 +1,48 @@
|
|
|
1
1
|
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
2
|
import { reservedRuleNames } from "./gbnfConsts.js";
|
|
3
|
+
import { GbnfVerbatimText } from "./GbnfVerbatimText.js";
|
|
3
4
|
export class GbnfWhitespace extends GbnfTerminal {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
scopeState;
|
|
6
|
+
newLine;
|
|
7
|
+
constructor(scopeState, { newLine = "before" } = {}) {
|
|
6
8
|
super();
|
|
7
|
-
this.
|
|
9
|
+
this.scopeState = scopeState;
|
|
10
|
+
this.newLine = newLine;
|
|
8
11
|
}
|
|
9
12
|
getGrammar() {
|
|
10
|
-
if (this.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
if (this.scopeState.settings.allowNewLines && this.newLine !== false) {
|
|
14
|
+
const values = [
|
|
15
|
+
...(this.newLine === "before"
|
|
16
|
+
? ["[\\n]"]
|
|
17
|
+
: []),
|
|
18
|
+
...(this.scopeState.currentNestingScope === 0
|
|
19
|
+
? []
|
|
20
|
+
: [
|
|
21
|
+
or([
|
|
22
|
+
new GbnfVerbatimText(" ".repeat(this.scopeState.currentNestingScope * this.scopeState.settings.scopePadSpaces)).getGrammar(),
|
|
23
|
+
new GbnfVerbatimText("\t".repeat(this.scopeState.currentNestingScope)).getGrammar()
|
|
24
|
+
])
|
|
25
|
+
]),
|
|
26
|
+
...(this.newLine === "after"
|
|
27
|
+
? ["[\\n]"]
|
|
28
|
+
: [])
|
|
29
|
+
];
|
|
30
|
+
return or([
|
|
31
|
+
values.join(" "),
|
|
32
|
+
"[ ]?"
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
35
|
+
return "[ ]?";
|
|
13
36
|
}
|
|
14
37
|
getRuleName() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
38
|
+
return reservedRuleNames.whitespace({
|
|
39
|
+
newLine: this.newLine,
|
|
40
|
+
scopeSpaces: this.scopeState.settings.scopePadSpaces,
|
|
41
|
+
nestingScope: this.scopeState.currentNestingScope
|
|
42
|
+
});
|
|
18
43
|
}
|
|
19
44
|
}
|
|
45
|
+
function or(definitions) {
|
|
46
|
+
return "(" + definitions.join(" | ") + ")";
|
|
47
|
+
}
|
|
20
48
|
//# sourceMappingURL=GbnfWhitespace.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GbnfWhitespace.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfWhitespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"GbnfWhitespace.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/GbnfWhitespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAGvD,MAAM,OAAO,cAAe,SAAQ,YAAY;IAC5B,UAAU,CAAqB;IAC/B,OAAO,CAA6B;IAEpD,YAAmB,UAA8B,EAAE,EAC/C,OAAO,GAAG,QAAQ,KAIlB,EAAE;QACF,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAEM,UAAU;QACb,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,aAAa,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,EAAE;YAClE,MAAM,MAAM,GAAG;gBACX,GAAG,CACC,IAAI,CAAC,OAAO,KAAK,QA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";
|
|
10
|
-
readonly whitespace: {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
readonly whitespace: ({ newLine, nestingScope, scopeSpaces }: {
|
|
11
|
+
newLine?: false | "before" | "after" | undefined;
|
|
12
|
+
nestingScope: number;
|
|
13
|
+
scopeSpaces: number;
|
|
14
|
+
}) => string;
|
|
14
15
|
};
|
|
@@ -7,9 +7,20 @@ export const reservedRuleNames = {
|
|
|
7
7
|
integer: "integer-number-rule"
|
|
8
8
|
},
|
|
9
9
|
string: "string-rule",
|
|
10
|
-
whitespace
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
whitespace({ newLine, nestingScope, scopeSpaces }) {
|
|
11
|
+
if (!newLine)
|
|
12
|
+
return "whitespace-no-new-lines-rule";
|
|
13
|
+
return [
|
|
14
|
+
"whitespace-",
|
|
15
|
+
newLine === "before"
|
|
16
|
+
? "b"
|
|
17
|
+
: newLine === "after"
|
|
18
|
+
? "a"
|
|
19
|
+
: "n",
|
|
20
|
+
"-" + nestingScope,
|
|
21
|
+
"-" + scopeSpaces,
|
|
22
|
+
"-rule"
|
|
23
|
+
].join("");
|
|
13
24
|
}
|
|
14
25
|
};
|
|
15
26
|
//# sourceMappingURL=gbnfConsts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gbnfConsts.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/gbnfConsts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC7B,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,cAAc;IACvB,MAAM,EAAE;QACJ,UAAU,EAAE,wBAAwB;QACpC,OAAO,EAAE,qBAAqB;KACjC;IACD,MAAM,EAAE,aAAa;IACrB,UAAU,EAAE
|
|
1
|
+
{"version":3,"file":"gbnfConsts.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/terminals/gbnfConsts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC7B,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,cAAc;IACvB,MAAM,EAAE;QACJ,UAAU,EAAE,wBAAwB;QACpC,OAAO,EAAE,qBAAqB;KACjC;IACD,MAAM,EAAE,aAAa;IACrB,UAAU,CAAC,EAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAE7C;QACG,IAAI,CAAC,OAAO;YACR,OAAO,8BAA8B,CAAC;QAE1C,OAAO;YACH,aAAa;YACb,OAAO,KAAK,QAAQ;gBAChB,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,OAAO,KAAK,OAAO;oBACjB,CAAC,CAAC,GAAG;oBACL,CAAC,CAAC,GAAG;YACb,GAAG,GAAG,YAAY;YAClB,GAAG,GAAG,WAAW;YACjB,OAAO;SACV,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,CAAC;CACK,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type GbnfJsonScopeSettings = {
|
|
2
|
+
readonly allowNewLines: boolean;
|
|
3
|
+
readonly scopePadSpaces: number;
|
|
4
|
+
};
|
|
5
|
+
export declare class GbnfJsonScopeState {
|
|
6
|
+
readonly settings: GbnfJsonScopeSettings;
|
|
7
|
+
readonly currentNestingScope: number;
|
|
8
|
+
constructor(settings?: GbnfJsonScopeSettings, currentNestingScope?: number);
|
|
9
|
+
getForNewScope(): GbnfJsonScopeState;
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class GbnfJsonScopeState {
|
|
2
|
+
settings;
|
|
3
|
+
currentNestingScope;
|
|
4
|
+
constructor(settings = {
|
|
5
|
+
allowNewLines: true,
|
|
6
|
+
scopePadSpaces: 4
|
|
7
|
+
}, currentNestingScope = 0) {
|
|
8
|
+
this.settings = settings;
|
|
9
|
+
this.currentNestingScope = currentNestingScope;
|
|
10
|
+
}
|
|
11
|
+
getForNewScope() {
|
|
12
|
+
return new GbnfJsonScopeState(this.settings, this.currentNestingScope + 1);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=GbnfJsonScopeState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GbnfJsonScopeState.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/utils/GbnfJsonScopeState.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,kBAAkB;IACX,QAAQ,CAAwB;IAChC,mBAAmB,CAAS;IAE5C,YAAmB,WAAkC;QACjD,aAAa,EAAE,IAAI;QACnB,cAAc,EAAE,CAAC;KACpB,EAAE,sBAA8B,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACnD,CAAC;IAEM,cAAc;QACjB,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,mBAAmB,GAAG,CAAC,CAAC,CAAC;IAC/E,CAAC;CACJ"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GbnfTerminal } from "../GbnfTerminal.js";
|
|
2
2
|
import { GbnfGrammarGenerator } from "../GbnfGrammarGenerator.js";
|
|
3
3
|
import { GbnfJsonSchema } from "../types.js";
|
|
4
|
-
|
|
4
|
+
import { GbnfJsonScopeState } from "./GbnfJsonScopeState.js";
|
|
5
|
+
export declare function getGbnfJsonTerminalForGbnfJsonSchema(schema: GbnfJsonSchema, grammarGenerator: GbnfGrammarGenerator, scopeState?: GbnfJsonScopeState): GbnfTerminal;
|
|
@@ -8,10 +8,11 @@ import { GbnfBoolean } from "../terminals/GbnfBoolean.js";
|
|
|
8
8
|
import { GbnfNull } from "../terminals/GbnfNull.js";
|
|
9
9
|
import { isGbnfJsonArraySchema, isGbnfJsonBasicSchemaIncludesType, isGbnfJsonConstSchema, isGbnfJsonEnumSchema, isGbnfJsonObjectSchema, isGbnfJsonOneOfSchema } from "../types.js";
|
|
10
10
|
import { getGbnfJsonTerminalForLiteral } from "./getGbnfJsonTerminalForLiteral.js";
|
|
11
|
-
|
|
11
|
+
import { GbnfJsonScopeState } from "./GbnfJsonScopeState.js";
|
|
12
|
+
export function getGbnfJsonTerminalForGbnfJsonSchema(schema, grammarGenerator, scopeState = new GbnfJsonScopeState()) {
|
|
12
13
|
if (isGbnfJsonOneOfSchema(schema)) {
|
|
13
14
|
const values = schema.oneOf
|
|
14
|
-
.map((altSchema) => getGbnfJsonTerminalForGbnfJsonSchema(altSchema, grammarGenerator));
|
|
15
|
+
.map((altSchema) => getGbnfJsonTerminalForGbnfJsonSchema(altSchema, grammarGenerator, scopeState));
|
|
15
16
|
return new GbnfOr(values);
|
|
16
17
|
}
|
|
17
18
|
else if (isGbnfJsonConstSchema(schema)) {
|
|
@@ -25,12 +26,12 @@ export function getGbnfJsonTerminalForGbnfJsonSchema(schema, grammarGenerator) {
|
|
|
25
26
|
return {
|
|
26
27
|
required: true,
|
|
27
28
|
key: new GbnfStringValue(propName),
|
|
28
|
-
value: getGbnfJsonTerminalForGbnfJsonSchema(propSchema, grammarGenerator)
|
|
29
|
+
value: getGbnfJsonTerminalForGbnfJsonSchema(propSchema, grammarGenerator, scopeState.getForNewScope())
|
|
29
30
|
};
|
|
30
|
-
}));
|
|
31
|
+
}), scopeState);
|
|
31
32
|
}
|
|
32
33
|
else if (isGbnfJsonArraySchema(schema)) {
|
|
33
|
-
return new GbnfArray(getGbnfJsonTerminalForGbnfJsonSchema(schema.items, grammarGenerator));
|
|
34
|
+
return new GbnfArray(getGbnfJsonTerminalForGbnfJsonSchema(schema.items, grammarGenerator, scopeState), scopeState);
|
|
34
35
|
}
|
|
35
36
|
const terminals = [];
|
|
36
37
|
if (isGbnfJsonBasicSchemaIncludesType(schema, "string"))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGbnfJsonTerminalForGbnfJsonSchema.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAC,aAAa,EAAC,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAC,SAAS,EAAC,MAAM,2BAA2B,CAAC;AAEpD,OAAO,EAAC,UAAU,EAAC,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAC,UAAU,EAAC,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAC;AAElD,OAAO,EACa,qBAAqB,EAAE,iCAAiC,EAAE,qBAAqB,EAAE,oBAAoB,EACrH,sBAAsB,EAAE,qBAAqB,EAChD,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,6BAA6B,EAAC,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"getGbnfJsonTerminalForGbnfJsonSchema.js","sourceRoot":"","sources":["../../../../src/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAC,aAAa,EAAC,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAC,SAAS,EAAC,MAAM,2BAA2B,CAAC;AAEpD,OAAO,EAAC,UAAU,EAAC,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAC,UAAU,EAAC,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,QAAQ,EAAC,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UAAU,CAAC,cAAc,EAAE,CAAC;aACzG,CAAC;QACN,CAAC,CAAC,EACF,UAAU,CACb,CAAC;KACL;SAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,EAAE;QACtC,OAAO,IAAI,SAAS,CAAC,oCAAoC,CAAC,MAAM,CAAC,KAAK,EAAE,gBAAgB,EAAE,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC;KACtH;IAED,MAAM,SAAS,GAAmB,EAAE,CAAC;IAErC,IAAI,iCAAiC,CAAC,MAAM,EAAE,QAAQ,CAAC;QACnD,SAAS,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC;IAErC,IAAI,iCAAiC,CAAC,MAAM,EAAE,QAAQ,CAAC;QACnD,SAAS,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,EAAC,eAAe,EAAE,IAAI,EAAC,CAAC,CAAC,CAAC;IAE5D,IAAI,iCAAiC,CAAC,MAAM,EAAE,SAAS,CAAC;QACpD,SAAS,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,EAAC,eAAe,EAAE,KAAK,EAAC,CAAC,CAAC,CAAC;IAE7D,IAAI,iCAAiC,CAAC,MAAM,EAAE,SAAS,CAAC;QACpD,SAAS,CAAC,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC;IAEtC,IAAI,iCAAiC,CAAC,MAAM,EAAE,MAAM,CAAC;QACjD,SAAS,CAAC,IAAI,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC;IAEnC,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { MergeUnionTypes } from "./mergeUnionTypes.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Parses a text template into a map of parts and their prefixes and suffixes.
|
|
4
4
|
* This parser assumes each part occurs exactly once in the template, and that all parts must occur in the order they are defined.
|
|
5
|
-
*
|
|
5
|
+
* @example
|
|
6
6
|
* ```typescript
|
|
7
7
|
* const res = parseTextTemplate(
|
|
8
8
|
* "Hello, {{name}}! What is the {{thing}}?",
|
|
@@ -25,7 +25,7 @@ import { MergeUnionTypes } from "./mergeUnionTypes.js";
|
|
|
25
25
|
* }
|
|
26
26
|
* });
|
|
27
27
|
* ```
|
|
28
|
-
*
|
|
28
|
+
* @example
|
|
29
29
|
* ```typescript
|
|
30
30
|
* const res2 = parseTextTemplate(
|
|
31
31
|
* "What is the {{thing}}?",
|
|
@@ -2,7 +2,7 @@ import { splitText } from "lifecycle-utils";
|
|
|
2
2
|
/**
|
|
3
3
|
* Parses a text template into a map of parts and their prefixes and suffixes.
|
|
4
4
|
* This parser assumes each part occurs exactly once in the template, and that all parts must occur in the order they are defined.
|
|
5
|
-
*
|
|
5
|
+
* @example
|
|
6
6
|
* ```typescript
|
|
7
7
|
* const res = parseTextTemplate(
|
|
8
8
|
* "Hello, {{name}}! What is the {{thing}}?",
|
|
@@ -25,7 +25,7 @@ import { splitText } from "lifecycle-utils";
|
|
|
25
25
|
* }
|
|
26
26
|
* });
|
|
27
27
|
* ```
|
|
28
|
-
*
|
|
28
|
+
* @example
|
|
29
29
|
* ```typescript
|
|
30
30
|
* const res2 = parseTextTemplate(
|
|
31
31
|
* "What is the {{thing}}?",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
4
|
+
export const runningInElectron = process.versions.electron != null;
|
|
5
|
+
export const runningInsideAsar = runningInElectron && __filename.toLowerCase().includes(".asar" + path.sep);
|
|
6
|
+
export const runningInBun = process.versions.bun != null;
|
|
7
|
+
export const runningInNode = !runningInElectron && !runningInBun;
|
|
8
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/utils/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAC;AAElC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,IAAI,IAAI,CAAC;AACnE,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5G,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,CAAC;AACzD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,iBAAiB,IAAI,CAAC,YAAY,CAAC"}
|
package/llama/addon.cpp
CHANGED
|
@@ -289,6 +289,10 @@ class AddonModel : public Napi::ObjectWrap<AddonModel> {
|
|
|
289
289
|
model_params.use_mlock = options.Get("useMlock").As<Napi::Boolean>().Value();
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
+
if (options.Has("checkTensors")) {
|
|
293
|
+
model_params.check_tensors = options.Get("checkTensors").As<Napi::Boolean>().Value();
|
|
294
|
+
}
|
|
295
|
+
|
|
292
296
|
if (options.Has("onLoadProgress")) {
|
|
293
297
|
auto onLoadProgressJSCallback = options.Get("onLoadProgress").As<Napi::Function>();
|
|
294
298
|
if (onLoadProgressJSCallback.IsFunction()) {
|
|
@@ -1483,6 +1487,11 @@ class AddonContextSampleTokenWorker : public Napi::AsyncWorker {
|
|
|
1483
1487
|
llama_token new_token_id = 0;
|
|
1484
1488
|
|
|
1485
1489
|
// Select the best prediction.
|
|
1490
|
+
if (llama_get_logits(ctx->ctx) == nullptr) {
|
|
1491
|
+
SetError("This model does not support token generation");
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1486
1495
|
auto logits = llama_get_logits_ith(ctx->ctx, batchLogitIndex);
|
|
1487
1496
|
auto n_vocab = llama_n_vocab(ctx->model->model);
|
|
1488
1497
|
|
|
@@ -1701,13 +1710,15 @@ static void addonLlamaCppLogCallback(ggml_log_level level, const char* text, voi
|
|
|
1701
1710
|
}
|
|
1702
1711
|
}
|
|
1703
1712
|
|
|
1704
|
-
if (
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1713
|
+
if (text != nullptr) {
|
|
1714
|
+
if (level == 2) {
|
|
1715
|
+
fputs(text, stderr);
|
|
1716
|
+
fflush(stderr);
|
|
1717
|
+
} else {
|
|
1718
|
+
fputs(text, stdout);
|
|
1719
|
+
fflush(stdout);
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1711
1722
|
}
|
|
1712
1723
|
|
|
1713
1724
|
Napi::Value setLogger(const Napi::CallbackInfo& info) {
|
package/llama/gitRelease.bundle
CHANGED
|
Binary file
|
package/llama/grammars/README.md
CHANGED
|
@@ -51,7 +51,7 @@ single-line ::= [^\n]+ "\n"`
|
|
|
51
51
|
|
|
52
52
|
## Sequences and Alternatives
|
|
53
53
|
|
|
54
|
-
The order of symbols in a sequence
|
|
54
|
+
The order of symbols in a sequence matters. For example, in `"1. " move " " move "\n"`, the `"1. "` must come before the first `move`, etc.
|
|
55
55
|
|
|
56
56
|
Alternatives, denoted by `|`, give different sequences that are acceptable. For example, in `move ::= pawn | nonpawn | castle`, `move` can be a `pawn` move, a `nonpawn` move, or a `castle`.
|
|
57
57
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"linux","platformInfo":{"name":"Ubuntu","version":"22.04"},"arch":"arm64","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"linux","platformInfo":{"name":"Ubuntu","version":"22.04"},"arch":"arm64","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"linux","platformInfo":{"name":"Ubuntu","version":"22.04"},"arch":"armv7l","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"linux","platformInfo":{"name":"Ubuntu","version":"22.04"},"arch":"armv7l","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"linux","platformInfo":{"name":"Ubuntu","version":"22.04"},"arch":"x64","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"linux","platformInfo":{"name":"Ubuntu","version":"22.04"},"arch":"x64","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"linux","platformInfo":{"name":"Ubuntu","version":"22.04"},"arch":"x64","gpu":"cuda","llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"linux","platformInfo":{"name":"Ubuntu","version":"22.04"},"arch":"x64","gpu":"cuda","llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"linux","platformInfo":{"name":"Ubuntu","version":"22.04"},"arch":"x64","gpu":"vulkan","llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"linux","platformInfo":{"name":"Ubuntu","version":"22.04"},"arch":"x64","gpu":"vulkan","llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"mac","platformInfo":{"name":"macOS","version":"21.6.0"},"arch":"arm64","gpu":"metal","llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"mac","platformInfo":{"name":"macOS","version":"21.6.0"},"arch":"arm64","gpu":"metal","llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"mac","platformInfo":{"name":"macOS","version":"21.6.0"},"arch":"x64","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"mac","platformInfo":{"name":"macOS","version":"21.6.0"},"arch":"x64","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"win","platformInfo":{"name":"Windows","version":"10.0.20348"},"arch":"arm64","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"win","platformInfo":{"name":"Windows","version":"10.0.20348"},"arch":"arm64","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"win","platformInfo":{"name":"Windows","version":"10.0.20348"},"arch":"x64","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"win","platformInfo":{"name":"Windows","version":"10.0.20348"},"arch":"x64","gpu":false,"llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"win","platformInfo":{"name":"Windows","version":"10.0.20348"},"arch":"x64","gpu":"cuda","llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"win","platformInfo":{"name":"Windows","version":"10.0.20348"},"arch":"x64","gpu":"cuda","llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"win","platformInfo":{"name":"Windows","version":"10.0.20348"},"arch":"x64","gpu":"vulkan","llamaCpp":{"repo":"ggerganov/llama.cpp","release":"
|
|
1
|
+
{"buildOptions":{"customCmakeOptions":{},"progressLogs":true,"platform":"win","platformInfo":{"name":"Windows","version":"10.0.20348"},"arch":"x64","gpu":"vulkan","llamaCpp":{"repo":"ggerganov/llama.cpp","release":"b2861"}}}
|
|
Binary file
|