classifyre-schemas 0.4.2__tar.gz

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.
@@ -0,0 +1,54 @@
1
+ .idea/
2
+ runner-logs/
3
+ dumps/
4
+ apps/web/playwright/.cache/
5
+ **/__pycache__/
6
+ *.py[cod]
7
+ .secrets
8
+ .claude/
9
+ .codex/
10
+ # Dependencies
11
+ node_modules
12
+ .pnp
13
+ .pnp.js
14
+
15
+ # Local env files
16
+ .env
17
+ .env.local
18
+ .env.development.local
19
+ .env.test.local
20
+ .env.production.local
21
+
22
+ # Testing
23
+ coverage
24
+
25
+ # Turbo
26
+ .turbo
27
+
28
+ # Vercel
29
+ .vercel
30
+
31
+ # Build Outputs
32
+ .next/
33
+ out/
34
+ build
35
+ dist
36
+ classifyre/apps/web/playwright/.cache/
37
+ apps/web/public/docs/
38
+
39
+ # Python cache artifacts
40
+ __pycache__/
41
+ *.pyc
42
+ # Debug
43
+ npm-debug.log*
44
+
45
+ # Misc
46
+ .DS_Store
47
+ *.pem
48
+
49
+ # Generated API Types (regenerate from openapi.json)
50
+ apps/web/lib/api/schema.ts
51
+ apps/web/lib/api/schema.d.ts
52
+ .tools/
53
+
54
+ bin/act
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: classifyre-schemas
3
+ Version: 0.4.2
4
+ Summary: Shared JSON schemas for Classifyre monorepo
5
+ Requires-Python: >=3.12
6
+ Requires-Dist: fastjsonschema==2.21.2
File without changes
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@workspace/schemas",
3
+ "version": "0.4.2",
4
+ "private": true,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.ts",
8
+ "./source-docs": "./src/source-docs.ts",
9
+ "./detector-docs": "./src/detector-docs.ts",
10
+ "./assistant": "./src/assistant.ts",
11
+ "./package.json": "./package.json",
12
+ "./all_input_sources": "./src/schemas/all_input_sources.json",
13
+ "./all_detectors": "./src/schemas/all_detectors.ts",
14
+ "./single_asset_scan_results": "./src/schemas/single_asset_scan_results.json",
15
+ "./all_input_examples": "./src/schemas/all_input_examples.json",
16
+ "./all_detectors_examples": "./src/schemas/all_detectors_examples.ts",
17
+ "./assistant_knowledge": "./src/schemas/assistant_knowledge.json",
18
+ "./assistant_contexts": "./src/schemas/assistant_contexts.json"
19
+ },
20
+ "files": [
21
+ "src"
22
+ ],
23
+ "dependencies": {
24
+ "zod": "^4.3.6"
25
+ },
26
+ "scripts": {
27
+ "validate-examples": "uv run python scripts/validate_examples.py",
28
+ "codegen": "bun run validate-examples"
29
+ }
30
+ }
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "classifyre-schemas"
3
+ version = "0.4.2"
4
+ description = "Shared JSON schemas for Classifyre monorepo"
5
+ requires-python = ">=3.12"
6
+ dependencies = [
7
+ "fastjsonschema==2.21.2",
8
+ ]
9
+
10
+ [tool.uv]
11
+ package = true
12
+
13
+ [build-system]
14
+ requires = ["hatchling"]
15
+ build-backend = "hatchling.build"
16
+
17
+ [tool.hatch.build.targets.wheel]
18
+ packages = ["src/schemas"]
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env python3
2
+ """Validate input examples against the input sources schema."""
3
+
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ import fastjsonschema
9
+
10
+ # Map source type to schema definition name
11
+ TYPE_TO_DEFINITION = {
12
+ "SLACK": "SlackInput",
13
+ "S3_COMPATIBLE_STORAGE": "S3CompatibleStorageInput",
14
+ "AZURE_BLOB_STORAGE": "AzureBlobStorageInput",
15
+ "GOOGLE_CLOUD_STORAGE": "GoogleCloudStorageInput",
16
+ "WORDPRESS": "WordPressInput",
17
+ "POSTGRESQL": "PostgreSQLInput",
18
+ "MYSQL": "MySQLInput",
19
+ "MSSQL": "MSSQLInput",
20
+ "ORACLE": "OracleInput",
21
+ "HIVE": "HiveInput",
22
+ "DATABRICKS": "DatabricksInput",
23
+ "SNOWFLAKE": "SnowflakeInput",
24
+ "MONGODB": "MongoDBInput",
25
+ "NEO4J": "Neo4jInput",
26
+ "POWERBI": "PowerBIInput",
27
+ "TABLEAU": "TableauInput",
28
+ "CONFLUENCE": "ConfluenceInput",
29
+ "JIRA": "JiraInput",
30
+ "SERVICEDESK": "ServiceDeskInput",
31
+ }
32
+
33
+ SCHEMAS_DIR = Path(__file__).parent.parent / "src" / "schemas"
34
+
35
+
36
+ def load_schema():
37
+ """Load the input sources schema."""
38
+ schema_path = SCHEMAS_DIR / "all_input_sources.json"
39
+ with open(schema_path, "r") as f:
40
+ return json.load(f)
41
+
42
+
43
+ def load_examples():
44
+ """Load the input examples."""
45
+ examples_path = SCHEMAS_DIR / "all_input_examples.json"
46
+ with open(examples_path, "r") as f:
47
+ return json.load(f)
48
+
49
+
50
+ def create_validation_schema_for_type(schema: dict, source_type: str) -> dict:
51
+ """Create a validation schema for a specific source type."""
52
+ definition_name = TYPE_TO_DEFINITION.get(source_type)
53
+ if not definition_name:
54
+ raise ValueError(f"Unknown source type: {source_type}")
55
+
56
+ # Create a schema that references the specific input definition
57
+ return {
58
+ "$schema": schema.get("$schema", "http://json-schema.org/draft-07/schema#"),
59
+ "$ref": f"#/definitions/{definition_name}",
60
+ "definitions": schema.get("definitions", {}),
61
+ }
62
+
63
+
64
+ def validate_examples():
65
+ """Validate all examples against the schema."""
66
+ schema = load_schema()
67
+ examples = load_examples()
68
+
69
+ errors = []
70
+ total_examples = 0
71
+ validated_examples = 0
72
+
73
+ for source_type, example_list in examples.items():
74
+ if not isinstance(example_list, list):
75
+ errors.append(f"Invalid format for {source_type}: expected array, got {type(example_list).__name__}")
76
+ continue
77
+
78
+ # Create validator for this source type
79
+ try:
80
+ type_schema = create_validation_schema_for_type(schema, source_type)
81
+ validator = fastjsonschema.compile(type_schema)
82
+ except ValueError as e:
83
+ # Skip types that don't have a schema definition
84
+ print(f"⚠️ Skipping {source_type}: {e}")
85
+ continue
86
+ except Exception as e:
87
+ errors.append(f"Failed to create validator for {source_type}: {e}")
88
+ continue
89
+
90
+ # Validate each example's config field
91
+ for idx, example in enumerate(example_list):
92
+ total_examples += 1
93
+
94
+ # Validate example structure
95
+ if not isinstance(example, dict):
96
+ errors.append(f"{source_type}[{idx}]: Example must be an object")
97
+ continue
98
+
99
+ if "name" not in example:
100
+ errors.append(f"{source_type}[{idx}]: Missing 'name' field")
101
+ if "description" not in example:
102
+ errors.append(f"{source_type}[{idx}]: Missing 'description' field")
103
+ if "config" not in example:
104
+ errors.append(f"{source_type}[{idx}]: Missing 'config' field")
105
+ continue
106
+
107
+ # Validate config against schema
108
+ try:
109
+ validator(example["config"])
110
+ validated_examples += 1
111
+ except fastjsonschema.JsonSchemaException as e:
112
+ errors.append(f"{source_type}[{idx}] ({example.get('name', 'unnamed')}): {e.message}")
113
+ except Exception as e:
114
+ errors.append(f"{source_type}[{idx}] ({example.get('name', 'unnamed')}): Unexpected error: {e}")
115
+
116
+ # Print results
117
+ print(f"Validated {validated_examples}/{total_examples} examples")
118
+
119
+ if errors:
120
+ print("\nValidation errors:")
121
+ for error in errors:
122
+ print(f" ❌ {error}")
123
+ return False
124
+
125
+ print("✅ All examples are valid!")
126
+ return True
127
+
128
+
129
+ if __name__ == "__main__":
130
+ success = validate_examples()
131
+ sys.exit(0 if success else 1)
@@ -0,0 +1,209 @@
1
+ import { z } from "zod";
2
+
3
+ export const assistantContextKeySchema = z.enum([
4
+ "source.create",
5
+ "source.edit",
6
+ "detector.create",
7
+ "semantic.glossary",
8
+ "semantic.metrics",
9
+ ]);
10
+
11
+ export type AssistantContextKey = z.infer<typeof assistantContextKeySchema>;
12
+
13
+ export const assistantOperationSchema = z.enum([
14
+ "create_source",
15
+ "update_source",
16
+ "test_source_connection",
17
+ "create_custom_detector",
18
+ "train_custom_detector",
19
+ "create_glossary_term",
20
+ "create_metric_definition",
21
+ "certify_metric",
22
+ ]);
23
+
24
+ export type AssistantOperation = z.infer<typeof assistantOperationSchema>;
25
+
26
+ export const assistantValidationStateSchema = z.object({
27
+ isValid: z.boolean(),
28
+ missingFields: z.array(z.string()),
29
+ errors: z.array(z.string()),
30
+ });
31
+
32
+ export type AssistantValidationState = z.infer<
33
+ typeof assistantValidationStateSchema
34
+ >;
35
+
36
+ export const assistantFieldPatchSchema = z.object({
37
+ path: z.string().min(1),
38
+ value: z.unknown(),
39
+ });
40
+
41
+ export type AssistantFieldPatch = z.infer<typeof assistantFieldPatchSchema>;
42
+
43
+ export const assistantChatMessageSchema = z.object({
44
+ role: z.enum(["user", "assistant"]),
45
+ content: z.string().min(1),
46
+ });
47
+
48
+ export type AssistantChatMessage = z.infer<typeof assistantChatMessageSchema>;
49
+
50
+ export const assistantPageContextSchema = z.object({
51
+ key: assistantContextKeySchema,
52
+ route: z.string().min(1),
53
+ title: z.string().min(1),
54
+ entityId: z.string().nullable().optional(),
55
+ values: z.record(z.string(), z.unknown()),
56
+ schema: z.record(z.string(), z.unknown()).nullable().optional(),
57
+ validation: assistantValidationStateSchema,
58
+ metadata: z.record(z.string(), z.unknown()).default({}),
59
+ supportedOperations: z.array(assistantOperationSchema),
60
+ });
61
+
62
+ export type AssistantPageContext = z.infer<typeof assistantPageContextSchema>;
63
+
64
+ export const assistantPendingConfirmationSchema = z.object({
65
+ operation: assistantOperationSchema,
66
+ title: z.string().min(1),
67
+ detail: z.string().min(1),
68
+ });
69
+
70
+ export type AssistantPendingConfirmation = z.infer<
71
+ typeof assistantPendingConfirmationSchema
72
+ >;
73
+
74
+ const assistantToastActionSchema = z.object({
75
+ type: z.literal("show_toast"),
76
+ tone: z.enum(["info", "success", "error"]).default("info"),
77
+ title: z.string().min(1),
78
+ description: z.string().optional(),
79
+ });
80
+
81
+ const assistantPatchFieldsActionSchema = z.object({
82
+ type: z.literal("patch_fields"),
83
+ patches: z.array(assistantFieldPatchSchema).min(1),
84
+ });
85
+
86
+ const assistantSyncSourceActionSchema = z.object({
87
+ type: z.literal("sync_source"),
88
+ sourceId: z.string().uuid(),
89
+ values: z.record(z.string(), z.unknown()),
90
+ schedule: z
91
+ .object({
92
+ enabled: z.boolean(),
93
+ cron: z.string().optional(),
94
+ timezone: z.string().optional(),
95
+ })
96
+ .optional(),
97
+ });
98
+
99
+ const assistantSyncDetectorActionSchema = z.object({
100
+ type: z.literal("sync_detector"),
101
+ detectorId: z.string().uuid(),
102
+ values: z.record(z.string(), z.unknown()),
103
+ });
104
+
105
+ const assistantSyncGlossaryTermActionSchema = z.object({
106
+ type: z.literal("sync_glossary_term"),
107
+ termId: z.string(),
108
+ values: z.record(z.string(), z.unknown()),
109
+ });
110
+
111
+ const assistantSyncMetricActionSchema = z.object({
112
+ type: z.literal("sync_metric"),
113
+ metricId: z.string(),
114
+ values: z.record(z.string(), z.unknown()),
115
+ });
116
+
117
+ const assistantAttachResultActionSchema = z.object({
118
+ type: z.literal("attach_result"),
119
+ kind: z.enum(["source_test", "detector_train", "operation"]),
120
+ title: z.string().min(1),
121
+ payload: z.record(z.string(), z.unknown()),
122
+ });
123
+
124
+ export const assistantUiActionSchema = z.discriminatedUnion("type", [
125
+ assistantToastActionSchema,
126
+ assistantPatchFieldsActionSchema,
127
+ assistantSyncSourceActionSchema,
128
+ assistantSyncDetectorActionSchema,
129
+ assistantSyncGlossaryTermActionSchema,
130
+ assistantSyncMetricActionSchema,
131
+ assistantAttachResultActionSchema,
132
+ ]);
133
+
134
+ export type AssistantUiAction = z.infer<typeof assistantUiActionSchema>;
135
+
136
+ export const assistantToolCallSummarySchema = z.object({
137
+ name: z.string().min(1),
138
+ status: z.enum(["success", "error"]),
139
+ detail: z.string().min(1),
140
+ });
141
+
142
+ export type AssistantToolCallSummary = z.infer<
143
+ typeof assistantToolCallSummarySchema
144
+ >;
145
+
146
+ export const assistantChatRequestSchema = z.object({
147
+ messages: z.array(assistantChatMessageSchema).min(1),
148
+ context: assistantPageContextSchema,
149
+ pendingConfirmation: assistantPendingConfirmationSchema.nullable().optional(),
150
+ });
151
+
152
+ export type AssistantChatRequest = z.infer<typeof assistantChatRequestSchema>;
153
+
154
+ export const assistantChatResponseSchema = z.object({
155
+ reply: z.string().min(1),
156
+ actions: z.array(assistantUiActionSchema),
157
+ pendingConfirmation: assistantPendingConfirmationSchema.nullable(),
158
+ toolCalls: z.array(assistantToolCallSummarySchema),
159
+ });
160
+
161
+ export type AssistantChatResponse = z.infer<typeof assistantChatResponseSchema>;
162
+
163
+ export const assistantContextRegistrySchema = z.record(
164
+ assistantContextKeySchema,
165
+ z.object({
166
+ title: z.string().min(1),
167
+ summary: z.string().min(1),
168
+ supportedOperations: z.array(assistantOperationSchema),
169
+ }),
170
+ );
171
+
172
+ export const assistantContexts = assistantContextRegistrySchema.parse({
173
+ "source.create": {
174
+ title: "Source Setup Assistant",
175
+ summary:
176
+ "Guide source creation, patch source fields, and confirm source creation or connection testing.",
177
+ supportedOperations: [
178
+ "create_source",
179
+ "update_source",
180
+ "test_source_connection",
181
+ ],
182
+ },
183
+ "source.edit": {
184
+ title: "Source Edit Assistant",
185
+ summary:
186
+ "Refine an existing source, patch source fields, and confirm updates or connection tests.",
187
+ supportedOperations: ["update_source", "test_source_connection"],
188
+ },
189
+ "detector.create": {
190
+ title: "Detector Studio Assistant",
191
+ summary:
192
+ "Brainstorm detector structure, patch detector fields, and confirm detector creation or training.",
193
+ supportedOperations: ["create_custom_detector", "train_custom_detector"],
194
+ },
195
+ "semantic.glossary": {
196
+ title: "Glossary Assistant",
197
+ summary:
198
+ "Help users define business glossary terms by describing what they want to track in plain language. Translate business intent into detector type filters, severity filters, and status filters.",
199
+ supportedOperations: ["create_glossary_term"],
200
+ },
201
+ "semantic.metrics": {
202
+ title: "Metrics Assistant",
203
+ summary:
204
+ "Help users create governed metrics by describing what they want to measure in plain language. Choose the right metric type (SIMPLE, RATIO, DERIVED, TREND) and build the definition.",
205
+ supportedOperations: ["create_metric_definition", "certify_metric"],
206
+ },
207
+ });
208
+
209
+ export type AssistantContextRegistry = typeof assistantContexts;