Skip to content

Commit f0d555c

Browse files
Require more APIs to use permission (#1199)
* gate more apis * Update libs/server/kiln_server/document_api.py allow agent to see progress Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update libs/server/kiln_server/utils/agent_checks/annotations/post_api_projects_project_id_rag_configs_progress.json Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 3dbd237 commit f0d555c

File tree

28 files changed

+96
-45
lines changed

28 files changed

+96
-45
lines changed

app/desktop/studio_server/copilot_api.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
RefineSpecApiOutput,
7676
SubmitAnswersRequest,
7777
)
78-
from kiln_server.utils.agent_checks.policy import ALLOW_AGENT
78+
from kiln_server.utils.agent_checks.policy import agent_policy_require_approval
7979
from pydantic import BaseModel, Field
8080

8181
logger = logging.getLogger(__name__)
@@ -115,7 +115,11 @@ class CreateSpecWithCopilotRequest(BaseModel):
115115

116116

117117
def connect_copilot_api(app: FastAPI):
118-
@app.post("/api/copilot/clarify_spec", tags=["Copilot"], openapi_extra=ALLOW_AGENT)
118+
@app.post(
119+
"/api/copilot/clarify_spec",
120+
tags=["Copilot"],
121+
openapi_extra=agent_policy_require_approval("Run Copilot spec clarification?"),
122+
)
119123
async def clarify_spec(input: ClarifySpecApiInput) -> ClarifySpecApiOutput:
120124
api_key = get_copilot_api_key()
121125
client = get_authenticated_client(api_key)
@@ -141,7 +145,11 @@ async def clarify_spec(input: ClarifySpecApiInput) -> ClarifySpecApiOutput:
141145
detail="Unknown error.",
142146
)
143147

144-
@app.post("/api/copilot/refine_spec", tags=["Copilot"], openapi_extra=ALLOW_AGENT)
148+
@app.post(
149+
"/api/copilot/refine_spec",
150+
tags=["Copilot"],
151+
openapi_extra=agent_policy_require_approval("Run Copilot spec refinement?"),
152+
)
145153
async def refine_spec(input: RefineSpecApiInput) -> RefineSpecApiOutput:
146154
api_key = get_copilot_api_key()
147155
client = get_authenticated_client(api_key)
@@ -168,7 +176,9 @@ async def refine_spec(input: RefineSpecApiInput) -> RefineSpecApiOutput:
168176
)
169177

170178
@app.post(
171-
"/api/copilot/generate_batch", tags=["Copilot"], openapi_extra=ALLOW_AGENT
179+
"/api/copilot/generate_batch",
180+
tags=["Copilot"],
181+
openapi_extra=agent_policy_require_approval("Run Copilot batch generation?"),
172182
)
173183
async def generate_batch(input: GenerateBatchApiInput) -> GenerateBatchApiOutput:
174184
api_key = get_copilot_api_key()
@@ -195,7 +205,11 @@ async def generate_batch(input: GenerateBatchApiInput) -> GenerateBatchApiOutput
195205
detail="Unknown error.",
196206
)
197207

198-
@app.post("/api/copilot/question_spec", tags=["Copilot"], openapi_extra=ALLOW_AGENT)
208+
@app.post(
209+
"/api/copilot/question_spec",
210+
tags=["Copilot"],
211+
openapi_extra=agent_policy_require_approval("Run Copilot spec questioner?"),
212+
)
199213
async def question_spec(
200214
input: SpecQuestionerApiInput,
201215
) -> QuestionSet:
@@ -226,7 +240,9 @@ async def question_spec(
226240
@app.post(
227241
"/api/copilot/refine_spec_with_question_answers",
228242
tags=["Copilot"],
229-
openapi_extra=ALLOW_AGENT,
243+
openapi_extra=agent_policy_require_approval(
244+
"Run Copilot spec refinement with question answers?"
245+
),
230246
)
231247
async def submit_question_answers(
232248
request: SubmitAnswersRequest,
@@ -256,7 +272,7 @@ async def submit_question_answers(
256272
@app.post(
257273
"/api/projects/{project_id}/tasks/{task_id}/spec_with_copilot",
258274
tags=["Copilot"],
259-
openapi_extra=ALLOW_AGENT,
275+
openapi_extra=agent_policy_require_approval("Create spec with Copilot?"),
260276
)
261277
async def create_spec_with_copilot(
262278
project_id: Annotated[

app/desktop/studio_server/data_gen_api.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
)
2424
from kiln_server.project_api import project_from_id
2525
from kiln_server.task_api import task_from_id
26-
from kiln_server.utils.agent_checks.policy import ALLOW_AGENT
26+
from kiln_server.utils.agent_checks.policy import (
27+
ALLOW_AGENT,
28+
agent_policy_require_approval,
29+
)
2730
from openai.types.chat import (
2831
ChatCompletionSystemMessageParam,
2932
ChatCompletionUserMessageParam,
@@ -127,7 +130,7 @@ def connect_data_gen_api(app: FastAPI):
127130
"/api/projects/{project_id}/tasks/{task_id}/generate_categories",
128131
summary="Generate Categories",
129132
tags=["Synthetic Data"],
130-
openapi_extra=ALLOW_AGENT,
133+
openapi_extra=agent_policy_require_approval("Generate categories using LLM?"),
131134
)
132135
async def generate_categories(
133136
project_id: Annotated[
@@ -172,7 +175,7 @@ async def generate_categories(
172175
"/api/projects/{project_id}/tasks/{task_id}/generate_inputs",
173176
summary="Generate Inputs",
174177
tags=["Synthetic Data"],
175-
openapi_extra=ALLOW_AGENT,
178+
openapi_extra=agent_policy_require_approval("Generate inputs using LLM?"),
176179
)
177180
async def generate_samples(
178181
project_id: Annotated[
@@ -241,7 +244,7 @@ async def save_sample(
241244
"/api/projects/{project_id}/tasks/{task_id}/generate_sample",
242245
summary="Generate Sample",
243246
tags=["Synthetic Data"],
244-
openapi_extra=ALLOW_AGENT,
247+
openapi_extra=agent_policy_require_approval("Generate a sample using LLM?"),
245248
)
246249
async def generate_sample(
247250
project_id: Annotated[
@@ -312,7 +315,7 @@ async def generate_sample(
312315
"/api/projects/{project_id}/tasks/{task_id}/generate_qna",
313316
summary="Generate Q&A Pairs",
314317
tags=["Synthetic Data"],
315-
openapi_extra=ALLOW_AGENT,
318+
openapi_extra=agent_policy_require_approval("Generate Q&A pairs using LLM?"),
316319
)
317320
async def generate_qna_pairs(
318321
project_id: Annotated[

app/desktop/studio_server/eval_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ async def create_eval_config(
764764
"/api/projects/{project_id}/tasks/{task_id}/evals/{eval_id}/eval_config/{eval_config_id}/run_comparison",
765765
summary="Run Run Config Comparison",
766766
tags=["Evals"],
767-
openapi_extra=ALLOW_AGENT,
767+
openapi_extra=agent_policy_require_approval("Run eval comparison?"),
768768
)
769769
async def run_eval_config(
770770
project_id: Annotated[
@@ -866,7 +866,9 @@ async def set_default_eval_config(
866866
"/api/projects/{project_id}/tasks/{task_id}/evals/{eval_id}/run_calibration",
867867
summary="Run Calibration",
868868
tags=["Evals"],
869-
openapi_extra=ALLOW_AGENT,
869+
openapi_extra=agent_policy_require_approval(
870+
"Run eval calibration? This runs LLM calls across all eval configs and uses AI credits."
871+
),
870872
)
871873
async def run_eval_config_eval(
872874
project_id: Annotated[

app/desktop/studio_server/finetune_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from kiln_server.task_api import task_from_id
5454
from kiln_server.utils.agent_checks.policy import (
5555
ALLOW_AGENT,
56+
DENY_AGENT,
5657
agent_policy_require_approval,
5758
)
5859
from pydantic import BaseModel, Field, model_validator
@@ -642,7 +643,7 @@ async def create_finetune(
642643
"/api/download_dataset_jsonl",
643644
summary="Download Dataset JSONL",
644645
tags=["Fine-tuning"],
645-
openapi_extra=ALLOW_AGENT,
646+
openapi_extra=DENY_AGENT,
646647
)
647648
async def download_dataset_jsonl(
648649
project_id: Annotated[

app/desktop/studio_server/repair_api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
from kiln_ai.datamodel.task_output import DataSource, DataSourceType
1515
from kiln_ai.utils.config import Config
1616
from kiln_server.run_api import model_provider_from_string, task_and_run_from_id
17-
from kiln_server.utils.agent_checks.policy import ALLOW_AGENT
17+
from kiln_server.utils.agent_checks.policy import (
18+
ALLOW_AGENT,
19+
agent_policy_require_approval,
20+
)
1821
from pydantic import BaseModel, ConfigDict, Field, ValidationError
1922

2023

@@ -39,7 +42,7 @@ def connect_repair_api(app: FastAPI):
3942
"/api/projects/{project_id}/tasks/{task_id}/runs/{run_id}/generate_repair",
4043
summary="Generate Repair",
4144
tags=["Runs"],
42-
openapi_extra=ALLOW_AGENT,
45+
openapi_extra=agent_policy_require_approval("Generate a repair using LLM?"),
4346
)
4447
async def run_repair(
4548
project_id: Annotated[

libs/server/kiln_server/document_api.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,9 @@ async def get_extractor_config(
13731373
@app.get(
13741374
"/api/projects/{project_id}/extractor_configs/{extractor_config_id}/run_extractor_config",
13751375
tags=["Documents"],
1376-
openapi_extra=ALLOW_AGENT,
1376+
openapi_extra=agent_policy_require_approval(
1377+
"Run document extractor? This processes all documents and may take significant time."
1378+
),
13771379
)
13781380
async def run_extractor_config(
13791381
project_id: Annotated[
@@ -1515,7 +1517,7 @@ async def get_extraction(
15151517
@app.get(
15161518
"/api/projects/{project_id}/documents/{document_id}/download",
15171519
tags=["Documents"],
1518-
openapi_extra=ALLOW_AGENT,
1520+
openapi_extra=DENY_AGENT,
15191521
)
15201522
async def download_document_file(
15211523
project_id: Annotated[
@@ -1547,7 +1549,7 @@ async def download_document_file(
15471549
@app.get(
15481550
"/api/projects/{project_id}/documents/{document_id}/download_extraction/{extraction_id}",
15491551
tags=["Documents"],
1550-
openapi_extra=ALLOW_AGENT,
1552+
openapi_extra=DENY_AGENT,
15511553
)
15521554
async def download_extraction(
15531555
project_id: Annotated[
@@ -1716,7 +1718,9 @@ async def get_extraction_progress(
17161718
@app.post(
17171719
"/api/projects/{project_id}/documents/{document_id}/extract",
17181720
tags=["Documents"],
1719-
openapi_extra=ALLOW_AGENT,
1721+
openapi_extra=agent_policy_require_approval(
1722+
"Run document extraction? This processes the document and may take time."
1723+
),
17201724
)
17211725
async def extract_file(
17221726
project_id: Annotated[
@@ -2349,7 +2353,9 @@ async def get_rag_config(
23492353
@app.get(
23502354
"/api/projects/{project_id}/rag_configs/{rag_config_id}/run",
23512355
tags=["Documents"],
2352-
openapi_extra=ALLOW_AGENT,
2356+
openapi_extra=agent_policy_require_approval(
2357+
"Run RAG config indexing? This re-indexes documents and may take time."
2358+
),
23532359
)
23542360
async def run_rag_config(
23552361
project_id: Annotated[
@@ -2484,7 +2490,9 @@ async def check_library_state(
24842490
@app.post(
24852491
"/api/projects/{project_id}/extractor_configs/{extractor_config_id}/documents/{document_id}/ephemeral_split",
24862492
tags=["Documents"],
2487-
openapi_extra=ALLOW_AGENT,
2493+
openapi_extra=agent_policy_require_approval(
2494+
"Run ephemeral document split? This triggers backend processing."
2495+
),
24882496
)
24892497
async def ephemeral_split_document(
24902498
project_id: Annotated[

libs/server/kiln_server/run_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ async def delete_runs(
377377
"/api/projects/{project_id}/tasks/{task_id}/run",
378378
summary="Execute Run",
379379
tags=["Runs"],
380-
openapi_extra=ALLOW_AGENT,
380+
openapi_extra=agent_policy_require_approval("Run task with LLM?"),
381381
)
382382
async def run_task(
383383
project_id: Annotated[

libs/server/kiln_server/utils/agent_checks/annotations/get_api_download_dataset_jsonl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"method": "get",
33
"path": "/api/download_dataset_jsonl",
44
"agent_policy": {
5-
"permission": "allow",
5+
"permission": "deny",
66
"requires_approval": false
77
}
88
}

libs/server/kiln_server/utils/agent_checks/annotations/get_api_projects_project_id_documents_document_id_download.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"method": "get",
33
"path": "/api/projects/{project_id}/documents/{document_id}/download",
44
"agent_policy": {
5-
"permission": "allow",
5+
"permission": "deny",
66
"requires_approval": false
77
}
88
}

libs/server/kiln_server/utils/agent_checks/annotations/get_api_projects_project_id_documents_document_id_download_extraction_extraction_id.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"method": "get",
33
"path": "/api/projects/{project_id}/documents/{document_id}/download_extraction/{extraction_id}",
44
"agent_policy": {
5-
"permission": "allow",
5+
"permission": "deny",
66
"requires_approval": false
77
}
88
}

0 commit comments

Comments
 (0)