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