mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
fix(web): align data contracts with backend schema
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import type { ContextGenerateModalHandle } from '../index'
|
||||
import type { ContextGenerateResponse } from '@/service/debug'
|
||||
import type { ContextGenerateResponse } from '@/contract/console/generator'
|
||||
import { act, fireEvent, render, screen } from '@testing-library/react'
|
||||
import * as React from 'react'
|
||||
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { ContextGenerateResponse } from '@/service/debug'
|
||||
import type { ContextGenerateResponse } from '@/contract/console/generator'
|
||||
import { fireEvent, render, screen } from '@testing-library/react'
|
||||
import * as React from 'react'
|
||||
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import type { PointerEvent, RefObject } from 'react'
|
||||
import type { VersionOption } from '../types'
|
||||
import type { ContextGenerateResponse } from '@/service/debug'
|
||||
import type { ContextGenerateResponse } from '@/contract/console/generator'
|
||||
import { RiArrowDownSLine, RiCheckLine, RiCloseLine, RiPlayLargeLine } from '@remixicon/react'
|
||||
import { useCallback, useMemo, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { ContextGenerateResponse } from '@/service/debug'
|
||||
import type { ContextGenerateResponse } from '@/contract/console/generator'
|
||||
import { act, renderHook, waitFor } from '@testing-library/react'
|
||||
import useContextGenData from '../use-context-gen-data'
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { ContextGenerateResponse } from '@/service/debug'
|
||||
import type { ContextGenerateResponse } from '@/contract/console/generator'
|
||||
import { useSessionStorageState } from 'ahooks'
|
||||
import { useCallback } from 'react'
|
||||
import { CONTEXT_GEN_STORAGE_SUFFIX, getContextGenStorageKey } from '../utils/storage'
|
||||
|
||||
@ -10,7 +10,7 @@ import type {
|
||||
ContextGenerateMessage,
|
||||
ContextGenerateParameterInfo,
|
||||
ContextGenerateResponse,
|
||||
} from '@/service/debug'
|
||||
} from '@/contract/console/generator'
|
||||
import type { CompletionParams, Model, ModelModeType } from '@/types/app'
|
||||
import { useBoolean, useSessionStorageState } from 'ahooks'
|
||||
import { useCallback, useMemo, useRef, useState } from 'react'
|
||||
@ -24,7 +24,8 @@ import { useStore } from '@/app/components/workflow/store'
|
||||
import { STORAGE_KEYS } from '@/config/storage-keys'
|
||||
import { useGetLanguage } from '@/context/i18n'
|
||||
import { languages } from '@/i18n-config/language'
|
||||
import { fetchContextGenerateSuggestedQuestions, generateContext } from '@/service/debug'
|
||||
import { consoleClient } from '@/service/client'
|
||||
import { fetchContextGenerateSuggestedQuestions } from '@/service/debug'
|
||||
import { AppModeEnum } from '@/types/app'
|
||||
import { storage } from '@/utils/storage'
|
||||
import { CONTEXT_GEN_STORAGE_SUFFIX, getContextGenStorageKey } from '../utils/storage'
|
||||
@ -35,7 +36,7 @@ export type ContextGenerateChatMessage = ContextGenerateMessage & {
|
||||
durationMs?: number
|
||||
}
|
||||
|
||||
export const normalizeCodeLanguage = (value?: string) => {
|
||||
export const normalizeCodeLanguage = (value?: string): CodeLanguage => {
|
||||
if (value === CodeLanguage.javascript)
|
||||
return CodeLanguage.javascript
|
||||
if (value === CodeLanguage.python3)
|
||||
@ -43,6 +44,12 @@ export const normalizeCodeLanguage = (value?: string) => {
|
||||
return CodeLanguage.python3
|
||||
}
|
||||
|
||||
export const normalizeContextGenerateLanguage = (value?: string): 'python3' | 'javascript' => {
|
||||
if (value === CodeLanguage.javascript)
|
||||
return CodeLanguage.javascript
|
||||
return CodeLanguage.python3
|
||||
}
|
||||
|
||||
const createChatMessageId = () => {
|
||||
return `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
||||
}
|
||||
@ -454,19 +461,21 @@ const useContextGenerate = ({
|
||||
setGeneratingTrue()
|
||||
generateStartRef.current = Date.now()
|
||||
try {
|
||||
const response = await generateContext({
|
||||
language: normalizeCodeLanguage(current?.code_language || codeNodeData?.code_language) as 'python3' | 'javascript',
|
||||
prompt_messages: nextMessages.map(({ role, content, tool_call_id }) => ({
|
||||
role,
|
||||
content,
|
||||
tool_call_id,
|
||||
})),
|
||||
model_config: {
|
||||
...modelConfig,
|
||||
const response = await consoleClient.generator.contextGenerate({
|
||||
body: {
|
||||
language: normalizeContextGenerateLanguage(current?.code_language || codeNodeData?.code_language),
|
||||
prompt_messages: nextMessages.map(({ role, content, tool_call_id }) => ({
|
||||
role,
|
||||
content,
|
||||
tool_call_id,
|
||||
})),
|
||||
model_config: {
|
||||
...modelConfig,
|
||||
},
|
||||
available_vars: availableVarsPayload,
|
||||
parameter_info: parameterInfo,
|
||||
code_context: codeContext,
|
||||
},
|
||||
available_vars: availableVarsPayload,
|
||||
parameter_info: parameterInfo,
|
||||
code_context: codeContext,
|
||||
})
|
||||
|
||||
if (response.error) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
import type { CodeNodeType, OutputVar } from '@/app/components/workflow/nodes/code/types'
|
||||
import type { Node, NodeOutPutVar } from '@/app/components/workflow/types'
|
||||
import type { ContextGenerateResponse } from '@/service/debug'
|
||||
import type { ContextGenerateResponse } from '@/contract/console/generator'
|
||||
import * as React from 'react'
|
||||
import { forwardRef, useCallback, useImperativeHandle, useMemo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
@ -15,7 +15,7 @@ import { NULL_STRATEGY } from '@/app/components/workflow/nodes/_base/constants'
|
||||
import { Type } from '@/app/components/workflow/nodes/llm/types'
|
||||
import { BlockEnum, EditionType, isPromptMessageContext, PromptRole, VarType } from '@/app/components/workflow/types'
|
||||
import { generateNewNode, getNodeCustomTypeByNodeDataType, mergeNodeDefaultData } from '@/app/components/workflow/utils'
|
||||
import { fetchNestedNodeGraph } from '@/service/workflow'
|
||||
import { consoleClient } from '@/service/client'
|
||||
import { FlowType } from '@/types/common'
|
||||
|
||||
// Constants
|
||||
@ -427,11 +427,14 @@ export function useMixedVariableExtractor({
|
||||
return
|
||||
const parameterSchema = resolveNestedNodeParameterSchema(paramKey)
|
||||
try {
|
||||
const response = await fetchNestedNodeGraph(configsMap.flowType, configsMap.flowId, {
|
||||
parent_node_id: toolNodeId,
|
||||
parameter_key: paramKey,
|
||||
context_source: [payload.agentId, 'context'],
|
||||
parameter_schema: parameterSchema,
|
||||
const response = await consoleClient.workflowDraft.nestedNodeGraph({
|
||||
params: { appId: configsMap.flowId },
|
||||
body: {
|
||||
parent_node_id: toolNodeId,
|
||||
parameter_key: paramKey,
|
||||
context_source: [payload.agentId, 'context'],
|
||||
parameter_schema: parameterSchema,
|
||||
},
|
||||
})
|
||||
const nestedNode = response?.graph?.nodes?.find(node => node.id === payload.extractorNodeId)
|
||||
const nestedNodeData = nestedNode?.data as Partial<LLMNodeType> | undefined
|
||||
|
||||
Reference in New Issue
Block a user