photon-grid-core 2.0.0 → 2.0.4

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 (175) hide show
  1. package/README.md +3 -3
  2. package/cell-selection/cell-selection-engine.d.ts.map +1 -1
  3. package/cell-selection/cell-selection-engine.js +11 -9
  4. package/cell-selection/cell-selection-engine.js.map +1 -1
  5. package/chart/range-chart-controller.d.ts +10 -0
  6. package/chart/range-chart-controller.d.ts.map +1 -1
  7. package/chart/range-chart-controller.js +22 -2
  8. package/chart/range-chart-controller.js.map +1 -1
  9. package/column-groups/column-group-drag-handler.d.ts.map +1 -1
  10. package/column-groups/column-group-drag-handler.js +64 -25
  11. package/column-groups/column-group-drag-handler.js.map +1 -1
  12. package/column-groups/column-group-header-builder.d.ts.map +1 -1
  13. package/column-groups/column-group-header-builder.js +7 -5
  14. package/column-groups/column-group-header-builder.js.map +1 -1
  15. package/column-groups/display-group-drag-handler.d.ts +7 -3
  16. package/column-groups/display-group-drag-handler.d.ts.map +1 -1
  17. package/column-groups/display-group-drag-handler.js +46 -7
  18. package/column-groups/display-group-drag-handler.js.map +1 -1
  19. package/column-groups/display-group-header-builder.d.ts +1 -1
  20. package/column-groups/display-group-header-builder.d.ts.map +1 -1
  21. package/column-groups/display-group-header-builder.js +9 -7
  22. package/column-groups/display-group-header-builder.js.map +1 -1
  23. package/core/column-model.d.ts +88 -5
  24. package/core/column-model.d.ts.map +1 -1
  25. package/core/column-model.js +215 -3
  26. package/core/column-model.js.map +1 -1
  27. package/core/create-grid.d.ts +54 -0
  28. package/core/create-grid.d.ts.map +1 -0
  29. package/core/create-grid.js +70 -0
  30. package/core/create-grid.js.map +1 -0
  31. package/core/grid-api.d.ts +10 -2
  32. package/core/grid-api.d.ts.map +1 -1
  33. package/core/grid-api.js +10 -0
  34. package/core/grid-api.js.map +1 -1
  35. package/core/grid-core.d.ts +7 -0
  36. package/core/grid-core.d.ts.map +1 -1
  37. package/core/grid-core.js +29 -8
  38. package/core/grid-core.js.map +1 -1
  39. package/core/grid-store.d.ts +5 -5
  40. package/core/grid-store.d.ts.map +1 -1
  41. package/core/pointer-utils.d.ts +59 -0
  42. package/core/pointer-utils.d.ts.map +1 -0
  43. package/core/pointer-utils.js +59 -0
  44. package/core/pointer-utils.js.map +1 -0
  45. package/drag-drop/drag-drop-engine.d.ts.map +1 -1
  46. package/drag-drop/drag-drop-engine.js +8 -8
  47. package/drag-drop/drag-drop-engine.js.map +1 -1
  48. package/engines/editing/cell-editor-engine.js +1 -1
  49. package/engines/editing/cell-editor-engine.js.map +1 -1
  50. package/index.d.ts +8 -3
  51. package/index.d.ts.map +1 -1
  52. package/index.js +4 -1
  53. package/index.js.map +1 -1
  54. package/package.json +1 -1
  55. package/photon-ai/index.d.ts +2 -0
  56. package/photon-ai/index.d.ts.map +1 -1
  57. package/photon-ai/index.js +2 -0
  58. package/photon-ai/index.js.map +1 -1
  59. package/photon-ai/photon-ai-panel.d.ts +40 -0
  60. package/photon-ai/photon-ai-panel.d.ts.map +1 -1
  61. package/photon-ai/photon-ai-panel.js +163 -8
  62. package/photon-ai/photon-ai-panel.js.map +1 -1
  63. package/photon-ai/photon-ai-service.d.ts +38 -1
  64. package/photon-ai/photon-ai-service.d.ts.map +1 -1
  65. package/photon-ai/photon-ai-service.js +72 -1
  66. package/photon-ai/photon-ai-service.js.map +1 -1
  67. package/photon-ai/provider/ai-provider.types.d.ts +174 -0
  68. package/photon-ai/provider/ai-provider.types.d.ts.map +1 -0
  69. package/photon-ai/provider/ai-provider.types.js +42 -0
  70. package/photon-ai/provider/ai-provider.types.js.map +1 -0
  71. package/photon-ai/provider/command-normalizer.d.ts +36 -0
  72. package/photon-ai/provider/command-normalizer.d.ts.map +1 -0
  73. package/photon-ai/provider/command-normalizer.js +120 -0
  74. package/photon-ai/provider/command-normalizer.js.map +1 -0
  75. package/photon-ai/provider/grid-context-builder.d.ts +37 -0
  76. package/photon-ai/provider/grid-context-builder.d.ts.map +1 -0
  77. package/photon-ai/provider/grid-context-builder.js +96 -0
  78. package/photon-ai/provider/grid-context-builder.js.map +1 -0
  79. package/photon-ai/provider/http-ai-provider.d.ts +42 -0
  80. package/photon-ai/provider/http-ai-provider.d.ts.map +1 -0
  81. package/photon-ai/provider/http-ai-provider.js +125 -0
  82. package/photon-ai/provider/http-ai-provider.js.map +1 -0
  83. package/photon-ai/provider/index.d.ts +30 -0
  84. package/photon-ai/provider/index.d.ts.map +1 -0
  85. package/photon-ai/provider/index.js +42 -0
  86. package/photon-ai/provider/index.js.map +1 -0
  87. package/photon-ai/provider/presets.d.ts +29 -0
  88. package/photon-ai/provider/presets.d.ts.map +1 -0
  89. package/photon-ai/provider/presets.js +110 -0
  90. package/photon-ai/provider/presets.js.map +1 -0
  91. package/photon-ai/provider/response-parsing.d.ts +22 -0
  92. package/photon-ai/provider/response-parsing.d.ts.map +1 -0
  93. package/photon-ai/provider/response-parsing.js +79 -0
  94. package/photon-ai/provider/response-parsing.js.map +1 -0
  95. package/photon-ai/provider/system-prompt.d.ts +26 -0
  96. package/photon-ai/provider/system-prompt.d.ts.map +1 -0
  97. package/photon-ai/provider/system-prompt.js +82 -0
  98. package/photon-ai/provider/system-prompt.js.map +1 -0
  99. package/photon-grid.min.js +497 -56
  100. package/renderer/body-renderer.d.ts +23 -0
  101. package/renderer/body-renderer.d.ts.map +1 -1
  102. package/renderer/body-renderer.js +102 -24
  103. package/renderer/body-renderer.js.map +1 -1
  104. package/renderer/column-chooser.d.ts +82 -0
  105. package/renderer/column-chooser.d.ts.map +1 -0
  106. package/renderer/column-chooser.js +335 -0
  107. package/renderer/column-chooser.js.map +1 -0
  108. package/renderer/column-menu.d.ts.map +1 -1
  109. package/renderer/column-menu.js +32 -20
  110. package/renderer/column-menu.js.map +1 -1
  111. package/renderer/column-style-manager.d.ts +27 -0
  112. package/renderer/column-style-manager.d.ts.map +1 -1
  113. package/renderer/column-style-manager.js +47 -0
  114. package/renderer/column-style-manager.js.map +1 -1
  115. package/renderer/detail-row-renderer.d.ts.map +1 -1
  116. package/renderer/detail-row-renderer.js +8 -6
  117. package/renderer/detail-row-renderer.js.map +1 -1
  118. package/renderer/grid-renderer.d.ts +10 -0
  119. package/renderer/grid-renderer.d.ts.map +1 -1
  120. package/renderer/grid-renderer.js +64 -20
  121. package/renderer/grid-renderer.js.map +1 -1
  122. package/renderer/group-drop-zone.js +14 -14
  123. package/renderer/group-drop-zone.js.map +1 -1
  124. package/renderer/header-renderer.d.ts +65 -0
  125. package/renderer/header-renderer.d.ts.map +1 -1
  126. package/renderer/header-renderer.js +347 -44
  127. package/renderer/header-renderer.js.map +1 -1
  128. package/renderer/row-animator.js +3 -3
  129. package/renderer/row-drag-renderer.js +6 -6
  130. package/renderer/row-drag-renderer.js.map +1 -1
  131. package/renderer/scroll-controller.d.ts +40 -0
  132. package/renderer/scroll-controller.d.ts.map +1 -1
  133. package/renderer/scroll-controller.js +184 -0
  134. package/renderer/scroll-controller.js.map +1 -1
  135. package/styles/base/column-chooser.css.d.ts +13 -0
  136. package/styles/base/column-chooser.css.d.ts.map +1 -0
  137. package/styles/base/column-chooser.css.js +241 -0
  138. package/styles/base/column-chooser.css.js.map +1 -0
  139. package/styles/base/column-context-menu.css.d.ts +1 -1
  140. package/styles/base/column-context-menu.css.d.ts.map +1 -1
  141. package/styles/base/column-context-menu.css.js +10 -0
  142. package/styles/base/column-context-menu.css.js.map +1 -1
  143. package/styles/base/filter.css.d.ts +1 -1
  144. package/styles/base/filter.css.js +1 -1
  145. package/styles/base/header.css.d.ts +1 -1
  146. package/styles/base/header.css.d.ts.map +1 -1
  147. package/styles/base/header.css.js +19 -0
  148. package/styles/base/header.css.js.map +1 -1
  149. package/styles/base/photon-ai.css.d.ts +1 -1
  150. package/styles/base/photon-ai.css.d.ts.map +1 -1
  151. package/styles/base/photon-ai.css.js +65 -0
  152. package/styles/base/photon-ai.css.js.map +1 -1
  153. package/styles/base/scrollbars.css.d.ts +1 -1
  154. package/styles/base/scrollbars.css.d.ts.map +1 -1
  155. package/styles/base/scrollbars.css.js +50 -4
  156. package/styles/base/scrollbars.css.js.map +1 -1
  157. package/styles/base/touch.css.d.ts +23 -0
  158. package/styles/base/touch.css.d.ts.map +1 -0
  159. package/styles/base/touch.css.js +85 -0
  160. package/styles/base/touch.css.js.map +1 -0
  161. package/styles/base-styles.d.ts.map +1 -1
  162. package/styles/base-styles.js +4 -0
  163. package/styles/base-styles.js.map +1 -1
  164. package/styles/themes/theme-dark.d.ts +1 -1
  165. package/styles/themes/theme-dark.d.ts.map +1 -1
  166. package/styles/themes/theme-dark.js +3 -0
  167. package/styles/themes/theme-dark.js.map +1 -1
  168. package/types/column.types.d.ts +36 -0
  169. package/types/column.types.d.ts.map +1 -1
  170. package/types/grid.types.d.ts +3 -2
  171. package/types/grid.types.d.ts.map +1 -1
  172. package/types/photon-ai.types.d.ts +125 -5
  173. package/types/photon-ai.types.d.ts.map +1 -1
  174. package/types/photon-ai.types.js +18 -1
  175. package/types/photon-ai.types.js.map +1 -1
@@ -1,5 +1,6 @@
1
1
  import type { GridApi } from '../core/grid-api';
2
2
  import { PhotonAICommandRegistry } from './photon-ai-registry';
3
+ import { type PhotonAIProvider } from './provider/ai-provider.types';
3
4
  import type { PhotonCommandResult } from './photon-ai.types';
4
5
  /**
5
6
  * The only public entry point into Photon AI. Runs the full deterministic
@@ -36,11 +37,25 @@ export declare class PhotonAIService {
36
37
  private readonly resolver;
37
38
  private readonly builder;
38
39
  private readonly executor;
40
+ /**
41
+ * Generative back-end, when one was configured (e.g. Gemini). `null` keeps
42
+ * Photon AI in its default fully-deterministic mode — the two modes share
43
+ * the same registry, executor, and result contract, so nothing else changes.
44
+ */
45
+ private readonly provider;
46
+ /** Extra domain guidance appended to the base system instruction; only meaningful when {@link provider} is set. */
47
+ private readonly providerSystemInstruction?;
48
+ /** Builds a fresh grid-context snapshot per generative request. Lazily constructed alongside a provider. */
49
+ private readonly contextBuilder;
50
+ /** Reshapes model-generated actions into executable commands. Lazily constructed alongside a provider. */
51
+ private readonly commandNormalizer;
39
52
  /**
40
53
  * @param api - The grid's own `GridApi` — every command runs through it, never around it.
41
54
  * @param registry - Supply a custom registry to fully replace the built-ins, or omit to get sort/filter/pin/visibility/grouping/selection out of the box.
55
+ * @param provider - Optional generative back-end. When supplied, {@link submitAsync} routes prompts through it; when omitted, only the synchronous deterministic pipeline is available.
56
+ * @param providerSystemInstruction - Optional extra guidance appended to the base system instruction sent to {@link provider}.
42
57
  */
43
- constructor(api: GridApi, registry?: PhotonAICommandRegistry);
58
+ constructor(api: GridApi, registry?: PhotonAICommandRegistry, provider?: PhotonAIProvider | null, providerSystemInstruction?: string);
44
59
  /** A registry pre-populated with every built-in intent — the default `PhotonAIService` uses when none is supplied. */
45
60
  static createDefaultRegistry(): PhotonAICommandRegistry;
46
61
  /** Registers additional custom intents at runtime (e.g. a third-party feature's own `registerAI()`). */
@@ -54,6 +69,28 @@ export declare class PhotonAIService {
54
69
  * aggregates their results.
55
70
  */
56
71
  submit(rawInput: string): PhotonCommandResult;
72
+ /** `true` when a generative back-end is configured — i.e. {@link submitAsync} will use the model rather than the deterministic pipeline. */
73
+ hasProvider(): boolean;
74
+ /**
75
+ * Async counterpart to {@link submit}. When a provider is configured, the
76
+ * prompt is interpreted by the model: the grid's current context (columns,
77
+ * capabilities, state) plus the user command are sent to the provider, and
78
+ * every returned action is executed through the *same* `CommandExecutor` the
79
+ * deterministic pipeline uses — so the two backends are interchangeable.
80
+ *
81
+ * With no provider configured, this simply awaits the synchronous
82
+ * deterministic pipeline, so callers can always use the async entry point
83
+ * regardless of mode. Like {@link submit}, it always resolves — provider and
84
+ * execution failures come back as `{ success: false }`, never a rejection.
85
+ */
86
+ submitAsync(rawInput: string, signal?: AbortSignal): Promise<PhotonCommandResult>;
87
+ /**
88
+ * Runs the model's actions in order and folds them into a single
89
+ * {@link PhotonCommandResult}. The model's natural-language `reply` is the
90
+ * user-facing message; per-command execution failures are appended so a
91
+ * partial success is never silently swallowed.
92
+ */
93
+ private executeGeneratedActions;
57
94
  private runClause;
58
95
  private runCommands;
59
96
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"photon-ai-service.d.ts","sourceRoot":"","sources":["../../src/photon-ai/photon-ai-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,KAAK,EAAiB,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAkB5E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,eAAe;IAYd,OAAO,CAAC,GAAG;IAXvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0B;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAE3C;;;OAGG;gBACiB,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,uBAAuB;IAOpE,sHAAsH;IACtH,MAAM,CAAC,qBAAqB,IAAI,uBAAuB;IAMvD,wGAAwG;IACxG,WAAW,IAAI,uBAAuB;IAItC,+IAA+I;IAC/I,mBAAmB,IAAI,IAAI;IAI3B;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB;IAe7C,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,WAAW;IAUnB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAgBxB,uJAAuJ;IACvJ,OAAO,CAAC,iBAAiB;IAKzB,mNAAmN;IACnN,OAAO,CAAC,WAAW;CASpB"}
1
+ {"version":3,"file":"photon-ai-service.d.ts","sourceRoot":"","sources":["../../src/photon-ai/photon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mBAAmB;IAe7C,4IAA4I;IAC5I,WAAW,IAAI,OAAO;IAItB;;;;;;;;;;;OAWG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAuBvF;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IAwB/B,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,WAAW;IAUnB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAgBxB,uJAAuJ;IACvJ,OAAO,CAAC,iBAAiB;IAKzB,mNAAmN;IACnN,OAAO,CAAC,WAAW;CASpB"}
@@ -7,6 +7,10 @@ import { CommandExecutor } from './command-executor';
7
7
  import { PhotonAICommandRegistry } from './photon-ai-registry';
8
8
  import { PhotonAIMemoryStore, columnSignature } from './photon-ai-memory';
9
9
  import { registerBuiltinCommands } from './builtins';
10
+ import { GridContextBuilder } from './provider/grid-context-builder';
11
+ import { CommandNormalizer } from './provider/command-normalizer';
12
+ import { buildSystemInstruction } from './provider/system-prompt';
13
+ import { describeProviderError } from './provider/ai-provider.types';
10
14
  /**
11
15
  * Pure conversational openers — no command content, so `normalizeInput`
12
16
  * strips every word away (they're all in its filler list) and the clause
@@ -49,8 +53,10 @@ export class PhotonAIService {
49
53
  /**
50
54
  * @param api - The grid's own `GridApi` — every command runs through it, never around it.
51
55
  * @param registry - Supply a custom registry to fully replace the built-ins, or omit to get sort/filter/pin/visibility/grouping/selection out of the box.
56
+ * @param provider - Optional generative back-end. When supplied, {@link submitAsync} routes prompts through it; when omitted, only the synchronous deterministic pipeline is available.
57
+ * @param providerSystemInstruction - Optional extra guidance appended to the base system instruction sent to {@link provider}.
52
58
  */
53
- constructor(api, registry) {
59
+ constructor(api, registry, provider, providerSystemInstruction) {
54
60
  this.api = api;
55
61
  this.parser = new IntentParser();
56
62
  this.builder = new CommandBuilder();
@@ -58,6 +64,10 @@ export class PhotonAIService {
58
64
  this.executor = new CommandExecutor(this.registry);
59
65
  this.memory = new PhotonAIMemoryStore(columnSignature(api.getAllColumns().map((c) => c.colId)));
60
66
  this.resolver = new EntityResolver(this.memory);
67
+ this.provider = provider ?? null;
68
+ this.providerSystemInstruction = providerSystemInstruction;
69
+ this.contextBuilder = this.provider ? new GridContextBuilder(this.api, this.registry) : null;
70
+ this.commandNormalizer = this.provider ? new CommandNormalizer(this.api) : null;
61
71
  }
62
72
  /** A registry pre-populated with every built-in intent — the default `PhotonAIService` uses when none is supplied. */
63
73
  static createDefaultRegistry() {
@@ -92,6 +102,67 @@ export class PhotonAIService {
92
102
  message: results.map((r, i) => `${i + 1}) ${r.message}`).join(' '),
93
103
  };
94
104
  }
105
+ /** `true` when a generative back-end is configured — i.e. {@link submitAsync} will use the model rather than the deterministic pipeline. */
106
+ hasProvider() {
107
+ return this.provider !== null;
108
+ }
109
+ /**
110
+ * Async counterpart to {@link submit}. When a provider is configured, the
111
+ * prompt is interpreted by the model: the grid's current context (columns,
112
+ * capabilities, state) plus the user command are sent to the provider, and
113
+ * every returned action is executed through the *same* `CommandExecutor` the
114
+ * deterministic pipeline uses — so the two backends are interchangeable.
115
+ *
116
+ * With no provider configured, this simply awaits the synchronous
117
+ * deterministic pipeline, so callers can always use the async entry point
118
+ * regardless of mode. Like {@link submit}, it always resolves — provider and
119
+ * execution failures come back as `{ success: false }`, never a rejection.
120
+ */
121
+ async submitAsync(rawInput, signal) {
122
+ const trimmed = rawInput.trim();
123
+ if (!trimmed)
124
+ return { success: false, message: 'Type a command first.' };
125
+ if (!this.provider || !this.contextBuilder || !this.commandNormalizer) {
126
+ return this.submit(trimmed);
127
+ }
128
+ try {
129
+ const gridContext = this.contextBuilder.build();
130
+ const generation = await this.provider.generate({
131
+ systemInstruction: buildSystemInstruction(this.providerSystemInstruction),
132
+ gridContext,
133
+ userCommand: trimmed,
134
+ signal,
135
+ });
136
+ return this.executeGeneratedActions(generation.actions, generation.reply);
137
+ }
138
+ catch (err) {
139
+ return { success: false, message: describeProviderError(err) };
140
+ }
141
+ }
142
+ /**
143
+ * Runs the model's actions in order and folds them into a single
144
+ * {@link PhotonCommandResult}. The model's natural-language `reply` is the
145
+ * user-facing message; per-command execution failures are appended so a
146
+ * partial success is never silently swallowed.
147
+ */
148
+ executeGeneratedActions(actions, reply) {
149
+ const normalizer = this.commandNormalizer;
150
+ const executionMessages = [];
151
+ const failures = [];
152
+ let lastCommand;
153
+ for (const action of actions) {
154
+ const command = normalizer.normalize(action);
155
+ const result = this.executor.execute(command, this.api);
156
+ executionMessages.push(result.message);
157
+ if (result.command)
158
+ lastCommand = result.command;
159
+ if (!result.success)
160
+ failures.push(result.message);
161
+ }
162
+ const message = reply || executionMessages.join(' ') || 'I understood your request but there was nothing to do.';
163
+ const combined = failures.length > 0 ? `${message} (${failures.join(' ')})` : message;
164
+ return { success: failures.length === 0, message: combined, command: lastCommand };
165
+ }
95
166
  runClause(clause) {
96
167
  const normalized = normalizeInput(clause);
97
168
  if (!normalized)
@@ -1 +1 @@
1
- {"version":3,"file":"photon-ai-service.js","sourceRoot":"","sources":["../../src/photon-ai/photon-ai-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGrD;;;;;GAKG;AACH,MAA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AE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAClE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;QACpD,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAChE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QAClD,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,qBAAqB,MAAM,qBAAqB,EAAE,CAAC;IACvF,CAAC;IAED,uJAAuJ;IAC/I,iBAAiB,CAAC,OAAsB;QAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;QACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAClE,CAAC;IAED,mNAAmN;IAC3M,WAAW;QACjB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;QAChC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC5C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnC,IAAI,KAAK,CAAC,CAAC,CAAC;oBAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,174 @@
1
+ import type { ColumnDataType, ColumnPinPosition } from '../../types/column.types';
2
+ /**
3
+ * The runtime contracts shared by every Photon AI generative provider. These
4
+ * types are intentionally provider-agnostic: {@link PhotonAIService} builds a
5
+ * {@link PhotonAIProviderRequest}, hands it to whichever {@link PhotonAIProvider}
6
+ * is configured, and executes the returned {@link PhotonAIGeneration} through
7
+ * the same command pipeline used by the deterministic interpreter — so a new
8
+ * back-end (Gemini today, another model tomorrow) only ever implements
9
+ * {@link PhotonAIProvider.generate}, never touches the grid.
10
+ */
11
+ /**
12
+ * One column, distilled to exactly what a language model needs to choose a
13
+ * target and a valid value. Deliberately excludes render functions, widths,
14
+ * and other presentation-only fields — sending them would waste tokens and
15
+ * leak irrelevant internals into the prompt.
16
+ */
17
+ export interface PhotonAIColumnContext {
18
+ /** Stable machine id — the value the model must echo back in a command's `colId`/`colIds`. */
19
+ readonly colId: string;
20
+ /** Human-facing column title (what the user is most likely to type). */
21
+ readonly header: string;
22
+ /** Underlying data field key. */
23
+ readonly field: string;
24
+ /** Data type — tells the model which filter operators and value formats make sense. */
25
+ readonly type: ColumnDataType;
26
+ readonly sortable: boolean;
27
+ readonly filterable: boolean;
28
+ readonly groupable: boolean;
29
+ /** Current pin side, or `null` when unpinned. */
30
+ readonly pinned: ColumnPinPosition;
31
+ readonly visible: boolean;
32
+ /**
33
+ * Allowed values for `dropdown`/`enum`-style columns, so the model filters
34
+ * by a value that actually exists rather than guessing. Omitted for
35
+ * free-form columns.
36
+ */
37
+ readonly options?: readonly (string | number)[];
38
+ }
39
+ /**
40
+ * A single grid action the model is allowed to emit, mirrored 1:1 from the
41
+ * live intent registry so the catalog can never drift from what the grid can
42
+ * actually execute. `type` is the intent key the model must reproduce in a
43
+ * command; `description` is the human blurb registered with that intent.
44
+ */
45
+ export interface PhotonAICapability {
46
+ readonly type: string;
47
+ readonly description: string;
48
+ }
49
+ /** A concise, model-friendly snapshot of the grid's live state at prompt time. */
50
+ export interface PhotonAIGridState {
51
+ readonly totalRowCount: number;
52
+ readonly visibleRowCount: number;
53
+ readonly sort: readonly PhotonAISortState[];
54
+ readonly filters: readonly PhotonAIFilterState[];
55
+ readonly groupedColumns: readonly string[];
56
+ readonly selectedRowCount: number;
57
+ }
58
+ export interface PhotonAISortState {
59
+ readonly colId: string;
60
+ readonly order: 'asc' | 'desc';
61
+ }
62
+ export interface PhotonAIFilterState {
63
+ readonly colId: string;
64
+ /** Short human summary of the active condition, e.g. `greaterThan 5000`. */
65
+ readonly summary: string;
66
+ }
67
+ /**
68
+ * Everything about the grid the model receives alongside the user's command:
69
+ * what columns exist, what actions are possible, and what state the grid is
70
+ * currently in. Built fresh per request by {@link PhotonAIService} so the
71
+ * model always reasons over the grid's *current* shape.
72
+ */
73
+ export interface PhotonGridContext {
74
+ readonly columns: readonly PhotonAIColumnContext[];
75
+ readonly capabilities: readonly PhotonAICapability[];
76
+ readonly state: PhotonAIGridState;
77
+ }
78
+ /**
79
+ * One executable instruction returned by the model. Structurally identical to
80
+ * a {@link import('../photon-ai.types').PhotonCommand} — `type` is an intent
81
+ * key from the capability catalog and `params` carries that intent's inputs —
82
+ * so a generated action flows straight into the existing `CommandExecutor`
83
+ * after light normalization.
84
+ */
85
+ export interface PhotonAIAction {
86
+ readonly type: string;
87
+ readonly params: Readonly<Record<string, unknown>>;
88
+ }
89
+ /** The parsed, validated result of one provider call. */
90
+ export interface PhotonAIGeneration {
91
+ /** Zero or more grid actions to execute, in order. Empty for a pure conversational reply. */
92
+ readonly actions: readonly PhotonAIAction[];
93
+ /** Natural-language message to show the user (streamed into the panel). */
94
+ readonly reply: string;
95
+ }
96
+ /**
97
+ * The provider-neutral, transformer-facing view of one prompt. This is what a
98
+ * consumer's {@link import('../../types/photon-ai.types').PhotonAIProviderConfig.requestTransformer}
99
+ * receives — everything needed to build any provider's request body, with no
100
+ * transport concern (URL, headers, auth) leaking in.
101
+ */
102
+ export interface PhotonAIRequest {
103
+ /** The assembled system instruction (role + output contract + any extra guidance). */
104
+ readonly systemInstruction: string;
105
+ /** The raw user command typed into the panel. */
106
+ readonly userCommand: string;
107
+ /** Structured grid context (columns, capabilities, live state). */
108
+ readonly gridContext: PhotonGridContext;
109
+ /** Resolved model id for this request. */
110
+ readonly model: string;
111
+ /** Resolved sampling temperature for this request. */
112
+ readonly temperature: number;
113
+ }
114
+ /**
115
+ * The provider-neutral, transformer-facing result. A consumer's
116
+ * {@link import('../../types/photon-ai.types').PhotonAIProviderConfig.responseTransformer}
117
+ * must return this shape from whatever the provider's raw JSON looked like.
118
+ * Identical in structure to {@link PhotonAIGeneration}.
119
+ */
120
+ export type PhotonAIResponse = PhotonAIGeneration;
121
+ /**
122
+ * What a provider receives. The service assembles the {@link systemInstruction}
123
+ * (role + output contract) and the structured {@link gridContext}; the provider
124
+ * decides how to serialize them into its own wire format and how to call its
125
+ * endpoint.
126
+ */
127
+ export interface PhotonAIProviderRequest {
128
+ readonly systemInstruction: string;
129
+ readonly gridContext: PhotonGridContext;
130
+ readonly userCommand: string;
131
+ /** Optional cooperative cancellation (e.g. panel closed mid-flight). */
132
+ readonly signal?: AbortSignal;
133
+ }
134
+ /**
135
+ * The one method every generative back-end implements. Must resolve with a
136
+ * validated {@link PhotonAIResponse} or reject with a
137
+ * {@link PhotonAIProviderError} — never leak a raw transport error to the UI.
138
+ */
139
+ export interface PhotonAIProvider {
140
+ generate(request: PhotonAIProviderRequest): Promise<PhotonAIResponse>;
141
+ }
142
+ /** Categorized failure reason, so the panel can show an actionable message rather than a stack trace. */
143
+ export declare enum PhotonAIErrorKind {
144
+ /** The request never reached the provider (offline, DNS, CORS). */
145
+ Network = "network",
146
+ /** Provider returned a non-2xx status not covered by a more specific kind. */
147
+ Http = "http",
148
+ /** HTTP 429 / quota exhausted. */
149
+ RateLimit = "rate-limit",
150
+ /** HTTP 401/403 — missing, invalid, or unauthorized API key. */
151
+ Auth = "auth",
152
+ /** The model refused or its output was safety-blocked. */
153
+ Blocked = "blocked",
154
+ /** Response arrived but could not be parsed into a {@link PhotonAIGeneration}. */
155
+ InvalidResponse = "invalid-response",
156
+ /** The request exceeded {@link import('../../types/photon-ai.types').PhotonAIProviderConfig.requestTimeoutMs}. */
157
+ Timeout = "timeout"
158
+ }
159
+ /**
160
+ * The single error type providers throw. Carries a machine-readable
161
+ * {@link PhotonAIErrorKind} (for retry/telemetry decisions) plus a
162
+ * user-facing message the panel can display verbatim.
163
+ */
164
+ export declare class PhotonAIProviderError extends Error {
165
+ readonly kind: PhotonAIErrorKind;
166
+ /** Upstream HTTP status, when the failure originated from an HTTP response. */
167
+ readonly status?: number | undefined;
168
+ constructor(kind: PhotonAIErrorKind, message: string,
169
+ /** Upstream HTTP status, when the failure originated from an HTTP response. */
170
+ status?: number | undefined);
171
+ }
172
+ /** A short, friendly one-liner for each failure kind, used when a provider throws to the panel. */
173
+ export declare function describeProviderError(error: unknown): string;
174
+ //# sourceMappingURL=ai-provider.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-provider.types.d.ts","sourceRoot":"","sources":["../../../src/photon-ai/provider/ai-provider.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElF;;;;;;;;GAQG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,8FAA8F;IAC9F,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uFAAuF;IACvF,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,iDAAiD;IACjD,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAA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AQ,KAAK;IAE5C,QAAQ,CAAC,IAAI,EAAE,iBAAiB;IAEhC,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;gBAHf,IAAI,EAAE,iBAAiB,EAChC,OAAO,EAAE,MAAM;IACf,+EAA+E;IACtE,MAAM,CAAC,EAAE,MAAM,YAAA;CAK3B;AAED,mGAAmG;AACnG,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAI5D"}
@@ -0,0 +1,42 @@
1
+ /** Categorized failure reason, so the panel can show an actionable message rather than a stack trace. */
2
+ export var PhotonAIErrorKind;
3
+ (function (PhotonAIErrorKind) {
4
+ /** The request never reached the provider (offline, DNS, CORS). */
5
+ PhotonAIErrorKind["Network"] = "network";
6
+ /** Provider returned a non-2xx status not covered by a more specific kind. */
7
+ PhotonAIErrorKind["Http"] = "http";
8
+ /** HTTP 429 / quota exhausted. */
9
+ PhotonAIErrorKind["RateLimit"] = "rate-limit";
10
+ /** HTTP 401/403 — missing, invalid, or unauthorized API key. */
11
+ PhotonAIErrorKind["Auth"] = "auth";
12
+ /** The model refused or its output was safety-blocked. */
13
+ PhotonAIErrorKind["Blocked"] = "blocked";
14
+ /** Response arrived but could not be parsed into a {@link PhotonAIGeneration}. */
15
+ PhotonAIErrorKind["InvalidResponse"] = "invalid-response";
16
+ /** The request exceeded {@link import('../../types/photon-ai.types').PhotonAIProviderConfig.requestTimeoutMs}. */
17
+ PhotonAIErrorKind["Timeout"] = "timeout";
18
+ })(PhotonAIErrorKind || (PhotonAIErrorKind = {}));
19
+ /**
20
+ * The single error type providers throw. Carries a machine-readable
21
+ * {@link PhotonAIErrorKind} (for retry/telemetry decisions) plus a
22
+ * user-facing message the panel can display verbatim.
23
+ */
24
+ export class PhotonAIProviderError extends Error {
25
+ constructor(kind, message,
26
+ /** Upstream HTTP status, when the failure originated from an HTTP response. */
27
+ status) {
28
+ super(message);
29
+ this.kind = kind;
30
+ this.status = status;
31
+ this.name = 'PhotonAIProviderError';
32
+ }
33
+ }
34
+ /** A short, friendly one-liner for each failure kind, used when a provider throws to the panel. */
35
+ export function describeProviderError(error) {
36
+ if (error instanceof PhotonAIProviderError)
37
+ return error.message;
38
+ if (error instanceof Error)
39
+ return `Photon AI request failed: ${error.message}`;
40
+ return 'Photon AI request failed due to an unexpected error.';
41
+ }
42
+ //# sourceMappingURL=ai-provider.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-provider.types.js","sourceRoot":"","sources":["../../../src/photon-ai/provider/ai-provider.types.ts"],"names":[],"mappings":"AA2JA,yGAAyG;AACzG,MAAM,CAAN,IAAY,iBAeX;AAfD,WAAY,iBAAiB;IAC3B,mEAAmE;IACnE,wCAAmB,CAAA;IACnB,8EAA8E;IAC9E,kCAAa,CAAA;IACb,kCAAkC;IAClC,6CAAwB,CAAA;IACxB,gEAAgE;IAChE,kCAAa,CAAA;IACb,0DAA0D;IAC1D,wCAAmB,CAAA;IACnB,kFAAkF;IAClF,yDAAoC,CAAA;IACpC,kHAAkH;IAClH,wCAAmB,CAAA;AACrB,CAAC,EAfW,iBAAiB,KAAjB,iBAAiB,QAe5B;AAED;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YACW,IAAuB,EAChC,OAAe;IACf,+EAA+E;IACtE,MAAe;QAExB,KAAK,CAAC,OAAO,CAAC,CAAC;QALN,SAAI,GAAJ,IAAI,CAAmB;QAGvB,WAAM,GAAN,MAAM,CAAS;QAGxB,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,mGAAmG;AACnG,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,IAAI,KAAK,YAAY,qBAAqB;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjE,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC;IAChF,OAAO,sDAAsD,CAAC;AAChE,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { GridApi } from '../../core/grid-api';
2
+ import type { PhotonCommand } from '../photon-ai.types';
3
+ import type { PhotonAIAction } from './ai-provider.types';
4
+ /**
5
+ * Bridges a model-generated {@link PhotonAIAction} to a fully-formed
6
+ * {@link PhotonCommand} the existing `CommandExecutor` can run unchanged.
7
+ *
8
+ * A language model reliably produces the *shape* of a command (an intent key
9
+ * plus the target column and value) but not the incidental details the
10
+ * deterministic builders add for free — the display `header`, `Date` objects
11
+ * for date filters, a default operator, numeric coercion. Rather than force
12
+ * the model to reproduce all of that (fragile, token-heavy), this normalizer
13
+ * backfills it deterministically from the live grid:
14
+ *
15
+ * - resolves `colId`/`colIds` against real columns (tolerating a header used
16
+ * in place of an id, since models occasionally do that),
17
+ * - backfills the `header` param used by every intent's result message,
18
+ * - coerces `applyFilter` values to the column's type (ISO string → `Date`,
19
+ * numeric string → `number`) and defaults a sensible operator.
20
+ *
21
+ * It is intentionally the *only* place provider output is reshaped, mirroring
22
+ * the role `CommandBuilder` plays for the deterministic pipeline.
23
+ */
24
+ export declare class CommandNormalizer {
25
+ private readonly api;
26
+ constructor(api: GridApi);
27
+ /** Reshapes one action into an executable command. Never throws — worst case, the executor reports an unknown/invalid command. */
28
+ normalize(action: PhotonAIAction): PhotonCommand;
29
+ /** Resolves and canonicalizes `colId`/`colIds`, then backfills the human `header` label. */
30
+ private normalizeColumnTargets;
31
+ /** Coerces `applyFilter`'s value(s) to the target column's data type and supplies a default operator. */
32
+ private normalizeFilterParams;
33
+ /** Matches by exact colId first, then case-insensitively by header — models sometimes echo the visible header. */
34
+ private resolveColumn;
35
+ }
36
+ //# sourceMappingURL=command-normalizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-normalizer.d.ts","sourceRoot":"","sources":["../../../src/photon-ai/provider/command-normalizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,OAAO;IAEzC,kIAAkI;IAClI,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,aAAa;IAYhD,4FAA4F;IAC5F,OAAO,CAAC,sBAAsB;IAsB9B,yGAAyG;IACzG,OAAO,CAAC,qBAAqB;IAiB7B,kHAAkH;IAClH,OAAO,CAAC,aAAa;CAMtB"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Bridges a model-generated {@link PhotonAIAction} to a fully-formed
3
+ * {@link PhotonCommand} the existing `CommandExecutor` can run unchanged.
4
+ *
5
+ * A language model reliably produces the *shape* of a command (an intent key
6
+ * plus the target column and value) but not the incidental details the
7
+ * deterministic builders add for free — the display `header`, `Date` objects
8
+ * for date filters, a default operator, numeric coercion. Rather than force
9
+ * the model to reproduce all of that (fragile, token-heavy), this normalizer
10
+ * backfills it deterministically from the live grid:
11
+ *
12
+ * - resolves `colId`/`colIds` against real columns (tolerating a header used
13
+ * in place of an id, since models occasionally do that),
14
+ * - backfills the `header` param used by every intent's result message,
15
+ * - coerces `applyFilter` values to the column's type (ISO string → `Date`,
16
+ * numeric string → `number`) and defaults a sensible operator.
17
+ *
18
+ * It is intentionally the *only* place provider output is reshaped, mirroring
19
+ * the role `CommandBuilder` plays for the deterministic pipeline.
20
+ */
21
+ export class CommandNormalizer {
22
+ constructor(api) {
23
+ this.api = api;
24
+ }
25
+ /** Reshapes one action into an executable command. Never throws — worst case, the executor reports an unknown/invalid command. */
26
+ normalize(action) {
27
+ const params = { ...action.params };
28
+ this.normalizeColumnTargets(params);
29
+ if (action.type === 'applyFilter') {
30
+ this.normalizeFilterParams(params);
31
+ }
32
+ return { type: action.type, params };
33
+ }
34
+ /** Resolves and canonicalizes `colId`/`colIds`, then backfills the human `header` label. */
35
+ normalizeColumnTargets(params) {
36
+ if (typeof params.colId === 'string') {
37
+ const column = this.resolveColumn(params.colId);
38
+ if (column) {
39
+ params.colId = column.colId;
40
+ if (typeof params.header !== 'string')
41
+ params.header = column.header;
42
+ }
43
+ }
44
+ if (Array.isArray(params.colIds)) {
45
+ const columns = params.colIds
46
+ .map((id) => (typeof id === 'string' ? this.resolveColumn(id) : undefined))
47
+ .filter((c) => !!c);
48
+ if (columns.length > 0) {
49
+ params.colIds = columns.map((c) => c.colId);
50
+ if (typeof params.header !== 'string') {
51
+ params.header = columns.map((c) => c.header).join('", "');
52
+ }
53
+ }
54
+ }
55
+ }
56
+ /** Coerces `applyFilter`'s value(s) to the target column's data type and supplies a default operator. */
57
+ normalizeFilterParams(params) {
58
+ const colId = typeof params.colId === 'string' ? params.colId : undefined;
59
+ const column = colId ? this.resolveColumn(colId) : undefined;
60
+ if (!column)
61
+ return;
62
+ params.colId = column.colId;
63
+ if (typeof params.operator !== 'string') {
64
+ params.operator = defaultOperatorFor(column.type);
65
+ }
66
+ params.value = coerceValue(params.value, column.type);
67
+ if (params.valueTo !== undefined) {
68
+ params.valueTo = coerceValue(params.valueTo, column.type);
69
+ }
70
+ }
71
+ /** Matches by exact colId first, then case-insensitively by header — models sometimes echo the visible header. */
72
+ resolveColumn(idOrHeader) {
73
+ const byId = this.api.getColumn(idOrHeader);
74
+ if (byId)
75
+ return byId;
76
+ const needle = idOrHeader.trim().toLowerCase();
77
+ return this.api.getAllColumns().find((c) => c.header.toLowerCase() === needle);
78
+ }
79
+ }
80
+ /** Default operator when the model omitted one — mirrors the deterministic filter builder. */
81
+ function defaultOperatorFor(type) {
82
+ if (type === 'number' || type === 'currency' || type === 'percentage')
83
+ return 'equals';
84
+ if (type === 'date' || type === 'time')
85
+ return 'equals';
86
+ if (type === 'boolean')
87
+ return 'equals';
88
+ if (type === 'dropdown')
89
+ return 'equals';
90
+ return 'contains';
91
+ }
92
+ /** Coerces a JSON-safe primitive from the model into the runtime type the grid's filter engine expects. */
93
+ function coerceValue(value, type) {
94
+ if (value === null || value === undefined)
95
+ return value;
96
+ if (type === 'date' || type === 'time') {
97
+ if (value instanceof Date)
98
+ return value;
99
+ const date = new Date(String(value));
100
+ return Number.isNaN(date.getTime()) ? value : date;
101
+ }
102
+ if (type === 'number' || type === 'currency' || type === 'percentage') {
103
+ if (typeof value === 'number')
104
+ return value;
105
+ const num = Number(String(value).replace(/,/g, '').trim());
106
+ return Number.isNaN(num) ? value : num;
107
+ }
108
+ if (type === 'boolean') {
109
+ if (typeof value === 'boolean')
110
+ return value;
111
+ const text = String(value).trim().toLowerCase();
112
+ if (['true', 'yes', 'active', 'enabled', 'on', '1'].includes(text))
113
+ return true;
114
+ if (['false', 'no', 'inactive', 'disabled', 'off', '0'].includes(text))
115
+ return false;
116
+ return value;
117
+ }
118
+ return value;
119
+ }
120
+ //# sourceMappingURL=command-normalizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-normalizer.js","sourceRoot":"","sources":["../../../src/photon-ai/provider/command-normalizer.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,iBAAiB;IAC5B,YAA6B,GAAY;QAAZ,QAAG,GAAH,GAAG,CAAS;IAAG,CAAC;IAE7C,kIAAkI;IAClI,SAAS,CAAC,MAAsB;QAC9B,MAAM,MAAM,GAA4B,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QAE7D,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAEpC,IAAI,MAAM,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YAClC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IACvC,CAAC;IAED,4FAA4F;IACpF,sBAAsB,CAAC,MAA+B;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,CAAC;QAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAChD,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QAChF,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QACrF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { GridApi } from '../../core/grid-api';
2
+ import type { PhotonAICommandRegistry } from '../photon-ai-registry';
3
+ import type { PhotonGridContext } from './ai-provider.types';
4
+ /**
5
+ * Distills the live grid into the compact {@link PhotonGridContext} a language
6
+ * model needs to interpret a command: which columns exist, which actions are
7
+ * possible, and what the grid currently looks like.
8
+ *
9
+ * Every piece is read from the *live* {@link GridApi} and
10
+ * {@link PhotonAICommandRegistry} at build time, so the model always reasons
11
+ * over the grid's current shape — including any custom intents a host app
12
+ * registered at runtime (they appear in {@link buildCapabilities} automatically
13
+ * because it reads the registry, never a hard-coded list). This is what keeps
14
+ * the generative back-end in lock-step with the deterministic one: both are
15
+ * driven by the same registry.
16
+ */
17
+ export declare class GridContextBuilder {
18
+ private readonly api;
19
+ private readonly registry;
20
+ constructor(api: GridApi, registry: PhotonAICommandRegistry);
21
+ /** Builds a fresh snapshot. Cheap enough to call once per prompt. */
22
+ build(): PhotonGridContext;
23
+ private buildColumns;
24
+ private toColumnContext;
25
+ /** Enumerated values a `dropdown`/`enum` column accepts, so the model filters by a real value. */
26
+ private columnOptions;
27
+ /**
28
+ * The catalog of actions the model may emit — one entry per registered
29
+ * intent. Sourced from the registry so it never drifts from what
30
+ * `CommandExecutor` can actually run.
31
+ */
32
+ private buildCapabilities;
33
+ private buildState;
34
+ private buildSortState;
35
+ private buildFilterState;
36
+ }
37
+ //# sourceMappingURL=grid-context-builder.d.ts.map