Skip to content

Commit 7c4041e

Browse files
committed
use new cf worker endpoint
1 parent 6632365 commit 7c4041e

10 files changed

Lines changed: 56 additions & 31 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ out/
1616
make/
1717
artifacts/
1818
mikework/
19+
.env
1920

2021
# Yarn Modern
2122
.pnp.*

Taskfile.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ tasks:
2626
- docsite:build:embedded
2727
- build:backend
2828
env:
29-
WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central"
30-
WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev/"
29+
WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env"
30+
WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev"
31+
WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev"
3132

3233
electron:start:
3334
desc: Run the Electron application directly.
@@ -39,6 +40,7 @@ tasks:
3940
- docsite:build:embedded
4041
- build:backend
4142
env:
43+
WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env"
4244
WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev"
4345
WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev"
4446

@@ -49,6 +51,7 @@ tasks:
4951
- npm:install
5052
- build:backend:quickdev
5153
env:
54+
WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env"
5255
WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central"
5356
WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev/"
5457

cmd/server/main-server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sync"
1414
"time"
1515

16+
"github.com/joho/godotenv"
1617
"github.com/wavetermdev/waveterm/pkg/authkey"
1718
"github.com/wavetermdev/waveterm/pkg/blockcontroller"
1819
"github.com/wavetermdev/waveterm/pkg/blocklogger"
@@ -53,6 +54,14 @@ const TelemetryCountsInterval = 1 * time.Hour
5354

5455
var shutdownOnce sync.Once
5556

57+
func init() {
58+
envFilePath := os.Getenv("WAVETERM_ENVFILE")
59+
if envFilePath != "" {
60+
log.Printf("applying env file: %s\n", envFilePath)
61+
_ = godotenv.Load(envFilePath)
62+
}
63+
}
64+
5665
func doShutdown(reason string) {
5766
shutdownOnce.Do(func() {
5867
log.Printf("shutting down: %s\n", reason)

frontend/app/view/tsunami/tsunami.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,23 @@ class TsunamiViewModel extends WebViewModel {
9696

9797
setAppMeta(meta: TsunamiAppMeta) {
9898
console.log("tsunami app meta:", meta);
99-
99+
100100
const rtInfo: ObjRTInfo = {};
101101
if (meta.title) {
102102
rtInfo["tsunami:title"] = meta.title;
103103
}
104104
if (meta.shortdesc) {
105105
rtInfo["tsunami:shortdesc"] = meta.shortdesc;
106106
}
107-
107+
108108
if (Object.keys(rtInfo).length > 0) {
109109
const oref = WOS.makeORef("block", this.blockId);
110110
const data: CommandSetRTInfoData = {
111111
oref: oref,
112-
data: rtInfo
112+
data: rtInfo,
113113
};
114-
115-
RpcApi.SetRTInfoCommand(TabRpcClient, data).catch((e) =>
116-
console.log("error setting RT info", e)
117-
);
114+
115+
RpcApi.SetRTInfoCommand(TabRpcClient, data).catch((e) => console.log("error setting RT info", e));
118116
}
119117
}
120118

@@ -157,28 +155,29 @@ const TsunamiView = memo((props: ViewComponentProps<TsunamiViewModel>) => {
157155

158156
const handleConsoleMessage = (e: any) => {
159157
const message = e.message;
160-
if (typeof message === 'string' && message.startsWith('TSUNAMI_META ')) {
158+
if (typeof message === "string" && message.startsWith("TSUNAMI_META ")) {
161159
try {
162-
const jsonStr = message.substring('TSUNAMI_META '.length);
160+
const jsonStr = message.substring("TSUNAMI_META ".length);
163161
const meta = JSON.parse(jsonStr);
164162
if (meta.title || meta.shortdesc) {
165163
model.setAppMeta(meta);
166-
164+
167165
if (meta.title) {
168-
const truncatedTitle = meta.title.length > 77 ? meta.title.substring(0, 77) + "..." : meta.title;
166+
const truncatedTitle =
167+
meta.title.length > 77 ? meta.title.substring(0, 77) + "..." : meta.title;
169168
globalStore.set(model.viewName, truncatedTitle);
170169
}
171170
}
172171
} catch (error) {
173-
console.error('Failed to parse TSUNAMI_META message:', error);
172+
console.error("Failed to parse TSUNAMI_META message:", error);
174173
}
175174
}
176175
};
177176

178-
webviewElement.addEventListener('console-message', handleConsoleMessage);
177+
webviewElement.addEventListener("console-message", handleConsoleMessage);
179178

180179
return () => {
181-
webviewElement.removeEventListener('console-message', handleConsoleMessage);
180+
webviewElement.removeEventListener("console-message", handleConsoleMessage);
182181
};
183182
}, [domReady, model]);
184183

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require (
1919
github.com/gorilla/websocket v1.5.3
2020
github.com/invopop/jsonschema v0.13.0
2121
github.com/jmoiron/sqlx v1.4.0
22+
github.com/joho/godotenv v1.5.1
2223
github.com/junegunn/fzf v0.65.2
2324
github.com/kevinburke/ssh_config v1.2.0
2425
github.com/launchdarkly/eventsource v1.10.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcI
111111
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
112112
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
113113
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
114+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
115+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
114116
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
115117
github.com/junegunn/fzf v0.65.2 h1:Uz6Qey1K4JoGNMskYlwRDnGuCEu/sAh+NxQ4YdX3yn0=
116118
github.com/junegunn/fzf v0.65.2/go.mod h1:0PctWYfS0aCfyLFEIUjtE+PIXD2UFKaHgbIHiECG7Bo=

pkg/aiusechat/anthropic/anthropic-backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
const (
27-
AnthropicDefaultBaseURL = "https://api.anthropic.com"
27+
AnthropicDefaultBaseURL = "https://api.anthropic.com/v1/messages"
2828
AnthropicDefaultAPIVersion = "2023-06-01"
2929
AnthropicDefaultMaxTokens = 4096
3030
AnthropicThinkingBudget = 1024

pkg/aiusechat/anthropic/anthropic-convertmessage.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/google/uuid"
1919
"github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes"
2020
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
21+
"github.com/wavetermdev/waveterm/pkg/waveobj"
22+
"github.com/wavetermdev/waveterm/pkg/wstore"
2123
)
2224

2325
// these conversions are based off the anthropic spec
@@ -26,19 +28,15 @@ import (
2628
// buildAnthropicHTTPRequest creates a complete HTTP request for the Anthropic API
2729
func buildAnthropicHTTPRequest(ctx context.Context, msgs []anthropicInputMessage, chatOpts uctypes.WaveChatOpts) (*http.Request, error) {
2830
opts := chatOpts.Config
29-
if opts.APIToken == "" {
30-
return nil, errors.New("Anthropic API token missing")
31-
}
3231
if opts.Model == "" {
3332
return nil, errors.New("opts.model is required")
3433
}
3534

3635
// Set defaults
37-
baseURL := opts.BaseURL
38-
if baseURL == "" {
39-
baseURL = AnthropicDefaultBaseURL
36+
endpoint := opts.BaseURL
37+
if endpoint == "" {
38+
endpoint = AnthropicDefaultBaseURL
4039
}
41-
endpoint := strings.TrimRight(baseURL, "/") + "/v1/messages"
4240

4341
apiVersion := opts.APIVersion
4442
if apiVersion == "" {
@@ -120,6 +118,10 @@ func buildAnthropicHTTPRequest(ctx context.Context, msgs []anthropicInputMessage
120118
}
121119
log.Printf("tools: %s\n", strings.Join(toolNames, ", "))
122120
log.Printf("anthropicMsgs JSON:\n%s", jsonStr)
121+
log.Printf("has-api-key: %v\n", opts.APIToken != "")
122+
if endpoint != AnthropicDefaultBaseURL {
123+
log.Printf("baseurl: %s\n", endpoint)
124+
}
123125
}
124126

125127
var buf bytes.Buffer
@@ -133,11 +135,19 @@ func buildAnthropicHTTPRequest(ctx context.Context, msgs []anthropicInputMessage
133135
if err != nil {
134136
return nil, err
135137
}
138+
client, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
139+
if err != nil {
140+
return nil, fmt.Errorf("error getting client for Wave AI request: %w", err)
141+
}
136142

137143
req.Header.Set("content-type", "application/json")
138-
req.Header.Set("x-api-key", opts.APIToken)
144+
if opts.APIToken != "" {
145+
req.Header.Set("x-api-key", opts.APIToken)
146+
}
139147
req.Header.Set("anthropic-version", apiVersion)
140148
req.Header.Set("accept", "text/event-stream")
149+
req.Header.Set("X-Wave-ClientId", client.OID)
150+
req.Header.Set("X-Wave-APIType", "anthropic")
141151

142152
return req, nil
143153
}

pkg/aiusechat/tools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ func GetTsunamiSetConfigToolDefinition(block *waveobj.Block, rtInfo *waveobj.Obj
376376
}
377377
}
378378

379+
// for testing
379380
func GetAdderToolDefinition() uctypes.ToolDefinition {
380381
return uctypes.ToolDefinition{
381382
Name: "adder",

pkg/aiusechat/usechat.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ const (
2626
)
2727

2828
const DefaultClaudeModel = "claude-sonnet-4-20250514"
29+
const DefaultAIEndpoint = "https://cfapi.waveterm.dev/api/waveai"
2930

3031
func getWaveAISettings() (*uctypes.AIOptsType, error) {
31-
anthropicSecret := os.Getenv("WAVETERM_ANTHROPIC_SECRET")
32-
if anthropicSecret == "" {
33-
return nil, fmt.Errorf("no anthropic secret found")
32+
baseUrl := DefaultAIEndpoint
33+
if os.Getenv("WAVETERM_WAVEAI_ENDPOINT") != "" {
34+
baseUrl = os.Getenv("WAVETERM_WAVEAI_ENDPOINT")
3435
}
3536
return &uctypes.AIOptsType{
36-
APIToken: anthropicSecret,
3737
Model: DefaultClaudeModel,
3838
APIType: APIType_Anthropic,
3939
MaxTokens: 4 * 1024,
4040
ThinkingLevel: uctypes.ThinkingLevelMedium,
41+
BaseURL: baseUrl,
4142
}, nil
4243
}
4344

@@ -291,8 +292,6 @@ func WaveAIPostMessageHandler(w http.ResponseWriter, r *http.Request) {
291292
},
292293
}
293294

294-
// Create tools array with adder tool
295-
chatOpts.Tools = append(chatOpts.Tools, GetAdderToolDefinition())
296295
chatOpts.TabStateGenerator = func() (string, []uctypes.ToolDefinition, error) {
297296
return GenerateTabStateAndTools(r.Context(), req.TabId, req.WidgetAccess)
298297
}

0 commit comments

Comments
 (0)