@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.
Files changed (139) hide show
  1. package/README.md +41 -0
  2. package/lib/JavaScriptEvaluator.d.ts +71 -0
  3. package/lib/JavaScriptEvaluator.js +245 -0
  4. package/lib/JavaScriptEvaluator.js.map +1 -0
  5. package/lib/TemplateArchiveProcessor.d.ts +151 -0
  6. package/lib/TemplateArchiveProcessor.js +447 -0
  7. package/lib/TemplateArchiveProcessor.js.map +1 -0
  8. package/lib/TemplateMarkInterpreter.d.ts +34 -0
  9. package/lib/TemplateMarkInterpreter.js +689 -0
  10. package/lib/TemplateMarkInterpreter.js.map +1 -0
  11. package/lib/TemplateMarkNodes.d.ts +19 -0
  12. package/lib/TemplateMarkNodes.js +45 -0
  13. package/lib/TemplateMarkNodes.js.map +1 -0
  14. package/lib/TemplateMarkToJavaScriptCompiler.d.ts +20 -0
  15. package/lib/TemplateMarkToJavaScriptCompiler.js +99 -0
  16. package/lib/TemplateMarkToJavaScriptCompiler.js.map +1 -0
  17. package/lib/TypeScriptCompilationContext.d.ts +42 -0
  18. package/lib/TypeScriptCompilationContext.js +170 -0
  19. package/lib/TypeScriptCompilationContext.js.map +1 -0
  20. package/lib/TypeScriptRuntime.d.ts +17 -0
  21. package/lib/TypeScriptRuntime.js +84 -0
  22. package/lib/TypeScriptRuntime.js.map +1 -0
  23. package/lib/TypeScriptToJavaScriptCompiler.d.ts +11 -0
  24. package/lib/TypeScriptToJavaScriptCompiler.js +169 -0
  25. package/lib/TypeScriptToJavaScriptCompiler.js.map +1 -0
  26. package/lib/drafting/Boolean/index.d.ts +6 -0
  27. package/lib/drafting/Boolean/index.js +30 -0
  28. package/lib/drafting/Boolean/index.js.map +1 -0
  29. package/lib/drafting/DateTime/index.d.ts +8 -0
  30. package/lib/drafting/DateTime/index.js +33 -0
  31. package/lib/drafting/DateTime/index.js.map +1 -0
  32. package/lib/drafting/Double/format.d.ts +14 -0
  33. package/lib/drafting/Double/format.js +62 -0
  34. package/lib/drafting/Double/format.js.map +1 -0
  35. package/lib/drafting/Double/index.d.ts +8 -0
  36. package/lib/drafting/Double/index.js +33 -0
  37. package/lib/drafting/Double/index.js.map +1 -0
  38. package/lib/drafting/DraftFormat.d.ts +5 -0
  39. package/lib/drafting/DraftFormat.js +18 -0
  40. package/lib/drafting/DraftFormat.js.map +1 -0
  41. package/lib/drafting/Duration/index.d.ts +6 -0
  42. package/lib/drafting/Duration/index.js +39 -0
  43. package/lib/drafting/Duration/index.js.map +1 -0
  44. package/lib/drafting/Integer/format.d.ts +14 -0
  45. package/lib/drafting/Integer/format.js +52 -0
  46. package/lib/drafting/Integer/format.js.map +1 -0
  47. package/lib/drafting/Integer/index.d.ts +8 -0
  48. package/lib/drafting/Integer/index.js +33 -0
  49. package/lib/drafting/Integer/index.js.map +1 -0
  50. package/lib/drafting/Long/index.d.ts +8 -0
  51. package/lib/drafting/Long/index.js +33 -0
  52. package/lib/drafting/Long/index.js.map +1 -0
  53. package/lib/drafting/MonetaryAmount/currencycode.d.ts +35 -0
  54. package/lib/drafting/MonetaryAmount/currencycode.js +53 -0
  55. package/lib/drafting/MonetaryAmount/currencycode.js.map +1 -0
  56. package/lib/drafting/MonetaryAmount/formatTokens.d.ts +13 -0
  57. package/lib/drafting/MonetaryAmount/formatTokens.js +44 -0
  58. package/lib/drafting/MonetaryAmount/formatTokens.js.map +1 -0
  59. package/lib/drafting/MonetaryAmount/index.d.ts +13 -0
  60. package/lib/drafting/MonetaryAmount/index.js +51 -0
  61. package/lib/drafting/MonetaryAmount/index.js.map +1 -0
  62. package/lib/drafting/PreciseAmount/index.d.ts +17 -0
  63. package/lib/drafting/PreciseAmount/index.js +113 -0
  64. package/lib/drafting/PreciseAmount/index.js.map +1 -0
  65. package/lib/drafting/String/index.d.ts +6 -0
  66. package/lib/drafting/String/index.js +25 -0
  67. package/lib/drafting/String/index.js.map +1 -0
  68. package/lib/drafting/index.d.ts +2 -0
  69. package/lib/drafting/index.js +63 -0
  70. package/lib/drafting/index.js.map +1 -0
  71. package/lib/index.d.ts +7 -0
  72. package/lib/index.js +42 -0
  73. package/lib/index.js.map +1 -0
  74. package/lib/llm/LLMConfig.d.ts +121 -0
  75. package/lib/llm/LLMConfig.js +30 -0
  76. package/lib/llm/LLMConfig.js.map +1 -0
  77. package/lib/llm/LLMExecutor.d.ts +77 -0
  78. package/lib/llm/LLMExecutor.js +603 -0
  79. package/lib/llm/LLMExecutor.js.map +1 -0
  80. package/lib/llm/ModelManagerSchema.d.ts +14 -0
  81. package/lib/llm/ModelManagerSchema.js +67 -0
  82. package/lib/llm/ModelManagerSchema.js.map +1 -0
  83. package/lib/llm/Reasoners.d.ts +190 -0
  84. package/lib/llm/Reasoners.js +643 -0
  85. package/lib/llm/Reasoners.js.map +1 -0
  86. package/lib/model-gen/concerto.d.ts +13 -0
  87. package/lib/model-gen/concerto.js +4 -0
  88. package/lib/model-gen/concerto.js.map +1 -0
  89. package/lib/model-gen/concerto.metamodel@1.0.0.d.ts +196 -0
  90. package/lib/model-gen/concerto.metamodel@1.0.0.js +4 -0
  91. package/lib/model-gen/concerto.metamodel@1.0.0.js.map +1 -0
  92. package/lib/model-gen/concerto@1.0.0.d.ts +19 -0
  93. package/lib/model-gen/concerto@1.0.0.js +4 -0
  94. package/lib/model-gen/concerto@1.0.0.js.map +1 -0
  95. package/lib/model-gen/org.accordproject.ciceromark@0.6.0.d.ts +49 -0
  96. package/lib/model-gen/org.accordproject.ciceromark@0.6.0.js +4 -0
  97. package/lib/model-gen/org.accordproject.ciceromark@0.6.0.js.map +1 -0
  98. package/lib/model-gen/org.accordproject.commonmark@0.5.0.d.ts +89 -0
  99. package/lib/model-gen/org.accordproject.commonmark@0.5.0.js +4 -0
  100. package/lib/model-gen/org.accordproject.commonmark@0.5.0.js.map +1 -0
  101. package/lib/model-gen/org.accordproject.templatemark@0.5.0.d.ts +76 -0
  102. package/lib/model-gen/org.accordproject.templatemark@0.5.0.js +11 -0
  103. package/lib/model-gen/org.accordproject.templatemark@0.5.0.js.map +1 -0
  104. package/lib/runtime/declarations.d.ts +2 -0
  105. package/lib/runtime/declarations.js +21 -0
  106. package/lib/runtime/declarations.js.map +1 -0
  107. package/lib/slc/model-gen/concerto.d.ts +13 -0
  108. package/lib/slc/model-gen/concerto.decorator@1.0.0.d.ts +6 -0
  109. package/lib/slc/model-gen/concerto.decorator@1.0.0.js +5 -0
  110. package/lib/slc/model-gen/concerto.decorator@1.0.0.js.map +1 -0
  111. package/lib/slc/model-gen/concerto.js +5 -0
  112. package/lib/slc/model-gen/concerto.js.map +1 -0
  113. package/lib/slc/model-gen/concerto@1.0.0.d.ts +24 -0
  114. package/lib/slc/model-gen/concerto@1.0.0.js +6 -0
  115. package/lib/slc/model-gen/concerto@1.0.0.js.map +1 -0
  116. package/lib/slc/model-gen/org.accordproject.contract@0.2.0.d.ts +7 -0
  117. package/lib/slc/model-gen/org.accordproject.contract@0.2.0.js +5 -0
  118. package/lib/slc/model-gen/org.accordproject.contract@0.2.0.js.map +1 -0
  119. package/lib/slc/model-gen/org.accordproject.runtime@0.2.0.d.ts +15 -0
  120. package/lib/slc/model-gen/org.accordproject.runtime@0.2.0.js +4 -0
  121. package/lib/slc/model-gen/org.accordproject.runtime@0.2.0.js.map +1 -0
  122. package/lib/slc/model-gen/org.accordproject.time@0.3.0.d.ts +46 -0
  123. package/lib/slc/model-gen/org.accordproject.time@0.3.0.js +48 -0
  124. package/lib/slc/model-gen/org.accordproject.time@0.3.0.js.map +1 -0
  125. package/lib/utils.d.ts +35 -0
  126. package/lib/utils.js +122 -0
  127. package/lib/utils.js.map +1 -0
  128. package/lib/worker.d.ts +1 -0
  129. package/{dist → lib}/worker.js +12 -10
  130. package/lib/worker.js.map +1 -0
  131. package/package.json +46 -25
  132. package/umd/template-engine.js +13 -0
  133. package/umd/template-engine.js.LICENSE.txt +21 -0
  134. package/dist/index.d.ts +0 -186
  135. package/dist/index.js +0 -1275
  136. package/dist/index.js.map +0 -1
  137. package/dist/index.mjs +0 -1248
  138. package/dist/index.mjs.map +0 -1
  139. 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
+ }