Spaces:
Sleeping

File size: 2,247 Bytes
d4255ec
 
 
 
 
42fb3ca
bb3e925
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42fb3ca
 
 
 
 
 
 
 
 
bb3e925
42fb3ca
 
 
 
 
 
 
 
 
 
 
bb3e925
42fb3ca
 
bb3e925
42fb3ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb3e925
42fb3ca
 
 
 
d4255ec
42fb3ca
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const LOCAL_API_BASE_URL = 'http://127.0.0.1:7860'

function getApiBaseUrl() {
  return import.meta.env.DEV ? LOCAL_API_BASE_URL : ''
}

export type RecommendedHfAsset = {
  name: string
  type: 'space' | 'model' | 'dataset' | 'doc' | 'tool'
  hf_id: string
  url: string
  role: string
  why_relevant: string
  use_mode: 'fork' | 'reference' | 'connect_as_tool' | 'use_model' | 'dataset_source'
  agent_ready: boolean
  mcp_ready: boolean
  confidence: 'high' | 'medium' | 'low'
  source?: 'hf_hub_search' | 'curated_catalog'
  likes?: number
  downloads?: number
  tags?: string[]
  attach_to_node_id: string
  note?: string
}

export type GeneratedArchitectureNode = {
  id: string
  label: string
  type: 'input' | 'hf_model' | 'hf_inference' | 'frontend' | 'backend' | 'data' | 'deployment' | 'agent' | 'guardrail'
  hf_component?: string
  role?: string
  why?: string
  confidence?: number
  hf_tag?: string
  recommended_assets?: RecommendedHfAsset[]
}

export type GeneratedArchitectureEdge = {
  source: string
  target: string
  label?: string
}

export type GeneratedArchitecture = {
  summary?: string
  recommended_stack?: string[]
  recommended_hf_assets?: RecommendedHfAsset[]
  assumptions?: string[]
  next_steps?: string[]
  build_prompt?: string
  product_name: string
  one_liner: string
  user_input_summary: string
  recommended_hf_stack: Array<{
    layer: string
    component: string
    hf_ecosystem: string
    reason: string
  }>
  nodes: GeneratedArchitectureNode[]
  edges: GeneratedArchitectureEdge[]
  roadmap: Array<{
    phase: string
    tasks: string[]
  }>
}

export type GenerateArchitectureResponse = {
  type: 'architecture'
  source: 'hf_llm' | 'mock'
  prompt_version?: string
  architecture: GeneratedArchitecture
}

export async function generateArchitecture(transcript: string): Promise<GenerateArchitectureResponse> {
  const response = await fetch(`${getApiBaseUrl()}/api/generate-architecture`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ transcript }),
  })

  if (!response.ok) {
    throw new Error(`Architecture generation failed: ${response.status}`)
  }

  return response.json() as Promise<GenerateArchitectureResponse>
}