create-safest-tools 0.2.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/LICENSE +201 -0
- package/README.md +71 -0
- package/bin/create-safest-tools.mjs +12 -0
- package/package.json +34 -0
- package/src/cli.mjs +128 -0
- package/src/config.mjs +151 -0
- package/src/scaffold.mjs +30 -0
- package/template/LICENSE +201 -0
- package/template/README.md +35 -0
- package/template/console/README.md +28 -0
- package/template/console/analytics/AnalyticsWorkspace.tsx +55 -0
- package/template/console/analytics/controller.ts +133 -0
- package/template/console/analytics/events.ts +33 -0
- package/template/console/analytics/store.ts +33 -0
- package/template/console/analytics/types.ts +38 -0
- package/template/console/appeals/AppealWorkspace.tsx +73 -0
- package/template/console/appeals/controller.ts +125 -0
- package/template/console/appeals/events.ts +33 -0
- package/template/console/appeals/store.ts +35 -0
- package/template/console/appeals/types.ts +37 -0
- package/template/console/assistant/AssistantWorkspace.tsx +133 -0
- package/template/console/assistant/types.ts +34 -0
- package/template/console/auth/AccountJourney.tsx +69 -0
- package/template/console/auth/InvitationAcceptance.tsx +145 -0
- package/template/console/auth/OAuthButtons.tsx +78 -0
- package/template/console/auth/OperatorLogin.tsx +110 -0
- package/template/console/auth/PasswordRecovery.tsx +132 -0
- package/template/console/auth/account-route.ts +15 -0
- package/template/console/auth/browser-navigation.ts +7 -0
- package/template/console/auth/events.ts +15 -0
- package/template/console/command/CommandCentre.tsx +119 -0
- package/template/console/command/controller.ts +267 -0
- package/template/console/command/events.ts +19 -0
- package/template/console/command/store.ts +36 -0
- package/template/console/command/types.ts +61 -0
- package/template/console/components/AnalystIdentity.tsx +25 -0
- package/template/console/components/PageHeader.tsx +27 -0
- package/template/console/configuration/ConfigurationDialog.tsx +200 -0
- package/template/console/configuration/ConfigurationWorkspace.tsx +66 -0
- package/template/console/configuration/FormBuilder.tsx +143 -0
- package/template/console/configuration/api.ts +40 -0
- package/template/console/configuration/events.ts +14 -0
- package/template/console/configuration/types.ts +79 -0
- package/template/console/lib/format.ts +49 -0
- package/template/console/lib/http.ts +96 -0
- package/template/console/main.tsx +225 -0
- package/template/console/operations/OperationsWorkspace.tsx +126 -0
- package/template/console/operations/controller.ts +237 -0
- package/template/console/operations/events.ts +37 -0
- package/template/console/operations/store.ts +32 -0
- package/template/console/operations/types.ts +107 -0
- package/template/console/people/PeopleWorkspace.tsx +81 -0
- package/template/console/people/types.ts +25 -0
- package/template/console/profile/ProfileWorkspace.tsx +136 -0
- package/template/console/profile/events.ts +9 -0
- package/template/console/profile/types.ts +6 -0
- package/template/console/quality/QualityWorkspace.tsx +87 -0
- package/template/console/quality/controller.ts +154 -0
- package/template/console/quality/events.ts +34 -0
- package/template/console/quality/store.ts +36 -0
- package/template/console/quality/types.ts +70 -0
- package/template/console/queues/QueueEditor.tsx +173 -0
- package/template/console/queues/QueueWorkspace.tsx +109 -0
- package/template/console/queues/controller.ts +194 -0
- package/template/console/queues/events.ts +34 -0
- package/template/console/queues/store.ts +37 -0
- package/template/console/queues/types.ts +102 -0
- package/template/console/registry/RegistryDialog.tsx +198 -0
- package/template/console/registry/RegistryWorkspace.tsx +108 -0
- package/template/console/registry/events.ts +14 -0
- package/template/console/registry/types.ts +52 -0
- package/template/console/reports/ReportDrawer.tsx +159 -0
- package/template/console/reports/ReportWorkspace.tsx +90 -0
- package/template/console/reports/controller.ts +517 -0
- package/template/console/reports/events.ts +42 -0
- package/template/console/reports/store.ts +39 -0
- package/template/console/reports/types.ts +230 -0
- package/template/console/settings/BrandEditor.tsx +126 -0
- package/template/console/settings/ChannelDialog.tsx +241 -0
- package/template/console/settings/SettingsWorkspace.tsx +155 -0
- package/template/console/settings/events.ts +19 -0
- package/template/console/settings/handoff.ts +22 -0
- package/template/console/settings/types.ts +93 -0
- package/template/console/shell/WorkspaceShell.tsx +160 -0
- package/template/console/shell/controller.ts +182 -0
- package/template/console/shell/events.ts +25 -0
- package/template/console/shell/navigation.ts +61 -0
- package/template/console/shell/store.ts +56 -0
- package/template/console/shell/types.ts +86 -0
- package/template/console/workflows/CreateWorkflowDialog.tsx +87 -0
- package/template/console/workflows/WorkflowCanvas.tsx +42 -0
- package/template/console/workflows/WorkflowDialogs.tsx +6 -0
- package/template/console/workflows/WorkflowStudio.tsx +331 -0
- package/template/console/workflows/WorkflowWorkspace.tsx +82 -0
- package/template/console/workflows/events.ts +17 -0
- package/template/console/workflows/graph.ts +156 -0
- package/template/console/workflows/templates.ts +70 -0
- package/template/console/workflows/types.ts +201 -0
- package/template/gitignore.template +18 -0
- package/template/migrations/0001_reports_foundation.sql +444 -0
- package/template/migrations/0002_human_report_loop.sql +65 -0
- package/template/migrations/0003_delivery_reliability.sql +18 -0
- package/template/migrations/0004_public_intake.sql +14 -0
- package/template/migrations/0005_operations_visibility.sql +24 -0
- package/template/migrations/0006_ai_governance.sql +198 -0
- package/template/migrations/0007_ai_release_gates.sql +6 -0
- package/template/migrations/0008_retention_analytics_exports.sql +52 -0
- package/template/migrations/0009_retention_derived_copies.sql +14 -0
- package/template/migrations/0010_ai_quality_controls.sql +26 -0
- package/template/migrations/0011_analyst_presence.sql +28 -0
- package/template/migrations/0012_queue_policies.sql +87 -0
- package/template/migrations/0013_routing_agents.sql +63 -0
- package/template/migrations/0014_webhook_enrichments.sql +122 -0
- package/template/migrations/0015_queue_owned_ai.sql +55 -0
- package/template/migrations/0016_operator_accounts.sql +67 -0
- package/template/migrations/0017_operator_profiles_and_recovery.sql +33 -0
- package/template/migrations/0018_platform_configuration.sql +382 -0
- package/template/migrations/0019_workflow_authoring_runtime.sql +372 -0
- package/template/migrations/0020_tasks_findings_assistant_budgets.sql +427 -0
- package/template/migrations/0021_abuse_evidence_operations.sql +324 -0
- package/template/migrations/0022_workflow_dispatch_operations.sql +42 -0
- package/template/migrations/0023_component_connection_execution.sql +75 -0
- package/template/migrations/0024_access_runtime_integrity.sql +72 -0
- package/template/migrations/0025_installation_timezone.sql +11 -0
- package/template/migrations/0026_ai_and_egress_execution_controls.sql +49 -0
- package/template/migrations/0027_prompt_and_ai_registry.sql +37 -0
- package/template/migrations/0028_step_attempt_ai_provenance.sql +13 -0
- package/template/migrations/0029_evidence_fetch_transport.sql +5 -0
- package/template/migrations/0030_evidence_dlq_incidents.sql +45 -0
- package/template/migrations/0031_shadow_quality_integrity.sql +7 -0
- package/template/migrations/0032_action_delivery_outbox.sql +55 -0
- package/template/migrations/0033_configuration_and_assistant_drafts.sql +43 -0
- package/template/migrations/0034_installation_integrations.sql +31 -0
- package/template/migrations/0035_workspace_governance.sql +21 -0
- package/template/migrations/0036_published_routing_baseline.sql +15 -0
- package/template/migrations/0037_builtin_phishing_specialist.sql +71 -0
- package/template/migrations/0038_remove_deprecated_enrichment_runtime.sql +228 -0
- package/template/migrations/0039_secure_reporting_channels.sql +45 -0
- package/template/migrations/0040_notification_only_reporting.sql +24 -0
- package/template/migrations/0041_better_auth_credentials.sql +17 -0
- package/template/package.json +47 -0
- package/template/public/_headers +27 -0
- package/template/public/app-icon-192.png +0 -0
- package/template/public/app-icon-512.png +0 -0
- package/template/public/brand-icon.svg +7 -0
- package/template/public/brand-tokens.css +80 -0
- package/template/public/console/auth-shell.js +19340 -0
- package/template/public/customer-brand.js +58 -0
- package/template/public/embed/embed.css +139 -0
- package/template/public/embed/embed.js +408 -0
- package/template/public/embed/index.html +91 -0
- package/template/public/favicon.svg +7 -0
- package/template/public/fonts/Manrope-Variable.ttf +0 -0
- package/template/public/fonts/Newsreader-Italic-Variable.ttf +0 -0
- package/template/public/fonts/Newsreader-Variable.ttf +0 -0
- package/template/public/index.html +123 -0
- package/template/public/logo-primary.svg +7 -0
- package/template/public/logo-reversed.svg +7 -0
- package/template/public/manifest.webmanifest +21 -0
- package/template/public/public-report.js +184 -0
- package/template/public/report/index.html +39 -0
- package/template/public/report/public-report.css +20 -0
- package/template/public/social-card.png +0 -0
- package/template/public/styles.css +1521 -0
- package/template/public/widget.css +80 -0
- package/template/public/widget.js +220 -0
- package/template/reports.config.example.json +38 -0
- package/template/reports.schema.json +89 -0
- package/template/scripts/reports-auth-onboarding.mjs +180 -0
- package/template/scripts/reports-backup.mjs +276 -0
- package/template/scripts/reports-cloudflare-preflight.mjs +152 -0
- package/template/scripts/reports-deploy.mjs +173 -0
- package/template/scripts/reports-plan.mjs +226 -0
- package/template/scripts/reports-restore.mjs +180 -0
- package/template/scripts/reports-secrets.mjs +73 -0
- package/template/scripts/reports-uninstall-plan.mjs +32 -0
- package/template/src/agent-executor.ts +330 -0
- package/template/src/ai-observability.ts +163 -0
- package/template/src/ai-registry-validation.ts +244 -0
- package/template/src/ai-registry.ts +292 -0
- package/template/src/api-cursor.ts +84 -0
- package/template/src/assistant.ts +554 -0
- package/template/src/audit.ts +39 -0
- package/template/src/backup-service.ts +269 -0
- package/template/src/budget-control.ts +127 -0
- package/template/src/component-executor.ts +845 -0
- package/template/src/configuration-registry.ts +550 -0
- package/template/src/connection-egress.ts +430 -0
- package/template/src/connection-oauth.ts +368 -0
- package/template/src/evidence-service.ts +335 -0
- package/template/src/human-tasks.ts +316 -0
- package/template/src/index.ts +4114 -0
- package/template/src/installation-admin.ts +301 -0
- package/template/src/intake-abuse.ts +156 -0
- package/template/src/platform-registry-validation.ts +367 -0
- package/template/src/platform-registry.ts +753 -0
- package/template/src/report-admin.ts +342 -0
- package/template/src/report-ai-quality.ts +390 -0
- package/template/src/report-ai-validation.ts +80 -0
- package/template/src/report-ai.ts +857 -0
- package/template/src/report-auth.ts +292 -0
- package/template/src/report-better-auth.ts +583 -0
- package/template/src/report-context-schema.ts +132 -0
- package/template/src/report-context.ts +126 -0
- package/template/src/report-crypto.ts +142 -0
- package/template/src/report-delivery.ts +579 -0
- package/template/src/report-form-validation.ts +51 -0
- package/template/src/report-governance.ts +510 -0
- package/template/src/report-http.ts +90 -0
- package/template/src/report-operations.ts +685 -0
- package/template/src/report-operator-accounts.ts +810 -0
- package/template/src/report-presence.ts +398 -0
- package/template/src/report-queue-validation.ts +309 -0
- package/template/src/report-queues.ts +478 -0
- package/template/src/report-repository.ts +972 -0
- package/template/src/report-router-agent.ts +328 -0
- package/template/src/report-router-validation.ts +81 -0
- package/template/src/report-routing.ts +178 -0
- package/template/src/report-turnstile.ts +142 -0
- package/template/src/report-types.ts +224 -0
- package/template/src/report-validation.ts +279 -0
- package/template/src/report-workflow-validation.ts +119 -0
- package/template/src/report-workflow.ts +886 -0
- package/template/src/shadow-quality.ts +278 -0
- package/template/src/workflow-actions.ts +782 -0
- package/template/src/workflow-compiler.ts +230 -0
- package/template/src/workflow-dynamic-runtime.ts +613 -0
- package/template/src/workflow-effects.ts +316 -0
- package/template/src/workflow-expressions.ts +191 -0
- package/template/src/workflow-platform-types.ts +121 -0
- package/template/src/workflow-platform-validation.ts +540 -0
- package/template/src/workflow-repository.ts +916 -0
- package/template/src/workflow-runs.ts +686 -0
- package/template/src/workflow-simulator.ts +211 -0
- package/template/src/workspace-branding.ts +128 -0
- package/template/src/workspace-governance.ts +279 -0
- package/template/tsconfig.console.json +23 -0
- package/template/tsconfig.json +22 -0
- package/template/vite.console.config.ts +20 -0
- package/template/worker-configuration.d.ts +65 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
PRAGMA foreign_keys = ON;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE dead_letter_items RENAME TO dead_letter_items_v1;
|
|
4
|
+
|
|
5
|
+
CREATE TABLE dead_letter_items (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
fingerprint TEXT NOT NULL UNIQUE,
|
|
8
|
+
source_queue TEXT NOT NULL,
|
|
9
|
+
source_message_id TEXT NOT NULL,
|
|
10
|
+
job_type TEXT NOT NULL CHECK (job_type IN ('route_report', 'process_ai_report', 'deliver_action', 'deliver_notification', 'invalid')),
|
|
11
|
+
job_id TEXT,
|
|
12
|
+
report_id TEXT REFERENCES reports(id),
|
|
13
|
+
outbox_id TEXT,
|
|
14
|
+
state TEXT NOT NULL DEFAULT 'open' CHECK (state IN ('open', 'acknowledged', 'resolved')),
|
|
15
|
+
error_code TEXT NOT NULL,
|
|
16
|
+
occurrence_count INTEGER NOT NULL DEFAULT 1 CHECK (occurrence_count > 0),
|
|
17
|
+
details_json TEXT NOT NULL DEFAULT '{}',
|
|
18
|
+
first_seen_at TEXT NOT NULL,
|
|
19
|
+
last_seen_at TEXT NOT NULL,
|
|
20
|
+
resolved_at TEXT
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
INSERT INTO dead_letter_items (
|
|
24
|
+
id, fingerprint, source_queue, source_message_id, job_type, job_id, report_id, outbox_id,
|
|
25
|
+
state, error_code, occurrence_count, details_json, first_seen_at, last_seen_at, resolved_at
|
|
26
|
+
)
|
|
27
|
+
SELECT id, fingerprint, source_queue, source_message_id, job_type, job_id, report_id, outbox_id,
|
|
28
|
+
state, error_code, occurrence_count, details_json, first_seen_at, last_seen_at, resolved_at
|
|
29
|
+
FROM dead_letter_items_v1;
|
|
30
|
+
|
|
31
|
+
DROP TABLE dead_letter_items_v1;
|
|
32
|
+
|
|
33
|
+
CREATE INDEX dead_letter_items_state_idx
|
|
34
|
+
ON dead_letter_items(state, last_seen_at DESC, id DESC);
|
|
35
|
+
CREATE INDEX dead_letter_items_report_idx
|
|
36
|
+
ON dead_letter_items(report_id, last_seen_at DESC, id DESC);
|
|
37
|
+
|
|
38
|
+
ALTER TABLE message_template_versions ADD COLUMN automation_allowed INTEGER NOT NULL DEFAULT 0 CHECK (automation_allowed IN (0, 1));
|
|
39
|
+
ALTER TABLE message_template_versions ADD COLUMN variables_schema_json TEXT NOT NULL DEFAULT '{}';
|
|
40
|
+
|
|
41
|
+
CREATE TABLE ai_queue_config_versions (
|
|
42
|
+
id TEXT PRIMARY KEY,
|
|
43
|
+
queue_id TEXT NOT NULL REFERENCES queue_definitions(id),
|
|
44
|
+
version INTEGER NOT NULL CHECK (version > 0),
|
|
45
|
+
mode TEXT NOT NULL CHECK (mode IN ('off', 'shadow', 'assist', 'autonomous_low_priority')),
|
|
46
|
+
enabled INTEGER NOT NULL DEFAULT 0 CHECK (enabled IN (0, 1)),
|
|
47
|
+
provider TEXT NOT NULL CHECK (provider IN ('workers_ai')),
|
|
48
|
+
model TEXT NOT NULL,
|
|
49
|
+
input_cost_microusd_per_million INTEGER NOT NULL DEFAULT 0 CHECK (input_cost_microusd_per_million >= 0),
|
|
50
|
+
output_cost_microusd_per_million INTEGER NOT NULL DEFAULT 0 CHECK (output_cost_microusd_per_million >= 0),
|
|
51
|
+
prompt_version TEXT NOT NULL,
|
|
52
|
+
policy_version_id TEXT NOT NULL REFERENCES policy_versions(id),
|
|
53
|
+
eligible_form_versions_json TEXT NOT NULL,
|
|
54
|
+
eligible_sources_json TEXT NOT NULL,
|
|
55
|
+
eligible_reason_codes_json TEXT NOT NULL,
|
|
56
|
+
eligible_target_types_json TEXT NOT NULL,
|
|
57
|
+
allowed_fields_json TEXT NOT NULL,
|
|
58
|
+
allowed_outcomes_json TEXT NOT NULL,
|
|
59
|
+
allowed_action_codes_json TEXT NOT NULL DEFAULT '[]',
|
|
60
|
+
allowed_template_ids_json TEXT NOT NULL,
|
|
61
|
+
confidence_threshold REAL NOT NULL CHECK (confidence_threshold >= 0 AND confidence_threshold <= 1),
|
|
62
|
+
max_follow_up_turns INTEGER NOT NULL CHECK (max_follow_up_turns >= 0 AND max_follow_up_turns <= 5),
|
|
63
|
+
max_wait_hours INTEGER NOT NULL CHECK (max_wait_hours >= 1 AND max_wait_hours <= 720),
|
|
64
|
+
daily_report_budget INTEGER NOT NULL CHECK (daily_report_budget >= 0),
|
|
65
|
+
daily_cost_budget_microusd INTEGER NOT NULL CHECK (daily_cost_budget_microusd >= 0),
|
|
66
|
+
quality_sample_rate REAL NOT NULL CHECK (quality_sample_rate >= 0 AND quality_sample_rate <= 1),
|
|
67
|
+
fallback_queue_id TEXT NOT NULL REFERENCES queue_definitions(id),
|
|
68
|
+
pause_state TEXT NOT NULL DEFAULT 'ready' CHECK (pause_state IN ('ready', 'paused', 'budget_exhausted', 'quality_paused')),
|
|
69
|
+
published_at TEXT,
|
|
70
|
+
retired_at TEXT,
|
|
71
|
+
created_by TEXT NOT NULL,
|
|
72
|
+
created_at TEXT NOT NULL,
|
|
73
|
+
idempotency_key TEXT NOT NULL UNIQUE,
|
|
74
|
+
UNIQUE (queue_id, version)
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
CREATE INDEX ai_queue_config_active_idx
|
|
78
|
+
ON ai_queue_config_versions(queue_id, enabled, pause_state, published_at, retired_at, version DESC);
|
|
79
|
+
|
|
80
|
+
ALTER TABLE background_jobs ADD COLUMN ai_config_version_id TEXT REFERENCES ai_queue_config_versions(id);
|
|
81
|
+
|
|
82
|
+
CREATE TABLE ai_runs (
|
|
83
|
+
id TEXT PRIMARY KEY,
|
|
84
|
+
report_id TEXT NOT NULL REFERENCES reports(id),
|
|
85
|
+
background_job_id TEXT NOT NULL UNIQUE REFERENCES background_jobs(id),
|
|
86
|
+
config_version_id TEXT NOT NULL REFERENCES ai_queue_config_versions(id),
|
|
87
|
+
mode TEXT NOT NULL CHECK (mode IN ('shadow', 'assist', 'autonomous_low_priority')),
|
|
88
|
+
provider TEXT NOT NULL,
|
|
89
|
+
model TEXT NOT NULL,
|
|
90
|
+
prompt_version TEXT NOT NULL,
|
|
91
|
+
policy_version_id TEXT NOT NULL REFERENCES policy_versions(id),
|
|
92
|
+
status TEXT NOT NULL CHECK (status IN ('running', 'succeeded', 'invalid', 'failed', 'escalated')),
|
|
93
|
+
input_references_json TEXT NOT NULL,
|
|
94
|
+
output_json TEXT,
|
|
95
|
+
error_code TEXT,
|
|
96
|
+
started_at TEXT NOT NULL,
|
|
97
|
+
finished_at TEXT,
|
|
98
|
+
input_units INTEGER,
|
|
99
|
+
output_units INTEGER,
|
|
100
|
+
estimated_cost_microusd INTEGER NOT NULL DEFAULT 0 CHECK (estimated_cost_microusd >= 0)
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
CREATE INDEX ai_runs_report_idx ON ai_runs(report_id, started_at DESC, id DESC);
|
|
104
|
+
CREATE INDEX ai_runs_config_status_idx ON ai_runs(config_version_id, status, started_at DESC, id DESC);
|
|
105
|
+
|
|
106
|
+
CREATE TABLE ai_results (
|
|
107
|
+
id TEXT PRIMARY KEY,
|
|
108
|
+
ai_run_id TEXT NOT NULL UNIQUE REFERENCES ai_runs(id) ON DELETE CASCADE,
|
|
109
|
+
outcome TEXT NOT NULL,
|
|
110
|
+
policy_code TEXT,
|
|
111
|
+
evidence_references_json TEXT NOT NULL,
|
|
112
|
+
summary TEXT NOT NULL,
|
|
113
|
+
confidence REAL,
|
|
114
|
+
uncertain INTEGER NOT NULL CHECK (uncertain IN (0, 1)),
|
|
115
|
+
message_template_id TEXT REFERENCES message_template_versions(id),
|
|
116
|
+
message_variables_json TEXT,
|
|
117
|
+
action_code TEXT,
|
|
118
|
+
escalation_code TEXT,
|
|
119
|
+
validation_state TEXT NOT NULL CHECK (validation_state IN ('valid', 'invalid')),
|
|
120
|
+
validation_errors_json TEXT NOT NULL,
|
|
121
|
+
created_at TEXT NOT NULL
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
CREATE TABLE ai_tool_calls (
|
|
125
|
+
id TEXT PRIMARY KEY,
|
|
126
|
+
ai_run_id TEXT NOT NULL REFERENCES ai_runs(id) ON DELETE CASCADE,
|
|
127
|
+
tool_name TEXT NOT NULL,
|
|
128
|
+
input_references_json TEXT NOT NULL,
|
|
129
|
+
status TEXT NOT NULL CHECK (status IN ('allowed', 'denied', 'succeeded', 'failed')),
|
|
130
|
+
error_code TEXT,
|
|
131
|
+
created_at TEXT NOT NULL
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
CREATE TABLE ai_quality_samples (
|
|
135
|
+
id TEXT PRIMARY KEY,
|
|
136
|
+
ai_run_id TEXT NOT NULL UNIQUE REFERENCES ai_runs(id),
|
|
137
|
+
report_id TEXT NOT NULL REFERENCES reports(id),
|
|
138
|
+
sample_reason TEXT NOT NULL,
|
|
139
|
+
state TEXT NOT NULL CHECK (state IN ('pending', 'claimed', 'complete')),
|
|
140
|
+
selected_at TEXT NOT NULL
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
CREATE TABLE quality_reviews (
|
|
144
|
+
id TEXT PRIMARY KEY,
|
|
145
|
+
sample_id TEXT NOT NULL UNIQUE REFERENCES ai_quality_samples(id),
|
|
146
|
+
reviewer_id TEXT NOT NULL,
|
|
147
|
+
agrees INTEGER NOT NULL CHECK (agrees IN (0, 1)),
|
|
148
|
+
notes TEXT NOT NULL,
|
|
149
|
+
created_at TEXT NOT NULL
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
CREATE TABLE ai_usage_daily (
|
|
153
|
+
usage_date TEXT NOT NULL,
|
|
154
|
+
config_version_id TEXT NOT NULL REFERENCES ai_queue_config_versions(id),
|
|
155
|
+
reports_started INTEGER NOT NULL DEFAULT 0 CHECK (reports_started >= 0),
|
|
156
|
+
reports_resolved INTEGER NOT NULL DEFAULT 0 CHECK (reports_resolved >= 0),
|
|
157
|
+
reports_escalated INTEGER NOT NULL DEFAULT 0 CHECK (reports_escalated >= 0),
|
|
158
|
+
failures INTEGER NOT NULL DEFAULT 0 CHECK (failures >= 0),
|
|
159
|
+
estimated_cost_microusd INTEGER NOT NULL DEFAULT 0 CHECK (estimated_cost_microusd >= 0),
|
|
160
|
+
updated_at TEXT NOT NULL,
|
|
161
|
+
PRIMARY KEY (usage_date, config_version_id)
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
INSERT INTO message_template_versions (
|
|
165
|
+
id, installation_id, template_key, version, audience, purpose, locale,
|
|
166
|
+
body_template, published_at, created_by, created_at, automation_allowed, variables_schema_json
|
|
167
|
+
) VALUES
|
|
168
|
+
('ai-more-context-v1', 'default', 'ai-more-context', 1, 'reporter', 'follow_up', 'en',
|
|
169
|
+
'Automated review needs one more detail: {{missing_item}}. Reply here, or request review by a person.',
|
|
170
|
+
strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), 'system', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), 1,
|
|
171
|
+
'{"missing_item":{"type":"string","minLength":3,"maxLength":160}}'),
|
|
172
|
+
('ai-no-violation-v1', 'default', 'ai-no-violation', 1, 'reporter', 'outcome', 'en',
|
|
173
|
+
'Automated review did not find a violation under {{policy_code}}. You may request review by a person.',
|
|
174
|
+
strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), 'system', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), 1,
|
|
175
|
+
'{"policy_code":{"type":"string","minLength":1,"maxLength":100}}'),
|
|
176
|
+
('ai-out-of-scope-v1', 'default', 'ai-out-of-scope', 1, 'reporter', 'outcome', 'en',
|
|
177
|
+
'This report is outside the scope of {{policy_code}}. You may request review by a person.',
|
|
178
|
+
strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), 'system', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), 1,
|
|
179
|
+
'{"policy_code":{"type":"string","minLength":1,"maxLength":100}}');
|
|
180
|
+
|
|
181
|
+
INSERT INTO ai_queue_config_versions (
|
|
182
|
+
id, queue_id, version, mode, enabled, provider, model, prompt_version, policy_version_id,
|
|
183
|
+
input_cost_microusd_per_million, output_cost_microusd_per_million,
|
|
184
|
+
eligible_form_versions_json, eligible_sources_json, eligible_reason_codes_json, eligible_target_types_json,
|
|
185
|
+
allowed_fields_json, allowed_outcomes_json, allowed_action_codes_json, allowed_template_ids_json,
|
|
186
|
+
confidence_threshold, max_follow_up_turns, max_wait_hours, daily_report_budget,
|
|
187
|
+
daily_cost_budget_microusd, quality_sample_rate, fallback_queue_id, pause_state,
|
|
188
|
+
published_at, created_by, created_at, idempotency_key
|
|
189
|
+
) VALUES (
|
|
190
|
+
'low-priority-ai-v1', 'low-priority-ai', 1, 'shadow', 0, 'workers_ai',
|
|
191
|
+
'@cf/meta/llama-3.1-8b-instruct-fast', 'safest-low-priority-v1', 'general-policy-v1', 0, 0,
|
|
192
|
+
'["general-v1"]', '["widget","public_page","server_api"]', '["spam"]',
|
|
193
|
+
'["message","profile","listing","account"]', '["answers.details","target.type","evidence.references"]',
|
|
194
|
+
'["out_of_scope","insufficient_information","no_violation_found","escalate_to_human"]', '[]',
|
|
195
|
+
'["ai-more-context-v1","ai-no-violation-v1","ai-out-of-scope-v1"]',
|
|
196
|
+
0.85, 1, 72, 100, 1000000, 0.10, 'standard-human', 'ready',
|
|
197
|
+
strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), 'system', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), 'seed:low-priority-ai-v1'
|
|
198
|
+
);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
PRAGMA foreign_keys = ON;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE ai_queue_config_versions ADD COLUMN minimum_shadow_runs INTEGER NOT NULL DEFAULT 25 CHECK (minimum_shadow_runs >= 1 AND minimum_shadow_runs <= 100000);
|
|
4
|
+
ALTER TABLE ai_queue_config_versions ADD COLUMN minimum_quality_reviews INTEGER NOT NULL DEFAULT 5 CHECK (minimum_quality_reviews >= 0 AND minimum_quality_reviews <= 100000);
|
|
5
|
+
ALTER TABLE ai_queue_config_versions ADD COLUMN maximum_failure_rate REAL NOT NULL DEFAULT 0.05 CHECK (maximum_failure_rate >= 0 AND maximum_failure_rate <= 1);
|
|
6
|
+
ALTER TABLE ai_queue_config_versions ADD COLUMN maximum_disagreement_rate REAL NOT NULL DEFAULT 0.10 CHECK (maximum_disagreement_rate >= 0 AND maximum_disagreement_rate <= 1);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
PRAGMA foreign_keys = ON;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE case_messages ADD COLUMN redacted_at TEXT;
|
|
4
|
+
ALTER TABLE report_answers ADD COLUMN redacted_at TEXT;
|
|
5
|
+
ALTER TABLE report_participants ADD COLUMN reference_redacted_at TEXT;
|
|
6
|
+
ALTER TABLE report_targets ADD COLUMN sensitive_redacted_at TEXT;
|
|
7
|
+
|
|
8
|
+
CREATE TABLE legal_holds (
|
|
9
|
+
id TEXT PRIMARY KEY,
|
|
10
|
+
report_id TEXT NOT NULL REFERENCES reports(id) ON DELETE CASCADE,
|
|
11
|
+
reason TEXT NOT NULL,
|
|
12
|
+
state TEXT NOT NULL CHECK (state IN ('active', 'released')),
|
|
13
|
+
placed_by TEXT NOT NULL,
|
|
14
|
+
idempotency_key TEXT NOT NULL UNIQUE,
|
|
15
|
+
created_at TEXT NOT NULL,
|
|
16
|
+
released_by TEXT,
|
|
17
|
+
release_idempotency_key TEXT UNIQUE,
|
|
18
|
+
released_at TEXT
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
CREATE UNIQUE INDEX legal_holds_one_active_idx ON legal_holds(report_id) WHERE state = 'active';
|
|
22
|
+
CREATE INDEX legal_holds_state_idx ON legal_holds(state, created_at, id);
|
|
23
|
+
|
|
24
|
+
CREATE TABLE deletion_requests (
|
|
25
|
+
id TEXT PRIMARY KEY,
|
|
26
|
+
report_id TEXT NOT NULL REFERENCES reports(id) ON DELETE CASCADE,
|
|
27
|
+
scope TEXT NOT NULL CHECK (scope IN ('participant_data', 'all_permitted_data')),
|
|
28
|
+
reason TEXT NOT NULL,
|
|
29
|
+
state TEXT NOT NULL CHECK (state IN ('pending', 'blocked_by_hold', 'complete', 'failed')),
|
|
30
|
+
requested_by TEXT NOT NULL,
|
|
31
|
+
idempotency_key TEXT NOT NULL UNIQUE,
|
|
32
|
+
requested_at TEXT NOT NULL,
|
|
33
|
+
completed_at TEXT,
|
|
34
|
+
last_error_code TEXT
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
CREATE INDEX deletion_requests_state_idx ON deletion_requests(state, requested_at, id);
|
|
38
|
+
|
|
39
|
+
CREATE TABLE retention_jobs (
|
|
40
|
+
id TEXT PRIMARY KEY,
|
|
41
|
+
job_kind TEXT NOT NULL CHECK (job_kind IN ('scheduled_retention', 'deletion_request')),
|
|
42
|
+
state TEXT NOT NULL CHECK (state IN ('running', 'complete', 'failed')),
|
|
43
|
+
cutoff_at TEXT NOT NULL,
|
|
44
|
+
messages_redacted INTEGER NOT NULL DEFAULT 0 CHECK (messages_redacted >= 0),
|
|
45
|
+
reports_anonymized INTEGER NOT NULL DEFAULT 0 CHECK (reports_anonymized >= 0),
|
|
46
|
+
portal_sessions_revoked INTEGER NOT NULL DEFAULT 0 CHECK (portal_sessions_revoked >= 0),
|
|
47
|
+
error_code TEXT,
|
|
48
|
+
started_at TEXT NOT NULL,
|
|
49
|
+
finished_at TEXT
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
CREATE INDEX retention_jobs_state_idx ON retention_jobs(state, started_at DESC, id DESC);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
PRAGMA foreign_keys = ON;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE decisions ADD COLUMN sensitive_redacted_at TEXT;
|
|
4
|
+
ALTER TABLE notices ADD COLUMN redacted_at TEXT;
|
|
5
|
+
ALTER TABLE appeals ADD COLUMN reason_redacted_at TEXT;
|
|
6
|
+
ALTER TABLE appeal_decisions ADD COLUMN rationale_redacted_at TEXT;
|
|
7
|
+
ALTER TABLE action_outbox ADD COLUMN payload_redacted_at TEXT;
|
|
8
|
+
ALTER TABLE notification_outbox ADD COLUMN payload_redacted_at TEXT;
|
|
9
|
+
ALTER TABLE ai_runs ADD COLUMN output_redacted_at TEXT;
|
|
10
|
+
ALTER TABLE ai_results ADD COLUMN redacted_at TEXT;
|
|
11
|
+
ALTER TABLE quality_reviews ADD COLUMN notes_redacted_at TEXT;
|
|
12
|
+
|
|
13
|
+
CREATE INDEX deletion_requests_report_state_idx
|
|
14
|
+
ON deletion_requests(report_id, state, requested_at, id);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
PRAGMA foreign_keys = ON;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE ai_quality_samples ADD COLUMN claimed_by TEXT;
|
|
4
|
+
ALTER TABLE ai_quality_samples ADD COLUMN claimed_at TEXT;
|
|
5
|
+
ALTER TABLE ai_quality_samples ADD COLUMN claim_expires_at TEXT;
|
|
6
|
+
|
|
7
|
+
ALTER TABLE quality_reviews ADD COLUMN issue_codes_json TEXT NOT NULL DEFAULT '[]';
|
|
8
|
+
ALTER TABLE quality_reviews ADD COLUMN corrected_outcome_code TEXT;
|
|
9
|
+
ALTER TABLE quality_reviews ADD COLUMN corrected_policy_code TEXT;
|
|
10
|
+
ALTER TABLE quality_reviews ADD COLUMN idempotency_key TEXT;
|
|
11
|
+
|
|
12
|
+
CREATE UNIQUE INDEX quality_reviews_idempotency_idx ON quality_reviews(idempotency_key);
|
|
13
|
+
CREATE INDEX ai_quality_samples_work_idx
|
|
14
|
+
ON ai_quality_samples(state, claim_expires_at, selected_at, id);
|
|
15
|
+
|
|
16
|
+
ALTER TABLE ai_queue_config_versions ADD COLUMN pause_reason TEXT;
|
|
17
|
+
ALTER TABLE ai_queue_config_versions ADD COLUMN paused_at TEXT;
|
|
18
|
+
|
|
19
|
+
ALTER TABLE ai_usage_daily ADD COLUMN eligible_reports INTEGER NOT NULL DEFAULT 0 CHECK (eligible_reports >= 0);
|
|
20
|
+
ALTER TABLE ai_usage_daily ADD COLUMN waiting_for_reporter INTEGER NOT NULL DEFAULT 0 CHECK (waiting_for_reporter >= 0);
|
|
21
|
+
ALTER TABLE ai_usage_daily ADD COLUMN human_review_requests INTEGER NOT NULL DEFAULT 0 CHECK (human_review_requests >= 0);
|
|
22
|
+
ALTER TABLE ai_usage_daily ADD COLUMN appeals_filed INTEGER NOT NULL DEFAULT 0 CHECK (appeals_filed >= 0);
|
|
23
|
+
ALTER TABLE ai_usage_daily ADD COLUMN appeal_reversals INTEGER NOT NULL DEFAULT 0 CHECK (appeal_reversals >= 0);
|
|
24
|
+
ALTER TABLE ai_usage_daily ADD COLUMN invalid_outputs INTEGER NOT NULL DEFAULT 0 CHECK (invalid_outputs >= 0);
|
|
25
|
+
ALTER TABLE ai_usage_daily ADD COLUMN provider_errors INTEGER NOT NULL DEFAULT 0 CHECK (provider_errors >= 0);
|
|
26
|
+
ALTER TABLE ai_usage_daily ADD COLUMN timeouts INTEGER NOT NULL DEFAULT 0 CHECK (timeouts >= 0);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
PRAGMA foreign_keys = ON;
|
|
2
|
+
|
|
3
|
+
CREATE TABLE analyst_profiles (
|
|
4
|
+
actor_id TEXT PRIMARY KEY,
|
|
5
|
+
display_name TEXT NOT NULL,
|
|
6
|
+
email TEXT,
|
|
7
|
+
avatar_url TEXT,
|
|
8
|
+
avatar_color TEXT NOT NULL,
|
|
9
|
+
roles_json TEXT NOT NULL,
|
|
10
|
+
created_at TEXT NOT NULL,
|
|
11
|
+
updated_at TEXT NOT NULL,
|
|
12
|
+
last_authenticated_at TEXT NOT NULL
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
CREATE TABLE analyst_sessions (
|
|
16
|
+
id TEXT PRIMARY KEY,
|
|
17
|
+
actor_id TEXT NOT NULL REFERENCES analyst_profiles(actor_id) ON DELETE CASCADE,
|
|
18
|
+
activity_state TEXT NOT NULL DEFAULT 'online'
|
|
19
|
+
CHECK (activity_state IN ('online', 'viewing', 'editing', 'away')),
|
|
20
|
+
active_report_id TEXT REFERENCES reports(id) ON DELETE SET NULL,
|
|
21
|
+
connected_at TEXT NOT NULL,
|
|
22
|
+
last_seen_at TEXT NOT NULL
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
CREATE INDEX analyst_sessions_presence_idx
|
|
26
|
+
ON analyst_sessions(last_seen_at DESC, actor_id, id);
|
|
27
|
+
CREATE INDEX analyst_sessions_report_idx
|
|
28
|
+
ON analyst_sessions(active_report_id, last_seen_at DESC, id);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
PRAGMA foreign_keys = ON;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE queue_definitions ADD COLUMN description TEXT NOT NULL DEFAULT '';
|
|
4
|
+
ALTER TABLE queue_definitions ADD COLUMN purpose TEXT NOT NULL DEFAULT 'reports'
|
|
5
|
+
CHECK (purpose IN ('reports', 'appeals', 'quality', 'operations'));
|
|
6
|
+
ALTER TABLE queue_definitions ADD COLUMN status TEXT NOT NULL DEFAULT 'active'
|
|
7
|
+
CHECK (status IN ('active', 'paused', 'archived'));
|
|
8
|
+
ALTER TABLE queue_definitions ADD COLUMN position INTEGER NOT NULL DEFAULT 100;
|
|
9
|
+
ALTER TABLE queue_definitions ADD COLUMN active_version_id TEXT;
|
|
10
|
+
ALTER TABLE queue_definitions ADD COLUMN created_by TEXT NOT NULL DEFAULT 'system';
|
|
11
|
+
|
|
12
|
+
ALTER TABLE queue_versions ADD COLUMN management_mode TEXT NOT NULL DEFAULT 'human'
|
|
13
|
+
CHECK (management_mode IN ('human', 'ai', 'hybrid'));
|
|
14
|
+
ALTER TABLE queue_versions ADD COLUMN routing_criteria_json TEXT NOT NULL DEFAULT '{"match":"all","conditions":[]}';
|
|
15
|
+
ALTER TABLE queue_versions ADD COLUMN reviewer_instructions TEXT NOT NULL DEFAULT 'Review the report against the published customer policy.';
|
|
16
|
+
ALTER TABLE queue_versions ADD COLUMN ai_instructions TEXT;
|
|
17
|
+
ALTER TABLE queue_versions ADD COLUMN enrichment_requirements_json TEXT NOT NULL DEFAULT '[]';
|
|
18
|
+
ALTER TABLE queue_versions ADD COLUMN ai_bounds_json TEXT NOT NULL DEFAULT '{}';
|
|
19
|
+
ALTER TABLE queue_versions ADD COLUMN retired_at TEXT;
|
|
20
|
+
|
|
21
|
+
UPDATE queue_definitions
|
|
22
|
+
SET purpose = CASE queue_kind
|
|
23
|
+
WHEN 'appeal' THEN 'appeals'
|
|
24
|
+
WHEN 'operations' THEN 'operations'
|
|
25
|
+
ELSE 'reports'
|
|
26
|
+
END,
|
|
27
|
+
position = CASE id
|
|
28
|
+
WHEN 'urgent-human' THEN 10
|
|
29
|
+
WHEN 'standard-human' THEN 20
|
|
30
|
+
WHEN 'low-priority-ai' THEN 30
|
|
31
|
+
WHEN 'appeals' THEN 40
|
|
32
|
+
ELSE 50
|
|
33
|
+
END,
|
|
34
|
+
description = CASE id
|
|
35
|
+
WHEN 'urgent-human' THEN 'Protected, uncertain, urgent, or high-impact reports requiring human review.'
|
|
36
|
+
WHEN 'standard-human' THEN 'General reports requiring a human decision.'
|
|
37
|
+
WHEN 'low-priority-ai' THEN 'Bounded low-priority automation with mandatory human fallback.'
|
|
38
|
+
WHEN 'appeals' THEN 'Human-only review of contested decisions.'
|
|
39
|
+
ELSE 'Delivery failures and operational recovery work.'
|
|
40
|
+
END;
|
|
41
|
+
|
|
42
|
+
UPDATE queue_versions
|
|
43
|
+
SET management_mode = CASE
|
|
44
|
+
WHEN queue_id = 'low-priority-ai' THEN 'ai'
|
|
45
|
+
ELSE 'human'
|
|
46
|
+
END,
|
|
47
|
+
routing_criteria_json = CASE queue_id
|
|
48
|
+
WHEN 'urgent-human' THEN '{"match":"any","conditions":[{"field":"safeguard.requires_human","operator":"eq","value":true}]}'
|
|
49
|
+
WHEN 'low-priority-ai' THEN '{"match":"all","conditions":[{"field":"safeguard.requires_human","operator":"eq","value":false},{"field":"priority","operator":"lte","value":30}]}'
|
|
50
|
+
ELSE '{"match":"all","conditions":[]}'
|
|
51
|
+
END,
|
|
52
|
+
reviewer_instructions = CASE queue_id
|
|
53
|
+
WHEN 'urgent-human' THEN 'Review promptly. Treat the submission as an allegation, preserve uncertainty, and do not delegate the final decision to AI.'
|
|
54
|
+
WHEN 'standard-human' THEN 'Review the allegation and referenced evidence against the published customer policy. Record the evidence considered and rationale.'
|
|
55
|
+
WHEN 'appeals' THEN 'A human appeal reviewer must independently assess the contested decision and record a reasoned outcome.'
|
|
56
|
+
WHEN 'operations' THEN 'Investigate the failed job, preserve accepted reports, and record any recovery action.'
|
|
57
|
+
ELSE 'Review AI output and all referenced evidence before accepting or changing the recommendation.'
|
|
58
|
+
END,
|
|
59
|
+
ai_instructions = CASE queue_id
|
|
60
|
+
WHEN 'low-priority-ai' THEN 'Assess only eligible low-priority reports against the published policy. Escalate uncertainty, missing evidence, protected cases, failures, and out-of-bound outcomes to a human.'
|
|
61
|
+
ELSE NULL
|
|
62
|
+
END,
|
|
63
|
+
ai_bounds_json = CASE queue_id
|
|
64
|
+
WHEN 'low-priority-ai' THEN '{"allowed_outcomes":[],"confidence_threshold":0.85,"max_follow_up_turns":1,"autonomous_actions":false}'
|
|
65
|
+
ELSE '{}'
|
|
66
|
+
END;
|
|
67
|
+
|
|
68
|
+
UPDATE queue_definitions
|
|
69
|
+
SET active_version_id = (
|
|
70
|
+
SELECT qv.id FROM queue_versions qv
|
|
71
|
+
WHERE qv.queue_id = queue_definitions.id AND qv.published_at IS NOT NULL
|
|
72
|
+
ORDER BY qv.version DESC LIMIT 1
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
CREATE INDEX queue_definitions_admin_idx
|
|
76
|
+
ON queue_definitions(purpose, status, position, name, id);
|
|
77
|
+
CREATE INDEX queue_versions_policy_idx
|
|
78
|
+
ON queue_versions(queue_id, published_at DESC, version DESC, id);
|
|
79
|
+
|
|
80
|
+
CREATE TABLE configuration_mutations (
|
|
81
|
+
idempotency_key TEXT PRIMARY KEY,
|
|
82
|
+
action TEXT NOT NULL,
|
|
83
|
+
actor_id TEXT NOT NULL,
|
|
84
|
+
target_id TEXT NOT NULL,
|
|
85
|
+
response_json TEXT NOT NULL,
|
|
86
|
+
created_at TEXT NOT NULL
|
|
87
|
+
);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
PRAGMA foreign_keys = ON;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE reports ADD COLUMN queue_version_id TEXT REFERENCES queue_versions(id);
|
|
4
|
+
ALTER TABLE reports ADD COLUMN routing_agent_version_id TEXT;
|
|
5
|
+
ALTER TABLE reports ADD COLUMN routing_reason_json TEXT;
|
|
6
|
+
|
|
7
|
+
CREATE TABLE routing_agent_versions (
|
|
8
|
+
id TEXT PRIMARY KEY,
|
|
9
|
+
installation_id TEXT NOT NULL REFERENCES installations(id),
|
|
10
|
+
version INTEGER NOT NULL CHECK (version > 0),
|
|
11
|
+
enabled INTEGER NOT NULL DEFAULT 0 CHECK (enabled IN (0, 1)),
|
|
12
|
+
rollout_mode TEXT NOT NULL CHECK (rollout_mode IN ('off', 'shadow', 'active')),
|
|
13
|
+
provider TEXT NOT NULL DEFAULT 'workers_ai' CHECK (provider = 'workers_ai'),
|
|
14
|
+
model TEXT NOT NULL,
|
|
15
|
+
instructions TEXT NOT NULL,
|
|
16
|
+
candidate_queue_ids_json TEXT NOT NULL,
|
|
17
|
+
safeguard_queue_id TEXT NOT NULL REFERENCES queue_definitions(id),
|
|
18
|
+
default_queue_id TEXT NOT NULL REFERENCES queue_definitions(id),
|
|
19
|
+
confidence_threshold REAL NOT NULL CHECK (confidence_threshold BETWEEN 0 AND 1),
|
|
20
|
+
allowed_fields_json TEXT NOT NULL,
|
|
21
|
+
published_at TEXT NOT NULL,
|
|
22
|
+
created_by TEXT NOT NULL,
|
|
23
|
+
created_at TEXT NOT NULL,
|
|
24
|
+
idempotency_key TEXT NOT NULL UNIQUE,
|
|
25
|
+
UNIQUE (installation_id, version)
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
CREATE INDEX routing_agent_versions_active_idx
|
|
29
|
+
ON routing_agent_versions(installation_id, published_at DESC, version DESC, id);
|
|
30
|
+
|
|
31
|
+
CREATE TABLE routing_agent_runs (
|
|
32
|
+
id TEXT PRIMARY KEY,
|
|
33
|
+
report_id TEXT NOT NULL REFERENCES reports(id) ON DELETE CASCADE,
|
|
34
|
+
routing_agent_version_id TEXT NOT NULL REFERENCES routing_agent_versions(id),
|
|
35
|
+
background_job_id TEXT NOT NULL UNIQUE REFERENCES background_jobs(id),
|
|
36
|
+
status TEXT NOT NULL CHECK (status IN ('running', 'succeeded', 'failed', 'rejected', 'shadowed')),
|
|
37
|
+
candidate_queue_ids_json TEXT NOT NULL,
|
|
38
|
+
selected_queue_id TEXT REFERENCES queue_definitions(id),
|
|
39
|
+
confidence REAL,
|
|
40
|
+
needs_human INTEGER CHECK (needs_human IN (0, 1)),
|
|
41
|
+
rationale TEXT,
|
|
42
|
+
validation_errors_json TEXT NOT NULL DEFAULT '[]',
|
|
43
|
+
started_at TEXT NOT NULL,
|
|
44
|
+
finished_at TEXT
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
CREATE INDEX routing_agent_runs_report_idx
|
|
48
|
+
ON routing_agent_runs(report_id, started_at DESC, id DESC);
|
|
49
|
+
|
|
50
|
+
INSERT INTO routing_agent_versions (
|
|
51
|
+
id, installation_id, version, enabled, rollout_mode, provider, model, instructions,
|
|
52
|
+
candidate_queue_ids_json, safeguard_queue_id, default_queue_id, confidence_threshold,
|
|
53
|
+
allowed_fields_json, published_at, created_by, created_at, idempotency_key
|
|
54
|
+
) VALUES (
|
|
55
|
+
'report-router-v1', 'default', 1, 0, 'off', 'workers_ai',
|
|
56
|
+
'@cf/meta/llama-3.1-8b-instruct-fast',
|
|
57
|
+
'Choose only among the supplied eligible queue identifiers. Route uncertainty or protected cases to a human. Do not decide the report.',
|
|
58
|
+
'["urgent-human","standard-human","low-priority-ai"]',
|
|
59
|
+
'urgent-human', 'standard-human', 0.85,
|
|
60
|
+
'["reason_code","source","target_type","answers.details","trusted_facts"]',
|
|
61
|
+
strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), 'system', strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
|
|
62
|
+
'seed:report-router-v1'
|
|
63
|
+
);
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
PRAGMA foreign_keys = ON;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE dead_letter_items RENAME TO dead_letter_items_v2;
|
|
4
|
+
|
|
5
|
+
CREATE TABLE dead_letter_items (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
fingerprint TEXT NOT NULL UNIQUE,
|
|
8
|
+
source_queue TEXT NOT NULL,
|
|
9
|
+
source_message_id TEXT NOT NULL,
|
|
10
|
+
job_type TEXT NOT NULL CHECK (job_type IN ('route_report', 'process_ai_report', 'run_enrichment', 'deliver_action', 'deliver_notification', 'invalid')),
|
|
11
|
+
job_id TEXT,
|
|
12
|
+
report_id TEXT REFERENCES reports(id),
|
|
13
|
+
outbox_id TEXT,
|
|
14
|
+
state TEXT NOT NULL DEFAULT 'open' CHECK (state IN ('open', 'acknowledged', 'resolved')),
|
|
15
|
+
error_code TEXT NOT NULL,
|
|
16
|
+
occurrence_count INTEGER NOT NULL DEFAULT 1 CHECK (occurrence_count > 0),
|
|
17
|
+
details_json TEXT NOT NULL DEFAULT '{}',
|
|
18
|
+
first_seen_at TEXT NOT NULL,
|
|
19
|
+
last_seen_at TEXT NOT NULL,
|
|
20
|
+
resolved_at TEXT
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
INSERT INTO dead_letter_items (
|
|
24
|
+
id, fingerprint, source_queue, source_message_id, job_type, job_id, report_id, outbox_id,
|
|
25
|
+
state, error_code, occurrence_count, details_json, first_seen_at, last_seen_at, resolved_at
|
|
26
|
+
)
|
|
27
|
+
SELECT id, fingerprint, source_queue, source_message_id, job_type, job_id, report_id, outbox_id,
|
|
28
|
+
state, error_code, occurrence_count, details_json, first_seen_at, last_seen_at, resolved_at
|
|
29
|
+
FROM dead_letter_items_v2;
|
|
30
|
+
|
|
31
|
+
DROP TABLE dead_letter_items_v2;
|
|
32
|
+
|
|
33
|
+
CREATE INDEX dead_letter_items_state_idx
|
|
34
|
+
ON dead_letter_items(state, last_seen_at DESC, id DESC);
|
|
35
|
+
CREATE INDEX dead_letter_items_report_idx
|
|
36
|
+
ON dead_letter_items(report_id, last_seen_at DESC, id DESC);
|
|
37
|
+
|
|
38
|
+
CREATE TABLE enrichment_definitions (
|
|
39
|
+
id TEXT PRIMARY KEY,
|
|
40
|
+
installation_id TEXT NOT NULL REFERENCES installations(id),
|
|
41
|
+
enrichment_key TEXT NOT NULL,
|
|
42
|
+
name TEXT NOT NULL,
|
|
43
|
+
description TEXT NOT NULL DEFAULT '',
|
|
44
|
+
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'paused', 'archived')),
|
|
45
|
+
active_version_id TEXT,
|
|
46
|
+
created_by TEXT NOT NULL,
|
|
47
|
+
created_at TEXT NOT NULL,
|
|
48
|
+
updated_at TEXT NOT NULL,
|
|
49
|
+
UNIQUE (installation_id, enrichment_key)
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
CREATE TABLE enrichment_definition_versions (
|
|
53
|
+
id TEXT PRIMARY KEY,
|
|
54
|
+
definition_id TEXT NOT NULL REFERENCES enrichment_definitions(id) ON DELETE CASCADE,
|
|
55
|
+
version INTEGER NOT NULL CHECK (version > 0),
|
|
56
|
+
webhook_url TEXT NOT NULL,
|
|
57
|
+
secret_binding TEXT NOT NULL,
|
|
58
|
+
timeout_ms INTEGER NOT NULL CHECK (timeout_ms BETWEEN 250 AND 30000),
|
|
59
|
+
max_attempts INTEGER NOT NULL CHECK (max_attempts BETWEEN 1 AND 10),
|
|
60
|
+
ttl_seconds INTEGER NOT NULL CHECK (ttl_seconds BETWEEN 60 AND 2592000),
|
|
61
|
+
input_fields_json TEXT NOT NULL,
|
|
62
|
+
output_schema_json TEXT NOT NULL,
|
|
63
|
+
published_at TEXT NOT NULL,
|
|
64
|
+
created_by TEXT NOT NULL,
|
|
65
|
+
created_at TEXT NOT NULL,
|
|
66
|
+
UNIQUE (definition_id, version)
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
CREATE INDEX enrichment_definitions_admin_idx
|
|
70
|
+
ON enrichment_definitions(status, name, id);
|
|
71
|
+
CREATE INDEX enrichment_definition_versions_idx
|
|
72
|
+
ON enrichment_definition_versions(definition_id, version DESC, id);
|
|
73
|
+
|
|
74
|
+
CREATE TABLE enrichment_requests (
|
|
75
|
+
id TEXT PRIMARY KEY,
|
|
76
|
+
report_id TEXT NOT NULL REFERENCES reports(id) ON DELETE CASCADE,
|
|
77
|
+
queue_version_id TEXT NOT NULL REFERENCES queue_versions(id),
|
|
78
|
+
definition_version_id TEXT NOT NULL REFERENCES enrichment_definition_versions(id),
|
|
79
|
+
enrichment_key TEXT NOT NULL,
|
|
80
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'processing', 'retrying', 'complete', 'failed')),
|
|
81
|
+
attempt_count INTEGER NOT NULL DEFAULT 0 CHECK (attempt_count >= 0),
|
|
82
|
+
next_attempt_at TEXT NOT NULL,
|
|
83
|
+
last_error_code TEXT,
|
|
84
|
+
created_at TEXT NOT NULL,
|
|
85
|
+
updated_at TEXT NOT NULL,
|
|
86
|
+
completed_at TEXT,
|
|
87
|
+
UNIQUE (report_id, queue_version_id, enrichment_key)
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
CREATE INDEX enrichment_requests_due_idx
|
|
91
|
+
ON enrichment_requests(status, next_attempt_at, id);
|
|
92
|
+
CREATE INDEX enrichment_requests_report_idx
|
|
93
|
+
ON enrichment_requests(report_id, status, id);
|
|
94
|
+
|
|
95
|
+
CREATE TABLE enrichment_attempts (
|
|
96
|
+
id TEXT PRIMARY KEY,
|
|
97
|
+
enrichment_request_id TEXT NOT NULL REFERENCES enrichment_requests(id) ON DELETE CASCADE,
|
|
98
|
+
attempt_number INTEGER NOT NULL CHECK (attempt_number > 0),
|
|
99
|
+
request_nonce TEXT NOT NULL,
|
|
100
|
+
response_status INTEGER,
|
|
101
|
+
response_class TEXT NOT NULL,
|
|
102
|
+
error_code TEXT,
|
|
103
|
+
started_at TEXT NOT NULL,
|
|
104
|
+
finished_at TEXT NOT NULL,
|
|
105
|
+
UNIQUE (enrichment_request_id, attempt_number)
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
CREATE TABLE enrichment_results (
|
|
109
|
+
id TEXT PRIMARY KEY,
|
|
110
|
+
enrichment_request_id TEXT NOT NULL UNIQUE REFERENCES enrichment_requests(id) ON DELETE CASCADE,
|
|
111
|
+
report_id TEXT NOT NULL REFERENCES reports(id) ON DELETE CASCADE,
|
|
112
|
+
enrichment_key TEXT NOT NULL,
|
|
113
|
+
subject_reference TEXT NOT NULL,
|
|
114
|
+
data_json TEXT NOT NULL,
|
|
115
|
+
response_sha256 TEXT NOT NULL,
|
|
116
|
+
definition_version_id TEXT NOT NULL REFERENCES enrichment_definition_versions(id),
|
|
117
|
+
fetched_at TEXT NOT NULL,
|
|
118
|
+
expires_at TEXT NOT NULL
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
CREATE INDEX enrichment_results_report_idx
|
|
122
|
+
ON enrichment_results(report_id, enrichment_key, expires_at DESC, id);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
PRAGMA foreign_keys = ON;
|
|
2
|
+
|
|
3
|
+
ALTER TABLE ai_queue_config_versions
|
|
4
|
+
ADD COLUMN queue_version_id TEXT REFERENCES queue_versions(id);
|
|
5
|
+
|
|
6
|
+
CREATE UNIQUE INDEX ai_queue_config_queue_version_idx
|
|
7
|
+
ON ai_queue_config_versions(queue_version_id)
|
|
8
|
+
WHERE queue_version_id IS NOT NULL;
|
|
9
|
+
|
|
10
|
+
UPDATE ai_queue_config_versions
|
|
11
|
+
SET queue_version_id = (
|
|
12
|
+
SELECT q.active_version_id FROM queue_definitions q
|
|
13
|
+
WHERE q.id = ai_queue_config_versions.queue_id
|
|
14
|
+
)
|
|
15
|
+
WHERE id IN (
|
|
16
|
+
SELECT c.id FROM ai_queue_config_versions c
|
|
17
|
+
WHERE c.id = (
|
|
18
|
+
SELECT latest.id FROM ai_queue_config_versions latest
|
|
19
|
+
WHERE latest.queue_id = c.queue_id
|
|
20
|
+
ORDER BY latest.version DESC, latest.created_at DESC, latest.id DESC LIMIT 1
|
|
21
|
+
)
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
INSERT INTO ai_queue_config_versions (
|
|
25
|
+
id, queue_id, queue_version_id, version, mode, enabled, provider, model,
|
|
26
|
+
input_cost_microusd_per_million, output_cost_microusd_per_million,
|
|
27
|
+
prompt_version, policy_version_id, eligible_form_versions_json, eligible_sources_json,
|
|
28
|
+
eligible_reason_codes_json, eligible_target_types_json, allowed_fields_json, allowed_outcomes_json,
|
|
29
|
+
allowed_action_codes_json, allowed_template_ids_json, confidence_threshold, max_follow_up_turns,
|
|
30
|
+
max_wait_hours, daily_report_budget, daily_cost_budget_microusd, quality_sample_rate,
|
|
31
|
+
minimum_shadow_runs, minimum_quality_reviews, maximum_failure_rate, maximum_disagreement_rate,
|
|
32
|
+
fallback_queue_id, pause_state, published_at, created_by, created_at, idempotency_key
|
|
33
|
+
)
|
|
34
|
+
SELECT
|
|
35
|
+
qv.id || '-ai-runtime', qv.queue_id, qv.id, qv.version, qv.mode, 1, 'workers_ai',
|
|
36
|
+
'@cf/meta/llama-3.1-8b-instruct-fast', 0, 0, 'queue-policy-' || qv.id, 'general-policy-v1',
|
|
37
|
+
'["general-v1"]', '["signed_widget","public_page","server_api"]',
|
|
38
|
+
'["harassment","spam","other"]', '["message","profile","listing","account","file","transaction","service"]',
|
|
39
|
+
'["target.type","answers.details","evidence.references","enrichments"]',
|
|
40
|
+
CASE
|
|
41
|
+
WHEN json_array_length(COALESCE(json_extract(qv.ai_bounds_json, '$.allowedOutcomes'), json_extract(qv.ai_bounds_json, '$.allowed_outcomes'), '[]')) > 0
|
|
42
|
+
THEN COALESCE(json_extract(qv.ai_bounds_json, '$.allowedOutcomes'), json_extract(qv.ai_bounds_json, '$.allowed_outcomes'))
|
|
43
|
+
ELSE '["no_violation_found","out_of_scope","insufficient_information","escalate_to_human"]'
|
|
44
|
+
END,
|
|
45
|
+
'[]', '["ai-more-context-v1","ai-no-violation-v1","ai-out-of-scope-v1"]',
|
|
46
|
+
COALESCE(json_extract(qv.ai_bounds_json, '$.confidenceThreshold'), json_extract(qv.ai_bounds_json, '$.confidence_threshold'), 0.85),
|
|
47
|
+
COALESCE(json_extract(qv.ai_bounds_json, '$.maxFollowUpTurns'), json_extract(qv.ai_bounds_json, '$.max_follow_up_turns'), 0),
|
|
48
|
+
168, 100, 1000000, 0.1, 25, 10, 0.1, 0.1, qv.fallback_queue_id,
|
|
49
|
+
'ready', qv.published_at, qv.created_by, qv.created_at, 'queue-policy-runtime:' || qv.id
|
|
50
|
+
FROM queue_versions qv
|
|
51
|
+
WHERE qv.management_mode IN ('ai', 'hybrid') AND qv.mode != 'off'
|
|
52
|
+
AND qv.fallback_queue_id IS NOT NULL
|
|
53
|
+
AND NOT EXISTS (
|
|
54
|
+
SELECT 1 FROM ai_queue_config_versions c WHERE c.queue_version_id = qv.id
|
|
55
|
+
);
|