@accordproject/template-engine 4.0.0 → 5.0.0
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/lib/JavaScriptEvaluator.js +14 -17
- package/lib/JavaScriptEvaluator.js.map +1 -1
- package/lib/TemplateArchiveProcessor.d.ts +93 -3
- package/lib/TemplateArchiveProcessor.js +322 -27
- package/lib/TemplateArchiveProcessor.js.map +1 -1
- package/lib/TypeScriptCompilationContext.d.ts +27 -0
- package/lib/TypeScriptCompilationContext.js +116 -3
- package/lib/TypeScriptCompilationContext.js.map +1 -1
- package/lib/drafting/MonetaryAmount/formatTokens.d.ts +13 -0
- package/lib/drafting/MonetaryAmount/formatTokens.js +44 -0
- package/lib/drafting/MonetaryAmount/formatTokens.js.map +1 -0
- package/lib/drafting/MonetaryAmount/index.js +2 -18
- package/lib/drafting/MonetaryAmount/index.js.map +1 -1
- package/lib/drafting/PreciseAmount/index.d.ts +17 -0
- package/lib/drafting/PreciseAmount/index.js +113 -0
- package/lib/drafting/PreciseAmount/index.js.map +1 -0
- package/lib/drafting/index.js +24 -4
- package/lib/drafting/index.js.map +1 -1
- package/lib/llm/LLMConfig.d.ts +121 -0
- package/lib/llm/LLMConfig.js +30 -0
- package/lib/llm/LLMConfig.js.map +1 -0
- package/lib/llm/LLMExecutor.d.ts +77 -0
- package/lib/llm/LLMExecutor.js +603 -0
- package/lib/llm/LLMExecutor.js.map +1 -0
- package/lib/llm/ModelManagerSchema.d.ts +14 -0
- package/lib/llm/ModelManagerSchema.js +67 -0
- package/lib/llm/ModelManagerSchema.js.map +1 -0
- package/lib/llm/Reasoners.d.ts +190 -0
- package/lib/llm/Reasoners.js +643 -0
- package/lib/llm/Reasoners.js.map +1 -0
- package/lib/model-gen/concerto@1.0.0.d.ts +2 -2
- package/lib/runtime/declarations.d.ts +0 -1
- package/lib/runtime/declarations.js +1 -2
- package/lib/runtime/declarations.js.map +1 -1
- package/lib/slc/model-gen/concerto@1.0.0.d.ts +2 -2
- package/lib/utils.d.ts +29 -0
- package/lib/utils.js +51 -0
- package/lib/utils.js.map +1 -1
- package/package.json +19 -9
- package/umd/template-engine.js +8 -8
- package/umd/template-engine.js.LICENSE.txt +1 -7
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.treeShakeModel = treeShakeModel;
|
|
18
|
+
// ModelManager tree-shaking.
|
|
19
|
+
//
|
|
20
|
+
// Instead of loading a pre-generated schema.json and guessing which definition
|
|
21
|
+
// is the "request" / "response" / "state" / "event" by matching on the type
|
|
22
|
+
// name (which breaks for templates that call their response `PayOut`, `Payout`,
|
|
23
|
+
// etc.), we:
|
|
24
|
+
//
|
|
25
|
+
// 1. ask the Template for the *exact* fully-qualified type names it declares
|
|
26
|
+
// (these are reliable because they are computed from the runtime base
|
|
27
|
+
// classes the types extend, not from their names);
|
|
28
|
+
// 2. build a dependency graph of the whole ModelManager;
|
|
29
|
+
// 3. tree-shake that graph down to only the types reachable from the roots we
|
|
30
|
+
// care about; and
|
|
31
|
+
// 4. generate a minimal JSON Schema from that subgraph.
|
|
32
|
+
//
|
|
33
|
+
// See concerto-codegen `lib/common/graph.js` (ConcertoGraphVisitor +
|
|
34
|
+
// DirectedGraph.findConnectedGraph) and `test/common/graph.js` for the upstream
|
|
35
|
+
// pattern this mirrors.
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
37
|
+
const codegen = require('@accordproject/concerto-codegen');
|
|
38
|
+
const { ConcertoGraphVisitor, DirectedGraph } = codegen.Common;
|
|
39
|
+
const { JSONSchemaVisitor } = codegen.CodeGen;
|
|
40
|
+
/**
|
|
41
|
+
* Tree-shake a template's ModelManager down to only the declarations reachable
|
|
42
|
+
* from `roots`, returning both the JSON Schema definitions and the reduced
|
|
43
|
+
* model files.
|
|
44
|
+
*
|
|
45
|
+
* @param template a cicero-core Template
|
|
46
|
+
* @param roots fully-qualified type names to keep (and their dependencies)
|
|
47
|
+
*/
|
|
48
|
+
function treeShakeModel(template, roots) {
|
|
49
|
+
const modelManager = template.getModelManager();
|
|
50
|
+
// 1. Build the full dependency graph: every type is a vertex, every field /
|
|
51
|
+
// relationship / supertype / decorator reference is an edge.
|
|
52
|
+
const graph = new DirectedGraph();
|
|
53
|
+
modelManager.accept(new ConcertoGraphVisitor(), {
|
|
54
|
+
graph,
|
|
55
|
+
// Add reverse edges supertype -> subtype so that keeping a base type also
|
|
56
|
+
// keeps its concrete subtypes (needed for abstract request/response bases).
|
|
57
|
+
includeDerivedTypes: true,
|
|
58
|
+
});
|
|
59
|
+
// 2. BFS from the roots to find the maximal connected subgraph.
|
|
60
|
+
const connected = graph.findConnectedGraph(roots);
|
|
61
|
+
// 3. Filter the ModelManager to just the reachable declarations.
|
|
62
|
+
const filtered = modelManager.filter((decl) => connected.hasVertex(decl.getFullyQualifiedName()));
|
|
63
|
+
// 4. Generate JSON Schema definitions
|
|
64
|
+
const schema = filtered.accept(new JSONSchemaVisitor(), {});
|
|
65
|
+
return { definitions: schema.definitions ?? {} };
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=ModelManagerSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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C,MAAM,CAAC,IAAI,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAC;IAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { LLMProviderConfig, GroqProviderConfig, OpenAIProviderConfig, AnthropicProviderConfig, GoogleProviderConfig, MistralProviderConfig, OpenRouterProviderConfig, OllamaProviderConfig, OpenAICompatibleProviderConfig, BaseProviderConfig, OpenAIEffort } from './LLMConfig';
|
|
2
|
+
/**
|
|
3
|
+
* A single chat turn sent to a provider.
|
|
4
|
+
*/
|
|
5
|
+
export interface ChatMessage {
|
|
6
|
+
role: 'system' | 'user' | 'assistant';
|
|
7
|
+
content: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Raw content returned by a provider.
|
|
11
|
+
*/
|
|
12
|
+
export interface ReasonerResult {
|
|
13
|
+
content: string;
|
|
14
|
+
}
|
|
15
|
+
export type JsonSchema = Record<string, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* Base interface for provider-specific reasoners.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class BaseReasoner {
|
|
20
|
+
/**
|
|
21
|
+
* Completes a chat request.
|
|
22
|
+
* @param messages - conversation turns
|
|
23
|
+
* @param schema - optional JSON Schema for structured output
|
|
24
|
+
*/
|
|
25
|
+
abstract complete(messages: ChatMessage[], schema?: JsonSchema): Promise<ReasonerResult>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Groq-backed reasoner.
|
|
29
|
+
*/
|
|
30
|
+
export declare class GroqReasoner extends BaseReasoner {
|
|
31
|
+
private clientPromise?;
|
|
32
|
+
private readonly config;
|
|
33
|
+
constructor(config: GroqProviderConfig);
|
|
34
|
+
/**
|
|
35
|
+
* Loads the Groq client on first use.
|
|
36
|
+
*/
|
|
37
|
+
private getClient;
|
|
38
|
+
complete(messages: ChatMessage[], schema?: JsonSchema): Promise<ReasonerResult>;
|
|
39
|
+
}
|
|
40
|
+
interface OpenAIChatMessageParam {
|
|
41
|
+
role: 'system' | 'user' | 'assistant';
|
|
42
|
+
content: string;
|
|
43
|
+
}
|
|
44
|
+
interface OpenAIResponseFormat {
|
|
45
|
+
type: 'json_schema';
|
|
46
|
+
json_schema: {
|
|
47
|
+
name: string;
|
|
48
|
+
strict: boolean;
|
|
49
|
+
schema: JsonSchema;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
interface OpenAIChatCompletionCreateParams {
|
|
53
|
+
model: string;
|
|
54
|
+
messages: OpenAIChatMessageParam[];
|
|
55
|
+
stream: false;
|
|
56
|
+
response_format?: OpenAIResponseFormat;
|
|
57
|
+
/** Reasoning depth; reasoning models only. */
|
|
58
|
+
reasoning_effort?: OpenAIEffort;
|
|
59
|
+
/** OpenAI-native token limit field. */
|
|
60
|
+
max_completion_tokens?: number;
|
|
61
|
+
/** Legacy token limit field used by OpenAI-compatible APIs. */
|
|
62
|
+
max_tokens?: number;
|
|
63
|
+
}
|
|
64
|
+
interface OpenAIChatCompletionResponse {
|
|
65
|
+
choices?: Array<{
|
|
66
|
+
message?: {
|
|
67
|
+
content?: string | null;
|
|
68
|
+
};
|
|
69
|
+
}>;
|
|
70
|
+
}
|
|
71
|
+
interface OpenAIClient {
|
|
72
|
+
chat: {
|
|
73
|
+
completions: {
|
|
74
|
+
create: (args: OpenAIChatCompletionCreateParams) => Promise<OpenAIChatCompletionResponse>;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* OpenAI-backed reasoner.
|
|
80
|
+
*/
|
|
81
|
+
export declare class OpenAIReasoner extends BaseReasoner {
|
|
82
|
+
private clientPromise?;
|
|
83
|
+
private readonly apiKey;
|
|
84
|
+
private readonly model;
|
|
85
|
+
private readonly maxTokens;
|
|
86
|
+
private readonly effort?;
|
|
87
|
+
constructor(config: OpenAIProviderConfig);
|
|
88
|
+
/**
|
|
89
|
+
* Loads the OpenAI client on first use.
|
|
90
|
+
*/
|
|
91
|
+
private getClient;
|
|
92
|
+
complete(messages: ChatMessage[], schema?: JsonSchema): Promise<ReasonerResult>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Anthropic-backed reasoner.
|
|
96
|
+
*/
|
|
97
|
+
export declare class AnthropicReasoner extends BaseReasoner {
|
|
98
|
+
private clientPromise?;
|
|
99
|
+
private readonly apiKey;
|
|
100
|
+
private readonly model;
|
|
101
|
+
private readonly maxTokens;
|
|
102
|
+
private readonly effort?;
|
|
103
|
+
private readonly thinking;
|
|
104
|
+
constructor(config: AnthropicProviderConfig);
|
|
105
|
+
/**
|
|
106
|
+
* Loads the Anthropic client on first use.
|
|
107
|
+
*/
|
|
108
|
+
private getClient;
|
|
109
|
+
complete(messages: ChatMessage[], schema?: JsonSchema): Promise<ReasonerResult>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Base reasoner for providers that expose an OpenAI-compatible chat API.
|
|
113
|
+
*/
|
|
114
|
+
export declare class OpenAICompatibleReasoner extends BaseReasoner {
|
|
115
|
+
protected clientPromise?: Promise<OpenAIClient>;
|
|
116
|
+
protected readonly apiKey: string;
|
|
117
|
+
protected readonly model: string;
|
|
118
|
+
protected readonly maxTokens: number;
|
|
119
|
+
protected readonly baseUrl: string;
|
|
120
|
+
constructor(config: BaseProviderConfig, baseUrl: string, defaultApiKey?: string);
|
|
121
|
+
/**
|
|
122
|
+
* Loads the OpenAI-compatible client on first use.
|
|
123
|
+
*/
|
|
124
|
+
private getClient;
|
|
125
|
+
complete(messages: ChatMessage[], schema?: JsonSchema): Promise<ReasonerResult>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* OpenRouter-backed reasoner.
|
|
129
|
+
*/
|
|
130
|
+
export declare class OpenRouterReasoner extends BaseReasoner {
|
|
131
|
+
private clientPromise?;
|
|
132
|
+
private readonly apiKey;
|
|
133
|
+
private readonly model;
|
|
134
|
+
private readonly maxTokens;
|
|
135
|
+
constructor(config: OpenRouterProviderConfig);
|
|
136
|
+
/**
|
|
137
|
+
* Loads the OpenRouter client on first use.
|
|
138
|
+
*/
|
|
139
|
+
private getClient;
|
|
140
|
+
complete(messages: ChatMessage[], schema?: JsonSchema): Promise<ReasonerResult>;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Ollama-backed reasoner.
|
|
144
|
+
*/
|
|
145
|
+
export declare class OllamaReasoner extends OpenAICompatibleReasoner {
|
|
146
|
+
constructor(config: OllamaProviderConfig);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Reasoner for arbitrary OpenAI-compatible endpoints.
|
|
150
|
+
*/
|
|
151
|
+
export declare class OpenAICompatibleCustomReasoner extends OpenAICompatibleReasoner {
|
|
152
|
+
constructor(config: OpenAICompatibleProviderConfig);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Google-backed reasoner.
|
|
156
|
+
*/
|
|
157
|
+
export declare class GoogleReasoner extends BaseReasoner {
|
|
158
|
+
private clientPromise?;
|
|
159
|
+
private readonly apiKey;
|
|
160
|
+
private readonly model;
|
|
161
|
+
private readonly maxTokens;
|
|
162
|
+
constructor(config: GoogleProviderConfig);
|
|
163
|
+
/**
|
|
164
|
+
* Loads the Google client on first use.
|
|
165
|
+
*/
|
|
166
|
+
private getClient;
|
|
167
|
+
complete(messages: ChatMessage[], schema?: JsonSchema): Promise<ReasonerResult>;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Mistral-backed reasoner.
|
|
171
|
+
*/
|
|
172
|
+
export declare class MistralReasoner extends BaseReasoner {
|
|
173
|
+
private clientPromise?;
|
|
174
|
+
private readonly apiKey;
|
|
175
|
+
private readonly model;
|
|
176
|
+
private readonly maxTokens;
|
|
177
|
+
constructor(config: MistralProviderConfig);
|
|
178
|
+
/**
|
|
179
|
+
* Loads the Mistral client on first use.
|
|
180
|
+
*/
|
|
181
|
+
private getClient;
|
|
182
|
+
complete(messages: ChatMessage[], schema?: JsonSchema): Promise<ReasonerResult>;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Creates a provider-specific reasoner.
|
|
186
|
+
* @param config - provider configuration
|
|
187
|
+
* @returns a reasoner for the selected provider
|
|
188
|
+
*/
|
|
189
|
+
export declare function createReasoner(config: LLMProviderConfig): BaseReasoner;
|
|
190
|
+
export {};
|