mirror of
https://github.com/langgenius/dify.git
synced 2026-05-09 12:59:18 +08:00
Ports service_api/app/{completion,workflow}.py to bearer-authed
/openapi/v1/apps/<app_id>/{info,chat-messages,completion-messages,workflows/run}.
Architecture:
- New controllers/openapi/auth/ package: Pipeline + Step protocol over
one mutable Context. Endpoints attach via @APP_PIPELINE.guard(scope=...)
— single attachment point; forgetting auth is structurally impossible.
- Pipeline order: BearerCheck -> ScopeCheck -> AppResolver -> AppAuthzCheck
-> CallerMount.
- Strategies vary along independent axes: AclStrategy (EE webapp-auth inner
API) vs MembershipStrategy (CE TenantAccountJoin); AccountMounter vs
EndUserMounter dispatched by SubjectType.
- App is in URL path (not header). Each non-GET has typed Pydantic Request;
each non-SSE response has typed Pydantic Response. Bearer-as-identity:
body 'user' field stripped, ignored if present.
Adds InvokeFrom.OPENAPI enum variant. Emits app.run.openapi audit log
on successful invocation via standard logger extra={"audit": True, ...}
convention.
15 lines
407 B
Python
15 lines
407 B
Python
from controllers.openapi._models import MessageMetadata, UsageInfo
|
|
|
|
|
|
def test_usage_info_defaults_zero():
|
|
u = UsageInfo()
|
|
assert u.prompt_tokens == 0
|
|
assert u.completion_tokens == 0
|
|
assert u.total_tokens == 0
|
|
|
|
|
|
def test_message_metadata_accepts_partial():
|
|
m = MessageMetadata(usage=UsageInfo(total_tokens=10))
|
|
assert m.usage.total_tokens == 10
|
|
assert m.retriever_resources == []
|