Skip to content
Merged
1 change: 1 addition & 0 deletions client/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const config: CodegenConfig = {
'../server/libs/automation/automation-configuration/automation-configuration-graphql/src/main/resources/graphql/*.graphqls',
'../server/libs/automation/automation-search/automation-search-graphql/src/main/resources/graphql/*.graphqls',
'../server/libs/automation/automation-task/automation-task-graphql/src/main/resources/graphql/*.graphqls',
'../server/ee/libs/automation/automation-ai/automation-ai-gateway/automation-ai-gateway-graphql/src/main/resources/graphql/*.graphqls',
'../server/libs/platform/platform-security/platform-security-graphql/src/main/resources/graphql/*.graphqls',
'../server/libs/platform/platform-component/platform-component-log/platform-component-log-graphql/src/main/resources/graphql/*.graphqls',
'../server/libs/ai/mcp/mcp-server-configuration/mcp-server-configuration-graphql/src/main/resources/graphql/*.graphqls',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query aiDefaultModel($environment: ID!) {
aiDefaultModel(environment: $environment) {
provider
model
}
}
13 changes: 13 additions & 0 deletions client/src/graphql/platform/ai-providers/aiProviderCatalog.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query aiProviderCatalog($environment: ID!) {
aiProviderCatalog(environment: $environment) {
key
name
icon
enabled
supportsModelById
models {
name
label
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import {usePropertyCodeEditorDialogStore} from '@/pages/platform/workflow-editor/components/properties/components/property-code-editor/property-code-editor-dialog/stores/usePropertyCodeEditorDialogStore';
import {getTask} from '@/pages/platform/workflow-editor/utils/getTask';
import {useCopilotStore} from '@/shared/components/copilot/stores/useCopilotStore';
import {parseJson} from '@/shared/components/ai-chat/messages/toToolResultDataPart';
import useCopilotCodeToolResultStore from '@/shared/components/copilot/stores/useCopilotCodeToolResultStore';
import useCopilotPostTurnRegistry from '@/shared/components/copilot/stores/useCopilotPostTurnRegistry';
import {MODE, Source, useCopilotStore} from '@/shared/components/copilot/stores/useCopilotStore';
import useCopilotToolResultHandlerRegistry from '@/shared/components/copilot/stores/useCopilotToolResultHandlerRegistry';
import {extractScriptFromDefinition} from '@/shared/components/copilot/utils/extractScriptFromDefinition';
import {Workflow} from '@/shared/middleware/platform/configuration';
import {useCallback, useEffect, useState} from 'react';
import {useShallow} from 'zustand/react/shallow';

const APPLIED_TO_EDITOR_MESSAGE = '✓ Applied changes to the editor.';

interface UsePropertyCodeEditorDialogProps {
onClose?: () => void;
value?: string;
Expand Down Expand Up @@ -81,6 +88,45 @@ export const usePropertyCodeEditorDialog = ({
}
}, [value, editorValue, setDirty, setSaving]);

useEffect(() => {
const unregisterToolResult = useCopilotToolResultHandlerRegistry
.getState()
.register('updateScriptComponentCode', (content) => {
const result = parseJson<{definition?: string}>(content, 'updateScriptComponentCode result');

if (result?.definition) {
useCopilotCodeToolResultStore.getState().setLastUpdatedDefinition(result.definition);
}
});

const unregisterPostTurn = useCopilotPostTurnRegistry.getState().register(Source.CODE_EDITOR, () => {
const {appendToLastAssistantMessage, context} = useCopilotStore.getState();

const definition = useCopilotCodeToolResultStore.getState().lastUpdatedDefinition;

useCopilotCodeToolResultStore.getState().clear();

if (context?.mode !== MODE.BUILD || definition == null) {
return;
}

const code = extractScriptFromDefinition(definition, workflowNodeName);

if (code == null) {
return;
}

setEditorValue(code);

appendToLastAssistantMessage(APPLIED_TO_EDITOR_MESSAGE);
});

return () => {
unregisterToolResult();
unregisterPostTurn();
};
}, [setEditorValue, workflowNodeName]);

const currentWorkflowTask = getTask({
tasks: workflow.tasks || [],
workflowNodeName,
Expand Down
Loading
Loading