TiddlyWiki5 icon indicating copy to clipboard operation
TiddlyWiki5 copied to clipboard

[IDEA] Info tiddler for client-server setup, and run action on server side when on client-server setup

Open linonetwo opened this issue 9 months ago • 5 comments

Is your feature request related to a problem? Please describe.

Long running task like AI procedures may have performance impact, cause lagging on user interface (until we have async-rendering and fiber artecture like ReactJS)

And AI may need to do "function calling" or "comupter use" with https://modelcontextprotocol.io/quickstart/user or https://www.w3.org/community/webagents/ , this needs to be run on server side. (I assume user is using nodejs on localhost of his own PC, a cloud nodejs wiki provider like tiddlyweb should run nodejs instance in sandboxed invironment)

Describe the solution you'd like

A new info tiddler indecates this tw instance is client-server setup (nodejs wiki, tiddlyweb, or MWS), and it is on its client side or server side.

An official server route to run $:/Tags/Action tiddler on server side. A new action widget to trigger calling of this server route, and it can capture variables from environment as context to send to server together.

Describe alternatives you've considered

Or we could completely give up AI function calling integration, and always call external app like clude desktop from frontend, but this will make Tiddlywiki never AI-native.

Additional context

I just read the https://modelcontextprotocol.io/quickstart/user and saw it can run tools from cli. I can make a plugin with it, but instead of rely on its package, I want to make "computer use" native to tiddlywiki.

And this may allow perform relink on server side, when client side tiddlers are lazy-loaded https://github.com/TiddlyWiki/TiddlyWiki5/issues/4767

linonetwo avatar Mar 11 '25 15:03 linonetwo

I think there is already an action widget which can trigger an arbitrary HTTP request.

Server routes are dead simple to implement yourself.

For determining whether you're on the server client you have multiple options including checking $tw.node and $tw.browser, checking whether the sync adapter is file system or tiddlyweb.

If you need the check in the wiki, you could check for the presence of tiddlers which are known to only be on the client such as some of the tiddlyweb state tiddlers.

You can also exclude specific tiddlers from being sent to the client using filters and then check whether those are present or not.

Arlen22 avatar Apr 06 '25 13:04 Arlen22

@Arlen22 I want to standardlize this, to encourage plugin authors use this more. So it can speed up all nodejs wiki.

It will feels like https://react.dev/reference/rsc/use-server , run expensive actions on server, and wait for SSE to push result back to frontend.

linonetwo avatar Apr 06 '25 15:04 linonetwo

I think the standard way to do it would be for the server to push the response to a tiddler, which then gets synced back to the client. The client could specify the name of the output tiddler in its request to the server.

The existing http action widget probably isn't at all intuitive for anyone who is used to using fetch.

I wonder if there is a way to improve the action widget (at least from a developer perspective without making it hard for users to work with).

Arlen22 avatar Apr 06 '25 15:04 Arlen22

I see what you mean though. It feels like all the pieces are there but none of them are put together.

Arlen22 avatar Apr 06 '25 16:04 Arlen22

Also I need this to be a standard route, so I can safely implement it as an IPC call on TidGi, like I've implement SSE as an IPC but since its PR was rejected, I'm not very cretain about it now.

https://github.com/tiddly-gittly/TidGi-Desktop/blob/29a9e4555dada49f471b7f6727c6b04fb3aa45fa/src/services/wiki/wikiWorker/ipcServerRoutes.ts#L51-L56 (This prevent data lost when wiki switch, which will cause ip change. And is more secure and fast as it use IPC instead of HTTP request)

The plan is to support triggering server-side AI agent operations, expecially MCP tool calling that requires access to nodejs. For now, without it, I have to implement AI features directly on TidGi app, instead of TW plugins.

linonetwo avatar Apr 13 '25 17:04 linonetwo