@accordproject/template-engine 3.1.0 → 4.2.1
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 +41 -0
- package/lib/JavaScriptEvaluator.d.ts +71 -0
- package/lib/JavaScriptEvaluator.js +245 -0
- package/lib/JavaScriptEvaluator.js.map +1 -0
- package/lib/TemplateArchiveProcessor.d.ts +151 -0
- package/lib/TemplateArchiveProcessor.js +447 -0
- package/lib/TemplateArchiveProcessor.js.map +1 -0
- package/lib/TemplateMarkInterpreter.d.ts +34 -0
- package/lib/TemplateMarkInterpreter.js +689 -0
- package/lib/TemplateMarkInterpreter.js.map +1 -0
- package/lib/TemplateMarkNodes.d.ts +19 -0
- package/lib/TemplateMarkNodes.js +45 -0
- package/lib/TemplateMarkNodes.js.map +1 -0
- package/lib/TemplateMarkToJavaScriptCompiler.d.ts +20 -0
- package/lib/TemplateMarkToJavaScriptCompiler.js +99 -0
- package/lib/TemplateMarkToJavaScriptCompiler.js.map +1 -0
- package/lib/TypeScriptCompilationContext.d.ts +42 -0
- package/lib/TypeScriptCompilationContext.js +170 -0
- package/lib/TypeScriptCompilationContext.js.map +1 -0
- package/lib/TypeScriptRuntime.d.ts +17 -0
- package/lib/TypeScriptRuntime.js +84 -0
- package/lib/TypeScriptRuntime.js.map +1 -0
- package/lib/TypeScriptToJavaScriptCompiler.d.ts +11 -0
- package/lib/TypeScriptToJavaScriptCompiler.js +169 -0
- package/lib/TypeScriptToJavaScriptCompiler.js.map +1 -0
- package/lib/drafting/Boolean/index.d.ts +6 -0
- package/lib/drafting/Boolean/index.js +30 -0
- package/lib/drafting/Boolean/index.js.map +1 -0
- package/lib/drafting/DateTime/index.d.ts +8 -0
- package/lib/drafting/DateTime/index.js +33 -0
- package/lib/drafting/DateTime/index.js.map +1 -0
- package/lib/drafting/Double/format.d.ts +14 -0
- package/lib/drafting/Double/format.js +62 -0
- package/lib/drafting/Double/format.js.map +1 -0
- package/lib/drafting/Double/index.d.ts +8 -0
- package/lib/drafting/Double/index.js +33 -0
- package/lib/drafting/Double/index.js.map +1 -0
- package/lib/drafting/DraftFormat.d.ts +5 -0
- package/lib/drafting/DraftFormat.js +18 -0
- package/lib/drafting/DraftFormat.js.map +1 -0
- package/lib/drafting/Duration/index.d.ts +6 -0
- package/lib/drafting/Duration/index.js +39 -0
- package/lib/drafting/Duration/index.js.map +1 -0
- package/lib/drafting/Integer/format.d.ts +14 -0
- package/lib/drafting/Integer/format.js +52 -0
- package/lib/drafting/Integer/format.js.map +1 -0
- package/lib/drafting/Integer/index.d.ts +8 -0
- package/lib/drafting/Integer/index.js +33 -0
- package/lib/drafting/Integer/index.js.map +1 -0
- package/lib/drafting/Long/index.d.ts +8 -0
- package/lib/drafting/Long/index.js +33 -0
- package/lib/drafting/Long/index.js.map +1 -0
- package/lib/drafting/MonetaryAmount/currencycode.d.ts +35 -0
- package/lib/drafting/MonetaryAmount/currencycode.js +53 -0
- package/lib/drafting/MonetaryAmount/currencycode.js.map +1 -0
- 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.d.ts +13 -0
- package/lib/drafting/MonetaryAmount/index.js +51 -0
- package/lib/drafting/MonetaryAmount/index.js.map +1 -0
- 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/String/index.d.ts +6 -0
- package/lib/drafting/String/index.js +25 -0
- package/lib/drafting/String/index.js.map +1 -0
- package/lib/drafting/index.d.ts +2 -0
- package/lib/drafting/index.js +63 -0
- package/lib/drafting/index.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +42 -0
- package/lib/index.js.map +1 -0
- 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.d.ts +13 -0
- package/lib/model-gen/concerto.js +4 -0
- package/lib/model-gen/concerto.js.map +1 -0
- package/lib/model-gen/concerto.metamodel@1.0.0.d.ts +196 -0
- package/lib/model-gen/concerto.metamodel@1.0.0.js +4 -0
- package/lib/model-gen/concerto.metamodel@1.0.0.js.map +1 -0
- package/lib/model-gen/concerto@1.0.0.d.ts +19 -0
- package/lib/model-gen/concerto@1.0.0.js +4 -0
- package/lib/model-gen/concerto@1.0.0.js.map +1 -0
- package/lib/model-gen/org.accordproject.ciceromark@0.6.0.d.ts +49 -0
- package/lib/model-gen/org.accordproject.ciceromark@0.6.0.js +4 -0
- package/lib/model-gen/org.accordproject.ciceromark@0.6.0.js.map +1 -0
- package/lib/model-gen/org.accordproject.commonmark@0.5.0.d.ts +89 -0
- package/lib/model-gen/org.accordproject.commonmark@0.5.0.js +4 -0
- package/lib/model-gen/org.accordproject.commonmark@0.5.0.js.map +1 -0
- package/lib/model-gen/org.accordproject.templatemark@0.5.0.d.ts +76 -0
- package/lib/model-gen/org.accordproject.templatemark@0.5.0.js +11 -0
- package/lib/model-gen/org.accordproject.templatemark@0.5.0.js.map +1 -0
- package/lib/runtime/declarations.d.ts +2 -0
- package/lib/runtime/declarations.js +21 -0
- package/lib/runtime/declarations.js.map +1 -0
- package/lib/slc/model-gen/concerto.d.ts +13 -0
- package/lib/slc/model-gen/concerto.decorator@1.0.0.d.ts +6 -0
- package/lib/slc/model-gen/concerto.decorator@1.0.0.js +5 -0
- package/lib/slc/model-gen/concerto.decorator@1.0.0.js.map +1 -0
- package/lib/slc/model-gen/concerto.js +5 -0
- package/lib/slc/model-gen/concerto.js.map +1 -0
- package/lib/slc/model-gen/concerto@1.0.0.d.ts +24 -0
- package/lib/slc/model-gen/concerto@1.0.0.js +6 -0
- package/lib/slc/model-gen/concerto@1.0.0.js.map +1 -0
- package/lib/slc/model-gen/org.accordproject.contract@0.2.0.d.ts +7 -0
- package/lib/slc/model-gen/org.accordproject.contract@0.2.0.js +5 -0
- package/lib/slc/model-gen/org.accordproject.contract@0.2.0.js.map +1 -0
- package/lib/slc/model-gen/org.accordproject.runtime@0.2.0.d.ts +15 -0
- package/lib/slc/model-gen/org.accordproject.runtime@0.2.0.js +4 -0
- package/lib/slc/model-gen/org.accordproject.runtime@0.2.0.js.map +1 -0
- package/lib/slc/model-gen/org.accordproject.time@0.3.0.d.ts +46 -0
- package/lib/slc/model-gen/org.accordproject.time@0.3.0.js +48 -0
- package/lib/slc/model-gen/org.accordproject.time@0.3.0.js.map +1 -0
- package/lib/utils.d.ts +35 -0
- package/lib/utils.js +122 -0
- package/lib/utils.js.map +1 -0
- package/lib/worker.d.ts +1 -0
- package/{dist → lib}/worker.js +12 -10
- package/lib/worker.js.map +1 -0
- package/package.json +46 -25
- package/umd/template-engine.js +13 -0
- package/umd/template-engine.js.LICENSE.txt +21 -0
- package/dist/index.d.ts +0 -186
- package/dist/index.js +0 -1275
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -1248
- package/dist/index.mjs.map +0 -1
- package/dist/worker.js.map +0 -1
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.ANTHROPIC_EFFORT_LEVELS = exports.OPENAI_EFFORT_LEVELS = exports.GROQ_EFFORT_LEVELS = void 0;
|
|
17
|
+
/** Effort levels the Groq API accepts. */
|
|
18
|
+
exports.GROQ_EFFORT_LEVELS = ['none', 'low', 'medium', 'high'];
|
|
19
|
+
/**
|
|
20
|
+
* Effort levels the OpenAI Chat Completions API accepts. Only reasoning models
|
|
21
|
+
* take the parameter at all — a non-reasoning model (e.g. `gpt-4o`) rejects it.
|
|
22
|
+
*/
|
|
23
|
+
exports.OPENAI_EFFORT_LEVELS = ['minimal', 'low', 'medium', 'high'];
|
|
24
|
+
/**
|
|
25
|
+
* Effort levels the Anthropic Messages API accepts (GA, no beta header).
|
|
26
|
+
* Supported on Opus 4.5+ and Sonnet 5; `xhigh` arrived with Opus 4.7, and
|
|
27
|
+
* Sonnet 4.5 / Haiku 4.5 reject the parameter entirely.
|
|
28
|
+
*/
|
|
29
|
+
exports.ANTHROPIC_EFFORT_LEVELS = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
30
|
+
//# sourceMappingURL=LLMConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LLMConfig.js","sourceRoot":"","sources":["../../src/llm/LLMConfig.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAIH,0CAA0C;AAC7B,QAAA,kBAAkB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;AAI7E;;;GAGG;AACU,QAAA,oBAAoB,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;AAIlF;;;;GAIG;AACU,QAAA,uBAAuB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAU,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Template } from '@accordproject/cicero-core';
|
|
2
|
+
import { LLMExecutorConfig } from './LLMConfig';
|
|
3
|
+
import type { TriggerResponse, InitResponse } from '../TemplateArchiveProcessor';
|
|
4
|
+
/**
|
|
5
|
+
* Executes an Accord Project template's `init` / `trigger` operations using an
|
|
6
|
+
* LLM, deriving the request/response/state/event schemas from the template's own
|
|
7
|
+
* ModelManager. Used as a fallback when a template carries no executable logic,
|
|
8
|
+
* or when LLM execution is explicitly forced.
|
|
9
|
+
*/
|
|
10
|
+
export declare class LLMExecutor {
|
|
11
|
+
/** The template being executed. */
|
|
12
|
+
private readonly template;
|
|
13
|
+
private readonly config;
|
|
14
|
+
private readonly reasoner;
|
|
15
|
+
private readonly fullSchema;
|
|
16
|
+
/**
|
|
17
|
+
* True when the schema defines no custom State type (only the base runtime
|
|
18
|
+
* State). Stateless templates return `{}` from init and omit `state` from
|
|
19
|
+
* trigger responses entirely.
|
|
20
|
+
*/
|
|
21
|
+
private readonly stateless;
|
|
22
|
+
/** Schema instances are per-executor so the object reference is stable for
|
|
23
|
+
* Anthropic's 24-hour grammar cache (same object = cache hit).
|
|
24
|
+
* For full-schema providers the defs are derived from the template's own
|
|
25
|
+
* ModelManager via tree-shaking — no external schema.json required. */
|
|
26
|
+
private readonly initSchema;
|
|
27
|
+
private readonly triggerSchema;
|
|
28
|
+
private readonly roots;
|
|
29
|
+
private readonly promptSchema;
|
|
30
|
+
/**
|
|
31
|
+
* Creates an executor for a template.
|
|
32
|
+
* @param template - template to execute
|
|
33
|
+
* @param config - LLM configuration
|
|
34
|
+
*/
|
|
35
|
+
constructor(template: Template, config: LLMExecutorConfig);
|
|
36
|
+
/**
|
|
37
|
+
* Builds the shared prompt context.
|
|
38
|
+
* @returns prompt context
|
|
39
|
+
*/
|
|
40
|
+
private buildSharedContext;
|
|
41
|
+
/**
|
|
42
|
+
* Sends a request to the active reasoner with retries.
|
|
43
|
+
* @param messages - the chat messages to send
|
|
44
|
+
* @param schema - the JSON Schema the response must satisfy
|
|
45
|
+
* @returns the model response content
|
|
46
|
+
* @throws the last error if every attempt fails
|
|
47
|
+
*/
|
|
48
|
+
private ask;
|
|
49
|
+
/**
|
|
50
|
+
* Computes the initial contract state.
|
|
51
|
+
* @param data - the data for the template
|
|
52
|
+
* @param currentTime - the current time, defaults to now
|
|
53
|
+
* @param utcOffset - the UTC offset, defaults to zero
|
|
54
|
+
* @returns the new state
|
|
55
|
+
*/
|
|
56
|
+
init(data: any, currentTime?: string, utcOffset?: number): Promise<InitResponse>;
|
|
57
|
+
/**
|
|
58
|
+
* Evaluates a trigger request.
|
|
59
|
+
*
|
|
60
|
+
* Stateful templates (`!this.stateless`) must always be evaluated against
|
|
61
|
+
* `priorState` — the state produced by a prior call to {@link init} (or by
|
|
62
|
+
* a prior call to `trigger`) — since there is no implicit "empty" state for
|
|
63
|
+
* a template that declares custom State fields. Stateless templates ignore
|
|
64
|
+
* `priorState` entirely.
|
|
65
|
+
* @param data - the data for the template
|
|
66
|
+
* @param request - the request to send to the contract logic
|
|
67
|
+
* @param priorState - the state to evaluate the request against. Required
|
|
68
|
+
* for stateful templates (must originate from init() or a previous
|
|
69
|
+
* trigger()); ignored for stateless templates.
|
|
70
|
+
* @param currentTime - the current time. Only used when the request carries
|
|
71
|
+
* no `$timestamp`, which always takes precedence; defaults to now
|
|
72
|
+
* @param utcOffset - the UTC offset, defaults to zero
|
|
73
|
+
* @returns the response, updated state, and any events
|
|
74
|
+
* @throws {Error} if the template is stateful and no priorState is supplied
|
|
75
|
+
*/
|
|
76
|
+
trigger(data: any, request: any, priorState?: any, currentTime?: string, utcOffset?: number): Promise<TriggerResponse>;
|
|
77
|
+
}
|