@praxisui/ai 10.0.0-rc.44 → 10.0.0-rc.46

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.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": "1.0.0",
3
- "generatedAt": "2026-11-09T21:30:37.724Z",
3
+ "generatedAt": "2026-11-15T00:03:48.148Z",
4
4
  "packageName": "@praxisui/ai",
5
- "packageVersion": "10.0.0-rc.44",
5
+ "packageVersion": "10.0.0-rc.46",
6
6
  "sourceRegistry": "praxis-component-registry-ingestion",
7
7
  "sourceRegistryVersion": "1.0.0",
8
8
  "componentCount": 0,
@@ -3190,9 +3190,23 @@ class AiResponseValidatorService {
3190
3190
  ];
3191
3191
  }
3192
3192
  const fieldErrors = [];
3193
+ const allowedRoots = Array.isArray(context.allowedOntologicalRoots)
3194
+ ? context.allowedOntologicalRoots.filter(Boolean)
3195
+ : [];
3193
3196
  this.collectVarPaths(condition, new Set()).forEach((path) => {
3194
3197
  const rootField = path.split('.')[0];
3195
- if (!rootField || !(rootField in context.fieldSchemas)) {
3198
+ if (allowedRoots.length > 0 && (!path.includes('.') || !allowedRoots.includes(rootField))) {
3199
+ fieldErrors.push({
3200
+ field: 'condition',
3201
+ message: `Raiz ontológica inválida em condition: '${rootField}' (permitidas: ${allowedRoots.join(', ')})`,
3202
+ severity: 'error',
3203
+ code: 'INVALID_ONTOLOGICAL_FACT_ROOT',
3204
+ });
3205
+ return;
3206
+ }
3207
+ const isKnownField = Boolean(rootField) &&
3208
+ (path in context.fieldSchemas || rootField in context.fieldSchemas);
3209
+ if (!isKnownField) {
3196
3210
  fieldErrors.push({
3197
3211
  field: 'condition',
3198
3212
  message: `Campo inválido em condition: ${path}`,
@@ -3349,7 +3363,7 @@ class AiResponseValidatorService {
3349
3363
  }
3350
3364
  isValidTargetId(id, targetType, context) {
3351
3365
  if (targetType === 'field') {
3352
- return id in context.fieldSchemas;
3366
+ return id in context.fieldSchemas || `draft.${id}` in context.fieldSchemas;
3353
3367
  }
3354
3368
  if (targetType === 'section' && context.targetSchemas?.sections) {
3355
3369
  return id in context.targetSchemas.sections;
@@ -3370,7 +3384,11 @@ class AiResponseValidatorService {
3370
3384
  findSimilarTargetId(invalidId, targetType, context) {
3371
3385
  let candidates = [];
3372
3386
  if (targetType === 'field') {
3373
- candidates = Object.keys(context.fieldSchemas);
3387
+ const rawKeys = Object.keys(context.fieldSchemas);
3388
+ const strippedDraftKeys = rawKeys
3389
+ .filter((key) => key.startsWith('draft.'))
3390
+ .map((key) => key.slice('draft.'.length));
3391
+ candidates = Array.from(new Set([...strippedDraftKeys, ...rawKeys]));
3374
3392
  }
3375
3393
  else if (targetType === 'section' && context.targetSchemas?.sections) {
3376
3394
  candidates = Object.keys(context.targetSchemas.sections);
@@ -11498,27 +11516,34 @@ class AiContextBuilderService {
11498
11516
  /**
11499
11517
  * Builds the complete context for the AI prompt
11500
11518
  */
11501
- buildPromptContext(fieldSchemas, targetType, propertySchema) {
11519
+ buildPromptContext(fieldSchemas, targetType, propertySchema, allowedOntologicalRoots) {
11502
11520
  const minifiedFields = this.schemaMinifier.minify(fieldSchemas);
11503
11521
  const fieldsText = this.schemaMinifier.toPromptFormat(minifiedFields);
11504
11522
  const properties = propertySchema[targetType] || [];
11505
11523
  const propertiesText = this.formatProperties(properties);
11506
11524
  const operatorsText = this.formatOperators();
11525
+ const normalizedRoots = Array.isArray(allowedOntologicalRoots)
11526
+ ? allowedOntologicalRoots.filter(Boolean)
11527
+ : undefined;
11507
11528
  return {
11508
11529
  fieldsText,
11509
11530
  propertiesText,
11510
11531
  operatorsText,
11511
11532
  targetType,
11512
11533
  minifiedFields,
11534
+ allowedOntologicalRoots: normalizedRoots?.length ? normalizedRoots : undefined,
11513
11535
  };
11514
11536
  }
11515
11537
  buildRulePrompt(userPrompt, context) {
11538
+ const ontologicalSection = context.allowedOntologicalRoots?.length
11539
+ ? `\nRAÍZES ONTOLÓGICAS PERMITIDAS (GRAFO DE FATOS /schemas/domain):\n- Raízes válidas para {"var": "..."} em "condition": ${context.allowedOntologicalRoots.join(', ')}\n- Toda referência {"var": "..."} em "condition" DEVE usar caminho pontilhado iniciado por uma dessas raízes (ex.: "draft.campo", "current.campo", "${context.allowedOntologicalRoots[0]}.campo").\n- É PROIBIDO usar o saco escalar legado "facts.*" ou caminhos sem raiz ontológica em "condition".\n- Em "targetIds" para targetType="field", use o identificador do campo do formulário sem o prefixo "draft.".\n`
11540
+ : '';
11516
11541
  return `
11517
11542
  Você é um assistente especializado em criar regras de formulário.
11518
11543
 
11519
11544
  CAMPOS DISPONÍVEIS NO FORMULÁRIO:
11520
11545
  ${context.fieldsText}
11521
-
11546
+ ${ontologicalSection}
11522
11547
  PROPRIEDADES QUE VOCÊ PODE APLICAR EM "${context.targetType.toUpperCase()}":
11523
11548
  ${context.propertiesText}
11524
11549
 
@@ -11579,12 +11604,15 @@ Resposta (JSON puro, sem markdown):
11579
11604
  `.trim();
11580
11605
  }
11581
11606
  buildSuggestionPrompt(context) {
11607
+ const ontologicalHint = context.allowedOntologicalRoots?.length
11608
+ ? `\nRAÍZES ONTOLÓGICAS DISPONÍVEIS: ${context.allowedOntologicalRoots.join(', ')} (sugira também regras que cruzem estado proposto 'draft', estado atual 'current', conceitos relacionados 1-hop ou agregações 'neighborhood' quando presentes).\n`
11609
+ : '';
11582
11610
  return `
11583
11611
  Você é um assistente de UX para formulários.
11584
11612
 
11585
11613
  CAMPOS DISPONÍVEIS:
11586
11614
  ${context.fieldsText}
11587
-
11615
+ ${ontologicalHint}
11588
11616
  ALVO ATUAL: ${context.targetType}
11589
11617
 
11590
11618
  TAREFA:
@@ -11710,7 +11738,7 @@ class AiRuleWizardDialogComponent {
11710
11738
  this.suggestions = this.suggestionsCache.get(cacheKey) || [];
11711
11739
  return;
11712
11740
  }
11713
- const context = this.contextBuilder.buildPromptContext(this.data.fieldSchemas, this.selectedTargetType, this.data.propertySchema);
11741
+ const context = this.contextBuilder.buildPromptContext(this.data.fieldSchemas, this.selectedTargetType, this.data.propertySchema, this.data.allowedOntologicalRoots);
11714
11742
  const requestId = ++this.suggestionsRequestId;
11715
11743
  this.loadingSuggestions = true;
11716
11744
  try {
@@ -11746,7 +11774,7 @@ class AiRuleWizardDialogComponent {
11746
11774
  this.warnings = [];
11747
11775
  this.streamingText = '';
11748
11776
  try {
11749
- const context = this.contextBuilder.buildPromptContext(this.data.fieldSchemas, this.selectedTargetType, this.data.propertySchema);
11777
+ const context = this.contextBuilder.buildPromptContext(this.data.fieldSchemas, this.selectedTargetType, this.data.propertySchema, this.data.allowedOntologicalRoots);
11750
11778
  const prompt = this.contextBuilder.buildRulePrompt(this.userPrompt, context);
11751
11779
  // Use streaming for better UX
11752
11780
  let fullText = '';
@@ -11774,7 +11802,8 @@ class AiRuleWizardDialogComponent {
11774
11802
  const valContext = {
11775
11803
  fieldSchemas: this.data.fieldSchemas,
11776
11804
  targetSchemas: this.data.targetSchemas,
11777
- propertySchema: this.data.propertySchema
11805
+ propertySchema: this.data.propertySchema,
11806
+ allowedOntologicalRoots: this.data.allowedOntologicalRoots,
11778
11807
  };
11779
11808
  const validation = this.validator.validate(response, valContext);
11780
11809
  if (!validation.valid) {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@praxisui/ai",
3
- "version": "10.0.0-rc.44",
3
+ "version": "10.0.0-rc.46",
4
4
  "description": "AI building blocks and assistant integration for Praxis UI applications.",
5
5
  "peerDependencies": {
6
6
  "@angular/common": "^21.0.0",
7
7
  "@angular/core": "^21.0.0",
8
- "@praxisui/core": "^10.0.0-rc.44",
8
+ "@praxisui/core": "^10.0.0-rc.46",
9
9
  "@angular/cdk": "^21.0.0",
10
10
  "@angular/forms": "^21.0.0",
11
11
  "@angular/material": "^21.0.0",
@@ -84,7 +84,7 @@ interface AiSelectedDomainDecisionRefContract {
84
84
  definitionId: string;
85
85
  ruleKey: string;
86
86
  version: number;
87
- source: 'policy-studio-selection';
87
+ source: 'rules-studio-selection' | 'policy-studio-selection';
88
88
  }
89
89
  interface AgenticAuthoringClientActionContract {
90
90
  schemaVersion: 'praxis-agentic-authoring-client-action.v1';
@@ -743,6 +743,8 @@ interface PromptContext {
743
743
  targetType: string;
744
744
  /** Structured list of fields for richer prompt suggestions */
745
745
  minifiedFields?: MinifiedField[];
746
+ /** Allowed ontological fact roots from /schemas/domain (e.g. ['draft', 'current', 'vinculo', 'neighborhood', 'context']) */
747
+ allowedOntologicalRoots?: string[];
746
748
  }
747
749
  /**
748
750
  * Example pair for Few-Shot Learning
@@ -1980,6 +1982,8 @@ interface ValidationContext {
1980
1982
  fieldSchemas: Record<string, FieldSchemaLike>;
1981
1983
  targetSchemas?: any;
1982
1984
  propertySchema: RulePropertySchema;
1985
+ /** Raízes ontológicas permitidas para o recurso (ex.: ['draft', 'current', 'vinculo', 'neighborhood', 'context']) */
1986
+ allowedOntologicalRoots?: string[];
1983
1987
  }
1984
1988
  declare class AiResponseValidatorService {
1985
1989
  /**
@@ -2968,7 +2972,7 @@ declare class AiContextBuilderService {
2968
2972
  /**
2969
2973
  * Builds the complete context for the AI prompt
2970
2974
  */
2971
- buildPromptContext(fieldSchemas: Record<string, FieldSchemaLike>, targetType: 'field' | 'section' | 'action' | 'row' | 'column' | 'visualBlock', propertySchema: RulePropertySchema): PromptContext;
2975
+ buildPromptContext(fieldSchemas: Record<string, FieldSchemaLike>, targetType: 'field' | 'section' | 'action' | 'row' | 'column' | 'visualBlock', propertySchema: RulePropertySchema, allowedOntologicalRoots?: string[]): PromptContext;
2972
2976
  buildRulePrompt(userPrompt: string, context: PromptContext): string;
2973
2977
  buildSuggestionPrompt(context: PromptContext): string;
2974
2978
  /**
@@ -2987,6 +2991,7 @@ interface AiWizardData {
2987
2991
  fieldSchemas: Record<string, FieldSchemaLike>;
2988
2992
  targetSchemas?: any;
2989
2993
  propertySchema: RulePropertySchema;
2994
+ allowedOntologicalRoots?: string[];
2990
2995
  }
2991
2996
  type WizardStep = 'prompt' | 'review';
2992
2997
  declare class AiRuleWizardDialogComponent implements OnInit {