Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ jobs:
run: find . -name moon.pkg -exec dirname {} \; | xargs moon check --target wasm
working-directory: sdks/moonbit/golem_sdk
- name: Test SDK
run: find . -name moon.pkg -exec dirname {} \; | xargs moon test --target wasm
run: ./scripts/run-sdk-tests.sh
working-directory: sdks/moonbit/golem_sdk
- name: Check tools
run: moon check cmd lib
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/publish-golem-moonbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ jobs:
working-directory: sdks/moonbit/golem_sdk
run: |
VERSION=${{ steps.get_version.outputs.version }}
sed -i "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" moon.mod.json
sed -i "s/^version = \".*\"$/version = \"$VERSION\"/" moon.mod
test "$(grep -Fxc "version = \"$VERSION\"" moon.mod)" -eq 1

- name: Set version in golem_sdk_tools
working-directory: sdks/moonbit/golem_sdk_tools
run: |
VERSION=${{ steps.get_version.outputs.version }}
sed -i "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" moon.mod.json
sed -i "s/^version = \".*\"$/version = \"$VERSION\"/" moon.mod
test "$(grep -Fxc "version = \"$VERSION\"" moon.mod)" -eq 1

- name: Check SDK
run: find . -name moon.pkg -exec dirname {} \; | xargs moon check --target wasm
working-directory: sdks/moonbit/golem_sdk

- name: Test SDK
run: find . -name moon.pkg -exec dirname {} \; | xargs moon test --target wasm
run: ./scripts/run-sdk-tests.sh
working-directory: sdks/moonbit/golem_sdk

- name: Install tools dependencies
Expand Down
12 changes: 6 additions & 6 deletions cli/golem-cli/src/model/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ impl Application {
.map(|component| &component.templates),
)
.flat_map(|templates| templates.clone().into_vec())
.filter_map(GuestLanguage::from_id_string)
.filter_map(GuestLanguage::from_component_template_name)
})
.collect()
}
Expand Down Expand Up @@ -2008,12 +2008,12 @@ impl<'a> Component<'a> {
self.component_name
}

// Guesses the language from the applied language templates, which are named after the
// language id they provide (see `GuestLanguage::from_id_string`).
// Guesses the language from the language-prefixed applied templates.
pub fn guess_language(&self) -> Option<GuestLanguage> {
self.applied_layers()
.iter()
.find_map(|(id, _)| id.template_name().and_then(GuestLanguage::from_id_string))
self.applied_layers().iter().find_map(|(id, _)| {
id.template_name()
.and_then(GuestLanguage::from_component_template_name)
})
}

pub fn source(&self) -> &Path {
Expand Down
34 changes: 34 additions & 0 deletions cli/golem-cli/src/model/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ impl GuestLanguage {
}
}

pub fn from_component_template_name(s: impl AsRef<str>) -> Option<GuestLanguage> {
let template_name = s.as_ref();
let language_id = template_name
.split_once('-')
.map_or(template_name, |(language_id, _)| language_id);
Self::from_id_string(language_id)
}

pub fn id(&self) -> &'static str {
match self {
GuestLanguage::Rust => "rust",
Expand Down Expand Up @@ -102,3 +110,29 @@ impl FromStr for GuestLanguage {
})
}
}

#[cfg(test)]
mod tests {
use super::GuestLanguage;
use test_r::test;

#[test]
fn component_template_names_retain_their_language_prefix() {
assert_eq!(
GuestLanguage::from_component_template_name("moonbit-tool-middleware"),
Some(GuestLanguage::MoonBit)
);
assert_eq!(
GuestLanguage::from_component_template_name("ts-agent-tool-middleware"),
Some(GuestLanguage::TypeScript)
);
assert_eq!(
GuestLanguage::from_component_template_name("rust"),
Some(GuestLanguage::Rust)
);
assert_eq!(
GuestLanguage::from_component_template_name("custom-moonbit"),
None
);
}
}
70 changes: 64 additions & 6 deletions cli/golem-cli/templates/moonbit/common-on-demand/golem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,85 @@ componentTemplates:
debug:
default: true
build:
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD reexports "GOLEM_MOONBIT_BUILD_SDK_PATH" "{{ componentDir }}"
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD reexports "GOLEM_MOONBIT_BUILD_SDK_PATH" "{{ componentDir }}" --role ordinary
dir: "{{ appRootDir }}"
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD agents "{{ appRootDir }}"
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD agents "{{ appRootDir }}" --component-dir "{{ componentDir }}" --role ordinary
dir: "{{ appRootDir }}"
- command: moon build --target wasm
dir: "{{ appRootDir }}"
- command: wasm-tools component embed "GOLEM_MOONBIT_BUILD_SDK_PATH/wit" "{{ appRootDir }}/_build/wasm/debug/build/{{ moonbitBuildPackagePath }}" --encoding utf16 --output "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.embed.wasm"
- command: wasm-tools component embed "GOLEM_MOONBIT_BUILD_SDK_PATH/wit" "{{ appRootDir }}/_build/wasm/debug/build/{{ moonbitBuildPackagePath }}" --world agent-guest --encoding utf16 --output "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.embed.wasm"
mkdirs:
- "{{ appRootDir }}/_build/wasm/debug"
- command: wasm-tools component new "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.embed.wasm" --output "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.agent.wasm"
componentWasm: "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.agent.wasm"
release:
build:
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD reexports "GOLEM_MOONBIT_BUILD_SDK_PATH" "{{ componentDir }}"
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD reexports "GOLEM_MOONBIT_BUILD_SDK_PATH" "{{ componentDir }}" --role ordinary
dir: "{{ appRootDir }}"
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD agents "{{ appRootDir }}"
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD agents "{{ appRootDir }}" --component-dir "{{ componentDir }}" --role ordinary
dir: "{{ appRootDir }}"
- command: moon build --target wasm --release
dir: "{{ appRootDir }}"
- command: wasm-tools component embed "GOLEM_MOONBIT_BUILD_SDK_PATH/wit" "{{ appRootDir }}/_build/wasm/release/build/{{ moonbitBuildPackagePath }}" --encoding utf16 --output "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.embed.wasm"
- command: wasm-tools component embed "GOLEM_MOONBIT_BUILD_SDK_PATH/wit" "{{ appRootDir }}/_build/wasm/release/build/{{ moonbitBuildPackagePath }}" --world agent-guest --encoding utf16 --output "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.embed.wasm"
mkdirs:
- "{{ appRootDir }}/_build/wasm/release"
- command: wasm-tools component new "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.embed.wasm" --output "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.agent.wasm"
componentWasm: "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.agent.wasm"
moonbit-tool-middleware:
presets:
debug:
default: true
build:
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD reexports "GOLEM_MOONBIT_BUILD_SDK_PATH" "{{ componentDir }}" --role tool-middleware
dir: "{{ appRootDir }}"
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD agents "{{ appRootDir }}" --component-dir "{{ componentDir }}" --role tool-middleware
dir: "{{ appRootDir }}"
- command: moon build --target wasm
dir: "{{ appRootDir }}"
- command: wasm-tools component embed "GOLEM_MOONBIT_BUILD_SDK_PATH/wit" "{{ appRootDir }}/_build/wasm/debug/build/{{ moonbitBuildPackagePath }}" --world tool-middleware-guest --encoding utf16 --output "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.tool-middleware.embed.wasm"
mkdirs:
- "{{ appRootDir }}/_build/wasm/debug"
- command: wasm-tools component new "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.tool-middleware.embed.wasm" --output "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.tool-middleware.wasm"
componentWasm: "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.tool-middleware.wasm"
release:
build:
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD reexports "GOLEM_MOONBIT_BUILD_SDK_PATH" "{{ componentDir }}" --role tool-middleware
dir: "{{ appRootDir }}"
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD agents "{{ appRootDir }}" --component-dir "{{ componentDir }}" --role tool-middleware
dir: "{{ appRootDir }}"
- command: moon build --target wasm --release
dir: "{{ appRootDir }}"
- command: wasm-tools component embed "GOLEM_MOONBIT_BUILD_SDK_PATH/wit" "{{ appRootDir }}/_build/wasm/release/build/{{ moonbitBuildPackagePath }}" --world tool-middleware-guest --encoding utf16 --output "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.tool-middleware.embed.wasm"
mkdirs:
- "{{ appRootDir }}/_build/wasm/release"
- command: wasm-tools component new "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.tool-middleware.embed.wasm" --output "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.tool-middleware.wasm"
componentWasm: "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.tool-middleware.wasm"
moonbit-agent-tool-middleware:
presets:
debug:
default: true
build:
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD reexports "GOLEM_MOONBIT_BUILD_SDK_PATH" "{{ componentDir }}" --role combined
dir: "{{ appRootDir }}"
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD agents "{{ appRootDir }}" --component-dir "{{ componentDir }}" --role combined
dir: "{{ appRootDir }}"
- command: moon build --target wasm
dir: "{{ appRootDir }}"
- command: wasm-tools component embed "GOLEM_MOONBIT_BUILD_SDK_PATH/wit" "{{ appRootDir }}/_build/wasm/debug/build/{{ moonbitBuildPackagePath }}" --world agent-tool-middleware-guest --encoding utf16 --output "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.agent-tool-middleware.embed.wasm"
mkdirs:
- "{{ appRootDir }}/_build/wasm/debug"
- command: wasm-tools component new "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.agent-tool-middleware.embed.wasm" --output "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.agent-tool-middleware.wasm"
componentWasm: "{{ appRootDir }}/_build/wasm/debug/{{ componentName | to_snake_case }}.agent-tool-middleware.wasm"
release:
build:
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD reexports "GOLEM_MOONBIT_BUILD_SDK_PATH" "{{ componentDir }}" --role combined
dir: "{{ appRootDir }}"
- command: GOLEM_MOONBIT_BUILD_TOOLS_CMD agents "{{ appRootDir }}" --component-dir "{{ componentDir }}" --role combined
dir: "{{ appRootDir }}"
- command: moon build --target wasm --release
dir: "{{ appRootDir }}"
- command: wasm-tools component embed "GOLEM_MOONBIT_BUILD_SDK_PATH/wit" "{{ appRootDir }}/_build/wasm/release/build/{{ moonbitBuildPackagePath }}" --world agent-tool-middleware-guest --encoding utf16 --output "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.agent-tool-middleware.embed.wasm"
mkdirs:
- "{{ appRootDir }}/_build/wasm/release"
- command: wasm-tools component new "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.agent-tool-middleware.embed.wasm" --output "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.agent-tool-middleware.wasm"
componentWasm: "{{ appRootDir }}/_build/wasm/release/{{ componentName | to_snake_case }}.agent-tool-middleware.wasm"
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
///|
#derive.agent
struct CombinedAgent {
name : String
}

///|
fn CombinedAgent::new(name : String) -> CombinedAgent {
{ name, }
}

///|
pub fn CombinedAgent::get_name(self : Self) -> String {
self.name
}

///|
pub fn CombinedAgent::use_ambient_tool(self : Self) -> Unit {
let client = @tool.ToolClient::new(self.name)
client.drop()
}

///|
#derive.universal_tool_middleware("combined-audit")
pub async fn combined_audit(
invocation : @toolMiddleware.RawToolInvocation,
underlying : @toolMiddleware.UnderlyingTool,
) -> Result[
@toolMiddleware.RawInvocationResult,
@toolMiddleware.ToolInvokeError[@toolMiddleware.RawTypedSchemaValue],
] {
underlying.invoke_raw(
invocation.command_path(),
invocation.input(),
invocation.stdin(),
)
}

///|
fn main {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
"golemcloud/golem_sdk/tool" @tool,
"golemcloud/golem_sdk/tool-middleware" @toolMiddleware,
}

options(
"is-main": true,
)
22 changes: 22 additions & 0 deletions cli/golem-cli/test-data/moonbit-tool-middleware-roles/golem.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
manifestVersion: 1.6.0

app: moonbit-tool-middleware-roles

version: v0.0.0

environments:
local:
server: local
componentPresets: debug
version: v0.0.0

components:
moonbit-tool-middleware-roles:ordinary:
dir: ordinary
templates: moonbit
moonbit-tool-middleware-roles:middleware:
dir: middleware
templates: moonbit-tool-middleware
moonbit-tool-middleware-roles:combined:
dir: combined
templates: moonbit-agent-tool-middleware
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
///|
#derive.universal_tool_middleware("pure-audit")
pub async fn pure_audit(
invocation : @toolMiddleware.RawToolInvocation,
underlying : @toolMiddleware.UnderlyingTool,
) -> Result[
@toolMiddleware.RawInvocationResult,
@toolMiddleware.ToolInvokeError[@toolMiddleware.RawTypedSchemaValue],
] {
underlying.invoke_raw(
invocation.command_path(),
invocation.input(),
invocation.stdin(),
)
}

///|
fn main {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {
"golemcloud/golem_sdk/tool-middleware" @toolMiddleware,
}

options(
"is-main": true,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "moonbit-tool-middleware-roles",
"version": "0.0.0",
"preferred-target": "wasm",
"deps": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
///|
#derive.agent
struct OrdinaryAgent {
name : String
}

///|
fn OrdinaryAgent::new(name : String) -> OrdinaryAgent {
{ name, }
}

///|
pub fn OrdinaryAgent::get_name(self : Self) -> String {
self.name
}

///|
pub fn OrdinaryAgent::use_ambient_tool(self : Self) -> Unit {
let client = @tool.ToolClient::new(self.name)
client.drop()
}

///|
fn main {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {
"golemcloud/golem_sdk/tool" @tool,
}

options(
"is-main": true,
)
1 change: 1 addition & 0 deletions cli/golem-cli/tests/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod app;
mod build_and_deploy_all;
mod cards;
mod directory_source_ifs;
mod moonbit_tool_middleware;
mod plugins;

inherit_test_dep!(Tracing);
Expand Down
Loading
Loading