create-windy 0.2.33 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +173 -17
- package/package.json +1 -1
- package/template/.agents/skills/windy-business-module/SKILL.md +10 -1
- package/template/.windy-template.json +2 -2
- package/template/AGENTS.md +9 -0
- package/template/README.md +3 -1
- package/template/apps/agent-server/Dockerfile +1 -0
- package/template/apps/agent-server/README.md +28 -5
- package/template/apps/agent-server/adk_web_agents/__init__.py +1 -0
- package/template/apps/agent-server/adk_web_agents/safe_debug/__init__.py +3 -0
- package/template/apps/agent-server/adk_web_agents/safe_debug/agent.py +40 -0
- package/template/apps/agent-server/pyproject.toml +1 -1
- package/template/apps/agent-server/src/southwind_agent_server/adk_adapter.py +191 -16
- package/template/apps/agent-server/src/southwind_agent_server/adk_failure.py +13 -0
- package/template/apps/agent-server/src/southwind_agent_server/adk_model.py +225 -0
- package/template/apps/agent-server/src/southwind_agent_server/adk_tools.py +76 -0
- package/template/apps/agent-server/src/southwind_agent_server/app.py +63 -3
- package/template/apps/agent-server/src/southwind_agent_server/contracts.py +35 -0
- package/template/apps/agent-server/src/southwind_agent_server/engine.py +2 -0
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine.py +31 -3
- package/template/apps/agent-server/src/southwind_agent_server/openai_provider.py +22 -9
- package/template/apps/agent-server/src/southwind_agent_server/provider_audit.py +144 -0
- package/template/apps/agent-server/src/southwind_agent_server/provider_governance.py +227 -0
- package/template/apps/agent-server/src/southwind_agent_server/service.py +1 -0
- package/template/apps/agent-server/tests/test_adk_adapter.py +305 -0
- package/template/apps/agent-server/tests/test_adk_web_agent.py +12 -0
- package/template/apps/agent-server/tests/test_api.py +16 -1
- package/template/apps/agent-server/tests/test_openai_provider.py +79 -0
- package/template/apps/agent-server/tests/test_provider_governance.py +215 -0
- package/template/apps/server/package.json +4 -1
- package/template/apps/server/src/agent/provider-input-governance.test.ts +82 -0
- package/template/apps/server/src/agent/provider-input-governance.ts +140 -0
- package/template/apps/server/src/agent/remote-runtime.test.ts +22 -0
- package/template/apps/server/src/agent/remote-runtime.ts +1 -0
- package/template/apps/server/src/agent/run-contracts.ts +2 -0
- package/template/apps/server/src/agent/run-facade.test.ts +52 -2
- package/template/apps/server/src/agent/run-facade.ts +38 -9
- package/template/apps/server/src/agent/tool-registry.ts +2 -6
- package/template/apps/server/src/application-services.ts +50 -0
- package/template/apps/server/src/audit/drizzle-log-store.ts +25 -0
- package/template/apps/server/src/audit/search-summary.ts +2 -6
- package/template/apps/server/src/auth/credential-restriction.ts +1 -0
- package/template/apps/server/src/auth/password.ts +30 -21
- package/template/apps/server/src/auth/routes.test.ts +44 -3
- package/template/apps/server/src/auth/routes.ts +6 -1
- package/template/apps/server/src/auth/runtime.ts +4 -1
- package/template/apps/server/src/auth/service.ts +25 -7
- package/template/apps/server/src/configuration/bootstrap.ts +20 -1
- package/template/apps/server/src/configuration/definition.test.ts +71 -0
- package/template/apps/server/src/configuration/definition.ts +242 -12
- package/template/apps/server/src/configuration/drizzle-repository.ts +36 -2
- package/template/apps/server/src/configuration/repository.ts +27 -2
- package/template/apps/server/src/configuration/routes.ts +4 -1
- package/template/apps/server/src/configuration/service.test.ts +100 -0
- package/template/apps/server/src/configuration/service.ts +50 -10
- package/template/apps/server/src/data-access/scoped-repository.integration.test.ts +3 -2
- package/template/apps/server/src/data-governance/export/service.ts +2 -6
- package/template/apps/server/src/example-modules.ts +4 -1
- package/template/apps/server/src/guards.ts +18 -5
- package/template/apps/server/src/http/request-source.test.ts +85 -0
- package/template/apps/server/src/http/request-source.ts +90 -0
- package/template/apps/server/src/index.ts +45 -45
- package/template/apps/server/src/license/routes.ts +2 -0
- package/template/apps/server/src/license/runtime-service.ts +10 -11
- package/template/apps/server/src/module-bootstrap.ts +2 -2
- package/template/apps/server/src/module-host/initialize-contracts.ts +6 -0
- package/template/apps/server/src/module-host/initialize.ts +30 -44
- package/template/apps/server/src/module-host/request-context.ts +29 -23
- package/template/apps/server/src/module-host/resource-file-policies.test.ts +197 -0
- package/template/apps/server/src/module-host/resource-file-policies.ts +108 -0
- package/template/apps/server/src/module-host/route-declaration.ts +45 -0
- package/template/apps/server/src/module-host/route-installer.ts +27 -3
- package/template/apps/server/src/module-host/storage-port.test.ts +170 -1
- package/template/apps/server/src/module-host/storage-port.ts +134 -1
- package/template/apps/server/src/module-host/storage-scope.ts +89 -0
- package/template/apps/server/src/module-host/tool-handlers.test.ts +305 -0
- package/template/apps/server/src/module-host/tool-handlers.ts +38 -4
- package/template/apps/server/src/module-host/user-directory-composition.test.ts +126 -0
- package/template/apps/server/src/module-host/user-directory-port.test.ts +238 -0
- package/template/apps/server/src/module-host/user-directory-port.ts +139 -0
- package/template/apps/server/src/module-host.ts +4 -0
- package/template/apps/server/src/notification/channel-adapter.ts +46 -0
- package/template/apps/server/src/notification/delivery-policy.test.ts +59 -0
- package/template/apps/server/src/notification/delivery-policy.ts +37 -0
- package/template/apps/server/src/notification/delivery-repository.ts +198 -0
- package/template/apps/server/src/notification/delivery-worker.test.ts +87 -0
- package/template/apps/server/src/notification/delivery-worker.ts +88 -0
- package/template/apps/server/src/notification/drizzle-management.ts +180 -0
- package/template/apps/server/src/notification/drizzle-query.ts +160 -0
- package/template/apps/server/src/notification/drizzle-repository.integration.test.ts +301 -0
- package/template/apps/server/src/notification/drizzle-repository.ts +156 -90
- package/template/apps/server/src/notification/extension-routes.test.ts +119 -0
- package/template/apps/server/src/notification/extension-routes.ts +111 -0
- package/template/apps/server/src/notification/memory-delivery-repository.ts +137 -0
- package/template/apps/server/src/notification/memory-support.ts +72 -0
- package/template/apps/server/src/notification/preference-repository.ts +95 -0
- package/template/apps/server/src/notification/recipient-directory.ts +104 -0
- package/template/apps/server/src/notification/repository.test.ts +171 -0
- package/template/apps/server/src/notification/repository.ts +179 -32
- package/template/apps/server/src/notification/revision-routes.test.ts +186 -0
- package/template/apps/server/src/notification/route-support.ts +225 -0
- package/template/apps/server/src/notification/routes.test.ts +182 -0
- package/template/apps/server/src/notification/routes.ts +225 -132
- package/template/apps/server/src/notification/service.test.ts +104 -0
- package/template/apps/server/src/notification/service.ts +140 -0
- package/template/apps/server/src/notification/smtp-adapter.test.ts +65 -0
- package/template/apps/server/src/notification/smtp-adapter.ts +68 -0
- package/template/apps/server/src/persistence.integration.test.ts +41 -2
- package/template/apps/server/src/route-guards.ts +1 -0
- package/template/apps/server/src/runtime-audit-list.test.ts +39 -0
- package/template/apps/server/src/runtime-development.ts +2 -0
- package/template/apps/server/src/runtime.test.ts +23 -9
- package/template/apps/server/src/runtime.ts +39 -2
- package/template/apps/server/src/scheduler/audit.ts +2 -11
- package/template/apps/server/src/scheduler/definitions.test.ts +6 -0
- package/template/apps/server/src/scheduler/definitions.ts +7 -0
- package/template/apps/server/src/scheduler/recovery-service.ts +2 -11
- package/template/apps/server/src/scheduler/routes.ts +2 -7
- package/template/apps/server/src/search/opensearch-client.test.ts +45 -0
- package/template/apps/server/src/search/opensearch-client.ts +145 -0
- package/template/apps/server/src/search/service.ts +2 -6
- package/template/apps/server/src/settings/routes.ts +15 -3
- package/template/apps/server/src/settings/runtime.ts +10 -1
- package/template/apps/server/src/storage/runtime.ts +13 -0
- package/template/apps/server/src/system/audit-query.ts +33 -4
- package/template/apps/server/src/system/audit-routes.test.ts +58 -4
- package/template/apps/server/src/system/audit-routes.ts +6 -5
- package/template/apps/server/src/system/built-in-roles.ts +1 -0
- package/template/apps/server/src/system/department-organization.ts +320 -0
- package/template/apps/server/src/system/department-routes.test.ts +207 -48
- package/template/apps/server/src/system/department-routes.ts +114 -33
- package/template/apps/server/src/system/drizzle-repository.ts +15 -7
- package/template/apps/server/src/system/drizzle-scoped-repository.ts +5 -3
- package/template/apps/server/src/system/drizzle-system.ts +37 -9
- package/template/apps/server/src/system/drizzle-transaction-context.ts +14 -0
- package/template/apps/server/src/system/identity-route-config.ts +7 -2
- package/template/apps/server/src/system/mutation-runner.ts +23 -0
- package/template/apps/server/src/system/organization-postgres.integration.test.ts +176 -0
- package/template/apps/server/src/system/resource-access-response.ts +12 -6
- package/template/apps/server/src/system/role-department-scope-policy.ts +55 -0
- package/template/apps/server/src/system/route-helpers.ts +2 -5
- package/template/apps/server/src/system/route-types.ts +12 -3
- package/template/apps/server/src/system/routes-validation.test.ts +26 -0
- package/template/apps/server/src/system/routes.test.ts +10 -2
- package/template/apps/server/src/system/routes.ts +70 -36
- package/template/apps/server/src/system/seed.ts +7 -0
- package/template/apps/server/src/work-order/data-scope.integration.test.ts +9 -2
- package/template/apps/server/src/work-order/opensearch-index.test.ts +97 -0
- package/template/apps/server/src/work-order/opensearch-index.ts +313 -0
- package/template/apps/server/src/work-order/search-provider.ts +60 -1
- package/template/apps/server/src/work-order/service.ts +42 -10
- package/template/apps/web/src/app/error-pages.ts +9 -0
- package/template/apps/web/src/components/auth/PasswordChangeForm.vue +16 -11
- package/template/apps/web/src/components/auth/PasswordChangeForm.webtest.ts +14 -0
- package/template/apps/web/src/components/common/FormDialog.vue +16 -2
- package/template/apps/web/src/components/common/ModalLayout.webtest.ts +20 -1
- package/template/apps/web/src/composables/useGlobalSearch.ts +68 -0
- package/template/apps/web/src/composables/usePlatformSettings.ts +8 -7
- package/template/apps/web/src/layout/GlobalSearchResults.vue +58 -0
- package/template/apps/web/src/layout/NavigationSearchDialog.vue +42 -6
- package/template/apps/web/src/layout/NavigationSearchDialog.webtest.ts +71 -0
- package/template/apps/web/src/layout/NotificationMenu.vue +73 -31
- package/template/apps/web/src/layout/NotificationMenu.webtest.ts +44 -1
- package/template/apps/web/src/layout/NotificationMenuItem.vue +61 -0
- package/template/apps/web/src/layout/NotificationPreferencesDialog.vue +181 -0
- package/template/apps/web/src/layout/NotificationPreferencesDialog.webtest.ts +80 -0
- package/template/apps/web/src/lib/date-time.ts +22 -10
- package/template/apps/web/src/lib/date-time.webtest.ts +9 -1
- package/template/apps/web/src/main.ts +14 -1
- package/template/apps/web/src/pages/auth/ChangePasswordPage.vue +16 -1
- package/template/apps/web/src/pages/configuration/components/ModuleConfigVersionList.vue +1 -0
- package/template/apps/web/src/pages/configuration/components/ModuleConfigurationEditor.vue +10 -0
- package/template/apps/web/src/pages/configuration/components/ModuleConfigurationWorkbench.vue +37 -6
- package/template/apps/web/src/pages/errors/PlatformErrorPage.vue +115 -0
- package/template/apps/web/src/pages/errors/PlatformErrorPage.webtest.ts +44 -0
- package/template/apps/web/src/pages/errors/error-page-extension.ts +26 -0
- package/template/apps/web/src/pages/system/SystemNotificationsPage.vue +136 -68
- package/template/apps/web/src/pages/system/SystemNotificationsPage.webtest.ts +224 -12
- package/template/apps/web/src/pages/system/audit-log-presenter.ts +86 -0
- package/template/apps/web/src/pages/system/audit-time-range.ts +28 -0
- package/template/apps/web/src/pages/system/components/AuditActionCell.vue +10 -69
- package/template/apps/web/src/pages/system/components/AuditActionCell.webtest.ts +20 -27
- package/template/apps/web/src/pages/system/components/AuditLogDetailDialog.vue +134 -0
- package/template/apps/web/src/pages/system/components/AuditLogDetailDialog.webtest.ts +76 -0
- package/template/apps/web/src/pages/system/components/AuditLogFilters.vue +116 -52
- package/template/apps/web/src/pages/system/components/AuditLogFilters.webtest.ts +52 -15
- package/template/apps/web/src/pages/system/components/NotificationHistoryDialog.vue +129 -0
- package/template/apps/web/src/pages/system/components/NotificationManagementCard.vue +91 -0
- package/template/apps/web/src/pages/system/components/NotificationPublishDialog.vue +121 -0
- package/template/apps/web/src/pages/system/components/NotificationPublishForm.vue +162 -1
- package/template/apps/web/src/pages/system/components/SystemResourceActions.vue +68 -0
- package/template/apps/web/src/pages/system/components/SystemResourceEditor.vue +74 -0
- package/template/apps/web/src/pages/system/components/SystemResourceFilters.vue +3 -4
- package/template/apps/web/src/pages/system/components/SystemResourcePage.vue +91 -98
- package/template/apps/web/src/pages/system/components/SystemResourcePage.webtest.ts +68 -0
- package/template/apps/web/src/pages/system/components/SystemResourceTable.vue +20 -1
- package/template/apps/web/src/pages/system/components/SystemResourceTable.webtest.ts +28 -7
- package/template/apps/web/src/pages/system/components/department/DepartmentOrganizationForm.vue +210 -0
- package/template/apps/web/src/pages/system/components/department/DepartmentTransitionDialog.vue +112 -0
- package/template/apps/web/src/pages/system/components/user-account/UserAccountForm.vue +17 -4
- package/template/apps/web/src/pages/system/composables/useDepartmentTransitions.ts +79 -0
- package/template/apps/web/src/pages/system/composables/useNotificationPermissions.ts +14 -0
- package/template/apps/web/src/pages/system/composables/useSystemResource.ts +2 -0
- package/template/apps/web/src/pages/system/composables/useSystemResource.webtest.ts +15 -2
- package/template/apps/web/src/pages/system/resource-config.ts +12 -4
- package/template/apps/web/src/router/error-navigation.ts +50 -0
- package/template/apps/web/src/router/error-navigation.webtest.ts +106 -0
- package/template/apps/web/src/router/index.ts +71 -0
- package/template/apps/web/src/router/index.webtest.ts +29 -0
- package/template/apps/web/src/router/manifest-routes.webtest.ts +4 -0
- package/template/apps/web/src/router/shared-scaffold-neutrality.webtest.ts +12 -0
- package/template/apps/web/src/services/auth-api.ts +5 -0
- package/template/apps/web/src/services/http.ts +43 -6
- package/template/apps/web/src/services/http.webtest.ts +70 -0
- package/template/apps/web/src/services/notification-api.ts +85 -2
- package/template/apps/web/src/services/notification-api.webtest.ts +110 -0
- package/template/apps/web/src/services/search-api.ts +39 -0
- package/template/apps/web/src/services/system-api.ts +18 -0
- package/template/apps/web/vitest.config.ts +1 -0
- package/template/docker-compose.yml +68 -0
- package/template/docs/architecture/ai-egress.md +49 -7
- package/template/docs/architecture/ai-runtime.md +34 -6
- package/template/docs/architecture/data-scope-query-enforcement.md +4 -0
- package/template/docs/architecture/object-storage.md +22 -2
- package/template/docs/architecture/search-provider-protocol.md +38 -2
- package/template/docs/development/custom-error-pages.md +78 -0
- package/template/docs/development/custom-login-page.md +3 -3
- package/template/docs/platform/agent-runtime.md +76 -7
- package/template/docs/platform/audit-reliability.md +46 -2
- package/template/docs/platform/business-user-directory.md +82 -0
- package/template/docs/platform/module-configuration.md +13 -4
- package/template/docs/platform/notifications.md +67 -11
- package/template/docs/platform/organization-membership.md +17 -3
- package/template/docs/platform/system-crud-api.md +16 -0
- package/template/docs/platform/web-system-crud.md +6 -2
- package/template/package.json +4 -0
- package/template/packages/config/index.test.ts +45 -0
- package/template/packages/config/package.json +1 -1
- package/template/packages/config/src/platform.ts +169 -48
- package/template/packages/database/drizzle/0035_material_nightshade.sql +10 -0
- package/template/packages/database/drizzle/0036_hesitant_speed.sql +35 -0
- package/template/packages/database/drizzle/0037_absent_nick_fury.sql +2 -0
- package/template/packages/database/drizzle/0038_uneven_wasp.sql +38 -0
- package/template/packages/database/drizzle/meta/0035_snapshot.json +7331 -0
- package/template/packages/database/drizzle/meta/0036_snapshot.json +7436 -0
- package/template/packages/database/drizzle/meta/0037_snapshot.json +7457 -0
- package/template/packages/database/drizzle/meta/0038_snapshot.json +7749 -0
- package/template/packages/database/drizzle/meta/_journal.json +28 -0
- package/template/packages/database/package.json +1 -1
- package/template/packages/database/src/schema/identity.ts +7 -0
- package/template/packages/database/src/schema/notifications.ts +135 -0
- package/template/packages/database/src/schema-notification-delivery.test.ts +54 -0
- package/template/packages/database/src/schema-workflow-notification.test.ts +40 -1
- package/template/packages/modules/package.json +1 -1
- package/template/packages/modules/src/ai-operation-composition.test.ts +68 -0
- package/template/packages/modules/src/ai-operation-composition.ts +115 -0
- package/template/packages/modules/src/manifest.ts +26 -0
- package/template/packages/modules/src/provider-data-policy-composition.test.ts +74 -0
- package/template/packages/modules/src/system-api-permissions.ts +54 -0
- package/template/packages/modules/src/system-audit-actions.ts +15 -0
- package/template/packages/modules/src/system-features.ts +6 -1
- package/template/packages/modules/src/system-module-catalog.test.ts +16 -0
- package/template/packages/modules/src/system-module-catalog.ts +28 -4
- package/template/packages/modules/src/system-modules.test.ts +13 -1
- package/template/packages/modules/src/system-modules.ts +12 -0
- package/template/packages/modules/src/system-permissions.ts +11 -5
- package/template/packages/server-sdk/index.ts +11 -0
- package/template/packages/server-sdk/package.json +3 -2
- package/template/packages/server-sdk/src/ai-operation-registration.ts +2 -1
- package/template/packages/server-sdk/src/module-host.ts +8 -0
- package/template/packages/server-sdk/src/request-context.ts +2 -0
- package/template/packages/server-sdk/src/storage-port.ts +66 -0
- package/template/packages/server-sdk/src/tool-registration.ts +6 -0
- package/template/packages/server-sdk/src/user-directory-port.ts +42 -0
- package/template/packages/shared/package.json +1 -1
- package/template/packages/shared/src/audit.ts +25 -0
- package/template/packages/shared/src/module-configuration.ts +5 -0
- package/template/packages/shared/src/notification.ts +92 -1
- package/template/packages/shared/src/password.ts +7 -2
- package/template/packages/shared/src/platform-settings.ts +2 -0
- package/template/packages/storage/package.json +1 -1
- package/template/packages/storage/src/upload-service.test.ts +16 -0
- package/template/packages/storage/src/upload-service.ts +5 -1
- package/template/scripts/notification-postgres-regression.ts +27 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sqlite3
|
|
4
|
+
import time
|
|
5
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Literal, cast
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
from southwind_agent_server.contracts import (
|
|
12
|
+
ProviderDataPolicy,
|
|
13
|
+
ProviderFieldPolicy,
|
|
14
|
+
ProviderInputFieldPolicy,
|
|
15
|
+
)
|
|
16
|
+
from southwind_agent_server.engine import SafeEngineError
|
|
17
|
+
from southwind_agent_server.provider_audit import (
|
|
18
|
+
ProviderAttemptAudit,
|
|
19
|
+
ProviderAuditStore,
|
|
20
|
+
)
|
|
21
|
+
from southwind_agent_server.provider_governance import ProviderRequestGovernance
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_dlp_redacts_before_send_and_audits_metadata_only(tmp_path: Path) -> None:
|
|
25
|
+
path = tmp_path / "provider-audit.sqlite3"
|
|
26
|
+
governance = ProviderRequestGovernance(
|
|
27
|
+
ProviderAuditStore(str(path), retention_days=90)
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
result = governance.authorize(
|
|
31
|
+
deployment_key="ai.openai-compatible",
|
|
32
|
+
operation_key="business.answer",
|
|
33
|
+
run_id="run_1",
|
|
34
|
+
attempt=1,
|
|
35
|
+
messages=[
|
|
36
|
+
{"role": "system", "content": "只回答问题"},
|
|
37
|
+
{"role": "user", "content": "联系 me@example.com"},
|
|
38
|
+
],
|
|
39
|
+
tools=(),
|
|
40
|
+
policy=policy(user_action="redact"),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
assert result.messages[1]["content"] == "联系 [REDACTED]"
|
|
44
|
+
row = (
|
|
45
|
+
sqlite3.connect(path)
|
|
46
|
+
.execute(
|
|
47
|
+
"""
|
|
48
|
+
select deployment_key, operation_key, run_id, attempt,
|
|
49
|
+
classifications, sent_bytes, decision
|
|
50
|
+
from provider_attempt_audit
|
|
51
|
+
"""
|
|
52
|
+
)
|
|
53
|
+
.fetchone()
|
|
54
|
+
)
|
|
55
|
+
assert row == (
|
|
56
|
+
"ai.openai-compatible",
|
|
57
|
+
"business.answer",
|
|
58
|
+
"run_1",
|
|
59
|
+
1,
|
|
60
|
+
"internal",
|
|
61
|
+
row[5],
|
|
62
|
+
"redact",
|
|
63
|
+
)
|
|
64
|
+
assert row[5] > 0
|
|
65
|
+
assert "me@example.com" not in path.read_bytes().decode(errors="ignore")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_missing_allowlist_and_dlp_reject_before_network(tmp_path: Path) -> None:
|
|
69
|
+
path = tmp_path / "provider-audit.sqlite3"
|
|
70
|
+
governance = ProviderRequestGovernance(
|
|
71
|
+
ProviderAuditStore(str(path), retention_days=90)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
with pytest.raises(SafeEngineError) as missing:
|
|
75
|
+
governance.authorize(
|
|
76
|
+
deployment_key="ai.openai-compatible",
|
|
77
|
+
operation_key="business.answer",
|
|
78
|
+
run_id="run_missing",
|
|
79
|
+
attempt=1,
|
|
80
|
+
messages=[{"role": "system", "content": "只回答问题"}],
|
|
81
|
+
tools=(),
|
|
82
|
+
policy=ProviderDataPolicy(input_fields=[], envelope_fields=[]),
|
|
83
|
+
)
|
|
84
|
+
assert missing.value.code == "FORBIDDEN"
|
|
85
|
+
|
|
86
|
+
with pytest.raises(SafeEngineError) as rejected:
|
|
87
|
+
governance.authorize(
|
|
88
|
+
deployment_key="ai.openai-compatible",
|
|
89
|
+
operation_key="business.answer",
|
|
90
|
+
run_id="run_reject",
|
|
91
|
+
attempt=1,
|
|
92
|
+
messages=[
|
|
93
|
+
{"role": "system", "content": "只回答问题"},
|
|
94
|
+
{"role": "user", "content": "password=do-not-send"},
|
|
95
|
+
],
|
|
96
|
+
tools=(),
|
|
97
|
+
policy=policy(user_action="reject"),
|
|
98
|
+
)
|
|
99
|
+
assert rejected.value.code == "FORBIDDEN"
|
|
100
|
+
decisions = (
|
|
101
|
+
sqlite3.connect(path)
|
|
102
|
+
.execute(
|
|
103
|
+
"select decision, sent_bytes from provider_attempt_audit "
|
|
104
|
+
"order by occurred_at"
|
|
105
|
+
)
|
|
106
|
+
.fetchall()
|
|
107
|
+
)
|
|
108
|
+
assert decisions == [("reject", 0), ("reject", 0)]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def test_attempts_are_unique_append_only_and_ttl_purge_is_bounded(
|
|
112
|
+
tmp_path: Path,
|
|
113
|
+
) -> None:
|
|
114
|
+
path = tmp_path / "provider-audit.sqlite3"
|
|
115
|
+
store = ProviderAuditStore(str(path), retention_days=1)
|
|
116
|
+
event = ProviderAttemptAudit(
|
|
117
|
+
"ai.openai-compatible",
|
|
118
|
+
"business.answer",
|
|
119
|
+
"run_1",
|
|
120
|
+
1,
|
|
121
|
+
("internal",),
|
|
122
|
+
42,
|
|
123
|
+
"allow",
|
|
124
|
+
)
|
|
125
|
+
store.append(event)
|
|
126
|
+
with pytest.raises(sqlite3.IntegrityError):
|
|
127
|
+
store.append(event)
|
|
128
|
+
|
|
129
|
+
database = sqlite3.connect(path)
|
|
130
|
+
database.execute(
|
|
131
|
+
"update provider_attempt_audit set occurred_at = ?",
|
|
132
|
+
(time.time() - 2 * 24 * 60 * 60,),
|
|
133
|
+
)
|
|
134
|
+
database.commit()
|
|
135
|
+
database.close()
|
|
136
|
+
|
|
137
|
+
assert store.purge_expired() == 1
|
|
138
|
+
health = store.health()
|
|
139
|
+
assert health["retainedRecords"] == 0
|
|
140
|
+
assert health["lastDeletedRecords"] == 1
|
|
141
|
+
assert health["totalDeletedRecords"] == 1
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_audit_store_serializes_concurrent_single_replica_writes(
|
|
145
|
+
tmp_path: Path,
|
|
146
|
+
) -> None:
|
|
147
|
+
store = ProviderAuditStore(
|
|
148
|
+
str(tmp_path / "provider-audit.sqlite3"),
|
|
149
|
+
retention_days=90,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
def append(attempt: int) -> None:
|
|
153
|
+
store.append(
|
|
154
|
+
ProviderAttemptAudit(
|
|
155
|
+
"ai.openai-compatible",
|
|
156
|
+
"business.answer",
|
|
157
|
+
"run_concurrent",
|
|
158
|
+
attempt,
|
|
159
|
+
("internal",),
|
|
160
|
+
42,
|
|
161
|
+
"allow",
|
|
162
|
+
)
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
with ThreadPoolExecutor(max_workers=4) as executor:
|
|
166
|
+
list(executor.map(append, range(1, 21)))
|
|
167
|
+
|
|
168
|
+
assert store.health()["retainedRecords"] == 20
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test_audit_failure_denies_provider_attempt() -> None:
|
|
172
|
+
class BrokenAudit:
|
|
173
|
+
def append(self, _event: ProviderAttemptAudit) -> None:
|
|
174
|
+
raise sqlite3.OperationalError("do-not-expose")
|
|
175
|
+
|
|
176
|
+
governance = ProviderRequestGovernance(cast(ProviderAuditStore, BrokenAudit()))
|
|
177
|
+
with pytest.raises(SafeEngineError) as captured:
|
|
178
|
+
governance.authorize(
|
|
179
|
+
deployment_key="ai.openai-compatible",
|
|
180
|
+
operation_key="business.answer",
|
|
181
|
+
run_id="run_audit_failure",
|
|
182
|
+
attempt=1,
|
|
183
|
+
messages=[
|
|
184
|
+
{"role": "system", "content": "只回答问题"},
|
|
185
|
+
{"role": "user", "content": "正常内容"},
|
|
186
|
+
],
|
|
187
|
+
tools=(),
|
|
188
|
+
policy=policy(user_action="redact"),
|
|
189
|
+
)
|
|
190
|
+
assert captured.value.code == "FORBIDDEN"
|
|
191
|
+
assert "do-not-expose" not in str(captured.value)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def policy(*, user_action: Literal["reject", "redact"]) -> ProviderDataPolicy:
|
|
195
|
+
return ProviderDataPolicy(
|
|
196
|
+
input_fields=[
|
|
197
|
+
ProviderInputFieldPolicy(
|
|
198
|
+
json_pointer="/question",
|
|
199
|
+
classification="internal",
|
|
200
|
+
dlp_action="redact",
|
|
201
|
+
)
|
|
202
|
+
],
|
|
203
|
+
envelope_fields=[
|
|
204
|
+
ProviderFieldPolicy(
|
|
205
|
+
field="instructions",
|
|
206
|
+
classification="internal",
|
|
207
|
+
dlp_action="reject",
|
|
208
|
+
),
|
|
209
|
+
ProviderFieldPolicy(
|
|
210
|
+
field="user-prompt",
|
|
211
|
+
classification="internal",
|
|
212
|
+
dlp_action=user_action,
|
|
213
|
+
),
|
|
214
|
+
],
|
|
215
|
+
)
|
|
@@ -26,9 +26,12 @@
|
|
|
26
26
|
"drizzle-orm": "^0.45.2",
|
|
27
27
|
"elysia": "^1.4.29",
|
|
28
28
|
"mysql2": "^3.22.6",
|
|
29
|
+
"nodemailer": "^9.0.3",
|
|
29
30
|
"pg": "^8.22.0",
|
|
30
31
|
"pino": "^10.3.1",
|
|
31
32
|
"zod": "^4.4.3"
|
|
32
33
|
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/nodemailer": "^8.0.1"
|
|
36
|
+
}
|
|
34
37
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { AiProviderDataPolicy } from "@southwind-ai/modules";
|
|
3
|
+
import {
|
|
4
|
+
governProviderInput,
|
|
5
|
+
ProviderInputGovernanceError,
|
|
6
|
+
} from "./provider-input-governance.js";
|
|
7
|
+
|
|
8
|
+
const policy: AiProviderDataPolicy = {
|
|
9
|
+
inputFields: [
|
|
10
|
+
{
|
|
11
|
+
jsonPointer: "/question",
|
|
12
|
+
classification: "internal",
|
|
13
|
+
dlpAction: "redact",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
jsonPointer: "/identity",
|
|
17
|
+
classification: "sensitive",
|
|
18
|
+
dlpAction: "reject",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
envelopeFields: [
|
|
22
|
+
{
|
|
23
|
+
field: "instructions",
|
|
24
|
+
classification: "internal",
|
|
25
|
+
dlpAction: "reject",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
field: "user-prompt",
|
|
29
|
+
classification: "internal",
|
|
30
|
+
dlpAction: "redact",
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
describe("Provider 输入字段治理", () => {
|
|
36
|
+
test("只保留 JSON Pointer allowlist 并在 Handler 前脱敏", () => {
|
|
37
|
+
const governed = governProviderInput(
|
|
38
|
+
{
|
|
39
|
+
question: "联系 me@example.com 或 13800138000",
|
|
40
|
+
internalCaseId: "case-secret",
|
|
41
|
+
},
|
|
42
|
+
policy,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(governed).toEqual({
|
|
46
|
+
question: "联系 [REDACTED] 或 [REDACTED]",
|
|
47
|
+
});
|
|
48
|
+
expect(JSON.stringify(governed)).not.toContain("case-secret");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test.each([
|
|
52
|
+
"password=do-not-send",
|
|
53
|
+
"Bearer abcdefghijklmnop",
|
|
54
|
+
"11010519491231002X",
|
|
55
|
+
"6222 0201 2345 6789 012",
|
|
56
|
+
])("高风险字段按 reject 策略拒绝:%s", (identity) => {
|
|
57
|
+
expect(() =>
|
|
58
|
+
governProviderInput({ question: "ok", identity }, policy),
|
|
59
|
+
).toThrow(ProviderInputGovernanceError);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("拒绝非对象输入和非法 JSON Pointer", () => {
|
|
63
|
+
expect(() => governProviderInput("raw", policy)).toThrow("输入必须是对象");
|
|
64
|
+
expect(() =>
|
|
65
|
+
governProviderInput(
|
|
66
|
+
{ question: "ok" },
|
|
67
|
+
{
|
|
68
|
+
...policy,
|
|
69
|
+
inputFields: [{ ...policy.inputFields[0]!, jsonPointer: "/bad~2" }],
|
|
70
|
+
},
|
|
71
|
+
),
|
|
72
|
+
).toThrow("JSON Pointer 无效");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("allowlist 只读取输入自身字段,不继承原型属性", () => {
|
|
76
|
+
const inherited = Object.create({
|
|
77
|
+
question: "prototype-secret",
|
|
78
|
+
}) as Record<string, string>;
|
|
79
|
+
|
|
80
|
+
expect(governProviderInput(inherited, policy)).toEqual({});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AiProviderDataPolicy,
|
|
3
|
+
AiProviderDlpAction,
|
|
4
|
+
} from "@southwind-ai/modules";
|
|
5
|
+
import type { ModuleAiJsonValue } from "@southwind-ai/server-sdk";
|
|
6
|
+
|
|
7
|
+
export class ProviderInputGovernanceError extends Error {
|
|
8
|
+
constructor(
|
|
9
|
+
readonly code: "INVALID_INPUT" | "FORBIDDEN",
|
|
10
|
+
message: string,
|
|
11
|
+
) {
|
|
12
|
+
super(message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const dlpPatterns = [
|
|
17
|
+
/\bBearer\s+[A-Za-z0-9._~+/=-]{8,}\b/giu,
|
|
18
|
+
/\b(?:api[_-]?key|secret|password|token)\s*[:=]\s*\S+/giu,
|
|
19
|
+
/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/giu,
|
|
20
|
+
/\b1[3-9]\d{9}\b/gu,
|
|
21
|
+
/\b\d{17}[\dXx]\b/gu,
|
|
22
|
+
/\b(?:\d[ -]?){16,30}\b/gu,
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export function governProviderInput(
|
|
26
|
+
input: ModuleAiJsonValue,
|
|
27
|
+
policy: AiProviderDataPolicy,
|
|
28
|
+
): ModuleAiJsonValue {
|
|
29
|
+
if (!isRecord(input)) {
|
|
30
|
+
throw new ProviderInputGovernanceError(
|
|
31
|
+
"INVALID_INPUT",
|
|
32
|
+
"Provider Operation 输入必须是对象",
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
const governed: Record<string, ModuleAiJsonValue> = Object.create(null);
|
|
36
|
+
for (const rule of policy.inputFields) {
|
|
37
|
+
const segments = parseJsonPointer(rule.jsonPointer);
|
|
38
|
+
const result = readPath(input, segments);
|
|
39
|
+
if (!result.found) continue;
|
|
40
|
+
writePath(governed, segments, governValue(result.value, rule.dlpAction));
|
|
41
|
+
}
|
|
42
|
+
return governed;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function governValue(
|
|
46
|
+
value: ModuleAiJsonValue,
|
|
47
|
+
action: AiProviderDlpAction,
|
|
48
|
+
): ModuleAiJsonValue {
|
|
49
|
+
if (typeof value === "string") {
|
|
50
|
+
if (!dlpPatterns.some((pattern) => matches(pattern, value))) return value;
|
|
51
|
+
if (action === "reject") {
|
|
52
|
+
throw new ProviderInputGovernanceError(
|
|
53
|
+
"FORBIDDEN",
|
|
54
|
+
"Provider 输入被 DLP 策略拒绝",
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return dlpPatterns.reduce(
|
|
58
|
+
(result, pattern) => result.replace(pattern, "[REDACTED]"),
|
|
59
|
+
value,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
return value.map((item) => governValue(item, action));
|
|
64
|
+
}
|
|
65
|
+
if (isRecord(value)) {
|
|
66
|
+
return Object.fromEntries(
|
|
67
|
+
Object.entries(value).map(([key, item]) => [
|
|
68
|
+
key,
|
|
69
|
+
governValue(item, action),
|
|
70
|
+
]),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function parseJsonPointer(pointer: string): string[] {
|
|
77
|
+
return pointer
|
|
78
|
+
.slice(1)
|
|
79
|
+
.split("/")
|
|
80
|
+
.map((segment) => {
|
|
81
|
+
if (/~(?:[^01]|$)/u.test(segment)) {
|
|
82
|
+
throw new ProviderInputGovernanceError(
|
|
83
|
+
"INVALID_INPUT",
|
|
84
|
+
"Provider 输入字段 JSON Pointer 无效",
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
const decoded = segment.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
88
|
+
if (["__proto__", "prototype", "constructor"].includes(decoded)) {
|
|
89
|
+
throw new ProviderInputGovernanceError(
|
|
90
|
+
"INVALID_INPUT",
|
|
91
|
+
"Provider 输入字段 JSON Pointer 无效",
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return decoded;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function readPath(
|
|
99
|
+
input: Record<string, ModuleAiJsonValue>,
|
|
100
|
+
segments: readonly string[],
|
|
101
|
+
): { found: boolean; value: ModuleAiJsonValue } {
|
|
102
|
+
let current: ModuleAiJsonValue = input;
|
|
103
|
+
for (const segment of segments) {
|
|
104
|
+
if (!isRecord(current) || !Object.hasOwn(current, segment)) {
|
|
105
|
+
return { found: false, value: null };
|
|
106
|
+
}
|
|
107
|
+
current = current[segment]!;
|
|
108
|
+
}
|
|
109
|
+
return { found: true, value: current };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function writePath(
|
|
113
|
+
output: Record<string, ModuleAiJsonValue>,
|
|
114
|
+
segments: readonly string[],
|
|
115
|
+
value: ModuleAiJsonValue,
|
|
116
|
+
): void {
|
|
117
|
+
let current = output;
|
|
118
|
+
segments.forEach((segment, index) => {
|
|
119
|
+
if (index === segments.length - 1) {
|
|
120
|
+
current[segment] = value;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const next = current[segment];
|
|
124
|
+
if (!isRecord(next)) {
|
|
125
|
+
current[segment] = Object.create(null);
|
|
126
|
+
}
|
|
127
|
+
current = current[segment] as Record<string, ModuleAiJsonValue>;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function matches(pattern: RegExp, value: string): boolean {
|
|
132
|
+
pattern.lastIndex = 0;
|
|
133
|
+
return pattern.test(value);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function isRecord(
|
|
137
|
+
value: ModuleAiJsonValue,
|
|
138
|
+
): value is Record<string, ModuleAiJsonValue> {
|
|
139
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
140
|
+
}
|
|
@@ -40,6 +40,27 @@ describe("RemoteAgentRuntime", () => {
|
|
|
40
40
|
mode: "configured-endpoint",
|
|
41
41
|
deploymentKey: "ai.openai-compatible",
|
|
42
42
|
},
|
|
43
|
+
providerDataPolicy: {
|
|
44
|
+
inputFields: [
|
|
45
|
+
{
|
|
46
|
+
jsonPointer: "/question",
|
|
47
|
+
classification: "internal",
|
|
48
|
+
dlpAction: "redact",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
envelopeFields: [
|
|
52
|
+
{
|
|
53
|
+
field: "instructions",
|
|
54
|
+
classification: "internal",
|
|
55
|
+
dlpAction: "reject",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
field: "user-prompt",
|
|
59
|
+
classification: "internal",
|
|
60
|
+
dlpAction: "redact",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
43
64
|
toolNetworkPolicy: { mode: "forbidden" },
|
|
44
65
|
executionGrant: "grant_1",
|
|
45
66
|
};
|
|
@@ -60,6 +81,7 @@ describe("RemoteAgentRuntime", () => {
|
|
|
60
81
|
mode: "configured-endpoint",
|
|
61
82
|
deploymentKey: "ai.openai-compatible",
|
|
62
83
|
},
|
|
84
|
+
providerDataPolicy: operation.providerDataPolicy,
|
|
63
85
|
toolNetworkPolicy: { mode: "forbidden" },
|
|
64
86
|
});
|
|
65
87
|
expect(
|
|
@@ -38,6 +38,7 @@ export class RemoteAgentRuntime implements AgentRuntimePort {
|
|
|
38
38
|
maxOutputBytes: request.limits.maxOutputBytes,
|
|
39
39
|
},
|
|
40
40
|
providerEgress: request.providerEgress,
|
|
41
|
+
providerDataPolicy: request.providerDataPolicy,
|
|
41
42
|
toolNetworkPolicy: request.toolNetworkPolicy,
|
|
42
43
|
executionGrant: request.executionGrant,
|
|
43
44
|
toolHostUrl: this.options.toolHostUrl,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
AiProviderDataPolicy,
|
|
2
3
|
AiProviderEgressPolicy,
|
|
3
4
|
AiToolNetworkPolicy,
|
|
4
5
|
} from "@southwind-ai/modules";
|
|
@@ -19,6 +20,7 @@ export interface AgentRuntimeOperation {
|
|
|
19
20
|
maxOutputBytes: number;
|
|
20
21
|
};
|
|
21
22
|
providerEgress: AiProviderEgressPolicy;
|
|
23
|
+
providerDataPolicy: AiProviderDataPolicy;
|
|
22
24
|
toolNetworkPolicy: AiToolNetworkPolicy;
|
|
23
25
|
executionGrant: string;
|
|
24
26
|
}
|
|
@@ -17,7 +17,7 @@ describe("Guarded Agent Run facade", () => {
|
|
|
17
17
|
const fixture = await createFixture();
|
|
18
18
|
const created = await fixture.facade.start(
|
|
19
19
|
"business.answer",
|
|
20
|
-
{ question: "你好" },
|
|
20
|
+
{ question: "你好", internalCaseId: "case-secret" },
|
|
21
21
|
"request-1",
|
|
22
22
|
fixture.context,
|
|
23
23
|
);
|
|
@@ -33,8 +33,18 @@ describe("Guarded Agent Run facade", () => {
|
|
|
33
33
|
instructions: "只回答当前业务问题。",
|
|
34
34
|
userPrompt: "你好",
|
|
35
35
|
allowedTools: [{ key: "business.records.list" }],
|
|
36
|
+
providerDataPolicy: {
|
|
37
|
+
inputFields: expect.arrayContaining([
|
|
38
|
+
expect.objectContaining({ jsonPointer: "/question" }),
|
|
39
|
+
]),
|
|
40
|
+
envelopeFields: expect.arrayContaining([
|
|
41
|
+
expect.objectContaining({ field: "instructions" }),
|
|
42
|
+
]),
|
|
43
|
+
},
|
|
36
44
|
});
|
|
37
45
|
expect(fixture.remote.started[0]?.executionGrant).toMatch(/^grant_/);
|
|
46
|
+
expect(fixture.remote.started[0]?.input).toEqual({ question: "你好" });
|
|
47
|
+
expect(JSON.stringify(fixture.prepared)).not.toContain("case-secret");
|
|
38
48
|
expect(() =>
|
|
39
49
|
fixture.facade.authorizeRun("run_1", fixture.context),
|
|
40
50
|
).not.toThrow();
|
|
@@ -250,7 +260,47 @@ function manifest(): ModuleManifest {
|
|
|
250
260
|
allowedToolKeys: ["business.records.list"],
|
|
251
261
|
dataClassification: "internal",
|
|
252
262
|
execution: "streaming",
|
|
253
|
-
|
|
263
|
+
providerEgress: {
|
|
264
|
+
mode: "configured-endpoint",
|
|
265
|
+
deploymentKey: "ai.openai-compatible",
|
|
266
|
+
},
|
|
267
|
+
providerDataPolicy: {
|
|
268
|
+
inputFields: [
|
|
269
|
+
{
|
|
270
|
+
jsonPointer: "/question",
|
|
271
|
+
classification: "internal",
|
|
272
|
+
dlpAction: "redact",
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
envelopeFields: [
|
|
276
|
+
{
|
|
277
|
+
field: "instructions",
|
|
278
|
+
classification: "internal",
|
|
279
|
+
dlpAction: "reject",
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
field: "user-prompt",
|
|
283
|
+
classification: "internal",
|
|
284
|
+
dlpAction: "redact",
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
field: "tool-definitions",
|
|
288
|
+
classification: "internal",
|
|
289
|
+
dlpAction: "reject",
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
field: "provider-output",
|
|
293
|
+
classification: "internal",
|
|
294
|
+
dlpAction: "redact",
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
field: "tool-results",
|
|
298
|
+
classification: "sensitive",
|
|
299
|
+
dlpAction: "redact",
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
},
|
|
303
|
+
toolNetworkPolicy: { mode: "forbidden" },
|
|
254
304
|
limits: {
|
|
255
305
|
maxDurationSeconds: 60,
|
|
256
306
|
maxInputBytes: 4096,
|
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
ModuleAiOperationHandlerRegistration,
|
|
13
13
|
} from "@southwind-ai/server-sdk";
|
|
14
14
|
import { evaluateAccessGuards } from "../access-guards.js";
|
|
15
|
-
import type
|
|
15
|
+
import { auditActor, type RequestGuardContext } from "../guards.js";
|
|
16
16
|
import type { InitializedModuleHosts } from "../module-host.js";
|
|
17
17
|
import { toModuleActor } from "../module-host.js";
|
|
18
18
|
import type { createServerRuntime } from "../runtime.js";
|
|
@@ -22,6 +22,10 @@ import type {
|
|
|
22
22
|
AgentRuntimePort,
|
|
23
23
|
AgentRuntimeStartResponse,
|
|
24
24
|
} from "./run-contracts.js";
|
|
25
|
+
import {
|
|
26
|
+
governProviderInput,
|
|
27
|
+
ProviderInputGovernanceError,
|
|
28
|
+
} from "./provider-input-governance.js";
|
|
25
29
|
|
|
26
30
|
type ServerRuntime = ReturnType<typeof createServerRuntime>;
|
|
27
31
|
|
|
@@ -88,7 +92,33 @@ export class AgentRunFacade {
|
|
|
88
92
|
);
|
|
89
93
|
}
|
|
90
94
|
assertInputSize(input, operation.definition.limits.maxInputBytes);
|
|
91
|
-
const
|
|
95
|
+
const providerPolicy = operation.definition.providerDataPolicy;
|
|
96
|
+
if (
|
|
97
|
+
operation.definition.providerEgress?.mode === "configured-endpoint" &&
|
|
98
|
+
!providerPolicy
|
|
99
|
+
) {
|
|
100
|
+
throw new AgentRunFacadeError(
|
|
101
|
+
"FORBIDDEN",
|
|
102
|
+
"Agent Operation 缺少 Provider 字段治理策略",
|
|
103
|
+
403,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
let governedInput = input;
|
|
107
|
+
try {
|
|
108
|
+
governedInput = providerPolicy
|
|
109
|
+
? governProviderInput(input, providerPolicy)
|
|
110
|
+
: input;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error instanceof ProviderInputGovernanceError) {
|
|
113
|
+
throw new AgentRunFacadeError(
|
|
114
|
+
error.code,
|
|
115
|
+
error.message,
|
|
116
|
+
error.code === "FORBIDDEN" ? 403 : 400,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
const plan = await operation.handler.prepare(governedInput, {
|
|
92
122
|
actor: toModuleActor(context.actor),
|
|
93
123
|
requestId: context.requestId,
|
|
94
124
|
});
|
|
@@ -104,12 +134,16 @@ export class AgentRunFacade {
|
|
|
104
134
|
const created = await this.remote.start(
|
|
105
135
|
{
|
|
106
136
|
operationKey,
|
|
107
|
-
input,
|
|
137
|
+
input: governedInput,
|
|
108
138
|
instructions: plan.instructions,
|
|
109
139
|
userPrompt: plan.userPrompt,
|
|
110
140
|
allowedTools: operation.tools,
|
|
111
141
|
limits: operation.definition.limits,
|
|
112
142
|
providerEgress: resolveProviderEgress(operation.definition),
|
|
143
|
+
providerDataPolicy: operation.definition.providerDataPolicy ?? {
|
|
144
|
+
inputFields: [],
|
|
145
|
+
envelopeFields: [],
|
|
146
|
+
},
|
|
113
147
|
toolNetworkPolicy: resolveToolNetworkPolicy(operation.definition),
|
|
114
148
|
executionGrant: grant.token,
|
|
115
149
|
},
|
|
@@ -120,12 +154,7 @@ export class AgentRunFacade {
|
|
|
120
154
|
id: randomUUIDv7(),
|
|
121
155
|
action: operation.definition.auditAction,
|
|
122
156
|
outcome: "success",
|
|
123
|
-
actor:
|
|
124
|
-
id: context.actor.id,
|
|
125
|
-
type:
|
|
126
|
-
context.actor.type === "anonymous" ? "user" : context.actor.type,
|
|
127
|
-
name: context.actor.name,
|
|
128
|
-
},
|
|
157
|
+
actor: auditActor(context),
|
|
129
158
|
target: {
|
|
130
159
|
type: "agent-run",
|
|
131
160
|
id: created.runId,
|
|
@@ -11,7 +11,7 @@ import type { AuditEvent, FeatureFlagDefinition } from "@southwind-ai/shared";
|
|
|
11
11
|
import Ajv, { type ValidateFunction } from "ajv";
|
|
12
12
|
import { evaluateAccessGuards } from "../access-guards.js";
|
|
13
13
|
import { isServerScopeContext } from "../data-access/context.js";
|
|
14
|
-
import type
|
|
14
|
+
import { auditActor, type RequestGuardContext } from "../guards.js";
|
|
15
15
|
import { findFeature } from "../route-guards.js";
|
|
16
16
|
import type { createServerRuntime } from "../runtime.js";
|
|
17
17
|
|
|
@@ -292,11 +292,7 @@ function toolEvent(
|
|
|
292
292
|
id: crypto.randomUUID(),
|
|
293
293
|
action: tool.auditAction,
|
|
294
294
|
outcome: "success",
|
|
295
|
-
actor:
|
|
296
|
-
id: context.actor.id,
|
|
297
|
-
type: context.actor.type === "anonymous" ? "user" : context.actor.type,
|
|
298
|
-
name: context.actor.name,
|
|
299
|
-
},
|
|
295
|
+
actor: auditActor(context),
|
|
300
296
|
target: { type: "agent-tool", id: tool.key, label: tool.label },
|
|
301
297
|
module: tool.module,
|
|
302
298
|
requestId: context.requestId,
|