File size: 2,043 Bytes
caf8059
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import APIRouter, Depends, Header
from pydantic import Field
from src.modules.skill.domain.models import Contract, Identifier


class StartRun(Contract):
    release_ref: str = Field(min_length=1, max_length=110)
    project_id: Identifier
    source_digest: str = Field(pattern=r'^[a-f0-9]{64}$')
    requirement: str = Field(min_length=1, max_length=6000)
    query: str = Field(min_length=1, max_length=300)


class ApproveRun(Contract):
    expected_digest: str = Field(pattern=r'^[a-f0-9]{64}$')


def build_router(runtime, principal):
    router = APIRouter(prefix='/api/v1/coding/runs', tags=['ZKCoding Runtime'])

    @router.get('/readiness')
    def readiness(actor=Depends(principal)):
        return runtime.readiness(actor)

    @router.post('', status_code=201)
    def create(data: StartRun, actor=Depends(principal), key: str = Header(alias='Idempotency-Key', min_length=8, max_length=128)):
        return runtime.create(actor, data.model_dump(), key)

    @router.get('/{run_id}')
    def get(run_id: str, actor=Depends(principal)):
        return runtime.get(actor, run_id)

    @router.post('/{run_id}/advance')
    def advance(run_id: str, actor=Depends(principal)):
        return runtime.advance(actor, run_id)

    @router.post('/{run_id}/approvals')
    def approve(run_id: str, data: ApproveRun, actor=Depends(principal)):
        return runtime.approve(actor, run_id, data.expected_digest)

    @router.post('/{run_id}/cancel')
    def cancel(run_id: str, actor=Depends(principal)):
        return runtime.cancel(actor, run_id)

    @router.post('/{run_id}/repair')
    def repair(run_id: str, actor=Depends(principal)):
        return runtime.repair(actor, run_id)

    @router.post('/{run_id}/recover')
    def recover(run_id: str, actor=Depends(principal)):
        return runtime.recover(actor, run_id)

    @router.post('/{run_id}/validation-evidence')
    def validation_evidence(run_id: str, actor=Depends(principal)):
        return runtime.validation_evidence(actor, run_id)

    return router