Skip to content

Commit 2608ab6

Browse files
committed
Fixes extension loading and data handling
Ensures extensions can load correctly by injecting a context containing i18n, API, and Cache. Populates socket URLs for extensions relying on Unix sockets, addressing potential connection issues. Improves AI query parameter handling by filtering and encoding parameters for AI generation requests, ensuring only relevant data is sent to the plugin.
1 parent f0ba6d2 commit 2608ab6

3 files changed

Lines changed: 45 additions & 6 deletions

File tree

console/atest-ui/src/views/Extension.vue

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
<script setup lang="ts">
2-
import { ref } from 'vue'
2+
import { ref, type Ref } from 'vue'
3+
import { useI18n } from 'vue-i18n'
34
import { API } from './net';
5+
import { Cache } from './cache';
46
57
interface Props {
68
name: string
79
}
810
const props = defineProps<Props>()
11+
const { t, locale } = useI18n()
12+
13+
interface PluginAppContext {
14+
i18n: {
15+
t: (key: string) => string
16+
locale: Ref<string>
17+
}
18+
API: typeof API
19+
Cache: typeof Cache
20+
}
21+
22+
const pluginContext: PluginAppContext = {
23+
i18n: { t, locale },
24+
API,
25+
Cache
26+
}
27+
928
const loading = ref(true)
1029
const loadPlugin = async (): Promise<void> => {
1130
try {
@@ -25,14 +44,14 @@ const loadPlugin = async (): Promise<void> => {
2544
2645
// Implement retry mechanism with exponential backoff
2746
const checkPluginLoad = (retries = 0, maxRetries = 10) => {
28-
const globalScope = globalThis as { ATestPlugin?: { mount?: (el: Element) => void } };
47+
const globalScope = globalThis as { ATestPlugin?: { mount?: (el: Element, context: PluginAppContext) => void } };
2948
const plugin = globalScope.ATestPlugin;
3049
3150
if (plugin && plugin.mount) {
3251
const container = document.getElementById("plugin-container");
3352
if (container) {
3453
container.innerHTML = ''; // Clear previous content
35-
plugin.mount(container);
54+
plugin.mount(container, pluginContext);
3655
loading.value = false;
3756
} else {
3857
loading.value = false;

pkg/server/remote_server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,9 @@ func (s *server) GetStores(ctx context.Context, in *SimpleQuery) (reply *Stores,
12251225
wg := sync.WaitGroup{}
12261226
mu := sync.Mutex{}
12271227
for _, item := range stores {
1228+
// Ensure socket URL is populated for extensions that rely on Unix sockets
1229+
handleStore(&item)
1230+
12281231
skip := false
12291232
for _, kind := range kinds.Data {
12301233
if in != nil && in.Kind != "" && !slices.Contains(kind.Categories, in.Kind) {
@@ -1670,6 +1673,9 @@ func (s *server) getLoaderByStoreName(storeName string) (loader testing.Writer,
16701673
var store *testing.Store
16711674
store, err = testing.NewStoreFactory(s.configDir).GetStore(storeName)
16721675
if err == nil && store != nil {
1676+
// Backfill socket URL when it is missing in the store definition
1677+
handleStore(store)
1678+
16731679
loader, err = s.storeWriterFactory.NewInstance(*store)
16741680
if err != nil {
16751681
err = fmt.Errorf("failed to new grpc loader from store %s, err: %v", store.Name, err)

pkg/testing/remote/grpc_store.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,19 @@ func (g *gRPCLoader) Query(query map[string]string) (result testing.DataResult,
327327
var dataResult *server.DataQueryResult
328328
offset, _ := strconv.ParseInt(query["offset"], 10, 64)
329329
limit, _ := strconv.ParseInt(query["limit"], 10, 64)
330+
queryType := query["type"]
331+
queryKey := query["key"]
330332
if dataResult, err = g.client.Query(g.ctx, &server.DataQuery{
333+
Type: queryType,
331334
Sql: query["sql"],
332-
Key: query["key"],
335+
Key: queryKey,
333336
Offset: offset,
334337
Limit: limit,
335338
}); err == nil {
339+
if strings.EqualFold(queryType, "ai") || strings.EqualFold(queryKey, "generate") {
340+
return g.convertAIResponse(dataResult), nil
341+
}
342+
336343
result.Pairs = pairToMap(dataResult.Data)
337344
for _, item := range dataResult.Items {
338345
result.Rows = append(result.Rows, pairToMap(item.Data))
@@ -485,9 +492,16 @@ func (g *gRPCLoader) handleAIQuery(query map[string]string) (testing.DataResult,
485492
return g.convertAIResponse(dataResult), nil
486493
}
487494

488-
// encodeAIGenerateParams encodes the original query parameters into JSON.
495+
// encodeAIGenerateParams filters and encodes AI generation parameters into JSON string.
496+
// This function intentionally excludes routing fields (like "method") and only propagates
497+
// the actual AI request payload that the plugin understands.
489498
func (g *gRPCLoader) encodeAIGenerateParams(query map[string]string) string {
490-
data, _ := json.Marshal(query)
499+
params := map[string]string{
500+
"model": query["model"],
501+
"prompt": query["prompt"],
502+
"config": query["config"],
503+
}
504+
data, _ := json.Marshal(params)
491505
return string(data)
492506
}
493507

0 commit comments

Comments
 (0)