Skip to content

Commit 668085c

Browse files
committed
got dynamic tsunami widget descriptions
1 parent 73a74be commit 668085c

11 files changed

Lines changed: 134 additions & 20 deletions

File tree

cmd/wsh/cmd/wshcmd-ssh.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,26 @@ func sshRun(cmd *cobra.Command, args []string) (rtnErr error) {
8080
data := wshrpc.CommandSetMetaData{
8181
ORef: waveobj.MakeORef(waveobj.OType_Block, blockId),
8282
Meta: map[string]any{
83-
waveobj.MetaKey_Connection: sshArg,
84-
waveobj.MetaKey_CmdCwd: nil,
85-
waveobj.MetaKey_CmdHasCurCwd: nil,
83+
waveobj.MetaKey_Connection: sshArg,
84+
waveobj.MetaKey_CmdCwd: nil,
8685
},
8786
}
8887
err := wshclient.SetMetaCommand(RpcClient, data, nil)
8988
if err != nil {
9089
return fmt.Errorf("setting connection in block: %w", err)
9190
}
91+
92+
// Clear the cmd:hascurcwd rtinfo field
93+
rtInfoData := wshrpc.CommandSetRTInfoData{
94+
ORef: waveobj.MakeORef(waveobj.OType_Block, blockId),
95+
Data: map[string]any{
96+
"cmd:hascurcwd": nil,
97+
},
98+
}
99+
err = wshclient.SetRTInfoCommand(RpcClient, rtInfoData, nil)
100+
if err != nil {
101+
return fmt.Errorf("setting RTInfo in block: %w", err)
102+
}
92103
WriteStderr("switched connection to %q\n", sshArg)
93104
return nil
94105
}

frontend/app/modals/conntypeahead.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,17 @@ const ChangeConnectionBlockModal = React.memo(
401401
}
402402
await RpcApi.SetMetaCommand(TabRpcClient, {
403403
oref: WOS.makeORef("block", blockId),
404-
meta: { connection: connName, file: newFile, "cmd:cwd": null, "cmd:hascurcwd": null },
404+
meta: { connection: connName, file: newFile, "cmd:cwd": null },
405405
});
406+
407+
const rtInfo = { "cmd:hascurcwd": null };
408+
const rtInfoData: CommandSetRTInfoData = {
409+
oref: WOS.makeORef("block", blockId),
410+
data: rtInfo
411+
};
412+
RpcApi.SetRTInfoCommand(TabRpcClient, rtInfoData).catch((e) =>
413+
console.log("error setting RT info", e)
414+
);
406415
try {
407416
await RpcApi.ConnEnsureCommand(
408417
TabRpcClient,

frontend/app/view/term/termwrap.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,20 @@ function handleOsc7Command(data: string, blockId: string, loaded: boolean): bool
125125
data = data.substring(nextSlashIdx);
126126
}
127127
setTimeout(() => {
128-
fireAndForget(() =>
129-
services.ObjectService.UpdateObjectMeta(WOS.makeORef("block", blockId), {
128+
fireAndForget(async () => {
129+
await services.ObjectService.UpdateObjectMeta(WOS.makeORef("block", blockId), {
130130
"cmd:cwd": data,
131-
"cmd:hascurcwd": true,
132-
})
133-
);
131+
});
132+
133+
const rtInfo = { "cmd:hascurcwd": true };
134+
const rtInfoData: CommandSetRTInfoData = {
135+
oref: WOS.makeORef("block", blockId),
136+
data: rtInfo
137+
};
138+
await RpcApi.SetRTInfoCommand(TabRpcClient, rtInfoData).catch((e) =>
139+
console.log("error setting RT info", e)
140+
);
141+
});
134142
}, 0);
135143
return true;
136144
}

frontend/types/gotypes.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ declare global {
557557
"cmd:initscript.zsh"?: string;
558558
"cmd:initscript.pwsh"?: string;
559559
"cmd:initscript.fish"?: string;
560-
"cmd:hascurcwd"?: boolean;
561560
"ai:*"?: boolean;
562561
"ai:preset"?: string;
563562
"ai:apitype"?: string;
@@ -636,6 +635,8 @@ declare global {
636635
type ObjRTInfo = {
637636
"tsunami:title"?: string;
638637
"tsunami:shortdesc"?: string;
638+
"tsunami:schemas"?: any;
639+
"cmd:hascurcwd"?: boolean;
639640
};
640641

641642
// iochantypes.Packet

pkg/aiusechat/tools.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@ import (
1010

1111
"github.com/google/uuid"
1212
"github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes"
13+
"github.com/wavetermdev/waveterm/pkg/blockcontroller"
1314
"github.com/wavetermdev/waveterm/pkg/waveobj"
1415
"github.com/wavetermdev/waveterm/pkg/wstore"
1516
)
1617

18+
func handleTsunamiBlockDesc(block *waveobj.Block) string {
19+
status := blockcontroller.GetBlockControllerRuntimeStatus(block.OID)
20+
if status == nil || status.ShellProcStatus != blockcontroller.Status_Running {
21+
return "tsunami framework widget that is currently not running"
22+
}
23+
24+
blockORef := waveobj.MakeORef(waveobj.OType_Block, block.OID)
25+
rtInfo := wstore.GetRTInfo(blockORef)
26+
if rtInfo != nil && rtInfo.TsunamiShortDesc != "" {
27+
return fmt.Sprintf("tsunami widget - %s", rtInfo.TsunamiShortDesc)
28+
}
29+
return "tsunami widget - unknown description"
30+
}
31+
1732
func MakeBlockShortDesc(block *waveobj.Block) string {
1833
if block.Meta == nil {
1934
return ""
@@ -28,7 +43,10 @@ func MakeBlockShortDesc(block *waveobj.Block) string {
2843
case "term":
2944
connection, hasConnection := block.Meta["connection"].(string)
3045
cwd, hasCwd := block.Meta["cmd:cwd"].(string)
31-
hasCurCwd, _ := block.Meta["cmd:hascurcwd"].(bool)
46+
47+
blockORef := waveobj.MakeORef(waveobj.OType_Block, block.OID)
48+
rtInfo := wstore.GetRTInfo(blockORef)
49+
hasCurCwd := rtInfo != nil && rtInfo.CmdHasCurCwd
3250

3351
var desc string
3452
if hasConnection && connection != "" {
@@ -75,7 +93,7 @@ func MakeBlockShortDesc(block *waveobj.Block) string {
7593
case "launcher":
7694
return "placeholder widget used to launch other widgets"
7795
case "tsunami":
78-
return "custom 'tsunami' framework widget"
96+
return handleTsunamiBlockDesc(block)
7997
default:
8098
return fmt.Sprintf("unknown widget with type %q", viewType)
8199
}

pkg/blockcontroller/tsunamicontroller.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@ package blockcontroller
55

66
import (
77
"context"
8+
"encoding/json"
89
"fmt"
910
"io"
1011
"log"
12+
"net/http"
1113
"os"
1214
"os/exec"
1315
"path/filepath"
1416
"runtime"
1517
"strings"
1618
"sync"
1719
"syscall"
20+
"time"
1821

1922
"github.com/wavetermdev/waveterm/pkg/utilds"
2023
"github.com/wavetermdev/waveterm/pkg/wavebase"
2124
"github.com/wavetermdev/waveterm/pkg/waveobj"
2225
"github.com/wavetermdev/waveterm/pkg/wps"
26+
"github.com/wavetermdev/waveterm/pkg/wstore"
2327
"github.com/wavetermdev/waveterm/tsunami/build"
2428
)
2529

@@ -81,6 +85,46 @@ func getCachesDir() string {
8185
return cacheDir
8286
}
8387

88+
func (c *TsunamiController) fetchAndSetSchemas(port int) {
89+
url := fmt.Sprintf("http://localhost:%d/api/schemas", port)
90+
client := &http.Client{
91+
Timeout: 10 * time.Second,
92+
}
93+
94+
resp, err := client.Get(url)
95+
if err != nil {
96+
log.Printf("TsunamiController: failed to fetch schemas from %s: %v", url, err)
97+
return
98+
}
99+
defer resp.Body.Close()
100+
101+
if resp.StatusCode != http.StatusOK {
102+
log.Printf("TsunamiController: received non-200 status %d from %s", resp.StatusCode, url)
103+
return
104+
}
105+
106+
var schemas any
107+
if err := json.NewDecoder(resp.Body).Decode(&schemas); err != nil {
108+
log.Printf("TsunamiController: failed to decode schemas response: %v", err)
109+
return
110+
}
111+
112+
blockRef := waveobj.MakeORef(waveobj.OType_Block, c.blockId)
113+
wstore.SetRTInfo(blockRef, map[string]any{
114+
"tsunami:schemas": schemas,
115+
})
116+
117+
log.Printf("TsunamiController: successfully fetched and cached schemas for block %s", c.blockId)
118+
}
119+
120+
func (c *TsunamiController) clearSchemas() {
121+
blockRef := waveobj.MakeORef(waveobj.OType_Block, c.blockId)
122+
wstore.SetRTInfo(blockRef, map[string]any{
123+
"tsunami:schemas": nil,
124+
})
125+
log.Printf("TsunamiController: cleared schemas for block %s", c.blockId)
126+
}
127+
84128
func getTsunamiAppCachePath(scope string, appName string, osArch string) (string, error) {
85129
cachesDir := getCachesDir()
86130
tsunamiCacheDir := filepath.Join(cachesDir, "tsunami-build-cache")
@@ -229,6 +273,11 @@ func (c *TsunamiController) Start(ctx context.Context, blockMeta waveobj.MetaMap
229273
})
230274
go c.sendStatusUpdate()
231275

276+
// Asynchronously fetch schemas after port is detected
277+
go func() {
278+
c.fetchAndSetSchemas(tsunamiProc.Port)
279+
}()
280+
232281
// Monitor process completion
233282
go func() {
234283
<-tsunamiProc.WaitCh
@@ -240,6 +289,7 @@ func (c *TsunamiController) Start(ctx context.Context, blockMeta waveobj.MetaMap
240289
c.port = 0
241290
c.exitCode = exitCodeFromWaitErr(tsunamiProc.WaitRtn)
242291
})
292+
c.clearSchemas()
243293
go c.sendStatusUpdate()
244294
}
245295
c.runLock.Unlock()
@@ -273,6 +323,7 @@ func (c *TsunamiController) Stop(graceful bool, newStatus string) error {
273323
c.status = newStatus
274324
c.port = 0
275325
})
326+
c.clearSchemas()
276327
go c.sendStatusUpdate()
277328
return nil
278329
}

pkg/waveobj/blockrtinfo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ package waveobj
66
type ObjRTInfo struct {
77
TsunamiTitle string `json:"tsunami:title,omitempty"`
88
TsunamiShortDesc string `json:"tsunami:shortdesc,omitempty"`
9+
TsunamiSchemas any `json:"tsunami:schemas,omitempty"`
10+
CmdHasCurCwd bool `json:"cmd:hascurcwd,omitempty"`
911
}

pkg/waveobj/metaconsts.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ const (
6060
MetaKey_CmdInitScriptZsh = "cmd:initscript.zsh"
6161
MetaKey_CmdInitScriptPwsh = "cmd:initscript.pwsh"
6262
MetaKey_CmdInitScriptFish = "cmd:initscript.fish"
63-
MetaKey_CmdHasCurCwd = "cmd:hascurcwd"
6463

6564
MetaKey_AiClear = "ai:*"
6665
MetaKey_AiPresetKey = "ai:preset"

pkg/waveobj/wtypemeta.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ type MetaTSType struct {
6161
CmdInitScriptZsh string `json:"cmd:initscript.zsh,omitempty"`
6262
CmdInitScriptPwsh string `json:"cmd:initscript.pwsh,omitempty"`
6363
CmdInitScriptFish string `json:"cmd:initscript.fish,omitempty"`
64-
CmdHasCurCwd bool `json:"cmd:hascurcwd,omitempty"`
6564

6665
// AI options match settings
6766
AiClear bool `json:"ai:*,omitempty"`

tsunami/demo/cpuchart/app.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ var (
3434
}(), &app.AtomMeta{
3535
Desc: "Historical CPU usage data points for charting",
3636
})
37+
currentCpuUsageAtom = app.DataAtom("currentCpuUsage", 0.0, &app.AtomMeta{
38+
Desc: "Current CPU usage percentage",
39+
Units: "%",
40+
Min: app.Ptr(0.0),
41+
Max: app.Ptr(100.0),
42+
})
3743
)
3844

3945
type CPUDataPoint struct {
@@ -156,6 +162,12 @@ var App = app.DefineComponent("App", func(_ struct{}) any {
156162
app.UseTicker(time.Second, func() {
157163
// Collect new CPU data point and shift the data window
158164
newPoint := generateCPUDataPoint()
165+
166+
// Update current CPU usage atom for easy AI access
167+
if newPoint.CPUUsage != nil {
168+
currentCpuUsageAtom.Set(*newPoint.CPUUsage)
169+
}
170+
159171
cpuDataAtom.SetFn(func(data []CPUDataPoint) []CPUDataPoint {
160172
currentDataPointCount := dataPointCountAtom.Get()
161173

@@ -194,6 +206,7 @@ var App = app.DefineComponent("App", func(_ struct{}) any {
194206
}
195207
}
196208
cpuDataAtom.Set(initialData)
209+
currentCpuUsageAtom.Set(0.0)
197210
}
198211

199212
// Read atom values once for rendering

0 commit comments

Comments
 (0)