Skip to content

Commit 1f95649

Browse files
committed
rpc call to add AI context
1 parent a2f1d4f commit 1f95649

6 files changed

Lines changed: 74 additions & 0 deletions

File tree

frontend/app/aipanel/waveai-model.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ export class WaveAIModel {
173173
return input != null && input.trim().length > 0;
174174
}
175175

176+
appendText(text: string) {
177+
const currentInput = globalStore.get(this.inputAtom);
178+
let newInput = currentInput;
179+
180+
if (newInput.length > 0 && !newInput.endsWith(" ") && !newInput.endsWith("\n")) {
181+
newInput += " ";
182+
}
183+
184+
newInput += text;
185+
globalStore.set(this.inputAtom, newInput);
186+
}
187+
176188
setModel(model: string) {
177189
const tabId = globalStore.get(atoms.staticTabId);
178190
RpcApi.SetMetaCommand(TabRpcClient, {

frontend/app/store/tabrpcclient.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2025, Command Line Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
import { WaveAIModel } from "@/app/aipanel/waveai-model";
45
import { getApi } from "@/app/store/global";
56
import { getLayoutModelForStaticTab } from "@/layout/index";
67
import { RpcResponseHelper, WshClient } from "./wshclient";
@@ -56,4 +57,24 @@ export class TabClient extends WshClient {
5657

5758
return await getApi().captureScreenshot(electronRect);
5859
}
60+
61+
async handle_waveaiaddcontext(rh: RpcResponseHelper, data: CommandWaveAIAddContextData): Promise<void> {
62+
const model = WaveAIModel.getInstance();
63+
64+
if (data.files && data.files.length > 0) {
65+
for (const fileData of data.files) {
66+
const blob = new Blob([fileData.data], { type: fileData.type });
67+
const file = new File([blob], fileData.name, { type: fileData.type });
68+
await model.addFile(file);
69+
}
70+
}
71+
72+
if (data.text) {
73+
model.appendText(data.text);
74+
}
75+
76+
if (data.submit) {
77+
model.focusInput();
78+
}
79+
}
5980
}

frontend/app/store/wshclientapi.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ class RpcApiType {
487487
return client.wshRpcCall("waitforroute", data, opts);
488488
}
489489

490+
// command "waveaiaddcontext" [call]
491+
WaveAIAddContextCommand(client: WshClient, data: CommandWaveAIAddContextData, opts?: RpcOpts): Promise<void> {
492+
return client.wshRpcCall("waveaiaddcontext", data, opts);
493+
}
494+
490495
// command "waveaienabletelemetry" [call]
491496
WaveAIEnableTelemetryCommand(client: WshClient, opts?: RpcOpts): Promise<void> {
492497
return client.wshRpcCall("waveaienabletelemetry", null, opts);

frontend/types/gotypes.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
declare global {
77

8+
// wshrpc.AIAttachedFile
9+
type AIAttachedFile = {
10+
name: string;
11+
type: string;
12+
size: number;
13+
data: string;
14+
};
15+
816
// wshrpc.ActivityDisplayType
917
type ActivityDisplayType = {
1018
width: number;
@@ -320,6 +328,13 @@ declare global {
320328
waitms: number;
321329
};
322330

331+
// wshrpc.CommandWaveAIAddContextData
332+
type CommandWaveAIAddContextData = {
333+
files?: AIAttachedFile[];
334+
text?: string;
335+
submit?: boolean;
336+
};
337+
323338
// wshrpc.CommandWaveAIToolApproveData
324339
type CommandWaveAIToolApproveData = {
325340
toolcallid: string;

pkg/wshrpc/wshclient/wshclient.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,12 @@ func WaitForRouteCommand(w *wshutil.WshRpc, data wshrpc.CommandWaitForRouteData,
581581
return resp, err
582582
}
583583

584+
// command "waveaiaddcontext", wshserver.WaveAIAddContextCommand
585+
func WaveAIAddContextCommand(w *wshutil.WshRpc, data wshrpc.CommandWaveAIAddContextData, opts *wshrpc.RpcOpts) error {
586+
_, err := sendRpcRequestCallHelper[any](w, "waveaiaddcontext", data, opts)
587+
return err
588+
}
589+
584590
// command "waveaienabletelemetry", wshserver.WaveAIEnableTelemetryCommand
585591
func WaveAIEnableTelemetryCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) error {
586592
_, err := sendRpcRequestCallHelper[any](w, "waveaienabletelemetry", nil, opts)

pkg/wshrpc/wshrpctypes.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ const (
143143
Command_GetWaveAIChat = "getwaveaichat"
144144
Command_GetWaveAIRateLimit = "getwaveairatelimit"
145145
Command_WaveAIToolApprove = "waveaitoolapprove"
146+
Command_WaveAIAddContext = "waveaiaddcontext"
146147

147148
Command_CaptureBlockScreenshot = "captureblockscreenshot"
148149

@@ -273,6 +274,7 @@ type WshRpcInterface interface {
273274
GetWaveAIChatCommand(ctx context.Context, data CommandGetWaveAIChatData) (*uctypes.UIChat, error)
274275
GetWaveAIRateLimitCommand(ctx context.Context) (*uctypes.RateLimitInfo, error)
275276
WaveAIToolApproveCommand(ctx context.Context, data CommandWaveAIToolApproveData) error
277+
WaveAIAddContextCommand(ctx context.Context, data CommandWaveAIAddContextData) error
276278

277279
// screenshot
278280
CaptureBlockScreenshotCommand(ctx context.Context, data CommandCaptureBlockScreenshotData) (string, error)
@@ -734,6 +736,19 @@ type CommandWaveAIToolApproveData struct {
734736
Approval string `json:"approval,omitempty"`
735737
}
736738

739+
type AIAttachedFile struct {
740+
Name string `json:"name"`
741+
Type string `json:"type"`
742+
Size int `json:"size"`
743+
Data []byte `json:"data"`
744+
}
745+
746+
type CommandWaveAIAddContextData struct {
747+
Files []AIAttachedFile `json:"files,omitempty"`
748+
Text string `json:"text,omitempty"`
749+
Submit bool `json:"submit,omitempty"`
750+
}
751+
737752
type CommandCaptureBlockScreenshotData struct {
738753
BlockId string `json:"blockid" wshcontext:"BlockId"`
739754
}

0 commit comments

Comments
 (0)