Will the Lua support eventually have a way to do the autocommit portion every 5 mins as well? Is there some sort of internal timer event that the Lua code could add a listener for?
What do you think about simply having a cron:second event that triggers every second (obviously)? It’s then possible to build fancier abstractions on top of that (like a proper cron scheduler).
This stuff will only make it to the v2 branch, but:
local secondsPassed = 0
event.listen {
name = "cron:secondPassed",
run = function()
secondsPassed = secondsPassed + 1
if secondsPassed % 60 == 20 then
print "Comittin' time"
git.sync()
end
end
}
Sounds good. Seems secondsPassed could grow to some large number if one doesn’t ‘System: Reload’ or reindex from time to time but maybe that is a non-issue.
You could also just look at the local time and see if it’s a multiple of x
Why keep a timer if you already have a clock Unless the time since first load is important of course. But then you could also just store that and subtract it from the clock.
It is pretty cool, I was able to whip up a quick “stream llm chat to editor” lua script with working streaming.
local openaiLib = js.import("https://esm.sh/[email protected]")
local openaiClient = js.new(openaiLib.OpenAI, {apiKey=apiKey, dangerouslyAllowBrowser=true})
function streamCompletionIntoEditor2(messages)
local startPos = string.len(editor.getText())
local resp = openaiClient.chat.completions.create({
model = "gpt-4o",
stream = true,
messages = js.tojs(messages)})
local fullResponse = "\n**Assistant**: "
editor.insertAtPos(fullResponse, startPos)
for value in js.eachIterable(resp) do
local newDelta = value.choices[1].delta.content
if newDelta ~= "" and newDelta ~= nil then
editor.insertAtPos(newDelta, startPos + string.len(fullResponse))
fullResponse = fullResponse + newDelta
end
end
editor.insertAtPos("\n**User**: ", startPos + string.len(fullResponse))
editor.moveCursor(startPos + string.len(fullResponse) + string.len("\n**User**: "), true)
end
Definitely missing features (and cheating by using an external lib), but I wasn’t expecting it to be so easy either
@justyns I have been building something very similar as a toy thing to stress test Lua. Will share it later. I also implemented (streaming chat) and a few other nice things.
Assuming that listening to cron:secondPassed causes a callback every second, no I was thinking more of SilverBullet’s plug manager or someone having a list of who wants to be called and when, allowing for just one callback that runs every second instead of one per plug.
But I guess my idea trades off fewer per second function calls for a single point of failure.
And that’s assuming I’ve not wildly misunderstood cron:secondPassed’s behaviour
First thanks for silvrbullet I really like
One question about the event, what happens when I close silverbullet, the events are launching while is closed? or is only working when the client is open?
I was want to do something that is launched in cron when silverbullet is closed.
I wanted to do:
Each morning read a list of objects generate a promt feed to an AI and sent a email/telebran bot message or something like that.
Events only trigger when the client is open and active (browsers even stop scheduling events, or at least delay them when a tab or window isn’t active). At least this is how it works in Sync mode and in v2, no real way around that. In v1, since Lua code also runs on the server, your client doesn’t need to be active.
I'm here coming from TiddlyWiki as my main Inter Personal Knowledge Management software and I had the fortune of finding SilverBullet while looking for a Lua way of accesing the SQLite LogSeq DB and found the Logseq to SilverBullet conversion script.
I have been successfully avoiding JS infamous syntax and its hypertrophied ecosystem for almost 20 years and I'm grateful for the people that goes deep there to allow other people to avoid it, like with SB or the hypermedia systems like HTMX or Datastar, bringing the possibility to develop rich interactive web experience without user/developer facing JS/TS. In fact, before knowing about hypermedia systems (HS) I imagined a Lua powered way of extending TiddlyWiki and once I found HS, my plan was to implement the idea by evolving Cardumem from a Lua based static site generator to an hypermedia wiki engine, extensible in YueScript, which is syntactically lighter but transpiles to Lua and its compatible with its ecosystem.
So yes, Lua and its variations/ecosystem are super cool and I'm pretty happy SB uses it as its extension language. In fact I think that I found SB previously but, if I remember well, its extension story was over complicated with a lot of JS/TS leaking to the user compared with the Space Lua . I'm pretty happy of the change.
BTW, here is the customary meme on why avoiding JS: