@ancplua/qyl-api-schema 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.
Files changed (54) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +89 -0
  3. package/VERSIONING.md +74 -0
  4. package/api/routes.tsp +1052 -0
  5. package/api/streaming.tsp +335 -0
  6. package/common/errors.tsp +206 -0
  7. package/common/pagination.tsp +254 -0
  8. package/common/types.tsp +345 -0
  9. package/generated/README.md +26 -0
  10. package/generated/otel-keys.gen.tsp +1648 -0
  11. package/index.tsp +55 -0
  12. package/intelligence/causal-rules.tsp +34 -0
  13. package/intelligence/diagnostic-patterns.tsp +54 -0
  14. package/intelligence/investigation-strategies.tsp +37 -0
  15. package/intelligence/main.tsp +19 -0
  16. package/intelligence/seed/patterns.tsp +172 -0
  17. package/intelligence/seed/rules.tsp +44 -0
  18. package/intelligence/seed/strategies.tsp +56 -0
  19. package/intelligence/signals.tsp +60 -0
  20. package/models/agent/agent-run.tsp +154 -0
  21. package/models/agent/tool-call.tsp +122 -0
  22. package/models/agent/workflow-checkpoint.tsp +50 -0
  23. package/models/agent/workflow-execution.tsp +136 -0
  24. package/models/alerting.tsp +436 -0
  25. package/models/configurator.tsp +433 -0
  26. package/models/control-graph.tsp +197 -0
  27. package/models/db.tsp +810 -0
  28. package/models/deployment.tsp +365 -0
  29. package/models/error.tsp +433 -0
  30. package/models/genai.tsp +1368 -0
  31. package/models/http.tsp +600 -0
  32. package/models/identity.tsp +213 -0
  33. package/models/issues.tsp +484 -0
  34. package/models/log.tsp +140 -0
  35. package/models/messaging.tsp +304 -0
  36. package/models/otel-config.tsp +455 -0
  37. package/models/retention.tsp +240 -0
  38. package/models/rpc.tsp +309 -0
  39. package/models/search.tsp +243 -0
  40. package/models/session.tsp +274 -0
  41. package/models/system.tsp +400 -0
  42. package/models/test.tsp +346 -0
  43. package/models/triage.tsp +113 -0
  44. package/models/workflow.tsp +396 -0
  45. package/models/workspace.tsp +435 -0
  46. package/otel/enums.tsp +392 -0
  47. package/otel/logs.tsp +135 -0
  48. package/otel/metrics.tsp +358 -0
  49. package/otel/otel-conventions.tsp +14 -0
  50. package/otel/profiles.tsp +335 -0
  51. package/otel/resource.tsp +257 -0
  52. package/otel/span.tsp +307 -0
  53. package/package.json +88 -0
  54. package/tspconfig.yaml +49 -0
package/index.tsp ADDED
@@ -0,0 +1,55 @@
1
+ // =============================================================================
2
+ // @ancplua/qyl-api-schema — published entry point
3
+ // =============================================================================
4
+ // Consumer-facing barrel. Mirrors main.tsp minus local emit routing.
5
+ // The local emitters depend on `file:` packages
6
+ // (@ancplua/typespec-emit-*) which are not shipped to registry consumers and
7
+ // would break TypeSpec import resolution.
8
+ //
9
+ // Use main.tsp inside this repo for local `tsp compile`; downstream consumers
10
+ // reach the public surface through this file via the `.` export.
11
+ // =============================================================================
12
+
13
+ import "@typespec/http";
14
+ import "@typespec/rest";
15
+ import "@typespec/openapi";
16
+ import "@typespec/openapi3";
17
+ import "@typespec/versioning";
18
+ import "@typespec/sse";
19
+ import "@typespec/events";
20
+
21
+ import "./generated/otel-keys.gen.tsp";
22
+
23
+ import "./common/types.tsp";
24
+ import "./common/errors.tsp";
25
+ import "./common/pagination.tsp";
26
+
27
+ import "./otel/enums.tsp";
28
+ import "./otel/resource.tsp";
29
+ import "./otel/span.tsp";
30
+ import "./otel/logs.tsp";
31
+ import "./otel/metrics.tsp";
32
+ import "./otel/profiles.tsp";
33
+
34
+ import "./models/genai.tsp";
35
+ import "./models/http.tsp";
36
+ import "./models/rpc.tsp";
37
+ import "./models/messaging.tsp";
38
+ import "./models/db.tsp";
39
+ import "./models/session.tsp";
40
+ import "./models/otel-config.tsp";
41
+ import "./models/log.tsp";
42
+ import "./models/error.tsp";
43
+ import "./models/test.tsp";
44
+ import "./models/deployment.tsp";
45
+ import "./models/system.tsp";
46
+ import "./models/identity.tsp";
47
+ import "./models/control-graph.tsp";
48
+
49
+ import "./api/routes.tsp";
50
+ import "./api/streaming.tsp";
51
+
52
+ using TypeSpec.Http;
53
+ using TypeSpec.Rest;
54
+ using TypeSpec.OpenAPI;
55
+ using TypeSpec.Versioning;
@@ -0,0 +1,34 @@
1
+ // =============================================================================
2
+ // ANcpLua v2.0 - Causal Rules
3
+ // =============================================================================
4
+ // Directed relationship between two diagnostic patterns: if cause is observed,
5
+ // effect is likely. Causal rules build a directed graph. Given matched patterns,
6
+ // the engine traverses causal edges to identify root causes (patterns with no
7
+ // incoming causal edges).
8
+ // =============================================================================
9
+
10
+ import "@typespec/openapi";
11
+
12
+ using TypeSpec.OpenAPI;
13
+
14
+ namespace Qyl.Api.Contracts.Intelligence;
15
+
16
+ @doc("Directed causal relationship between two diagnostic patterns")
17
+ model CausalRule {
18
+ @doc("Unique rule identifier")
19
+ id: string;
20
+
21
+ @doc("ID of the cause DiagnosticPattern")
22
+ causePattern: string;
23
+
24
+ @doc("ID of the effect DiagnosticPattern")
25
+ effectPattern: string;
26
+
27
+ @doc("Causal confidence (0.0-1.0)")
28
+ @minValue(0.0)
29
+ @maxValue(1.0)
30
+ strength: float64;
31
+
32
+ @doc("Time window for correlation (e.g. 5m, 1h)")
33
+ temporalWindow?: string;
34
+ }
@@ -0,0 +1,54 @@
1
+ // =============================================================================
2
+ // ANcpLua v2.0 - Diagnostic Patterns
3
+ // =============================================================================
4
+ // A named combination of signals that identifies a known failure mode.
5
+ // All signals in a pattern must match (conjunction). Multiple patterns can
6
+ // match the same telemetry — the engine returns all matches ranked by confidence.
7
+ // =============================================================================
8
+
9
+ import "@typespec/openapi";
10
+
11
+ using TypeSpec.OpenAPI;
12
+
13
+ namespace Qyl.Api.Contracts.Intelligence;
14
+
15
+ @doc("Classification category for diagnostic patterns")
16
+ enum PatternCategory {
17
+ @doc("Exception and error patterns")
18
+ error: "error",
19
+
20
+ @doc("Performance degradation")
21
+ latency: "latency",
22
+
23
+ @doc("Token/cost anomalies")
24
+ cost: "cost",
25
+
26
+ @doc("Service health patterns")
27
+ availability: "availability",
28
+
29
+ @doc("GenAI-specific failure modes")
30
+ genai: "genai",
31
+
32
+ @doc("Database and storage patterns")
33
+ data: "data",
34
+ }
35
+
36
+ @doc("Named combination of signals identifying a known failure mode")
37
+ model DiagnosticPattern {
38
+ @doc("Unique pattern identifier (e.g. genai_rate_limit)")
39
+ id: string;
40
+
41
+ @doc("Pattern classification")
42
+ category: PatternCategory;
43
+
44
+ @doc("Signals that must all match (conjunction)")
45
+ signals: Signal[];
46
+
47
+ @doc("What this pattern means diagnostically")
48
+ hypothesis: string;
49
+
50
+ @doc("Base confidence weight (0.0-1.0)")
51
+ @minValue(0.0)
52
+ @maxValue(1.0)
53
+ confidence: float64;
54
+ }
@@ -0,0 +1,37 @@
1
+ // =============================================================================
2
+ // ANcpLua v2.0 - Investigation Strategies
3
+ // =============================================================================
4
+ // A deterministic sequence of steps to investigate a matched pattern.
5
+ // The LLM does not invent investigation paths — it selects from known
6
+ // strategies and interprets results.
7
+ // =============================================================================
8
+
9
+ import "@typespec/openapi";
10
+
11
+ using TypeSpec.OpenAPI;
12
+
13
+ namespace Qyl.Api.Contracts.Intelligence;
14
+
15
+ @doc("Single step in an investigation strategy")
16
+ model InvestigationStep {
17
+ @doc("What to do (e.g. query_traces, get_code_location, compare_deployments)")
18
+ action: string;
19
+
20
+ @doc("Query template or tool name")
21
+ query: string;
22
+
23
+ @doc("Human-readable explanation of this step")
24
+ description: string;
25
+ }
26
+
27
+ @doc("Deterministic investigation sequence triggered by a matched pattern")
28
+ model InvestigationStrategy {
29
+ @doc("Unique strategy identifier")
30
+ id: string;
31
+
32
+ @doc("Trigger — pattern ID or category:X for category-wide triggers")
33
+ triggerPattern: string;
34
+
35
+ @doc("Ordered investigation steps")
36
+ steps: InvestigationStep[];
37
+ }
@@ -0,0 +1,19 @@
1
+ // =============================================================================
2
+ // ANcpLua v2.0 - Telemetry Intelligence Model
3
+ // =============================================================================
4
+ // Canonical reasoning model over telemetry data. Schema-driven, generated,
5
+ // deterministic. Defines diagnostic patterns, causal rules, and investigation
6
+ // strategies as typed data consumed by Loom, MCP, and dashboard.
7
+ //
8
+ // Source of truth: specs/telemetry-intelligence.md
9
+ // =============================================================================
10
+
11
+ import "@typespec/openapi";
12
+
13
+ import "./signals.tsp";
14
+ import "./diagnostic-patterns.tsp";
15
+ import "./causal-rules.tsp";
16
+ import "./investigation-strategies.tsp";
17
+ import "./seed/patterns.tsp";
18
+ import "./seed/rules.tsp";
19
+ import "./seed/strategies.tsp";
@@ -0,0 +1,172 @@
1
+ // =============================================================================
2
+ // ANcpLua v2.0 - Seed Diagnostic Patterns (v1)
3
+ // =============================================================================
4
+ // 19 initial diagnostic patterns (10 infra + 9 agent behavioral)
5
+ // Source: specs/telemetry-intelligence.md §5.1 + Microsoft Research AgentRx (March 2026)
6
+ // These compile to static registries in DiagnosticPatterns.g.cs.
7
+ //
8
+ // Signal attributes reference:
9
+ // - OTel semantic attributes (status_code, duration_ns, etc.)
10
+ // - qyl-derived attributes (gen_ai_provider_name, gen_ai_stop_reason, etc.)
11
+ // - Computed fields (occurrence_rate, span_count_under_parent, etc.)
12
+ // =============================================================================
13
+
14
+ namespace Qyl.Api.Contracts.Intelligence.Seed;
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // Pattern: genai_rate_limit
18
+ // Category: genai
19
+ // Signals: status_code=2, gen_ai_provider_name exists, error_type contains rate_limit
20
+ // Hypothesis: Provider throttling. Check quota, reduce concurrency, add backoff.
21
+ // Confidence: 0.9
22
+ // ---------------------------------------------------------------------------
23
+
24
+ // ---------------------------------------------------------------------------
25
+ // Pattern: genai_token_exhaustion
26
+ // Category: genai
27
+ // Signals: gen_ai_stop_reason=length
28
+ // Hypothesis: Context window exceeded. Reduce prompt size or switch to larger model.
29
+ // Confidence: 0.85
30
+ // ---------------------------------------------------------------------------
31
+
32
+ // ---------------------------------------------------------------------------
33
+ // Pattern: genai_content_filter
34
+ // Category: genai
35
+ // Signals: gen_ai_stop_reason contains content_filter
36
+ // Hypothesis: Content policy violation. Review prompt content.
37
+ // Confidence: 0.95
38
+ // ---------------------------------------------------------------------------
39
+
40
+ // ---------------------------------------------------------------------------
41
+ // Pattern: db_timeout
42
+ // Category: data
43
+ // Signals: exception_type=TimeoutException, db.system.name exists, duration_ns > 2000000000
44
+ // Hypothesis: Database query timeout. Check query plan, connection pool, lock contention.
45
+ // Confidence: 0.85
46
+ // ---------------------------------------------------------------------------
47
+
48
+ // ---------------------------------------------------------------------------
49
+ // Pattern: db_n_plus_one
50
+ // Category: data
51
+ // Signals: db.system.name exists, parent_span_id exists, span_count_under_parent > 10
52
+ // Hypothesis: N+1 query pattern. Batch or prefetch related data.
53
+ // Confidence: 0.80
54
+ // ---------------------------------------------------------------------------
55
+
56
+ // ---------------------------------------------------------------------------
57
+ // Pattern: http_5xx_cluster
58
+ // Category: error
59
+ // Signals: http.response.status_code gte 500, occurrence_rate > baseline * 3
60
+ // Hypothesis: Server error spike. Check recent deployments and upstream dependencies.
61
+ // Confidence: 0.75
62
+ // ---------------------------------------------------------------------------
63
+
64
+ // ---------------------------------------------------------------------------
65
+ // Pattern: deployment_regression
66
+ // Category: error
67
+ // Signals: error_type exists, first_seen_at > last_deployment_time
68
+ // Hypothesis: New error class after deployment. Compare with previous version.
69
+ // Confidence: 0.80
70
+ // ---------------------------------------------------------------------------
71
+
72
+ // ---------------------------------------------------------------------------
73
+ // Pattern: cascading_timeout
74
+ // Category: latency
75
+ // Signals: exception_type contains Timeout, downstream_service_error=true
76
+ // Hypothesis: Upstream failure causing downstream timeouts. Investigate root service first.
77
+ // Confidence: 0.70
78
+ // ---------------------------------------------------------------------------
79
+
80
+ // ---------------------------------------------------------------------------
81
+ // Pattern: memory_pressure_latency
82
+ // Category: latency
83
+ // Signals: process.runtime.dotnet.gc.duration gt 100, avg_latency > p99_baseline
84
+ // Hypothesis: GC pressure causing latency. Check memory allocation patterns.
85
+ // Confidence: 0.65
86
+ // ---------------------------------------------------------------------------
87
+
88
+ // ---------------------------------------------------------------------------
89
+ // Pattern: cost_spike
90
+ // Category: cost
91
+ // Signals: gen_ai_cost_usd > daily_average * 3
92
+ // Hypothesis: Abnormal cost increase. Identify the model, service, and session responsible.
93
+ // Confidence: 0.75
94
+ // ---------------------------------------------------------------------------
95
+
96
+ // =============================================================================
97
+ // Agent behavioral failure patterns (AgentRx taxonomy)
98
+ // Source: Microsoft Research AgentRx, March 2026
99
+ // 9 failure categories from Magentic-One and TAU-Retail benchmarks
100
+ // =============================================================================
101
+
102
+ // ---------------------------------------------------------------------------
103
+ // Pattern: agent_intent_plan_misalignment
104
+ // Category: agent
105
+ // Signals: gen_ai.agent.name exists, gen_ai.operation.name=invoke_agent, status_code=2
106
+ // Hypothesis: Agent plan diverges from user intent. Review task decomposition.
107
+ // Confidence: 0.70
108
+ // ---------------------------------------------------------------------------
109
+
110
+ // ---------------------------------------------------------------------------
111
+ // Pattern: agent_misinterpret_tool_info
112
+ // Category: agent
113
+ // Signals: gen_ai.tool.name exists, gen_ai.tool.call.id exists, error_type contains tool
114
+ // Hypothesis: Agent misinterpreted tool output or schema.
115
+ // Confidence: 0.75
116
+ // ---------------------------------------------------------------------------
117
+
118
+ // ---------------------------------------------------------------------------
119
+ // Pattern: agent_rai_policy_violation
120
+ // Category: agent
121
+ // Signals: gen_ai.agent.name exists, gen_ai.stop_reason contains content_filter
122
+ // Hypothesis: Agent triggered responsible AI policy violation.
123
+ // Confidence: 0.95
124
+ // ---------------------------------------------------------------------------
125
+
126
+ // ---------------------------------------------------------------------------
127
+ // Pattern: agent_plan_adherence_failure
128
+ // Category: agent
129
+ // Signals: gen_ai.agent.name exists, gen_ai.operation.name=invoke_agent, gen_ai.usage.output_tokens>0, child_span_count>20
130
+ // Hypothesis: Agent deviated from its own plan. Excessive tool calls suggest improvisation.
131
+ // Confidence: 0.65
132
+ // ---------------------------------------------------------------------------
133
+
134
+ // ---------------------------------------------------------------------------
135
+ // Pattern: agent_invent_new_info
136
+ // Category: agent
137
+ // Signals: gen_ai.agent.name exists, gen_ai.operation.name=invoke_agent
138
+ // Hypothesis: Agent fabricated information not in tool outputs. Cross-reference claims vs results.
139
+ // Confidence: 0.60
140
+ // ---------------------------------------------------------------------------
141
+
142
+ // ---------------------------------------------------------------------------
143
+ // Pattern: agent_invalid_invocation
144
+ // Category: agent
145
+ // Signals: gen_ai.tool.name exists, error_type contains invalid, gen_ai.agent.name exists
146
+ // Hypothesis: Agent called tool with invalid arguments or nonexistent name.
147
+ // Confidence: 0.85
148
+ // ---------------------------------------------------------------------------
149
+
150
+ // ---------------------------------------------------------------------------
151
+ // Pattern: agent_hallucination_doubt
152
+ // Category: agent
153
+ // Signals: gen_ai.agent.name exists, gen_ai.usage.output_tokens>500, gen_ai.tool.call.id not_exists
154
+ // Hypothesis: Long response without tool grounding. High hallucination risk.
155
+ // Confidence: 0.55
156
+ // ---------------------------------------------------------------------------
157
+
158
+ // ---------------------------------------------------------------------------
159
+ // Pattern: agent_instruction_adherence_failure
160
+ // Category: agent
161
+ // Signals: gen_ai.agent.name exists, gen_ai.operation.name=invoke_agent
162
+ // Hypothesis: Agent ignored or contradicted system prompt constraints.
163
+ // Confidence: 0.60
164
+ // ---------------------------------------------------------------------------
165
+
166
+ // ---------------------------------------------------------------------------
167
+ // Pattern: agent_underspecified_intent
168
+ // Category: agent
169
+ // Signals: gen_ai.agent.name exists, gen_ai.operation.name=invoke_agent, gen_ai.usage.input_tokens<50
170
+ // Hypothesis: Ambiguous request with insufficient context for reliable execution.
171
+ // Confidence: 0.65
172
+ // ---------------------------------------------------------------------------
@@ -0,0 +1,44 @@
1
+ // =============================================================================
2
+ // ANcpLua v2.0 - Seed Causal Rules (v1)
3
+ // =============================================================================
4
+ // 6 initial causal rules. Source: specs/telemetry-intelligence.md §5.2
5
+ // These compile to static registries in CausalRules.g.cs.
6
+ // =============================================================================
7
+
8
+ namespace Qyl.Api.Contracts.Intelligence.Seed;
9
+
10
+ // ---------------------------------------------------------------------------
11
+ // Rule: deploy_causes_regression
12
+ // Cause: deployment_regression → Effect: http_5xx_cluster
13
+ // Strength: 0.85, Window: 1h
14
+ // ---------------------------------------------------------------------------
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // Rule: rate_limit_causes_cascade
18
+ // Cause: genai_rate_limit → Effect: cascading_timeout
19
+ // Strength: 0.70, Window: 5m
20
+ // ---------------------------------------------------------------------------
21
+
22
+ // ---------------------------------------------------------------------------
23
+ // Rule: db_timeout_causes_http_error
24
+ // Cause: db_timeout → Effect: http_5xx_cluster
25
+ // Strength: 0.80, Window: 1m
26
+ // ---------------------------------------------------------------------------
27
+
28
+ // ---------------------------------------------------------------------------
29
+ // Rule: n_plus_one_causes_db_timeout
30
+ // Cause: db_n_plus_one → Effect: db_timeout
31
+ // Strength: 0.75, Window: 30s
32
+ // ---------------------------------------------------------------------------
33
+
34
+ // ---------------------------------------------------------------------------
35
+ // Rule: memory_causes_timeout
36
+ // Cause: memory_pressure_latency → Effect: cascading_timeout
37
+ // Strength: 0.65, Window: 5m
38
+ // ---------------------------------------------------------------------------
39
+
40
+ // ---------------------------------------------------------------------------
41
+ // Rule: token_exhaustion_causes_cost
42
+ // Cause: genai_token_exhaustion → Effect: cost_spike
43
+ // Strength: 0.60, Window: 1h
44
+ // ---------------------------------------------------------------------------
@@ -0,0 +1,56 @@
1
+ // =============================================================================
2
+ // ANcpLua v2.0 - Seed Investigation Strategies (v1)
3
+ // =============================================================================
4
+ // 4 initial investigation strategies. Source: specs/telemetry-intelligence.md §5.3
5
+ // These compile to static registries in InvestigationStrategies.g.cs.
6
+ //
7
+ // Trigger patterns use category:X syntax for category-wide triggers.
8
+ // Query templates are abstract qyl investigation hints; the runtime decides how to execute them.
9
+ // =============================================================================
10
+
11
+ namespace Qyl.Api.Contracts.Intelligence.Seed;
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // Strategy: investigate_error_issue
15
+ // Trigger: category:error (any error category pattern)
16
+ // Steps:
17
+ // 1. get_issue — SELECT * FROM error_issues WHERE id = ?
18
+ // 2. get_events — SELECT * FROM error_issue_events WHERE issue_id = ? ORDER BY timestamp DESC LIMIT 10
19
+ // 3. get_traces — SELECT * FROM spans WHERE trace_id IN (?) ORDER BY start_time_unix_nano
20
+ // 4. get_code_location — SELECT code_filepath, code_function, code_lineno FROM spans WHERE span_id = ?
21
+ // 5. correlate_deployment — SELECT * FROM deployments WHERE service_name = ? AND start_time <= ? ORDER BY start_time DESC LIMIT 1
22
+ // 6. check_fix_history — SELECT * FROM fix_runs WHERE issue_id = ?
23
+ // ---------------------------------------------------------------------------
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // Strategy: investigate_latency
27
+ // Trigger: category:latency (any latency category pattern)
28
+ // Steps:
29
+ // 1. identify_service — SELECT service_name, AVG(duration_ns), PERCENTILE_CONT(0.99) ... GROUP BY service_name
30
+ // 2. compare_distributions — SELECT duration_ns FROM spans WHERE service_name = ? AND start_time BETWEEN ? AND ?
31
+ // 3. find_regression_window — Time-series analysis of p99 latency
32
+ // 4. correlate_deployment — SELECT * FROM deployments WHERE service_name = ? AND start_time <= ? ORDER BY start_time DESC LIMIT 1
33
+ // 5. inspect_slow_spans — SELECT * FROM spans WHERE service_name = ? AND duration_ns > ? ORDER BY duration_ns DESC LIMIT 20
34
+ // ---------------------------------------------------------------------------
35
+
36
+ // ---------------------------------------------------------------------------
37
+ // Strategy: investigate_cost
38
+ // Trigger: category:cost (any cost category pattern)
39
+ // Steps:
40
+ // 1. identify_model — SELECT gen_ai_request_model, SUM(gen_ai_cost_usd) ... GROUP BY gen_ai_request_model
41
+ // 2. identify_service — SELECT service_name, SUM(gen_ai_cost_usd) ... GROUP BY service_name
42
+ // 3. identify_session — SELECT session_id, SUM(gen_ai_cost_usd) ... GROUP BY session_id ORDER BY 2 DESC
43
+ // 4. trace_to_root — Follow session → traces → spans
44
+ // 5. compare_to_baseline — Compare current period vs previous period
45
+ // ---------------------------------------------------------------------------
46
+
47
+ // ---------------------------------------------------------------------------
48
+ // Strategy: investigate_genai
49
+ // Trigger: category:genai (any genai category pattern)
50
+ // Steps:
51
+ // 1. get_error_details — SELECT * FROM spans WHERE status_code = 2 AND gen_ai_provider_name IS NOT NULL
52
+ // 2. check_provider_status — Evaluate gen_ai_provider_name + error frequency
53
+ // 3. analyze_token_usage — SELECT gen_ai_input_tokens, gen_ai_output_tokens FROM spans WHERE gen_ai_request_model = ?
54
+ // 4. check_prompt_patterns — Inspect spans around the error for prompt size trends
55
+ // 5. suggest_mitigation — Pattern-specific recommendation
56
+ // ---------------------------------------------------------------------------
@@ -0,0 +1,60 @@
1
+ // =============================================================================
2
+ // ANcpLua v2.0 - Signal Primitive
3
+ // =============================================================================
4
+ // The atomic unit of telemetry observation. A single attribute condition.
5
+ // Signals reference semconv attributes and qyl-derived attributes only.
6
+ // =============================================================================
7
+
8
+ import "@typespec/openapi";
9
+
10
+ using TypeSpec.OpenAPI;
11
+
12
+ namespace Qyl.Api.Contracts.Intelligence;
13
+
14
+ @doc("Comparison operator for signal evaluation")
15
+ enum SignalOperator {
16
+ @doc("Equals")
17
+ eq: "eq",
18
+
19
+ @doc("Not equals")
20
+ neq: "neq",
21
+
22
+ @doc("Greater than")
23
+ gt: "gt",
24
+
25
+ @doc("Greater than or equal")
26
+ gte: "gte",
27
+
28
+ @doc("Less than")
29
+ lt: "lt",
30
+
31
+ @doc("Less than or equal")
32
+ lte: "lte",
33
+
34
+ @doc("String contains")
35
+ contains: "contains",
36
+
37
+ @doc("Attribute is non-null")
38
+ exists: "exists",
39
+
40
+ @doc("Attribute is null")
41
+ not_exists: "not_exists",
42
+
43
+ @doc("Regex match")
44
+ matches: "matches",
45
+
46
+ @doc("Value in set (comma-separated)")
47
+ in_set: "in",
48
+ }
49
+
50
+ @doc("Atomic telemetry observation — a single attribute condition")
51
+ model Signal {
52
+ @doc("Telemetry attribute name (semconv or promoted column)")
53
+ attribute: string;
54
+
55
+ @doc("Comparison operator")
56
+ operator: SignalOperator;
57
+
58
+ @doc("Expected value (type-coerced at evaluation time). Omit for exists/not_exists.")
59
+ value?: string;
60
+ }