golem_rust_macro/
lib.rs

1// Copyright 2024-2025 Golem Cloud
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use proc_macro::TokenStream;
16use syn::DeriveInput;
17
18use crate::transaction::golem_operation_impl;
19
20mod agentic;
21mod transaction;
22mod value;
23
24#[proc_macro_derive(IntoValue, attributes(flatten_value, unit_case))]
25pub fn derive_into_value(input: TokenStream) -> TokenStream {
26    let ast: DeriveInput = syn::parse(input).expect("derive input");
27
28    value::derive_into_value(&ast)
29}
30
31#[proc_macro_derive(FromValueAndType, attributes(flatten_value, unit_case))]
32pub fn derive_from_value_and_type(input: TokenStream) -> TokenStream {
33    let ast: DeriveInput = syn::parse(input).expect("derive input");
34    value::derive_from_value_and_type(&ast)
35}
36
37#[proc_macro_derive(MultimodalSchema)]
38pub fn derive_multimodal(input: TokenStream) -> TokenStream {
39    agentic::derive_multimodal(input)
40}
41
42#[proc_macro_derive(Schema)]
43pub fn derive_schema(input: TokenStream) -> TokenStream {
44    agentic::derive_schema(input)
45}
46
47#[proc_macro_derive(AllowedLanguages, attributes(code))]
48pub fn derive_allowed_languages(input: TokenStream) -> TokenStream {
49    agentic::derive_allowed_languages(input)
50}
51
52#[proc_macro_derive(AllowedMimeTypes, attributes(mime_type))]
53pub fn derive_allowed_mimetypes(input: TokenStream) -> TokenStream {
54    agentic::derive_allowed_mime_types(input)
55}
56
57/// Defines a function as an `Operation` that can be used in transactions
58#[proc_macro_attribute]
59pub fn golem_operation(attr: TokenStream, item: TokenStream) -> TokenStream {
60    golem_operation_impl(attr, item)
61}
62
63#[proc_macro_attribute]
64pub fn agent_definition(attr: TokenStream, item: TokenStream) -> TokenStream {
65    agentic::agent_definition_impl(attr, item)
66}
67
68#[proc_macro_attribute]
69pub fn agent_implementation(attr: TokenStream, item: TokenStream) -> TokenStream {
70    agentic::agent_implementation_impl(attr, item)
71}