Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Conversation

@vigoo
Copy link
Contributor

@vigoo vigoo commented Jul 30, 2025

Work in progress

Resolves golemcloud/golem#1831
Resolves golemcloud/golem#1840

A couple of things are not good enough for a final release, but I would deal with them separately from this PR:

  • Replaced the default TS template group to be the agent one, because the CLI only supports the one named default at the moment (even though it is prepared to support multiple template groups per language). So the only TS template available now is the new one.
  • There is a very hacky hardcoded check in the linker mock that prevents overriding some WASI resources with mocks (pollable and input-stream and output-stream). I could not figure out how to do it properly and my guess is that it will have to be done in the wasmtime fork because some things are not exposed. Also I noticed that wasmtime itself has a very similar function to mock unavailable imports but that does not work either (for multiple reasons, there is also an open ticket about it in wasmtime).
  • The TS agent component is "witless" but many things in golem-cli depends on resolved WIT packages. So the PR adds support for pointing to a WASM (in this case, the precompiled golem_agent.wasm as the source wit and with that things are working - more or less. The transformation from the "source wit" to the "generated wit dir" is turned off in this case and this definitely breaks all the dependency related golem-cli features. This will have to be solved, at least partially, to be able to link with the golem-ai components, but can be done separately.
  • No effort have been made to have "up-to-date checks" for the new special build steps

Testable with

golem app new 
-> give a name
-> select ts
-> give a package name like `my:agent`
golem app ts-npm-install
golem app build

Requires a new published version of the agent SDK (golemcloud/golem-agentic#12) to finish testing the wrapping steps because right now it fails on the agent type extraction due to the wrong golem:rpc version used in the last published SDK package.

@afsalthaj
Copy link
Contributor

After I change ts-user to use rollup (instead of tsup) let's have a quick catchup to align a few things

args = ["--interfaces", "127.0.0.1", "--port", "41357", "schema.golem.cloud"]

## Agent template management
[tasks.rebuild-ts-agent-template]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a manual step on purpose. We will run it whenever we want to update the "base wasm" for agents, and the compiled WASM itself is part of the template. There is no need to do this on every build.

Ok(result)
}

fn jco_async_export_args(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed support for componentize.js/jco completely, as wasm-rquickjs seems to work well

ComponentItem::Type(_) => {}
ComponentItem::Resource(_resource) => {
resources.entry((name, inner_name)).or_default();
if &inner_name != "pollable"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The horrible hack mentioned in the PR description


const externalPackages = (id) => {
return (
id === "@afsalthaj/golem-ts-sdk" ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: replace with @golemcloud when published

Copy link
Contributor

@afsalthaj afsalthaj Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

published to golemcloud now.

@golemcloud/golem-ts-sdk@0.0.1-dev.3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Versions may keep getting updated, but ts-user is also updated with dev.3, the import statements changed after changing to golemcloud

@@ -0,0 +1,15 @@
import '../.metadata/metadata.index';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was generated build-time in Afsal's prototype but there is no need to do so, so I've just "hid it" in a different directory than src but it is just part of the template.

Copy link
Contributor

@afsalthaj afsalthaj Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get you.

  1. Why is generated file (the output of npm run build) part of the template even under hidden files?
  2. npm run build for user code builds a ts under .generated folder in prototype and then it gets build to dist/index.mjs
  3. If these are not used, then it won't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no npm run build just golem app build. Nothing was dynamic in that generated file, so it is no longer generated just part of the template.


templates:
ts:
build:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the TS agent build flow.

  • two calls to npx, first generated the type info, the second runs rollup to generate the bundled main.js
  • then we inject the main.js into pre-compiled golem_agent.wasm
  • then generate the static agent wrapper (this first extracts the agent types by instantiating the component and this is where we currently fail because of the old package version)
  • then compose with the generated wrapper to get the final component

@vigoo vigoo marked this pull request as ready for review August 4, 2025 15:10
@noise64
Copy link
Contributor

noise64 commented Aug 4, 2025

golem-cli --config-dir /tmp/.tmpDrVKuM app new test-app-name c go typescript rust
Assertion failed at golem-cli/tests/app/mod.rs:89:5:
assert!( outputs.success() )
with expansion:
false

status: exit status: 1
stdout: Selected profile: local
stdout: Created application directory: test-app-name
stdout: error: Template ts not found!

@vigoo vigoo merged commit 62f3644 into main Aug 5, 2025
4 checks passed
@vigoo vigoo deleted the ts-agent-template branch August 5, 2025 14:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

4 participants