@praxisui/ai 4.0.0-beta.0 → 6.0.0-beta.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/index.d.ts CHANGED
@@ -1,19 +1,148 @@
1
1
  import * as i0 from '@angular/core';
2
- import { OnInit, ChangeDetectorRef, OnDestroy, ElementRef } from '@angular/core';
3
- import * as _praxisui_core from '@praxisui/core';
4
- import { AiValueKind, AiCapability, GlobalConfigService, GlobalAiConfig, RulePropertySchema } from '@praxisui/core';
5
- import { Observable } from 'rxjs';
2
+ import { OnDestroy, ElementRef, OnInit, ChangeDetectorRef } from '@angular/core';
6
3
  import { Schema } from '@google/generative-ai';
4
+ import { Observable } from 'rxjs';
5
+ import { CdkOverlayOrigin } from '@angular/cdk/overlay';
6
+ import * as _praxisui_ai from '@praxisui/ai';
7
7
  import { MatDialogRef } from '@angular/material/dialog';
8
8
  import { MatSnackBar } from '@angular/material/snack-bar';
9
- import { FunctionRegistry, ContextProvider, ValidationIssue } from '@praxisui/specification';
10
- import { CdkOverlayOrigin } from '@angular/cdk/overlay';
11
9
 
12
10
  declare class PraxisAi {
13
11
  static ɵfac: i0.ɵɵFactoryDeclaration<PraxisAi, never>;
14
12
  static ɵcmp: i0.ɵɵComponentDeclaration<PraxisAi, "lib-praxis-ai", never, {}, {}, never, never, true, never>;
15
13
  }
16
14
 
15
+ declare const AI_STREAM_EVENT_TYPES: readonly ["status", "thought.step", "heartbeat", "result", "error", "cancelled"];
16
+ type AiJsonPrimitive = string | number | boolean | null;
17
+ type AiJsonArray = AiJsonValue[];
18
+ interface AiJsonObject {
19
+ [key: string]: AiJsonValue;
20
+ }
21
+ type AiJsonValue = AiJsonPrimitive | AiJsonObject | AiJsonArray;
22
+ interface AiSchemaContextContract {
23
+ path?: string | null;
24
+ operation?: string | null;
25
+ schemaType?: string | null;
26
+ }
27
+ interface AiChatMessageContract {
28
+ role: 'user' | 'assistant' | 'system';
29
+ content: string;
30
+ }
31
+ interface AiUiContextRefContract {
32
+ componentType?: string | null;
33
+ componentId?: string | null;
34
+ routeKey?: string | null;
35
+ schemaHash?: string | null;
36
+ variantId?: string | null;
37
+ }
38
+ interface AiCurrentStateDigestContract {
39
+ columns?: string[] | null;
40
+ sort?: string | null;
41
+ rowCount?: number | null;
42
+ }
43
+ interface AiOrchestratorRequestContract {
44
+ componentId: string;
45
+ componentType: string;
46
+ userPrompt?: string;
47
+ sessionId?: string;
48
+ mode?: 'new' | 'continue';
49
+ clientTurnId?: string;
50
+ messages?: AiChatMessageContract[];
51
+ summary?: string;
52
+ uiContextRef?: AiUiContextRefContract;
53
+ currentStateDigest?: AiCurrentStateDigestContract;
54
+ currentState: AiJsonObject;
55
+ dataProfile?: AiJsonObject | null;
56
+ schemaFields?: AiJsonObject[] | null;
57
+ runtimeState?: AiJsonObject | null;
58
+ suggestedPatch?: AiJsonObject | null;
59
+ contextHints?: AiJsonObject | null;
60
+ aiMode?: string;
61
+ requireSchema?: boolean;
62
+ resourcePath?: string;
63
+ contractVersion?: string;
64
+ schemaHash?: string;
65
+ schemaContext?: AiSchemaContextContract | null;
66
+ variantId?: string;
67
+ apiMethod?: string;
68
+ apiTags?: string;
69
+ apiSearchLimit?: number;
70
+ }
71
+ type AiOrchestratorResponseType = 'patch' | 'clarification' | 'error' | 'info';
72
+ interface AiPatchDiffContract {
73
+ path: string;
74
+ before?: AiJsonValue;
75
+ after?: AiJsonValue;
76
+ }
77
+ interface AiOptionContract {
78
+ value?: string | null;
79
+ label?: string | null;
80
+ example?: string | null;
81
+ contextHints?: AiJsonObject | null;
82
+ }
83
+ interface AiClarificationUiContract {
84
+ responseType?: 'text' | 'choice' | 'confirm' | 'mixed' | 'context';
85
+ selectionMode?: 'single' | 'multiple';
86
+ presentation?: 'buttons' | 'list' | 'chips';
87
+ allowCustom?: boolean | null;
88
+ }
89
+ interface AiMemoryInfoContract {
90
+ summaryUpdated?: boolean | null;
91
+ windowSize?: number | null;
92
+ cached?: boolean | null;
93
+ }
94
+ interface AiOrchestratorResponseContract {
95
+ sessionId?: string | null;
96
+ code?: string | null;
97
+ type?: AiOrchestratorResponseType;
98
+ contractVersion?: string | null;
99
+ schemaHash?: string | null;
100
+ patch?: AiJsonObject | null;
101
+ diff?: AiPatchDiffContract[] | null;
102
+ explanation?: string | null;
103
+ warnings?: string[] | null;
104
+ message?: string | null;
105
+ options?: string[] | null;
106
+ optionPayloads?: AiOptionContract[] | null;
107
+ contextRequest?: number[] | null;
108
+ clarification?: AiClarificationUiContract;
109
+ componentId?: string | null;
110
+ componentType?: string | null;
111
+ path?: string | null;
112
+ providedValue?: AiJsonValue;
113
+ allowedValues?: string[] | null;
114
+ memory?: AiMemoryInfoContract;
115
+ }
116
+ interface AiPatchStreamStartResponseContract {
117
+ streamId: string;
118
+ threadId: string;
119
+ turnId: string;
120
+ eventSchemaVersion: string;
121
+ streamAuthMode?: 'cookie' | 'signed_url_token' | null;
122
+ streamAccessToken?: string | null;
123
+ expiresAt: string;
124
+ fallbackPatchUrl: string;
125
+ }
126
+ interface AiPatchStreamCancelResponseContract {
127
+ streamId?: string | null;
128
+ threadId?: string | null;
129
+ turnId?: string | null;
130
+ terminalState: 'cancelled' | 'completed' | 'not_found';
131
+ message?: string | null;
132
+ }
133
+ interface AiPatchStreamEnvelopeContract<TPayload extends AiJsonObject = AiJsonObject> {
134
+ eventId?: string | null;
135
+ streamId: string;
136
+ threadId: string;
137
+ turnId: string;
138
+ seq: number;
139
+ eventSchemaVersion: string;
140
+ timestamp: string;
141
+ type: AiPatchStreamEventType$1;
142
+ payload: TPayload;
143
+ }
144
+ type AiPatchStreamEventType$1 = (typeof AI_STREAM_EVENT_TYPES)[number];
145
+
17
146
  /**
18
147
  * Models for Praxis AI (Centralized)
19
148
  */
@@ -28,8 +157,8 @@ interface AiRuleResponse {
28
157
  targetType: 'field' | 'section' | 'action' | 'row' | 'column';
29
158
  /** IDs of the target elements */
30
159
  targetIds: string[];
31
- /** Condition in DSL format (e.g., "age >= 18") or null for always applied */
32
- conditionDsl: string | null;
160
+ /** Canonical JSON Logic condition payload or null for always applied */
161
+ condition: AiJsonObject | null;
33
162
  /** Effects to apply */
34
163
  effects: {
35
164
  /** Properties to apply when condition is true */
@@ -59,7 +188,7 @@ interface PromptContext {
59
188
  fieldsText: string;
60
189
  /** List of available properties for the selected target type */
61
190
  propertiesText: string;
62
- /** List of supported DSL operators */
191
+ /** List of supported JSON Logic operators */
63
192
  operatorsText: string;
64
193
  /** Selected target type */
65
194
  targetType: string;
@@ -126,40 +255,32 @@ interface AiModel {
126
255
  topP?: number;
127
256
  topK?: number;
128
257
  }
129
- type ValueKind = AiValueKind;
130
- type Capability = AiCapability;
131
-
132
- declare class PraxisAiService {
133
- private globalConfigService;
134
- private genAI;
135
- private config;
136
- constructor(globalConfigService: GlobalConfigService);
137
- private syncConfig;
138
- classifyIntent(userInput: string, columns: string[]): Observable<any>;
139
- answerQuestion(userInput: string, targetConfig: any): Observable<string>;
140
- executeEnrichedPrompt(userInput: string, contextDescription: string, targetConfig: any, capabilities: any): Observable<any>;
141
- private formatCapabilities;
142
- private normalizeIntentClassification;
143
- generateContent(prompt: string, modelName?: string): Observable<string>;
144
- generateContentStream(prompt: string, modelName?: string): Observable<string>;
145
- generateJson<T>(prompt: string, modelName?: string, schema?: any): Observable<T | null>;
146
- isMockMode(): boolean;
147
- private extractUserIntent;
148
- private getMockPatch;
149
- listModels(apiKey?: string): Observable<AiModel[]>;
150
- testConnection(apiKey?: string, model?: string): Observable<boolean>;
151
- private resolveProvider;
152
- private isGeminiProvider;
153
- static ɵfac: i0.ɵɵFactoryDeclaration<PraxisAiService, [{ optional: true; }]>;
154
- static ɵprov: i0.ɵɵInjectableDeclaration<PraxisAiService>;
258
+ type ValueKind = 'boolean' | 'string' | 'number' | 'enum' | 'expression' | 'object' | 'array';
259
+ interface Capability {
260
+ path: string;
261
+ category: string;
262
+ valueKind: ValueKind | string;
263
+ allowedValues?: Array<string | number>;
264
+ description?: string;
265
+ critical?: boolean;
266
+ intentExamples?: string[];
267
+ dependsOn?: string;
268
+ example?: string;
269
+ safetyNotes?: string;
155
270
  }
156
-
157
- declare class AiConfigService {
158
- private globalConfig;
159
- getConfig(): AiIntegrationConfig;
160
- static ɵfac: i0.ɵɵFactoryDeclaration<AiConfigService, never>;
161
- static ɵprov: i0.ɵɵInjectableDeclaration<AiConfigService>;
271
+ type RulePropertyType = 'string' | 'boolean' | 'object' | 'enum' | 'number';
272
+ interface RulePropertyDefinition {
273
+ name: string;
274
+ type: RulePropertyType;
275
+ label: string;
276
+ description?: string;
277
+ enumValues?: Array<{
278
+ value: string;
279
+ label: string;
280
+ }>;
281
+ category?: 'content' | 'appearance' | 'behavior' | 'layout' | 'validation';
162
282
  }
283
+ type RulePropertySchema = Record<'field' | 'section' | 'action' | 'row' | 'column', RulePropertyDefinition[]>;
163
284
 
164
285
  interface PatchResult {
165
286
  success: boolean;
@@ -256,136 +377,63 @@ interface AiConfigAdapter<TConfig = any> {
256
377
  applyPatch(patch: Partial<TConfig>, intent?: string): Promise<PatchResult>;
257
378
  }
258
379
 
259
- declare const AI_STREAM_EVENT_TYPES: readonly ["status", "thought.step", "heartbeat", "result", "error", "cancelled"];
260
- type AiJsonPrimitive = string | number | boolean | null;
261
- type AiJsonArray = AiJsonValue[];
262
- interface AiJsonObject {
263
- [key: string]: AiJsonValue;
264
- }
265
- type AiJsonValue = AiJsonPrimitive | AiJsonObject | AiJsonArray;
266
- interface AiSchemaContextContract {
267
- path?: string | null;
268
- operation?: string | null;
269
- schemaType?: string | null;
270
- }
271
- interface AiChatMessageContract {
272
- role: 'user' | 'assistant' | 'system';
273
- content: string;
274
- }
275
- interface AiUiContextRefContract {
276
- componentType?: string | null;
277
- componentId?: string | null;
278
- routeKey?: string | null;
279
- schemaHash?: string | null;
280
- variantId?: string | null;
281
- }
282
- interface AiCurrentStateDigestContract {
283
- columns?: string[] | null;
284
- sort?: string | null;
285
- rowCount?: number | null;
286
- }
287
- interface AiOrchestratorRequestContract {
288
- componentId: string;
289
- componentType: string;
290
- userPrompt?: string;
291
- sessionId?: string;
292
- mode?: 'new' | 'continue';
293
- clientTurnId?: string;
294
- messages?: AiChatMessageContract[];
295
- summary?: string;
296
- uiContextRef?: AiUiContextRefContract;
297
- currentStateDigest?: AiCurrentStateDigestContract;
298
- currentState: AiJsonObject;
299
- dataProfile?: AiJsonObject | null;
300
- schemaFields?: AiJsonObject[] | null;
301
- runtimeState?: AiJsonObject | null;
302
- suggestedPatch?: AiJsonObject | null;
303
- contextHints?: AiJsonObject | null;
304
- aiMode?: string;
305
- requireSchema?: boolean;
306
- resourcePath?: string;
307
- contractVersion?: string;
308
- schemaHash?: string;
309
- schemaContext?: AiSchemaContextContract | null;
310
- variantId?: string;
311
- apiMethod?: string;
312
- apiTags?: string;
313
- apiSearchLimit?: number;
314
- }
315
- type AiOrchestratorResponseType = 'patch' | 'clarification' | 'error' | 'info';
316
- interface AiPatchDiffContract {
317
- path: string;
318
- before?: AiJsonValue;
319
- after?: AiJsonValue;
320
- }
321
- interface AiOptionContract {
322
- value?: string | null;
323
- label?: string | null;
324
- example?: string | null;
325
- contextHints?: AiJsonObject | null;
326
- }
327
- interface AiClarificationUiContract {
328
- responseType?: 'text' | 'choice' | 'confirm' | 'mixed' | 'context';
329
- selectionMode?: 'single' | 'multiple';
330
- presentation?: 'buttons' | 'list' | 'chips';
331
- allowCustom?: boolean | null;
332
- }
333
- interface AiMemoryInfoContract {
334
- summaryUpdated?: boolean | null;
335
- windowSize?: number | null;
336
- cached?: boolean | null;
337
- }
338
- interface AiOrchestratorResponseContract {
339
- sessionId?: string | null;
340
- code?: string | null;
341
- type?: AiOrchestratorResponseType;
342
- contractVersion?: string | null;
343
- schemaHash?: string | null;
344
- patch?: AiJsonObject | null;
345
- diff?: AiPatchDiffContract[] | null;
346
- explanation?: string | null;
347
- warnings?: string[] | null;
348
- message?: string | null;
349
- options?: string[] | null;
350
- optionPayloads?: AiOptionContract[] | null;
351
- contextRequest?: number[] | null;
352
- clarification?: AiClarificationUiContract;
353
- componentId?: string | null;
354
- componentType?: string | null;
355
- path?: string | null;
356
- providedValue?: AiJsonValue;
357
- allowedValues?: string[] | null;
358
- memory?: AiMemoryInfoContract;
359
- }
360
- interface AiPatchStreamStartResponseContract {
361
- streamId: string;
362
- threadId: string;
363
- turnId: string;
364
- eventSchemaVersion: string;
365
- streamAuthMode?: 'cookie' | 'signed_url_token' | null;
366
- streamAccessToken?: string | null;
367
- expiresAt: string;
368
- fallbackPatchUrl: string;
380
+ /**
381
+ * Base implementation for AI Adapters.
382
+ * Provides common validation logic against the Capabilities Catalog.
383
+ */
384
+ declare abstract class BaseAiAdapter<TConfig = any> implements AiConfigAdapter<TConfig> {
385
+ abstract componentName: string;
386
+ abstract getCurrentConfig(): TConfig;
387
+ abstract getCapabilities(): Capability[];
388
+ abstract applyPatch(patch: Partial<TConfig>, intent?: string): Promise<PatchResult>;
389
+ abstract createSnapshot(): any;
390
+ abstract restoreSnapshot(snapshot: any): Promise<void>;
391
+ getTaskPresets?(): Record<string, string[]>;
392
+ getSuggestions(_forceReload?: boolean): Promise<AiSuggestion[]>;
393
+ getSuggestionContext?(): Record<string, any>;
394
+ getRuntimeState?(): Record<string, any>;
395
+ /**
396
+ * Helper to validate a patch against the capabilities catalog.
397
+ * Removes keys that are not in the allowed paths.
398
+ */
399
+ protected validatePatchAgainstCapabilities(patch: any): any;
400
+ /**
401
+ * Helper to check if a patch contains critical changes.
402
+ */
403
+ protected getCriticalWarnings(patch: any): string[];
369
404
  }
370
- interface AiPatchStreamCancelResponseContract {
371
- streamId?: string | null;
372
- threadId?: string | null;
373
- turnId?: string | null;
374
- terminalState: 'cancelled' | 'completed' | 'not_found';
375
- message?: string | null;
405
+
406
+ interface FieldSchemaLike {
407
+ label: string;
408
+ type: string;
409
+ description?: string;
410
+ required?: boolean;
411
+ uiConfig?: {
412
+ category?: string;
413
+ };
414
+ allowedValues?: Array<{
415
+ value: any;
416
+ label: string;
417
+ }>;
376
418
  }
377
- interface AiPatchStreamEnvelopeContract<TPayload extends AiJsonObject = AiJsonObject> {
378
- eventId?: string | null;
379
- streamId: string;
380
- threadId: string;
381
- turnId: string;
382
- seq: number;
383
- eventSchemaVersion: string;
384
- timestamp: string;
385
- type: AiPatchStreamEventType$1;
386
- payload: TPayload;
419
+ declare class SchemaMinifierService {
420
+ /**
421
+ * Converts complete FieldSchemas into a minified version for AI context (Token optimized)
422
+ */
423
+ minify(schemas: Record<string, FieldSchemaLike>): MinifiedField[];
424
+ /**
425
+ * Formats minified fields into a string for the AI prompt (Legacy/Text mode)
426
+ */
427
+ toPromptFormat(fields: MinifiedField[]): string;
428
+ /**
429
+ * Transforms Praxis FieldSchemas into Google Gemini JSON Schema format.
430
+ * This enables "Response Schema" enforcement in the API.
431
+ */
432
+ toGeminiSchema(fields: Record<string, FieldSchemaLike>): Schema;
433
+ private mapTypeToGemini;
434
+ static ɵfac: i0.ɵɵFactoryDeclaration<SchemaMinifierService, never>;
435
+ static ɵprov: i0.ɵɵInjectableDeclaration<SchemaMinifierService>;
387
436
  }
388
- type AiPatchStreamEventType$1 = (typeof AI_STREAM_EVENT_TYPES)[number];
389
437
 
390
438
  declare const AI_INTENT_CONTRACT_VERSION: "v1.1";
391
439
  declare const AI_INTENT_CONTRACT_SCHEMA_HASH: "51b7901f1df633d89fc019a2e41f675cc5b87b135dfc8335aa96e53205034b26";
@@ -475,184 +523,67 @@ interface AiProviderStatusResponse {
475
523
  success?: boolean;
476
524
  message?: string;
477
525
  }
478
- interface AiContextTemplateMeta {
479
- variants?: Array<{
480
- id?: string;
481
- registryKey?: string;
482
- } | string>;
483
- defaultVariantId?: string;
484
- }
485
- interface AiContextTemplate {
486
- templateMeta?: AiContextTemplateMeta;
487
- }
488
- interface AiContextDTO {
489
- componentId?: string;
490
- componentType?: string;
491
- template?: AiContextTemplate | null;
492
- }
493
- interface AiHeaderContext {
494
- tenantId: string;
495
- env: string;
496
- userId: string;
497
- missing: string[];
498
- }
499
- declare class AiBackendApiService {
500
- private readonly http;
501
- private readonly globalConfig;
502
- private readonly storageOpts;
503
- private readonly baseUrl;
504
- private readonly contextUrl;
505
- getSuggestions(request: AiSuggestionsRequest): Observable<AiSuggestionsResponse>;
506
- getPatch(request: AiOrchestratorRequest): Observable<AiOrchestratorResponse>;
507
- startPatchStream(request: AiOrchestratorRequest): Observable<AiPatchStreamStartResponse>;
508
- connectPatchStream(streamId: string, lastEventId?: string, accessToken?: string): AiPatchStreamConnection;
509
- cancelPatchStream(streamId: string, accessToken?: string): Observable<AiPatchStreamCancelResponse>;
510
- listModels(request: AiProviderModelsRequest): Observable<AiProviderModelsResponse>;
511
- listProviderCatalog(): Observable<AiProviderCatalogResponse>;
512
- testProvider(request: AiProviderTestRequest): Observable<AiProviderTestResponse>;
513
- getAiStatus(): Observable<AiProviderStatusResponse>;
514
- getAiContext(componentId: string, componentType: string): Observable<AiContextDTO>;
515
- loadGlobalAiConfig(): Observable<GlobalAiConfig | null>;
516
- saveGlobalAiConfig(aiConfig: GlobalAiConfig): Observable<void>;
517
- getHeaderContext(): AiHeaderContext;
518
- private buildHeaders;
519
- private normalizeContractVersion;
520
- private normalizeContractSchemaHash;
521
- private resolveHeaderMap;
522
- private parsePatchStreamEnvelope;
523
- private isPatchStreamEnvelope;
524
- private isJsonObject;
525
- private probePatchStreamEndpoint;
526
- static ɵfac: i0.ɵɵFactoryDeclaration<AiBackendApiService, never>;
527
- static ɵprov: i0.ɵɵInjectableDeclaration<AiBackendApiService>;
528
- }
529
-
530
- interface FieldSchemaLike {
531
- label: string;
532
- type: string;
533
- description?: string;
534
- required?: boolean;
535
- uiConfig?: {
536
- category?: string;
537
- };
538
- allowedValues?: Array<{
539
- value: any;
540
- label: string;
541
- }>;
542
- }
543
- declare class SchemaMinifierService {
544
- /**
545
- * Converts complete FieldSchemas into a minified version for AI context (Token optimized)
546
- */
547
- minify(schemas: Record<string, FieldSchemaLike>): MinifiedField[];
548
- /**
549
- * Formats minified fields into a string for the AI prompt (Legacy/Text mode)
550
- */
551
- toPromptFormat(fields: MinifiedField[]): string;
552
- /**
553
- * Transforms Praxis FieldSchemas into Google Gemini JSON Schema format.
554
- * This enables "Response Schema" enforcement in the API.
555
- */
556
- toGeminiSchema(fields: Record<string, FieldSchemaLike>): Schema;
557
- private mapTypeToGemini;
558
- static ɵfac: i0.ɵɵFactoryDeclaration<SchemaMinifierService, never>;
559
- static ɵprov: i0.ɵɵInjectableDeclaration<SchemaMinifierService>;
560
- }
561
-
562
- declare class AiContextBuilderService {
563
- private schemaMinifier;
564
- constructor(schemaMinifier: SchemaMinifierService);
565
- /**
566
- * Builds the complete context for the AI prompt
567
- */
568
- buildPromptContext(fieldSchemas: Record<string, FieldSchemaLike>, targetType: 'field' | 'section' | 'action' | 'row' | 'column', propertySchema: RulePropertySchema): PromptContext;
569
- buildRulePrompt(userPrompt: string, context: PromptContext): string;
570
- buildSuggestionPrompt(context: PromptContext): string;
571
- /**
572
- * Formats available properties by targetType
573
- */
574
- private formatProperties;
575
- /**
576
- * Lists DSL operators with examples
577
- */
578
- private formatOperators;
579
- static ɵfac: i0.ɵɵFactoryDeclaration<AiContextBuilderService, never>;
580
- static ɵprov: i0.ɵɵInjectableDeclaration<AiContextBuilderService>;
581
- }
582
-
583
- /**
584
- * Normalize DSL expression by replacing aliases with standard operators
585
- */
586
- declare function normalizeDsl(dsl: string): string;
587
- /**
588
- * Configuration for parsing DSL expressions
589
- */
590
- interface DslParsingConfig {
591
- /** Available function registry */
592
- functionRegistry?: FunctionRegistry<any>;
593
- /** Context provider for variable resolution */
594
- contextProvider?: ContextProvider;
595
- /** Known field names for validation */
596
- knownFields?: string[];
597
- /** Enable performance warnings */
598
- enablePerformanceWarnings?: boolean;
599
- /** Maximum expression complexity */
600
- maxComplexity?: number;
526
+ interface AiContextTemplateMeta {
527
+ variants?: Array<{
528
+ id?: string;
529
+ registryKey?: string;
530
+ } | string>;
531
+ defaultVariantId?: string;
601
532
  }
602
- /**
603
- * Result of parsing a DSL expression
604
- */
605
- interface DslParsingResult<T extends object = any> {
606
- /** Whether parsing was successful */
607
- success: boolean;
608
- /** Parsed specification (if successful) */
609
- specification?: any;
610
- /** Validation issues found */
611
- issues: ValidationIssue[];
612
- /** Performance metrics */
613
- metrics?: {
614
- parseTime: number;
615
- complexity: number;
616
- };
533
+ interface AiContextTemplate {
534
+ templateMeta?: AiContextTemplateMeta;
617
535
  }
618
- /**
619
- * Dedicated service for DSL parsing and validation
620
- * Extracted from SpecificationBridgeService to follow SRP
621
- */
622
- declare class DslParsingService {
623
- constructor();
624
- /**
625
- * Parse a DSL expression into a specification
626
- */
627
- parseDsl<T extends object = any>(dslExpression: string, config?: DslParsingConfig): DslParsingResult<T>;
628
- /**
629
- * Normalize DSL expression (delegates to utility)
630
- */
631
- normalizeDsl(dsl: string): string;
632
- /**
633
- * Static wrapper for backward compatibility if needed
634
- */
635
- static normalizeDsl(dsl: string): string;
636
- /**
637
- * Validate DSL syntax without parsing
638
- */
639
- validateDsl(dslExpression: string, config?: DslParsingConfig): ValidationIssue[];
640
- /**
641
- * Get suggestions for DSL completion
642
- */
643
- getDslSuggestions(partialExpression: string, cursorPosition: number, config?: DslParsingConfig): string[];
644
- /**
645
- * Format DSL expression for readability
646
- */
647
- formatDsl(dslExpression: string): string;
648
- /**
649
- * Check if DSL expression is syntactically valid
650
- */
651
- isValidDsl(dslExpression: string, config?: DslParsingConfig): boolean;
652
- private calculateComplexity;
653
- private getCurrentToken;
654
- static ɵfac: i0.ɵɵFactoryDeclaration<DslParsingService, never>;
655
- static ɵprov: i0.ɵɵInjectableDeclaration<DslParsingService>;
536
+ interface AiContextDTO {
537
+ componentId?: string;
538
+ componentType?: string;
539
+ template?: AiContextTemplate | null;
540
+ }
541
+ interface AiHeaderContext {
542
+ tenantId: string;
543
+ env: string;
544
+ userId: string;
545
+ missing: string[];
546
+ }
547
+ interface AiGlobalConfigSnapshot {
548
+ provider?: string;
549
+ apiKey?: string;
550
+ model?: string;
551
+ temperature?: number;
552
+ maxTokens?: number;
553
+ timeout?: number;
554
+ retryAttempts?: number;
555
+ gatewayUrl?: string;
556
+ riskPolicy?: string;
557
+ }
558
+ declare class AiBackendApiService {
559
+ private readonly http;
560
+ private readonly globalConfigStore;
561
+ private readonly storageOpts;
562
+ private readonly baseUrl;
563
+ private readonly contextUrl;
564
+ getSuggestions(request: AiSuggestionsRequest): Observable<AiSuggestionsResponse>;
565
+ getPatch(request: AiOrchestratorRequest): Observable<AiOrchestratorResponse>;
566
+ startPatchStream(request: AiOrchestratorRequest): Observable<AiPatchStreamStartResponse>;
567
+ connectPatchStream(streamId: string, lastEventId?: string, accessToken?: string): AiPatchStreamConnection;
568
+ cancelPatchStream(streamId: string, accessToken?: string): Observable<AiPatchStreamCancelResponse>;
569
+ listModels(request: AiProviderModelsRequest): Observable<AiProviderModelsResponse>;
570
+ listProviderCatalog(): Observable<AiProviderCatalogResponse>;
571
+ testProvider(request: AiProviderTestRequest): Observable<AiProviderTestResponse>;
572
+ getAiStatus(): Observable<AiProviderStatusResponse>;
573
+ getAiContext(componentId: string, componentType: string): Observable<AiContextDTO>;
574
+ loadGlobalAiConfig(): Observable<AiGlobalConfigSnapshot | null>;
575
+ saveGlobalAiConfig(aiConfig: AiGlobalConfigSnapshot): Observable<void>;
576
+ getHeaderContext(): AiHeaderContext;
577
+ private buildHeaders;
578
+ private normalizeContractVersion;
579
+ private normalizeContractSchemaHash;
580
+ private resolveHeaderMap;
581
+ private parsePatchStreamEnvelope;
582
+ private isPatchStreamEnvelope;
583
+ private isJsonObject;
584
+ private probePatchStreamEndpoint;
585
+ static ɵfac: i0.ɵɵFactoryDeclaration<AiBackendApiService, never>;
586
+ static ɵprov: i0.ɵɵInjectableDeclaration<AiBackendApiService>;
656
587
  }
657
588
 
658
589
  interface ValidationContext {
@@ -661,14 +592,17 @@ interface ValidationContext {
661
592
  propertySchema: RulePropertySchema;
662
593
  }
663
594
  declare class AiResponseValidatorService {
664
- private dslParsingService;
665
- constructor(dslParsingService: DslParsingService);
666
595
  /**
667
596
  * Validates the complete AI response
668
597
  */
669
598
  validate(response: AiRuleResponse, context: ValidationContext): AiValidationResult;
670
599
  private validateStructure;
671
600
  private validateTargetIds;
601
+ private validateCondition;
602
+ private validateJsonLogicExpression;
603
+ private walkJsonLogicNode;
604
+ private isSupportedJsonLogicOperator;
605
+ private collectVarPaths;
672
606
  private isValidTargetId;
673
607
  private findSimilarTargetId;
674
608
  private calculateSimilarity;
@@ -678,114 +612,6 @@ declare class AiResponseValidatorService {
678
612
  static ɵprov: i0.ɵɵInjectableDeclaration<AiResponseValidatorService>;
679
613
  }
680
614
 
681
- interface AiWizardData {
682
- fieldSchemas: Record<string, FieldSchemaLike>;
683
- targetSchemas?: any;
684
- propertySchema: RulePropertySchema;
685
- }
686
- type WizardStep = 'prompt' | 'review';
687
- declare class AiRuleWizardDialogComponent implements OnInit {
688
- dialogRef: MatDialogRef<AiRuleWizardDialogComponent>;
689
- data: AiWizardData;
690
- private aiService;
691
- private validator;
692
- private snackBar;
693
- private contextBuilder;
694
- private cdr;
695
- selectedTargetType: 'field' | 'section' | 'action' | 'row' | 'column';
696
- userPrompt: string;
697
- isGenerating: boolean;
698
- validationError: string | null;
699
- loadingSuggestions: boolean;
700
- suggestions: string[];
701
- private suggestionsCache;
702
- private suggestionsRequestId;
703
- currentStep: WizardStep;
704
- generatedResponse: AiRuleResponse | null;
705
- warnings: AiValidationWarning[];
706
- loadingMessages: string[];
707
- currentLoadingMessage: string;
708
- streamingText: string;
709
- private loadingInterval;
710
- constructor(dialogRef: MatDialogRef<AiRuleWizardDialogComponent>, data: AiWizardData, aiService: PraxisAiService, validator: AiResponseValidatorService, snackBar: MatSnackBar, contextBuilder: AiContextBuilderService, cdr: ChangeDetectorRef);
711
- ngOnInit(): void;
712
- onTargetTypeChange(): void;
713
- getAvailableProperties(): _praxisui_core.RulePropertyDefinition[];
714
- loadSuggestions(forceRefresh?: boolean): Promise<void>;
715
- reloadSuggestions(): void;
716
- applySuggestion(text: string): void;
717
- generate(): Promise<void>;
718
- private startLoadingUX;
719
- private stopLoadingUX;
720
- backToPrompt(): void;
721
- confirm(): void;
722
- getProps(obj: any): {
723
- key: string;
724
- value: any;
725
- }[];
726
- hasProps(obj: any): boolean;
727
- static ɵfac: i0.ɵɵFactoryDeclaration<AiRuleWizardDialogComponent, never>;
728
- static ɵcmp: i0.ɵɵComponentDeclaration<AiRuleWizardDialogComponent, "praxis-ai-rule-wizard-dialog", never, {}, {}, never, never, true, never>;
729
- }
730
-
731
- declare class StreamingFeedbackComponent {
732
- title: string;
733
- displayText: string;
734
- isThinking: boolean;
735
- static ɵfac: i0.ɵɵFactoryDeclaration<StreamingFeedbackComponent, never>;
736
- static ɵcmp: i0.ɵɵComponentDeclaration<StreamingFeedbackComponent, "praxis-ai-streaming-feedback", never, { "title": { "alias": "title"; "required": false; }; "displayText": { "alias": "displayText"; "required": false; }; "isThinking": { "alias": "isThinking"; "required": false; }; }, {}, never, never, true, never>;
737
- }
738
-
739
- interface ConfigAgentRequest {
740
- adapter: AiConfigAdapter;
741
- userIntent: string;
742
- }
743
- interface ConfigAgentResponse {
744
- patch: any;
745
- explanation: string;
746
- applied: boolean;
747
- mockMode: boolean;
748
- }
749
- declare class AiConfigAgentService {
750
- private ai;
751
- constructor(ai: PraxisAiService);
752
- isMockMode(): boolean;
753
- /**
754
- * Legacy single-shot flow: builds a prompt with full config + capabilities.
755
- * Two-step flow is preferred (see TableAiAdapter.processUserIntent), but this remains as fallback.
756
- */
757
- generateConfigPatch(request: ConfigAgentRequest): Promise<ConfigAgentResponse>;
758
- private buildPrompt;
759
- static ɵfac: i0.ɵɵFactoryDeclaration<AiConfigAgentService, never>;
760
- static ɵprov: i0.ɵɵInjectableDeclaration<AiConfigAgentService>;
761
- }
762
-
763
- /**
764
- * Base implementation for AI Adapters.
765
- * Provides common validation logic against the Capabilities Catalog.
766
- */
767
- declare abstract class BaseAiAdapter<TConfig = any> implements AiConfigAdapter<TConfig> {
768
- abstract componentName: string;
769
- abstract getCurrentConfig(): TConfig;
770
- abstract getCapabilities(): Capability[];
771
- abstract applyPatch(patch: Partial<TConfig>, intent?: string): Promise<PatchResult>;
772
- abstract createSnapshot(): any;
773
- abstract restoreSnapshot(snapshot: any): Promise<void>;
774
- getTaskPresets?(): Record<string, string[]>;
775
- getSuggestions(_forceReload?: boolean): Promise<AiSuggestion[]>;
776
- getSuggestionContext?(): Record<string, any>;
777
- getRuntimeState?(): Record<string, any>;
778
- /**
779
- * Helper to validate a patch against the capabilities catalog.
780
- * Removes keys that are not in the allowed paths.
781
- */
782
- protected validatePatchAgainstCapabilities(patch: any): any;
783
- /**
784
- * Helper to check if a patch contains critical changes.
785
- */
786
- protected getCriticalWarnings(patch: any): string[];
787
- }
788
-
789
615
  type AssistantMessageRole = 'user' | 'assistant' | 'system';
790
616
  interface AssistantHistoryMessage {
791
617
  id: string;
@@ -1212,5 +1038,105 @@ declare class PraxisAiAssistantComponent implements OnDestroy {
1212
1038
  static ɵcmp: i0.ɵɵComponentDeclaration<PraxisAiAssistantComponent, "praxis-ai-assistant", never, { "adapter": { "alias": "adapter"; "required": true; }; "riskPolicy": { "alias": "riskPolicy"; "required": false; }; "allowManualPatchEdit": { "alias": "allowManualPatchEdit"; "required": false; }; }, {}, never, never, true, never>;
1213
1039
  }
1214
1040
 
1215
- export { AI_INTENT_CONTRACT_SCHEMA_HASH, AI_INTENT_CONTRACT_VERSION, AiBackendApiService, AiConfigAgentService, AiConfigService, AiContextBuilderService, AiPatchStreamConnectionError, AiResponseValidatorService, AiRuleWizardDialogComponent, BaseAiAdapter, DslParsingService, PraxisAi, PraxisAiAssistantComponent, PraxisAiService, SchemaMinifierService, StreamingFeedbackComponent, normalizeDsl };
1216
- export type { AiChatMessage, AiConfigAdapter, AiContextDTO, AiContextTemplate, AiContextTemplateMeta, AiCurrentStateDigest, AiExamplePair, AiHeaderContext, AiIntegrationConfig, AiModel, AiOrchestratorRequest, AiOrchestratorResponse, AiPatchDiff, AiPatchStreamCancelResponse, AiPatchStreamConnection, AiPatchStreamConnectionErrorKind, AiPatchStreamEnvelope, AiPatchStreamEventType, AiPatchStreamStartResponse, AiProviderCatalogItem, AiProviderCatalogResponse, AiProviderModelsRequest, AiProviderModelsResponse, AiProviderStatusResponse, AiProviderTestRequest, AiProviderTestResponse, AiRuleResponse, AiSchemaContext, AiSuggestion, AiSuggestionsRequest, AiSuggestionsResponse, AiUiContextRef, AiValidationError, AiValidationResult, AiValidationWarning, AiWizardData, Capability, ConfigAgentRequest, ConfigAgentResponse, DslParsingConfig, DslParsingResult, FieldSchemaLike, MinifiedField, PatchResult, PromptContext, ValidationContext, ValueKind };
1041
+ interface PraxisAiConfigSource {
1042
+ getAiConfigSnapshot?: () => Partial<AiIntegrationConfig> | null | undefined;
1043
+ aiConfigChanges$?: Observable<Partial<AiIntegrationConfig> | null>;
1044
+ }
1045
+ declare class PraxisAiService {
1046
+ private readonly configSource;
1047
+ private genAI;
1048
+ private config;
1049
+ constructor(configSource: PraxisAiConfigSource | null);
1050
+ private syncConfig;
1051
+ classifyIntent(userInput: string, columns: string[]): Observable<any>;
1052
+ answerQuestion(userInput: string, targetConfig: any): Observable<string>;
1053
+ executeEnrichedPrompt(userInput: string, contextDescription: string, targetConfig: any, capabilities: any): Observable<any>;
1054
+ private formatCapabilities;
1055
+ private normalizeIntentClassification;
1056
+ generateContent(prompt: string, modelName?: string): Observable<string>;
1057
+ generateContentStream(prompt: string, modelName?: string): Observable<string>;
1058
+ generateJson<T>(prompt: string, modelName?: string, schema?: any): Observable<T | null>;
1059
+ isMockMode(): boolean;
1060
+ private extractUserIntent;
1061
+ private getMockPatch;
1062
+ listModels(apiKey?: string): Observable<AiModel[]>;
1063
+ testConnection(apiKey?: string, model?: string): Observable<boolean>;
1064
+ private resolveProvider;
1065
+ private isGeminiProvider;
1066
+ static ɵfac: i0.ɵɵFactoryDeclaration<PraxisAiService, [{ optional: true; }]>;
1067
+ static ɵprov: i0.ɵɵInjectableDeclaration<PraxisAiService>;
1068
+ }
1069
+
1070
+ declare class AiContextBuilderService {
1071
+ private schemaMinifier;
1072
+ constructor(schemaMinifier: SchemaMinifierService);
1073
+ /**
1074
+ * Builds the complete context for the AI prompt
1075
+ */
1076
+ buildPromptContext(fieldSchemas: Record<string, FieldSchemaLike>, targetType: 'field' | 'section' | 'action' | 'row' | 'column', propertySchema: RulePropertySchema): PromptContext;
1077
+ buildRulePrompt(userPrompt: string, context: PromptContext): string;
1078
+ buildSuggestionPrompt(context: PromptContext): string;
1079
+ /**
1080
+ * Formats available properties by targetType
1081
+ */
1082
+ private formatProperties;
1083
+ /**
1084
+ * Lists JSON Logic operators with examples
1085
+ */
1086
+ private formatOperators;
1087
+ static ɵfac: i0.ɵɵFactoryDeclaration<AiContextBuilderService, never>;
1088
+ static ɵprov: i0.ɵɵInjectableDeclaration<AiContextBuilderService>;
1089
+ }
1090
+
1091
+ interface AiWizardData {
1092
+ fieldSchemas: Record<string, FieldSchemaLike>;
1093
+ targetSchemas?: any;
1094
+ propertySchema: RulePropertySchema;
1095
+ }
1096
+ type WizardStep = 'prompt' | 'review';
1097
+ declare class AiRuleWizardDialogComponent implements OnInit {
1098
+ dialogRef: MatDialogRef<AiRuleWizardDialogComponent>;
1099
+ data: AiWizardData;
1100
+ private aiService;
1101
+ private validator;
1102
+ private snackBar;
1103
+ private contextBuilder;
1104
+ private cdr;
1105
+ selectedTargetType: 'field' | 'section' | 'action' | 'row' | 'column';
1106
+ userPrompt: string;
1107
+ isGenerating: boolean;
1108
+ validationError: string | null;
1109
+ loadingSuggestions: boolean;
1110
+ suggestions: string[];
1111
+ private suggestionsCache;
1112
+ private suggestionsRequestId;
1113
+ currentStep: WizardStep;
1114
+ generatedResponse: AiRuleResponse | null;
1115
+ warnings: AiValidationWarning[];
1116
+ loadingMessages: string[];
1117
+ currentLoadingMessage: string;
1118
+ streamingText: string;
1119
+ private loadingInterval;
1120
+ constructor(dialogRef: MatDialogRef<AiRuleWizardDialogComponent>, data: AiWizardData, aiService: PraxisAiService, validator: AiResponseValidatorService, snackBar: MatSnackBar, contextBuilder: AiContextBuilderService, cdr: ChangeDetectorRef);
1121
+ ngOnInit(): void;
1122
+ onTargetTypeChange(): void;
1123
+ getAvailableProperties(): _praxisui_ai.RulePropertyDefinition[];
1124
+ loadSuggestions(forceRefresh?: boolean): Promise<void>;
1125
+ reloadSuggestions(): void;
1126
+ applySuggestion(text: string): void;
1127
+ generate(): Promise<void>;
1128
+ private startLoadingUX;
1129
+ private stopLoadingUX;
1130
+ backToPrompt(): void;
1131
+ confirm(): void;
1132
+ getProps(obj: any): {
1133
+ key: string;
1134
+ value: any;
1135
+ }[];
1136
+ hasProps(obj: any): boolean;
1137
+ static ɵfac: i0.ɵɵFactoryDeclaration<AiRuleWizardDialogComponent, never>;
1138
+ static ɵcmp: i0.ɵɵComponentDeclaration<AiRuleWizardDialogComponent, "praxis-ai-rule-wizard-dialog", never, {}, {}, never, never, true, never>;
1139
+ }
1140
+
1141
+ export { AI_INTENT_CONTRACT_SCHEMA_HASH, AI_INTENT_CONTRACT_VERSION, AiBackendApiService, AiPatchStreamConnectionError, AiResponseValidatorService, AiRuleWizardDialogComponent, BaseAiAdapter, PraxisAi, PraxisAiAssistantComponent, SchemaMinifierService };
1142
+ export type { AiChatMessage, AiConfigAdapter, AiContextDTO, AiContextTemplate, AiContextTemplateMeta, AiCurrentStateDigest, AiExamplePair, AiGlobalConfigSnapshot, AiHeaderContext, AiIntegrationConfig, AiModel, AiOrchestratorRequest, AiOrchestratorResponse, AiPatchDiff, AiPatchStreamCancelResponse, AiPatchStreamConnection, AiPatchStreamConnectionErrorKind, AiPatchStreamEnvelope, AiPatchStreamEventType, AiPatchStreamStartResponse, AiProviderCatalogItem, AiProviderCatalogResponse, AiProviderModelsRequest, AiProviderModelsResponse, AiProviderStatusResponse, AiProviderTestRequest, AiProviderTestResponse, AiRuleResponse, AiSchemaContext, AiSuggestion, AiSuggestionsRequest, AiSuggestionsResponse, AiUiContextRef, AiValidationError, AiValidationResult, AiValidationWarning, AiWizardData, Capability, FieldSchemaLike, MinifiedField, PatchResult, PromptContext, RulePropertyDefinition, RulePropertySchema, RulePropertyType, ValidationContext, ValueKind };