@holoscript/core 6.0.3 → 7.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.
Files changed (244) hide show
  1. package/README.md +40 -40
  2. package/dist/codebase/index.d.ts +25 -0
  3. package/dist/compiler/index.d.ts +82 -0
  4. package/dist/constants.d.ts +4 -0
  5. package/dist/coordinators/index.d.ts +189 -0
  6. package/dist/entries/interop.d.ts +9 -0
  7. package/dist/entries/scripting.d.ts +7 -0
  8. package/dist/index.d.ts +520 -19
  9. package/dist/paper-0c-spike/index.d.ts +29 -0
  10. package/dist/reconstruction/index.d.ts +78 -0
  11. package/dist/self-improvement/index.d.ts +0 -48
  12. package/dist/storage/index.d.ts +24 -0
  13. package/dist/tools/index.d.ts +33 -0
  14. package/dist/traitDocs/traitDocs.d.ts +69 -0
  15. package/dist/traits/index.d.ts +61 -0
  16. package/package.json +102 -19
  17. package/dist/GLTFPipeline-3KLWWUQO.cjs +0 -34
  18. package/dist/GLTFPipeline-LYII2ZVQ.js +0 -13
  19. package/dist/HoloScriptPlusParser-BZR5DELQ.js +0 -692
  20. package/dist/HoloScriptPlusParser-SBMYDNXO.cjs +0 -697
  21. package/dist/USDZExporter-MHEHXZB4.cjs +0 -709
  22. package/dist/USDZExporter-YA55ZS35.js +0 -707
  23. package/dist/chunk-26TLYBFD.js +0 -309
  24. package/dist/chunk-27LWW5FU.cjs +0 -410
  25. package/dist/chunk-2UX5LRAP.cjs +0 -833
  26. package/dist/chunk-32TWR3HE.js +0 -70
  27. package/dist/chunk-3FXV5S25.cjs +0 -633
  28. package/dist/chunk-3FYZOR7S.cjs +0 -69
  29. package/dist/chunk-3KEU5QYY.cjs +0 -175
  30. package/dist/chunk-4FCZDTD5.js +0 -610
  31. package/dist/chunk-4KJ2R7VP.cjs +0 -507
  32. package/dist/chunk-4SMUJFHL.js +0 -1213
  33. package/dist/chunk-54FHG2MX.js +0 -655
  34. package/dist/chunk-56IF4NTA.js +0 -56
  35. package/dist/chunk-5GLCTO44.js +0 -161
  36. package/dist/chunk-5TOFIR6L.js +0 -407
  37. package/dist/chunk-65RFOWZI.js +0 -765
  38. package/dist/chunk-6OQBLABR.js +0 -5240
  39. package/dist/chunk-6WNCRE6F.js +0 -126
  40. package/dist/chunk-74YCHHTE.js +0 -1872
  41. package/dist/chunk-7H5UNJZD.cjs +0 -1973
  42. package/dist/chunk-7KPI4EKH.cjs +0 -701
  43. package/dist/chunk-7LCYLPW2.cjs +0 -663
  44. package/dist/chunk-7N3JIJMT.js +0 -1395
  45. package/dist/chunk-7X2IEJIE.cjs +0 -2526
  46. package/dist/chunk-A6GO3DPZ.cjs +0 -1002
  47. package/dist/chunk-AC4BSHFV.js +0 -765
  48. package/dist/chunk-AIUXRS74.cjs +0 -3681
  49. package/dist/chunk-ARNKA274.cjs +0 -130
  50. package/dist/chunk-AW7WAELW.js +0 -975
  51. package/dist/chunk-BKIGPPVM.js +0 -629
  52. package/dist/chunk-BO2OKHIY.js +0 -6055
  53. package/dist/chunk-BU5ZAFMC.js +0 -115
  54. package/dist/chunk-BY3B7ZYV.cjs +0 -457
  55. package/dist/chunk-C2QHVHZF.js +0 -4066
  56. package/dist/chunk-C7BNX4XJ.js +0 -1043
  57. package/dist/chunk-CLYEIWA5.cjs +0 -408
  58. package/dist/chunk-CMYAWUX3.js +0 -4455
  59. package/dist/chunk-CN4NOESF.cjs +0 -416
  60. package/dist/chunk-CNVM7J3M.js +0 -883
  61. package/dist/chunk-CO2VM2DK.js +0 -1965
  62. package/dist/chunk-CQDOF3G7.cjs +0 -1404
  63. package/dist/chunk-DH5G2JUA.cjs +0 -614
  64. package/dist/chunk-DIEDKX5B.cjs +0 -660
  65. package/dist/chunk-DN7UFU63.cjs +0 -172
  66. package/dist/chunk-DXVCEFZB.js +0 -2027
  67. package/dist/chunk-EGIZHYJP.cjs +0 -85
  68. package/dist/chunk-EJA7G2C4.cjs +0 -428
  69. package/dist/chunk-ELLQPFAF.js +0 -830
  70. package/dist/chunk-EMO7HAKJ.cjs +0 -1875
  71. package/dist/chunk-ENV7K6XA.js +0 -282
  72. package/dist/chunk-EPWRXL6S.js +0 -2522
  73. package/dist/chunk-EUFLX2PI.js +0 -56956
  74. package/dist/chunk-F5LVGHNT.js +0 -449
  75. package/dist/chunk-FEFHPUEM.cjs +0 -6122
  76. package/dist/chunk-FF3Q7ADR.js +0 -380
  77. package/dist/chunk-GC3YU46J.js +0 -762
  78. package/dist/chunk-H6WMMLQK.cjs +0 -4492
  79. package/dist/chunk-H7XMORZI.js +0 -2731
  80. package/dist/chunk-HAN4V3PF.cjs +0 -2037
  81. package/dist/chunk-HBZYCASG.js +0 -4208
  82. package/dist/chunk-HF4OFY25.cjs +0 -4097
  83. package/dist/chunk-HHS6FMOU.cjs +0 -3813
  84. package/dist/chunk-HJJLD366.js +0 -1169
  85. package/dist/chunk-HKCVM6OK.cjs +0 -2237
  86. package/dist/chunk-HUFNKFA6.js +0 -698
  87. package/dist/chunk-I3XGTIHM.cjs +0 -1505
  88. package/dist/chunk-I6XZ5DZF.cjs +0 -488
  89. package/dist/chunk-IHOUYQIA.js +0 -406
  90. package/dist/chunk-ILRBGFVD.cjs +0 -72
  91. package/dist/chunk-KDB6BUMB.js +0 -3666
  92. package/dist/chunk-KUJRR4FJ.js +0 -657
  93. package/dist/chunk-KYM4XRFG.js +0 -421
  94. package/dist/chunk-L3Z2HIWJ.cjs +0 -793
  95. package/dist/chunk-LBPEZQAF.js +0 -2232
  96. package/dist/chunk-LER4WXW5.cjs +0 -286
  97. package/dist/chunk-LK5IAVH6.cjs +0 -1173
  98. package/dist/chunk-M6FU6S22.js +0 -2911
  99. package/dist/chunk-MWEFR6YQ.js +0 -1857
  100. package/dist/chunk-N5FTS757.cjs +0 -415
  101. package/dist/chunk-NCUHGRTZ.js +0 -752
  102. package/dist/chunk-NKRKT6V2.js +0 -69
  103. package/dist/chunk-NLPSZT4C.js +0 -630
  104. package/dist/chunk-NRUB55IT.cjs +0 -771
  105. package/dist/chunk-NTMZSDXM.cjs +0 -633
  106. package/dist/chunk-ODGMVILH.js +0 -9662
  107. package/dist/chunk-PBA6NXCT.cjs +0 -1216
  108. package/dist/chunk-PHENW4MQ.js +0 -65
  109. package/dist/chunk-PJMOXFPR.cjs +0 -1861
  110. package/dist/chunk-PLMYCCA4.js +0 -504
  111. package/dist/chunk-PPULB4GG.cjs +0 -9728
  112. package/dist/chunk-PQLGZKMC.cjs +0 -755
  113. package/dist/chunk-Q56TT7IL.js +0 -483
  114. package/dist/chunk-QHVVVN47.cjs +0 -2033
  115. package/dist/chunk-QWKUKVRE.js +0 -2026
  116. package/dist/chunk-RE3OKSYF.cjs +0 -424
  117. package/dist/chunk-RT7LJRSF.cjs +0 -57378
  118. package/dist/chunk-SPDELRRV.cjs +0 -319
  119. package/dist/chunk-SUCBB66F.js +0 -229
  120. package/dist/chunk-TSWTWZ42.cjs +0 -4214
  121. package/dist/chunk-UITWA6DV.cjs +0 -2829
  122. package/dist/chunk-UQW6SLM5.js +0 -172
  123. package/dist/chunk-V2ILLPHK.cjs +0 -237
  124. package/dist/chunk-V42NTCFH.js +0 -3645
  125. package/dist/chunk-VJ3L7CHT.cjs +0 -169
  126. package/dist/chunk-VJVCD5T5.cjs +0 -769
  127. package/dist/chunk-VK5AXKO3.js +0 -746
  128. package/dist/chunk-VSXOIUCF.cjs +0 -473
  129. package/dist/chunk-VZNKJZTT.cjs +0 -749
  130. package/dist/chunk-W76ETJTI.js +0 -678
  131. package/dist/chunk-WFJIDI2N.cjs +0 -424
  132. package/dist/chunk-WN3YF33G.cjs +0 -118
  133. package/dist/chunk-WUXIRGZP.cjs +0 -2915
  134. package/dist/chunk-WYH4GVZ5.js +0 -1488
  135. package/dist/chunk-X4YVN7H3.cjs +0 -888
  136. package/dist/chunk-X67XRI2T.js +0 -410
  137. package/dist/chunk-XDXZM3ZP.cjs +0 -1046
  138. package/dist/chunk-XH7SE4HH.cjs +0 -72
  139. package/dist/chunk-XNMEH2BI.js +0 -126
  140. package/dist/chunk-XSF76QRU.js +0 -468
  141. package/dist/chunk-XSUZMPVQ.cjs +0 -682
  142. package/dist/chunk-XUILI4KB.cjs +0 -430
  143. package/dist/chunk-Y5MUAYTO.js +0 -167
  144. package/dist/chunk-Y7VK5TH3.cjs +0 -129
  145. package/dist/chunk-YCMQQQ5U.cjs +0 -5244
  146. package/dist/chunk-YYXH45E2.js +0 -426
  147. package/dist/chunk-ZGTGVSTZ.js +0 -422
  148. package/dist/chunk-ZL6VJ6SN.js +0 -421
  149. package/dist/cli/holoscript-runner.cjs +0 -2258
  150. package/dist/cli/holoscript-runner.js +0 -2233
  151. package/dist/codebase/index.cjs +0 -336
  152. package/dist/codebase/index.js +0 -331
  153. package/dist/compiler/agent-inference.cjs +0 -29
  154. package/dist/compiler/agent-inference.js +0 -6
  155. package/dist/compiler/android-xr.cjs +0 -20
  156. package/dist/compiler/android-xr.js +0 -10
  157. package/dist/compiler/android.cjs +0 -21
  158. package/dist/compiler/android.js +0 -11
  159. package/dist/compiler/ar.cjs +0 -21
  160. package/dist/compiler/ar.js +0 -9
  161. package/dist/compiler/babylon.cjs +0 -18
  162. package/dist/compiler/babylon.js +0 -12
  163. package/dist/compiler/coco.cjs +0 -27
  164. package/dist/compiler/coco.js +0 -4
  165. package/dist/compiler/domain-block-utils.cjs +0 -595
  166. package/dist/compiler/domain-block-utils.js +0 -9
  167. package/dist/compiler/dtdl.cjs +0 -25
  168. package/dist/compiler/dtdl.js +0 -9
  169. package/dist/compiler/gltf-pipeline.cjs +0 -39
  170. package/dist/compiler/gltf-pipeline.js +0 -4
  171. package/dist/compiler/godot.cjs +0 -16
  172. package/dist/compiler/godot.js +0 -10
  173. package/dist/compiler/incremental.cjs +0 -30
  174. package/dist/compiler/incremental.js +0 -5
  175. package/dist/compiler/index.cjs +0 -1522
  176. package/dist/compiler/index.js +0 -1321
  177. package/dist/compiler/ios.cjs +0 -21
  178. package/dist/compiler/ios.js +0 -11
  179. package/dist/compiler/multi-layer.cjs +0 -27
  180. package/dist/compiler/multi-layer.js +0 -12
  181. package/dist/compiler/nodetoy.cjs +0 -23
  182. package/dist/compiler/nodetoy.js +0 -4
  183. package/dist/compiler/openxr.cjs +0 -16
  184. package/dist/compiler/openxr.js +0 -10
  185. package/dist/compiler/playcanvas.cjs +0 -17
  186. package/dist/compiler/playcanvas.js +0 -11
  187. package/dist/compiler/r3f.cjs +0 -35
  188. package/dist/compiler/r3f.js +0 -13
  189. package/dist/compiler/remotion.cjs +0 -23
  190. package/dist/compiler/remotion.js +0 -4
  191. package/dist/compiler/reproducibility.cjs +0 -39
  192. package/dist/compiler/reproducibility.js +0 -4
  193. package/dist/compiler/sdf.cjs +0 -22
  194. package/dist/compiler/sdf.js +0 -10
  195. package/dist/compiler/semantic-scene.cjs +0 -31
  196. package/dist/compiler/semantic-scene.js +0 -4
  197. package/dist/compiler/state.cjs +0 -18
  198. package/dist/compiler/state.js +0 -8
  199. package/dist/compiler/trait-composition.cjs +0 -27
  200. package/dist/compiler/trait-composition.js +0 -6
  201. package/dist/compiler/unity.cjs +0 -16
  202. package/dist/compiler/unity.js +0 -10
  203. package/dist/compiler/unreal.cjs +0 -20
  204. package/dist/compiler/unreal.js +0 -10
  205. package/dist/compiler/urdf.cjs +0 -46
  206. package/dist/compiler/urdf.js +0 -10
  207. package/dist/compiler/usd-physics.cjs +0 -24
  208. package/dist/compiler/usd-physics.js +0 -7
  209. package/dist/compiler/visionos.cjs +0 -16
  210. package/dist/compiler/visionos.js +0 -10
  211. package/dist/compiler/vrchat.cjs +0 -20
  212. package/dist/compiler/vrchat.js +0 -10
  213. package/dist/compiler/vrr.cjs +0 -22
  214. package/dist/compiler/vrr.js +0 -10
  215. package/dist/compiler/wasm.cjs +0 -34
  216. package/dist/compiler/wasm.js +0 -10
  217. package/dist/compiler/webgpu.cjs +0 -16
  218. package/dist/compiler/webgpu.js +0 -10
  219. package/dist/debugger.cjs +0 -21
  220. package/dist/debugger.js +0 -8
  221. package/dist/entries/interop.cjs +0 -62
  222. package/dist/entries/interop.js +0 -5
  223. package/dist/entries/scripting.cjs +0 -67
  224. package/dist/entries/scripting.js +0 -10
  225. package/dist/index.cjs +0 -61703
  226. package/dist/index.js +0 -58652
  227. package/dist/math/vec3.cjs +0 -57
  228. package/dist/math/vec3.js +0 -4
  229. package/dist/parser.cjs +0 -26
  230. package/dist/parser.js +0 -9
  231. package/dist/playwright-7DTEQCBD.cjs +0 -98673
  232. package/dist/playwright-BIZXMLD2.js +0 -98660
  233. package/dist/post-quantum-JTTAAGO3.cjs +0 -6
  234. package/dist/post-quantum-RVPVDEPI.js +0 -4
  235. package/dist/runtime.cjs +0 -16
  236. package/dist/runtime.js +0 -7
  237. package/dist/storage/index.cjs +0 -37
  238. package/dist/storage/index.js +0 -4
  239. package/dist/traits/index.cjs +0 -14331
  240. package/dist/traits/index.js +0 -12126
  241. package/dist/type-checker.cjs +0 -18
  242. package/dist/type-checker.js +0 -5
  243. package/dist/wot/index.cjs +0 -29
  244. package/dist/wot/index.js +0 -4
@@ -1,883 +0,0 @@
1
- import { init_CompilerBase, init_ANSNamespace, CompilerBase, ANSCapabilityPath } from './chunk-QWKUKVRE.js';
2
-
3
- // src/compiler/AgentInferenceExportTarget.ts
4
- init_CompilerBase();
5
- init_ANSNamespace();
6
- var DEFAULT_MODEL_CONFIG = {
7
- provider: "anthropic",
8
- name: "claude-sonnet-4-20250514",
9
- temperature: 0.7,
10
- maxTokens: 4096,
11
- topP: 0.9,
12
- topK: 40,
13
- systemPrompt: "You are a helpful AI agent."
14
- };
15
- var AGENT_TRAIT_NAMES = /* @__PURE__ */ new Set([
16
- "agent",
17
- "model",
18
- "inference",
19
- "system_prompt",
20
- "prompt",
21
- "temperature",
22
- "max_tokens",
23
- "top_p",
24
- "top_k",
25
- "tool",
26
- "tool_use",
27
- "reasoning",
28
- "memory",
29
- "persona"
30
- ]);
31
- var AgentInferenceCompiler = class extends CompilerBase {
32
- constructor(options = {}) {
33
- super();
34
- this.compilerName = "AgentInferenceCompiler";
35
- this.agents = [];
36
- this.warnings = [];
37
- this.options = {
38
- language: options.language ?? "typescript",
39
- defaultProvider: options.defaultProvider ?? "anthropic",
40
- defaultModel: options.defaultModel ?? "claude-sonnet-4-20250514",
41
- defaultTemperature: options.defaultTemperature ?? 0.7,
42
- defaultMaxTokens: options.defaultMaxTokens ?? 4096,
43
- includeTypes: options.includeTypes ?? true,
44
- includeReadme: options.includeReadme ?? true,
45
- includeEnvTemplate: options.includeEnvTemplate ?? true
46
- };
47
- }
48
- getRequiredCapability() {
49
- return ANSCapabilityPath.AGENT_INFERENCE;
50
- }
51
- /**
52
- * Compile a HoloScript composition to runnable agent inference scripts.
53
- *
54
- * Extracts agent definitions from objects with @agent/@model/@tool traits,
55
- * NPCs, dialogue trees, state machines, and domain blocks, then generates
56
- * a complete multi-file agent project.
57
- */
58
- compile(composition, agentToken, outputPath) {
59
- this.validateCompilerAccess(agentToken, outputPath);
60
- this.agents = [];
61
- this.warnings = [];
62
- this.extractAgentsFromObjects(composition);
63
- this.extractAgentsFromNPCs(composition);
64
- this.extractAgentsFromDomainBlocks(composition);
65
- if (this.agents.length === 0) {
66
- this.agents.push(this.createDefaultAgent(composition));
67
- this.warnings.push(
68
- "No @agent traits found in composition. Created default agent from composition name."
69
- );
70
- }
71
- const output = {};
72
- const ext = this.options.language === "typescript" ? "ts" : "py";
73
- output[`agent.${ext}`] = this.emitAgentScript(composition.name);
74
- const allTools = this.agents.flatMap((a) => a.tools);
75
- if (allTools.length > 0) {
76
- output[`tools.${ext}`] = this.emitToolDefinitions(allTools);
77
- }
78
- output["config.json"] = this.emitConfigJson();
79
- if (this.options.language === "typescript") {
80
- output["package.json"] = this.emitPackageJson(composition.name);
81
- if (this.options.includeTypes) {
82
- output["types.ts"] = this.emitTypeDefinitions();
83
- }
84
- } else {
85
- output["requirements.txt"] = this.emitRequirementsTxt();
86
- }
87
- if (this.options.includeEnvTemplate) {
88
- output[".env.example"] = this.emitEnvTemplate();
89
- }
90
- if (this.options.includeReadme) {
91
- output["README.md"] = this.emitReadme(composition.name);
92
- }
93
- return output;
94
- }
95
- /** Get extracted agents (for inspection/testing). */
96
- getAgents() {
97
- return this.agents;
98
- }
99
- /** Get warnings from last compilation. */
100
- getWarnings() {
101
- return this.warnings;
102
- }
103
- // ─── AST Extraction ─────────────────────────────────────────────────
104
- extractAgentsFromObjects(composition) {
105
- for (const obj of composition.objects) {
106
- if (this.hasAgentTraits(obj)) {
107
- this.agents.push(this.parseAgentObject(obj));
108
- }
109
- if (obj.children) {
110
- for (const child of obj.children) {
111
- if (this.hasAgentTraits(child)) {
112
- this.agents.push(this.parseAgentObject(child));
113
- }
114
- }
115
- }
116
- }
117
- }
118
- extractAgentsFromNPCs(composition) {
119
- for (const npc of composition.npcs) {
120
- this.agents.push(this.parseNPCAsAgent(npc, composition));
121
- }
122
- }
123
- extractAgentsFromDomainBlocks(composition) {
124
- if (!composition.domainBlocks) return;
125
- for (const block of composition.domainBlocks) {
126
- if (this.isAgentDomainBlock(block)) {
127
- this.agents.push(this.parseDomainBlockAsAgent(block));
128
- }
129
- }
130
- }
131
- hasAgentTraits(obj) {
132
- return obj.traits.some((t) => AGENT_TRAIT_NAMES.has(t.name));
133
- }
134
- parseAgentObject(obj) {
135
- const modelConfig = { ...DEFAULT_MODEL_CONFIG };
136
- modelConfig.provider = this.options.defaultProvider;
137
- modelConfig.name = this.options.defaultModel;
138
- modelConfig.temperature = this.options.defaultTemperature;
139
- modelConfig.maxTokens = this.options.defaultMaxTokens;
140
- const tools = [];
141
- const behaviors = [];
142
- const stateProperties = [];
143
- let role = "assistant";
144
- for (const trait of obj.traits) {
145
- switch (trait.name) {
146
- case "agent":
147
- role = this.extractStringValue(trait.config["role"]) ?? role;
148
- break;
149
- case "model":
150
- this.applyModelConfig(trait, modelConfig);
151
- break;
152
- case "inference":
153
- this.applyModelConfig(trait, modelConfig);
154
- break;
155
- case "system_prompt":
156
- case "prompt":
157
- modelConfig.systemPrompt = this.extractStringValue(trait.config["text"]) ?? this.extractStringValue(trait.config["content"]) ?? modelConfig.systemPrompt;
158
- break;
159
- case "temperature":
160
- modelConfig.temperature = this.extractNumberValue(trait.config["value"]) ?? modelConfig.temperature;
161
- break;
162
- case "max_tokens":
163
- modelConfig.maxTokens = this.extractNumberValue(trait.config["value"]) ?? modelConfig.maxTokens;
164
- break;
165
- case "top_p":
166
- modelConfig.topP = this.extractNumberValue(trait.config["value"]) ?? modelConfig.topP;
167
- break;
168
- case "top_k":
169
- modelConfig.topK = this.extractNumberValue(trait.config["value"]) ?? modelConfig.topK;
170
- break;
171
- case "tool":
172
- case "tool_use":
173
- tools.push(this.parseToolTrait(trait));
174
- break;
175
- case "persona":
176
- modelConfig.systemPrompt = this.extractStringValue(trait.config["description"]) ?? modelConfig.systemPrompt;
177
- break;
178
- }
179
- }
180
- if (obj.state) {
181
- for (const prop of obj.state.properties) {
182
- stateProperties.push({
183
- key: prop.key,
184
- type: typeof prop.value === "number" ? "number" : typeof prop.value === "boolean" ? "boolean" : "string",
185
- defaultValue: String(prop.value ?? "")
186
- });
187
- }
188
- }
189
- return {
190
- name: obj.name,
191
- role,
192
- modelConfig,
193
- tools,
194
- behaviors,
195
- stateProperties,
196
- dialogueHandlers: []
197
- };
198
- }
199
- parseNPCAsAgent(npc, composition) {
200
- const modelConfig = { ...DEFAULT_MODEL_CONFIG };
201
- modelConfig.provider = this.options.defaultProvider;
202
- modelConfig.name = this.options.defaultModel;
203
- modelConfig.temperature = this.options.defaultTemperature;
204
- modelConfig.maxTokens = this.options.defaultMaxTokens;
205
- const npcType = npc.npcType ?? "assistant";
206
- const npcProps = npc.properties.map((p) => `${p.key}: ${String(p.value)}`).join(", ");
207
- modelConfig.systemPrompt = `You are a ${npcType} named ${npc.name}. ${npcProps}`;
208
- const tools = npc.behaviors.map((b) => this.parseBehaviorAsTool(b));
209
- const behaviors = npc.behaviors.map((b) => ({
210
- name: b.name,
211
- trigger: b.trigger,
212
- actions: b.actions.map((a) => a.actionType),
213
- priority: b.priority ?? 0
214
- }));
215
- const dialogueHandlers = [];
216
- if (npc.dialogueTree) {
217
- const dialogue = composition.dialogues.find(
218
- // @ts-expect-error During migration
219
- (d) => d.name === npc.dialogueTree
220
- );
221
- if (dialogue) {
222
- dialogueHandlers.push({
223
- // @ts-expect-error During migration
224
- id: dialogue.name,
225
- // @ts-expect-error During migration
226
- prompt: `Dialogue tree: ${dialogue.name}`,
227
- // @ts-expect-error During migration
228
- responses: dialogue.nodes?.map((n) => n.text ?? n.name ?? "") ?? []
229
- });
230
- }
231
- }
232
- return {
233
- name: npc.name,
234
- role: npcType,
235
- modelConfig,
236
- tools,
237
- behaviors,
238
- stateProperties: [],
239
- dialogueHandlers
240
- };
241
- }
242
- parseDomainBlockAsAgent(block) {
243
- const modelConfig = { ...DEFAULT_MODEL_CONFIG };
244
- modelConfig.provider = this.options.defaultProvider;
245
- modelConfig.name = this.options.defaultModel;
246
- const name = block.name ?? block.blockType ?? "DomainAgent";
247
- const tools = [];
248
- if (block.objects) {
249
- for (const obj of block.objects) {
250
- tools.push({
251
- name: this.toSnakeCase(obj.name),
252
- description: `Domain operation: ${obj.name}`,
253
- // @ts-expect-error During migration
254
- parameters: obj.properties.map((p) => ({
255
- name: p.key,
256
- type: typeof p.value === "number" ? "number" : "string",
257
- description: `Parameter: ${p.key}`,
258
- required: true
259
- })),
260
- returnType: "unknown",
261
- source: "domain-block"
262
- });
263
- }
264
- }
265
- return {
266
- name,
267
- role: "domain-specialist",
268
- modelConfig,
269
- tools,
270
- behaviors: [],
271
- stateProperties: [],
272
- dialogueHandlers: []
273
- };
274
- }
275
- isAgentDomainBlock(block) {
276
- const agentBlockTypes = ["agent_block", "inference_block", "ai_block"];
277
- return agentBlockTypes.includes(block.blockType ?? "");
278
- }
279
- parseToolTrait(trait) {
280
- const name = this.extractStringValue(trait.config["name"]) ?? "unnamed_tool";
281
- const description = this.extractStringValue(trait.config["description"]) ?? "";
282
- const parameters = [];
283
- const paramsValue = trait.config["parameters"];
284
- if (Array.isArray(paramsValue)) {
285
- for (const param of paramsValue) {
286
- if (param && typeof param === "object" && !Array.isArray(param)) {
287
- const paramObj = param;
288
- parameters.push({
289
- name: this.extractStringValue(paramObj["name"]) ?? "param",
290
- type: this.extractStringValue(paramObj["type"]) ?? "string",
291
- description: this.extractStringValue(paramObj["description"]) ?? "",
292
- required: paramObj["required"] === true,
293
- defaultValue: paramObj["default"] != null ? String(paramObj["default"]) : void 0
294
- });
295
- }
296
- }
297
- }
298
- return {
299
- name,
300
- description,
301
- parameters,
302
- returnType: this.extractStringValue(trait.config["returns"]) ?? "string",
303
- source: "trait"
304
- };
305
- }
306
- parseBehaviorAsTool(behavior) {
307
- return {
308
- name: this.toSnakeCase(behavior.name),
309
- description: `Behavior: ${behavior.name} (triggered by: ${behavior.trigger})`,
310
- parameters: behavior.actions.map((a) => ({
311
- name: a.actionType,
312
- type: "string",
313
- description: `Action: ${a.actionType}`,
314
- required: false
315
- })),
316
- returnType: "void",
317
- source: "behavior"
318
- };
319
- }
320
- createDefaultAgent(composition) {
321
- return {
322
- name: composition.name,
323
- role: "assistant",
324
- modelConfig: {
325
- ...DEFAULT_MODEL_CONFIG,
326
- provider: this.options.defaultProvider,
327
- name: this.options.defaultModel,
328
- temperature: this.options.defaultTemperature,
329
- maxTokens: this.options.defaultMaxTokens,
330
- systemPrompt: `You are an AI agent for ${composition.name}.`
331
- },
332
- tools: [],
333
- behaviors: [],
334
- stateProperties: [],
335
- dialogueHandlers: []
336
- };
337
- }
338
- applyModelConfig(trait, config) {
339
- const provider = this.extractStringValue(trait.config["provider"]);
340
- if (provider && this.isModelProvider(provider)) {
341
- config.provider = provider;
342
- }
343
- config.name = this.extractStringValue(trait.config["name"]) ?? config.name;
344
- config.temperature = this.extractNumberValue(trait.config["temperature"]) ?? config.temperature;
345
- config.maxTokens = this.extractNumberValue(trait.config["max_tokens"]) ?? this.extractNumberValue(trait.config["maxTokens"]) ?? config.maxTokens;
346
- config.topP = this.extractNumberValue(trait.config["top_p"]) ?? config.topP;
347
- config.topK = this.extractNumberValue(trait.config["top_k"]) ?? config.topK;
348
- const systemPrompt = this.extractStringValue(trait.config["system_prompt"]);
349
- if (systemPrompt) {
350
- config.systemPrompt = systemPrompt;
351
- }
352
- }
353
- // ─── Code Generation (TypeScript) ───────────────────────────────────
354
- emitAgentScript(compositionName) {
355
- if (this.options.language === "python") {
356
- return this.emitAgentScriptPython(compositionName);
357
- }
358
- return this.emitAgentScriptTypeScript(compositionName);
359
- }
360
- emitAgentScriptTypeScript(compositionName) {
361
- const lines = [];
362
- lines.push("/**");
363
- lines.push(` * ${compositionName} \u2014 Agent Inference Script`);
364
- lines.push(" * Generated by HoloScript AgentInferenceCompiler");
365
- lines.push(" */");
366
- lines.push("");
367
- lines.push("import Anthropic from '@anthropic-ai/sdk';");
368
- lines.push("import { tools, type ToolName, executeToolCall } from './tools';");
369
- lines.push("import config from './config.json';");
370
- if (this.options.includeTypes) {
371
- lines.push("import type { AgentConfig, AgentState, Message } from './types';");
372
- }
373
- lines.push("");
374
- for (const agent of this.agents) {
375
- lines.push(`// \u2500\u2500\u2500 ${agent.name} \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`);
376
- lines.push("");
377
- lines.push(`export class ${this.toPascalCase(agent.name)}Agent {`);
378
- lines.push(" private client: Anthropic;");
379
- lines.push(" private messages: Anthropic.MessageParam[] = [];");
380
- lines.push(` private systemPrompt: string;`);
381
- lines.push("");
382
- if (agent.stateProperties.length > 0) {
383
- lines.push(" // Agent state");
384
- for (const prop of agent.stateProperties) {
385
- const tsType = prop.type === "number" ? "number" : prop.type === "boolean" ? "boolean" : "string";
386
- lines.push(` private ${prop.key}: ${tsType} = ${JSON.stringify(prop.defaultValue)};`);
387
- }
388
- lines.push("");
389
- }
390
- lines.push(" constructor(apiKey?: string) {");
391
- lines.push(" this.client = new Anthropic({ apiKey: apiKey ?? process.env['ANTHROPIC_API_KEY'] });");
392
- lines.push(` this.systemPrompt = ${JSON.stringify(agent.modelConfig.systemPrompt)};`);
393
- lines.push(" }");
394
- lines.push("");
395
- lines.push(" async run(userMessage: string): Promise<string> {");
396
- lines.push(" this.messages.push({ role: 'user', content: userMessage });");
397
- lines.push("");
398
- lines.push(" const response = await this.client.messages.create({");
399
- lines.push(` model: ${JSON.stringify(agent.modelConfig.name)},`);
400
- lines.push(` max_tokens: ${agent.modelConfig.maxTokens},`);
401
- lines.push(` temperature: ${agent.modelConfig.temperature},`);
402
- lines.push(` top_p: ${agent.modelConfig.topP},`);
403
- lines.push(" system: this.systemPrompt,");
404
- lines.push(" messages: this.messages,");
405
- if (agent.tools.length > 0) {
406
- lines.push(" tools,");
407
- }
408
- lines.push(" });");
409
- lines.push("");
410
- if (agent.tools.length > 0) {
411
- lines.push(" // Handle tool use loop");
412
- lines.push(" let currentResponse = response;");
413
- lines.push(" while (currentResponse.stop_reason === 'tool_use') {");
414
- lines.push(" const toolUseBlocks = currentResponse.content.filter(");
415
- lines.push(" (block): block is Anthropic.ToolUseBlock => block.type === 'tool_use'");
416
- lines.push(" );");
417
- lines.push("");
418
- lines.push(" const toolResults: Anthropic.ToolResultBlockParam[] = [];");
419
- lines.push(" for (const toolUse of toolUseBlocks) {");
420
- lines.push(" const result = await executeToolCall(");
421
- lines.push(" toolUse.name as ToolName,");
422
- lines.push(" toolUse.input as Record<string, unknown>");
423
- lines.push(" );");
424
- lines.push(" toolResults.push({");
425
- lines.push(" type: 'tool_result',");
426
- lines.push(" tool_use_id: toolUse.id,");
427
- lines.push(" content: typeof result === 'string' ? result : JSON.stringify(result),");
428
- lines.push(" });");
429
- lines.push(" }");
430
- lines.push("");
431
- lines.push(" this.messages.push({ role: 'assistant', content: currentResponse.content });");
432
- lines.push(" this.messages.push({ role: 'user', content: toolResults });");
433
- lines.push("");
434
- lines.push(" currentResponse = await this.client.messages.create({");
435
- lines.push(` model: ${JSON.stringify(agent.modelConfig.name)},`);
436
- lines.push(` max_tokens: ${agent.modelConfig.maxTokens},`);
437
- lines.push(` temperature: ${agent.modelConfig.temperature},`);
438
- lines.push(" system: this.systemPrompt,");
439
- lines.push(" messages: this.messages,");
440
- lines.push(" tools,");
441
- lines.push(" });");
442
- lines.push(" }");
443
- lines.push("");
444
- lines.push(" this.messages.push({ role: 'assistant', content: currentResponse.content });");
445
- lines.push(" const textBlocks = currentResponse.content.filter(");
446
- lines.push(" (block): block is Anthropic.TextBlock => block.type === 'text'");
447
- lines.push(" );");
448
- lines.push(" return textBlocks.map((b) => b.text).join('\\n');");
449
- } else {
450
- lines.push(" this.messages.push({ role: 'assistant', content: response.content });");
451
- lines.push(" const textBlocks = response.content.filter(");
452
- lines.push(" (block): block is Anthropic.TextBlock => block.type === 'text'");
453
- lines.push(" );");
454
- lines.push(" return textBlocks.map((b) => b.text).join('\\n');");
455
- }
456
- lines.push(" }");
457
- lines.push("");
458
- lines.push(" reset(): void {");
459
- lines.push(" this.messages = [];");
460
- lines.push(" }");
461
- lines.push("}");
462
- lines.push("");
463
- }
464
- lines.push("// \u2500\u2500\u2500 Main \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
465
- lines.push("");
466
- const primaryAgent = this.agents[0];
467
- lines.push("async function main(): Promise<void> {");
468
- lines.push(` const agent = new ${this.toPascalCase(primaryAgent.name)}Agent();`);
469
- lines.push("");
470
- lines.push(" // Interactive loop (stdin/stdout)");
471
- lines.push(" const readline = await import('readline');");
472
- lines.push(" const rl = readline.createInterface({");
473
- lines.push(" input: process.stdin,");
474
- lines.push(" output: process.stdout,");
475
- lines.push(" });");
476
- lines.push("");
477
- lines.push(` console.log('${this.escapeStringValue(compositionName, "TypeScript")} agent ready. Type a message or "quit" to exit.');`);
478
- lines.push("");
479
- lines.push(" const ask = (): void => {");
480
- lines.push(" rl.question('> ', async (input: string) => {");
481
- lines.push(" if (input.trim().toLowerCase() === 'quit') {");
482
- lines.push(" rl.close();");
483
- lines.push(" return;");
484
- lines.push(" }");
485
- lines.push(" try {");
486
- lines.push(" const response = await agent.run(input);");
487
- lines.push(" console.log(response);");
488
- lines.push(" } catch (err) {");
489
- lines.push(" console.error('Error:', err);");
490
- lines.push(" }");
491
- lines.push(" ask();");
492
- lines.push(" });");
493
- lines.push(" };");
494
- lines.push(" ask();");
495
- lines.push("}");
496
- lines.push("");
497
- lines.push("main().catch(console.error);");
498
- return lines.join("\n");
499
- }
500
- // ─── Code Generation (Python) ───────────────────────────────────────
501
- emitAgentScriptPython(compositionName) {
502
- const lines = [];
503
- lines.push('"""');
504
- lines.push(`${compositionName} \u2014 Agent Inference Script`);
505
- lines.push("Generated by HoloScript AgentInferenceCompiler");
506
- lines.push('"""');
507
- lines.push("");
508
- lines.push("import os");
509
- lines.push("import json");
510
- lines.push("import anthropic");
511
- lines.push("from tools import TOOLS, execute_tool_call");
512
- lines.push("");
513
- for (const agent of this.agents) {
514
- const className = this.toPascalCase(agent.name);
515
- lines.push("");
516
- lines.push(`class ${className}Agent:`);
517
- lines.push(` """${agent.role} agent."""`);
518
- lines.push("");
519
- lines.push(" def __init__(self, api_key: str | None = None):");
520
- lines.push(" self.client = anthropic.Anthropic(");
521
- lines.push(" api_key=api_key or os.environ.get('ANTHROPIC_API_KEY')");
522
- lines.push(" )");
523
- lines.push(` self.system_prompt = ${JSON.stringify(agent.modelConfig.systemPrompt)}`);
524
- lines.push(" self.messages: list[dict] = []");
525
- for (const prop of agent.stateProperties) {
526
- lines.push(` self.${prop.key} = ${JSON.stringify(prop.defaultValue)}`);
527
- }
528
- lines.push("");
529
- lines.push(" def run(self, user_message: str) -> str:");
530
- lines.push(" self.messages.append({'role': 'user', 'content': user_message})");
531
- lines.push("");
532
- lines.push(" response = self.client.messages.create(");
533
- lines.push(` model=${JSON.stringify(agent.modelConfig.name)},`);
534
- lines.push(` max_tokens=${agent.modelConfig.maxTokens},`);
535
- lines.push(` temperature=${agent.modelConfig.temperature},`);
536
- lines.push(" system=self.system_prompt,");
537
- lines.push(" messages=self.messages,");
538
- if (agent.tools.length > 0) {
539
- lines.push(" tools=TOOLS,");
540
- }
541
- lines.push(" )");
542
- lines.push("");
543
- if (agent.tools.length > 0) {
544
- lines.push(" while response.stop_reason == 'tool_use':");
545
- lines.push(" tool_results = []");
546
- lines.push(" for block in response.content:");
547
- lines.push(" if block.type == 'tool_use':");
548
- lines.push(" result = execute_tool_call(block.name, block.input)");
549
- lines.push(" tool_results.append({");
550
- lines.push(" 'type': 'tool_result',");
551
- lines.push(" 'tool_use_id': block.id,");
552
- lines.push(" 'content': str(result),");
553
- lines.push(" })");
554
- lines.push("");
555
- lines.push(" self.messages.append({'role': 'assistant', 'content': response.content})");
556
- lines.push(" self.messages.append({'role': 'user', 'content': tool_results})");
557
- lines.push("");
558
- lines.push(" response = self.client.messages.create(");
559
- lines.push(` model=${JSON.stringify(agent.modelConfig.name)},`);
560
- lines.push(` max_tokens=${agent.modelConfig.maxTokens},`);
561
- lines.push(` temperature=${agent.modelConfig.temperature},`);
562
- lines.push(" system=self.system_prompt,");
563
- lines.push(" messages=self.messages,");
564
- lines.push(" tools=TOOLS,");
565
- lines.push(" )");
566
- lines.push("");
567
- }
568
- lines.push(" self.messages.append({'role': 'assistant', 'content': response.content})");
569
- lines.push(" text_blocks = [b.text for b in response.content if b.type == 'text']");
570
- lines.push(" return '\\n'.join(text_blocks)");
571
- lines.push("");
572
- lines.push(" def reset(self):");
573
- lines.push(" self.messages = []");
574
- lines.push("");
575
- }
576
- const primaryAgent = this.agents[0];
577
- lines.push("");
578
- lines.push("if __name__ == '__main__':");
579
- lines.push(` agent = ${this.toPascalCase(primaryAgent.name)}Agent()`);
580
- lines.push(` print('${this.escapeStringValue(compositionName, "Python")} agent ready. Type a message or "quit" to exit.')`);
581
- lines.push(" while True:");
582
- lines.push(" user_input = input('> ')");
583
- lines.push(" if user_input.strip().lower() == 'quit':");
584
- lines.push(" break");
585
- lines.push(" try:");
586
- lines.push(" print(agent.run(user_input))");
587
- lines.push(" except Exception as e:");
588
- lines.push(" print(f'Error: {e}')");
589
- return lines.join("\n");
590
- }
591
- // ─── Tool Definitions ───────────────────────────────────────────────
592
- emitToolDefinitions(allTools) {
593
- if (this.options.language === "python") {
594
- return this.emitToolDefinitionsPython(allTools);
595
- }
596
- return this.emitToolDefinitionsTypeScript(allTools);
597
- }
598
- emitToolDefinitionsTypeScript(allTools) {
599
- const lines = [];
600
- lines.push("/**");
601
- lines.push(" * Tool definitions for agent inference");
602
- lines.push(" * Generated by HoloScript AgentInferenceCompiler");
603
- lines.push(" */");
604
- lines.push("");
605
- lines.push("import Anthropic from '@anthropic-ai/sdk';");
606
- lines.push("");
607
- const toolNames = allTools.map((t) => `'${t.name}'`);
608
- lines.push(`export type ToolName = ${toolNames.join(" | ")};`);
609
- lines.push("");
610
- lines.push("export const tools: Anthropic.Tool[] = [");
611
- for (const tool of allTools) {
612
- lines.push(" {");
613
- lines.push(` name: ${JSON.stringify(tool.name)},`);
614
- lines.push(` description: ${JSON.stringify(tool.description)},`);
615
- lines.push(" input_schema: {");
616
- lines.push(" type: 'object' as const,");
617
- lines.push(" properties: {");
618
- for (const param of tool.parameters) {
619
- lines.push(` ${param.name}: {`);
620
- lines.push(` type: ${JSON.stringify(this.toJsonSchemaType(param.type))},`);
621
- lines.push(` description: ${JSON.stringify(param.description)},`);
622
- lines.push(" },");
623
- }
624
- lines.push(" },");
625
- const required = tool.parameters.filter((p) => p.required).map((p) => `'${p.name}'`);
626
- if (required.length > 0) {
627
- lines.push(` required: [${required.join(", ")}],`);
628
- }
629
- lines.push(" },");
630
- lines.push(" },");
631
- }
632
- lines.push("];");
633
- lines.push("");
634
- lines.push("export async function executeToolCall(");
635
- lines.push(" name: ToolName,");
636
- lines.push(" input: Record<string, unknown>");
637
- lines.push("): Promise<unknown> {");
638
- lines.push(" switch (name) {");
639
- for (const tool of allTools) {
640
- lines.push(` case ${JSON.stringify(tool.name)}:`);
641
- lines.push(` // TODO: Implement ${tool.name}`);
642
- lines.push(` return \`[${tool.name}] called with: \${JSON.stringify(input)}\`;`);
643
- }
644
- lines.push(" default:");
645
- lines.push(" return `Unknown tool: ${name}`;");
646
- lines.push(" }");
647
- lines.push("}");
648
- return lines.join("\n");
649
- }
650
- emitToolDefinitionsPython(allTools) {
651
- const lines = [];
652
- lines.push('"""');
653
- lines.push("Tool definitions for agent inference");
654
- lines.push("Generated by HoloScript AgentInferenceCompiler");
655
- lines.push('"""');
656
- lines.push("");
657
- lines.push("");
658
- lines.push("TOOLS = [");
659
- for (const tool of allTools) {
660
- lines.push(" {");
661
- lines.push(` "name": ${JSON.stringify(tool.name)},`);
662
- lines.push(` "description": ${JSON.stringify(tool.description)},`);
663
- lines.push(' "input_schema": {');
664
- lines.push(' "type": "object",');
665
- lines.push(' "properties": {');
666
- for (const param of tool.parameters) {
667
- lines.push(` ${JSON.stringify(param.name)}: {`);
668
- lines.push(` "type": ${JSON.stringify(this.toJsonSchemaType(param.type))},`);
669
- lines.push(` "description": ${JSON.stringify(param.description)},`);
670
- lines.push(" },");
671
- }
672
- lines.push(" },");
673
- const required = tool.parameters.filter((p) => p.required).map((p) => JSON.stringify(p.name));
674
- if (required.length > 0) {
675
- lines.push(` "required": [${required.join(", ")}],`);
676
- }
677
- lines.push(" },");
678
- lines.push(" },");
679
- }
680
- lines.push("]");
681
- lines.push("");
682
- lines.push("");
683
- lines.push("def execute_tool_call(name: str, tool_input: dict) -> str:");
684
- for (const tool of allTools) {
685
- lines.push(` if name == ${JSON.stringify(tool.name)}:`);
686
- lines.push(` # TODO: Implement ${tool.name}`);
687
- lines.push(` return f"[${tool.name}] called with: {tool_input}"`);
688
- }
689
- lines.push(` return f"Unknown tool: {name}"`);
690
- return lines.join("\n");
691
- }
692
- // ─── Config & Package Files ─────────────────────────────────────────
693
- emitConfigJson() {
694
- const configs = this.agents.map((a) => ({
695
- name: a.name,
696
- role: a.role,
697
- model: {
698
- provider: a.modelConfig.provider,
699
- name: a.modelConfig.name,
700
- temperature: a.modelConfig.temperature,
701
- max_tokens: a.modelConfig.maxTokens,
702
- top_p: a.modelConfig.topP,
703
- top_k: a.modelConfig.topK
704
- },
705
- system_prompt: a.modelConfig.systemPrompt,
706
- tools: a.tools.map((t) => t.name)
707
- }));
708
- return JSON.stringify({ agents: configs }, null, 2);
709
- }
710
- emitPackageJson(compositionName) {
711
- const pkg = {
712
- name: this.toKebabCase(compositionName) + "-agent",
713
- version: "1.0.0",
714
- description: `Agent inference script for ${compositionName}`,
715
- type: "module",
716
- scripts: {
717
- start: "tsx agent.ts",
718
- build: "tsc"
719
- },
720
- dependencies: {
721
- "@anthropic-ai/sdk": "^0.39.0"
722
- },
723
- devDependencies: {
724
- tsx: "^4.0.0",
725
- typescript: "^5.5.0",
726
- "@types/node": "^20.0.0"
727
- }
728
- };
729
- const providers = new Set(this.agents.map((a) => a.modelConfig.provider));
730
- if (providers.has("openai")) {
731
- pkg.dependencies = { ...pkg.dependencies, openai: "^4.0.0" };
732
- }
733
- return JSON.stringify(pkg, null, 2);
734
- }
735
- emitRequirementsTxt() {
736
- const deps = ["anthropic>=0.39.0"];
737
- const providers = new Set(this.agents.map((a) => a.modelConfig.provider));
738
- if (providers.has("openai")) {
739
- deps.push("openai>=1.0.0");
740
- }
741
- return deps.join("\n") + "\n";
742
- }
743
- emitEnvTemplate() {
744
- const lines = [];
745
- lines.push("# Agent API Keys");
746
- const providers = new Set(this.agents.map((a) => a.modelConfig.provider));
747
- if (providers.has("anthropic")) {
748
- lines.push("ANTHROPIC_API_KEY=sk-ant-...");
749
- }
750
- if (providers.has("openai")) {
751
- lines.push("OPENAI_API_KEY=sk-...");
752
- }
753
- if (providers.has("ollama")) {
754
- lines.push("OLLAMA_HOST=http://localhost:11434");
755
- }
756
- return lines.join("\n") + "\n";
757
- }
758
- emitTypeDefinitions() {
759
- return `/**
760
- * Type definitions for agent inference
761
- * Generated by HoloScript AgentInferenceCompiler
762
- */
763
-
764
- export interface AgentConfig {
765
- name: string;
766
- role: string;
767
- model: {
768
- provider: string;
769
- name: string;
770
- temperature: number;
771
- max_tokens: number;
772
- top_p: number;
773
- top_k: number;
774
- };
775
- system_prompt: string;
776
- tools: string[];
777
- }
778
-
779
- export interface AgentState {
780
- [key: string]: string | number | boolean;
781
- }
782
-
783
- export interface Message {
784
- role: 'user' | 'assistant';
785
- content: string;
786
- }
787
-
788
- export interface ToolResult {
789
- tool_use_id: string;
790
- content: string;
791
- }
792
- `;
793
- }
794
- emitReadme(compositionName) {
795
- this.options.language === "typescript" ? "ts" : "py";
796
- const lines = [];
797
- lines.push(`# ${compositionName} Agent`);
798
- lines.push("");
799
- lines.push("Generated by HoloScript AgentInferenceCompiler.");
800
- lines.push("");
801
- lines.push("## Setup");
802
- lines.push("");
803
- if (this.options.language === "typescript") {
804
- lines.push("```bash");
805
- lines.push("npm install");
806
- lines.push("cp .env.example .env");
807
- lines.push("# Edit .env with your API key");
808
- lines.push("npm start");
809
- lines.push("```");
810
- } else {
811
- lines.push("```bash");
812
- lines.push("pip install -r requirements.txt");
813
- lines.push("cp .env.example .env");
814
- lines.push("# Edit .env with your API key");
815
- lines.push(`python agent.py`);
816
- lines.push("```");
817
- }
818
- lines.push("");
819
- lines.push("## Agents");
820
- lines.push("");
821
- for (const agent of this.agents) {
822
- lines.push(`### ${agent.name}`);
823
- lines.push(`- **Role**: ${agent.role}`);
824
- lines.push(`- **Model**: ${agent.modelConfig.name}`);
825
- lines.push(`- **Tools**: ${agent.tools.length > 0 ? agent.tools.map((t) => t.name).join(", ") : "none"}`);
826
- lines.push("");
827
- }
828
- return lines.join("\n");
829
- }
830
- // ─── Helpers ────────────────────────────────────────────────────────
831
- extractStringValue(value) {
832
- if (typeof value === "string") return value;
833
- return null;
834
- }
835
- extractNumberValue(value) {
836
- if (typeof value === "number") return value;
837
- return null;
838
- }
839
- isModelProvider(value) {
840
- return ["anthropic", "openai", "local", "ollama", "custom"].includes(value);
841
- }
842
- toJsonSchemaType(type) {
843
- switch (type.toLowerCase()) {
844
- case "number":
845
- case "float":
846
- case "int":
847
- case "integer":
848
- return "number";
849
- case "boolean":
850
- case "bool":
851
- return "boolean";
852
- case "array":
853
- case "list":
854
- return "array";
855
- case "object":
856
- case "dict":
857
- case "map":
858
- return "object";
859
- default:
860
- return "string";
861
- }
862
- }
863
- toPascalCase(name) {
864
- return name.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (_, c) => c.toUpperCase());
865
- }
866
- toSnakeCase(name) {
867
- return name.replace(/([A-Z])/g, "_$1").replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_/, "").toLowerCase();
868
- }
869
- toKebabCase(name) {
870
- return name.replace(/([A-Z])/g, "-$1").replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-/, "").toLowerCase();
871
- }
872
- };
873
- function createAgentInferenceCompiler(options) {
874
- return new AgentInferenceCompiler(options);
875
- }
876
- function createPythonAgentInferenceCompiler(options) {
877
- return new AgentInferenceCompiler({ ...options, language: "python" });
878
- }
879
- var AgentInferenceExportTarget_default = AgentInferenceCompiler;
880
-
881
- export { AgentInferenceCompiler, AgentInferenceExportTarget_default, createAgentInferenceCompiler, createPythonAgentInferenceCompiler };
882
- //# sourceMappingURL=chunk-CNVM7J3M.js.map
883
- //# sourceMappingURL=chunk-CNVM7J3M.js.map