@api-client/core 0.19.1 → 0.19.3

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 (125) hide show
  1. package/build/src/browser.d.ts +5 -1
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js +4 -0
  4. package/build/src/browser.js.map +1 -1
  5. package/build/src/index.d.ts +4 -0
  6. package/build/src/index.d.ts.map +1 -1
  7. package/build/src/index.js +4 -0
  8. package/build/src/index.js.map +1 -1
  9. package/build/src/mocking/ModelingMock.d.ts +2 -0
  10. package/build/src/mocking/ModelingMock.d.ts.map +1 -1
  11. package/build/src/mocking/ModelingMock.js +2 -0
  12. package/build/src/mocking/ModelingMock.js.map +1 -1
  13. package/build/src/mocking/lib/Ai.d.ts +11 -0
  14. package/build/src/mocking/lib/Ai.d.ts.map +1 -0
  15. package/build/src/mocking/lib/Ai.js +53 -0
  16. package/build/src/mocking/lib/Ai.js.map +1 -0
  17. package/build/src/modeling/ai/DataDomainDelta.d.ts +146 -0
  18. package/build/src/modeling/ai/DataDomainDelta.d.ts.map +1 -0
  19. package/build/src/modeling/ai/DataDomainDelta.js +729 -0
  20. package/build/src/modeling/ai/DataDomainDelta.js.map +1 -0
  21. package/build/src/modeling/ai/DomainSerialization.d.ts +20 -0
  22. package/build/src/modeling/ai/DomainSerialization.d.ts.map +1 -0
  23. package/build/src/modeling/ai/DomainSerialization.js +185 -0
  24. package/build/src/modeling/ai/DomainSerialization.js.map +1 -0
  25. package/build/src/modeling/ai/domain_response_schema.d.ts +806 -0
  26. package/build/src/modeling/ai/domain_response_schema.d.ts.map +1 -0
  27. package/build/src/modeling/ai/domain_response_schema.js +289 -0
  28. package/build/src/modeling/ai/domain_response_schema.js.map +1 -0
  29. package/build/src/modeling/ai/domain_tools.d.ts +68 -0
  30. package/build/src/modeling/ai/domain_tools.d.ts.map +1 -0
  31. package/build/src/modeling/ai/domain_tools.js +71 -0
  32. package/build/src/modeling/ai/domain_tools.js.map +1 -0
  33. package/build/src/modeling/ai/index.d.ts +10 -0
  34. package/build/src/modeling/ai/index.d.ts.map +1 -0
  35. package/build/src/modeling/ai/index.js +9 -0
  36. package/build/src/modeling/ai/index.js.map +1 -0
  37. package/build/src/modeling/ai/message_parser.d.ts +23 -0
  38. package/build/src/modeling/ai/message_parser.d.ts.map +1 -0
  39. package/build/src/modeling/ai/message_parser.js +93 -0
  40. package/build/src/modeling/ai/message_parser.js.map +1 -0
  41. package/build/src/modeling/ai/prompts/domain_system.d.ts +6 -0
  42. package/build/src/modeling/ai/prompts/domain_system.d.ts.map +1 -0
  43. package/build/src/modeling/ai/prompts/domain_system.js +80 -0
  44. package/build/src/modeling/ai/prompts/domain_system.js.map +1 -0
  45. package/build/src/modeling/ai/tools/DataDomain.tools.d.ts +25 -0
  46. package/build/src/modeling/ai/tools/DataDomain.tools.d.ts.map +1 -0
  47. package/build/src/modeling/ai/tools/DataDomain.tools.js +334 -0
  48. package/build/src/modeling/ai/tools/DataDomain.tools.js.map +1 -0
  49. package/build/src/modeling/ai/tools/Semantic.tools.d.ts +48 -0
  50. package/build/src/modeling/ai/tools/Semantic.tools.d.ts.map +1 -0
  51. package/build/src/modeling/ai/tools/Semantic.tools.js +36 -0
  52. package/build/src/modeling/ai/tools/Semantic.tools.js.map +1 -0
  53. package/build/src/modeling/ai/tools/config.d.ts +13 -0
  54. package/build/src/modeling/ai/tools/config.d.ts.map +1 -0
  55. package/build/src/modeling/ai/tools/config.js +2 -0
  56. package/build/src/modeling/ai/tools/config.js.map +1 -0
  57. package/build/src/modeling/ai/types.d.ts +302 -0
  58. package/build/src/modeling/ai/types.d.ts.map +1 -0
  59. package/build/src/modeling/ai/types.js +40 -0
  60. package/build/src/modeling/ai/types.js.map +1 -0
  61. package/build/src/models/AiMessage.d.ts +185 -0
  62. package/build/src/models/AiMessage.d.ts.map +1 -0
  63. package/build/src/models/AiMessage.js +203 -0
  64. package/build/src/models/AiMessage.js.map +1 -0
  65. package/build/src/models/AiSession.d.ts +80 -0
  66. package/build/src/models/AiSession.d.ts.map +1 -0
  67. package/build/src/models/AiSession.js +102 -0
  68. package/build/src/models/AiSession.js.map +1 -0
  69. package/build/src/models/kinds.d.ts +2 -0
  70. package/build/src/models/kinds.d.ts.map +1 -1
  71. package/build/src/models/kinds.js +2 -0
  72. package/build/src/models/kinds.js.map +1 -1
  73. package/build/src/sdk/AiSdk.d.ts +93 -0
  74. package/build/src/sdk/AiSdk.d.ts.map +1 -0
  75. package/build/src/sdk/AiSdk.js +348 -0
  76. package/build/src/sdk/AiSdk.js.map +1 -0
  77. package/build/src/sdk/RouteBuilder.d.ts +7 -0
  78. package/build/src/sdk/RouteBuilder.d.ts.map +1 -1
  79. package/build/src/sdk/RouteBuilder.js +18 -0
  80. package/build/src/sdk/RouteBuilder.js.map +1 -1
  81. package/build/src/sdk/Sdk.d.ts +2 -0
  82. package/build/src/sdk/Sdk.d.ts.map +1 -1
  83. package/build/src/sdk/Sdk.js +2 -0
  84. package/build/src/sdk/Sdk.js.map +1 -1
  85. package/build/src/sdk/SdkBase.d.ts +4 -0
  86. package/build/src/sdk/SdkBase.d.ts.map +1 -1
  87. package/build/src/sdk/SdkBase.js.map +1 -1
  88. package/build/src/sdk/SdkMock.d.ts +15 -0
  89. package/build/src/sdk/SdkMock.d.ts.map +1 -1
  90. package/build/src/sdk/SdkMock.js +118 -0
  91. package/build/src/sdk/SdkMock.js.map +1 -1
  92. package/build/tsconfig.tsbuildinfo +1 -1
  93. package/data/models/example-generator-api.json +22 -22
  94. package/package.json +3 -3
  95. package/src/mocking/ModelingMock.ts +2 -0
  96. package/src/mocking/lib/Ai.ts +71 -0
  97. package/src/modeling/ai/DataDomainDelta.ts +798 -0
  98. package/src/modeling/ai/DomainSerialization.ts +199 -0
  99. package/src/modeling/ai/domain_response_schema.ts +301 -0
  100. package/src/modeling/ai/domain_tools.ts +76 -0
  101. package/src/modeling/ai/message_parser.ts +101 -0
  102. package/src/modeling/ai/prompts/domain_system.ts +79 -0
  103. package/src/modeling/ai/readme.md +8 -0
  104. package/src/modeling/ai/tools/DataDomain.tools.ts +365 -0
  105. package/src/modeling/ai/tools/Semantic.tools.ts +38 -0
  106. package/src/modeling/ai/tools/config.ts +13 -0
  107. package/src/modeling/ai/tools/readme.md +3 -0
  108. package/src/modeling/ai/types.ts +306 -0
  109. package/src/models/AiMessage.ts +335 -0
  110. package/src/models/AiSession.ts +160 -0
  111. package/src/models/kinds.ts +2 -0
  112. package/src/sdk/AiSdk.ts +395 -0
  113. package/src/sdk/RouteBuilder.ts +27 -0
  114. package/src/sdk/Sdk.ts +3 -0
  115. package/src/sdk/SdkBase.ts +4 -0
  116. package/src/sdk/SdkMock.ts +185 -0
  117. package/tests/unit/mocking/current/Ai.spec.ts +109 -0
  118. package/tests/unit/modeling/ai/DataDomainDelta.spec.ts +419 -0
  119. package/tests/unit/modeling/ai/DomainAiTools.spec.ts +29 -0
  120. package/tests/unit/modeling/ai/DomainSerialization.spec.ts +143 -0
  121. package/tests/unit/modeling/ai/message_parser.spec.ts +157 -0
  122. package/tests/unit/modeling/ai/tools/DataDomain.tools.spec.ts +64 -0
  123. package/tests/unit/modeling/ai/tools/Semantic.tools.spec.ts +55 -0
  124. package/tests/unit/models/AiMessage.spec.ts +216 -0
  125. package/tests/unit/models/AiSession.spec.ts +147 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Semantic.tools.js","sourceRoot":"","sources":["../../../../../src/modeling/ai/tools/Semantic.tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgB,MAAM,oBAAoB,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAGnD;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAkB;IAC/C,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAA;IACtD,OAAO,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC9C,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,SAAS,EAAE,CAAC,CAAC,SAAS;KACvB,CAAC,CAAC,CAAA;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAAkB,EAAE,EAAE,UAAU,EAA2B;IACpG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,sCAAsC,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;IAC5E,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;IAC7C,CAAC;IACD,MAAM,EAAE,GAAG,UAA0B,CAAA;IACrC,MAAM,GAAG,GAAG,aAAa,CAAC,EAAE,CAAC,CAAA;IAC7B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,oBAAoB,UAAU,YAAY,CAAC,CAAA;IAC7D,CAAC;IACD,MAAM,GAAG,GAAG,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;IACvC,OAAO;QACL,GAAG,GAAG;QACN,YAAY,EAAE,GAAG,CAAC,YAAY;KAC/B,CAAA;AACH,CAAC","sourcesContent":["import { DataSemantics, SemanticType } from '../../Semantics.js'\nimport { AiSemanticsConfig } from '../Semantics.js'\nimport type { ToolConfig } from './config.js'\n\n/**\n * A tool that lists all available data semantics.\n */\nexport function list_semantics(config: ToolConfig) {\n config.logger?.silly('AI tool called: list_semantics')\n return Object.values(DataSemantics).map((s) => ({\n id: s.id,\n displayName: s.displayName,\n description: s.description,\n scope: s.scope,\n category: s.category,\n hasConfig: s.hasConfig,\n }))\n}\n\n/**\n * A tool that gets the details of a specific data semantic.\n */\nexport async function get_semantic_details(config: ToolConfig, { semanticId }: { semanticId?: string }) {\n config.logger?.silly('AI tool called: get_semantic_details', { semanticId })\n if (!semanticId) {\n throw new Error('Semantic ID is required.')\n }\n const id = semanticId as SemanticType\n const def = DataSemantics[id]\n if (!def) {\n throw new Error(`Semantic with ID ${semanticId} not found`)\n }\n const cnf = AiSemanticsConfig[id] || {}\n return {\n ...def,\n configSchema: cnf.configSchema,\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { Logger } from '../../../lib/logging/index.js';
2
+ import type { DataDomain } from '../../DataDomain.js';
3
+ export interface ToolConfig {
4
+ /**
5
+ * Logger used by the tools.
6
+ */
7
+ logger?: Logger<unknown>;
8
+ /**
9
+ * Some tools need access to the domain model to provide accurate information.
10
+ */
11
+ domain?: DataDomain;
12
+ }
13
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../../src/modeling/ai/tools/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAErD,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;IACxB;;OAEG;IACH,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../../src/modeling/ai/tools/config.ts"],"names":[],"mappings":"","sourcesContent":["import type { Logger } from '../../../lib/logging/index.js'\nimport type { DataDomain } from '../../DataDomain.js'\n\nexport interface ToolConfig {\n /**\n * Logger used by the tools.\n */\n logger?: Logger<unknown>\n /**\n * Some tools need access to the domain model to provide accurate information.\n */\n domain?: DataDomain\n}\n"]}
@@ -0,0 +1,302 @@
1
+ import type { IApiAssociationShape } from '../../amf/definitions/Shapes.js';
2
+ import type { Exception } from '../../exceptions/exception.js';
3
+ import type { AiSessionSchema } from '../../models/AiSession.js';
4
+ import type { DomainPropertyType } from '../DataFormat.js';
5
+ import type { OnDeleteRule } from '../index.js';
6
+ import { SemanticType } from '../Semantics.js';
7
+ import type { AssociationTarget, PropertySchema } from '../types.js';
8
+ import type { AiMessageSchema, AiModelMessage } from '../../models/AiMessage.js';
9
+ /**
10
+ * A copy of the `Type` enum from the `@google/genai` package.
11
+ * It's here so we don't need to import the nodejs only package.
12
+ */
13
+ export declare enum Type {
14
+ /**
15
+ * Not specified, should not be used.
16
+ */
17
+ TYPE_UNSPECIFIED = "TYPE_UNSPECIFIED",
18
+ /**
19
+ * OpenAPI string type
20
+ */
21
+ STRING = "STRING",
22
+ /**
23
+ * OpenAPI number type
24
+ */
25
+ NUMBER = "NUMBER",
26
+ /**
27
+ * OpenAPI integer type
28
+ */
29
+ INTEGER = "INTEGER",
30
+ /**
31
+ * OpenAPI boolean type
32
+ */
33
+ BOOLEAN = "BOOLEAN",
34
+ /**
35
+ * OpenAPI array type
36
+ */
37
+ ARRAY = "ARRAY",
38
+ /**
39
+ * OpenAPI object type
40
+ */
41
+ OBJECT = "OBJECT",
42
+ /**
43
+ * Null type
44
+ */
45
+ NULL = "NULL"
46
+ }
47
+ /**
48
+ * A lightweight representation of the `DataDomain` used specifically for serializing
49
+ * the current domain state and sending it as context to the AI endpoint.
50
+ * It omits complex internal graph structures, including only essential keys, names,
51
+ * descriptions, and the hierarchical structure of models and entities.
52
+ */
53
+ export interface AiDataDomainSchema {
54
+ key: string;
55
+ name: string;
56
+ models: AiDataModelSchema[];
57
+ entities: AiDomainEntitySchema[];
58
+ }
59
+ /**
60
+ * A stripped-down representation of a `DomainModel` sent to the AI as part of the
61
+ * domain context. It provides the AI with the existing model hierarchy and descriptions.
62
+ */
63
+ export interface AiDataModelSchema {
64
+ key: string;
65
+ name?: string;
66
+ description?: string;
67
+ }
68
+ /**
69
+ * Represents a semantic annotation applied to an entity, property, or association
70
+ * within the AI's understanding or response. It defines the "meaning" of a field
71
+ * (e.g., "Email", "Password", "Address").
72
+ */
73
+ export interface AiDomainSemantic {
74
+ id: SemanticType;
75
+ config?: Record<string, unknown>;
76
+ }
77
+ /**
78
+ * Represents a full or partial entity schema as generated by the AI in its response delta.
79
+ * It defines a new entity or updates to an existing one, including its properties,
80
+ * associations, semantics, and tags. This is also used by the `get_entity_details` tool
81
+ * to send detailed serialized entity information back to the AI.
82
+ */
83
+ export interface AiDomainEntityResponseSchema {
84
+ key: string;
85
+ modelKey: string;
86
+ name?: string;
87
+ displayName?: string;
88
+ description?: string;
89
+ tags?: string[];
90
+ semantics?: AiDomainSemantic[];
91
+ properties?: AiDomainProperty[];
92
+ associations?: AiDomainAssociation[];
93
+ }
94
+ /**
95
+ * A minimal representation of an entity used purely for context-setting when
96
+ * sending the current domain structure to the AI. It excludes deeply nested
97
+ * properties and associations to save token space.
98
+ */
99
+ export interface AiDomainEntitySchema {
100
+ key: string;
101
+ modelKey: string;
102
+ name?: string;
103
+ description?: string;
104
+ }
105
+ /**
106
+ * Represents a property definition generated by the AI. It maps the complex internal
107
+ * domain property structure into a simpler, flat structure that the AI generates,
108
+ * including data types, constraints, schema metadata, and semantics.
109
+ */
110
+ export interface AiDomainProperty {
111
+ key?: string;
112
+ name?: string;
113
+ displayName?: string;
114
+ description?: string;
115
+ type: DomainPropertyType;
116
+ constraints?: {
117
+ required?: boolean;
118
+ unique?: boolean;
119
+ index?: boolean;
120
+ primary?: boolean;
121
+ multiple?: boolean;
122
+ readOnly?: boolean;
123
+ writeOnly?: boolean;
124
+ };
125
+ deprecated?: boolean;
126
+ schema?: PropertySchema;
127
+ semantics?: AiDomainSemantic[];
128
+ tags?: string[];
129
+ }
130
+ /**
131
+ * Represents an association definition generated by the AI, linking an entity
132
+ * to one or more target entities. It includes relationship rules (like onDelete)
133
+ * and semantic annotations.
134
+ */
135
+ export interface AiDomainAssociation {
136
+ key: string;
137
+ name?: string;
138
+ displayName?: string;
139
+ description?: string;
140
+ targets: AssociationTarget[];
141
+ required?: boolean;
142
+ multiple?: boolean;
143
+ onDelete?: OnDeleteRule;
144
+ semantics?: AiDomainSemantic[];
145
+ schema?: IApiAssociationShape;
146
+ }
147
+ /**
148
+ * The core structure representing a set of modifications (a delta) proposed by the AI.
149
+ * It contains arrays of models and entities to add, delete, or modify. The application
150
+ * processes this delta to transition the data domain to the new requested state.
151
+ */
152
+ export interface AiDomainDelta {
153
+ /**
154
+ * Models to add to the domain.
155
+ */
156
+ addedModels?: AiDataModelSchema[];
157
+ /**
158
+ * Keys of models to delete from the domain.
159
+ */
160
+ deletedModelKeys?: string[];
161
+ /**
162
+ * Models to modify in the domain.
163
+ */
164
+ modifiedModels?: AiDataModelSchema[];
165
+ /**
166
+ * Entities to add to the domain.
167
+ */
168
+ addedEntities?: AiDomainEntityResponseSchema[];
169
+ /**
170
+ * Keys of entities to delete from the domain.
171
+ */
172
+ deletedEntityKeys?: string[];
173
+ /**
174
+ * Entities to modify in the domain.
175
+ */
176
+ modifiedEntities?: AiDomainEntityDelta[];
177
+ }
178
+ /**
179
+ * The expected JSON schema structure returned by the AI endpoint when performing
180
+ * data domain manipulation. It includes the AI's step-by-step reasoning and the
181
+ * actionable delta to be applied.
182
+ */
183
+ export interface AiDomainDeltaResponse {
184
+ /**
185
+ * The LLM reasoning.
186
+ */
187
+ reasoning: string;
188
+ /**
189
+ * Domain changes delta
190
+ */
191
+ delta?: AiDomainDelta;
192
+ }
193
+ /**
194
+ * Union type for progressive SSE stream chunks
195
+ * received from the AI generation endpoint.
196
+ */
197
+ export type AiStreamEvent = {
198
+ event: 'user-message';
199
+ data: AiMessageSchema;
200
+ } | {
201
+ event: 'agent-message';
202
+ data: AiMessageSchema;
203
+ } | {
204
+ event: 'thought-chunk';
205
+ data: string;
206
+ } | {
207
+ event: 'text-chunk';
208
+ data: string;
209
+ } | {
210
+ event: 'done';
211
+ data: AiMessageSchema;
212
+ } | {
213
+ event: 'error';
214
+ data: Exception;
215
+ } | {
216
+ event: 'session-updated';
217
+ data: AiSessionSchema;
218
+ };
219
+ /**
220
+ * Represents a targeted modification to an existing entity generated by the AI.
221
+ * Instead of providing the full entity state, the AI provides explicit arrays
222
+ * of properties, associations, and semantics to add, modify, or delete, enabling
223
+ * precise, non-destructive updates.
224
+ */
225
+ export interface AiDomainEntityDelta {
226
+ key: string;
227
+ modelKey?: string;
228
+ name?: string;
229
+ displayName?: string;
230
+ description?: string;
231
+ tags?: string[];
232
+ addedSemantics?: AiDomainSemantic[];
233
+ modifiedSemantics?: AiDomainSemantic[];
234
+ deletedSemanticIds?: SemanticType[];
235
+ addedProperties?: AiDomainProperty[];
236
+ modifiedProperties?: AiDomainPropertyDelta[];
237
+ deletedPropertyKeys?: string[];
238
+ addedAssociations?: AiDomainAssociation[];
239
+ modifiedAssociations?: AiDomainAssociationDelta[];
240
+ deletedAssociationKeys?: string[];
241
+ }
242
+ /**
243
+ * Represents a targeted modification to an existing property generated by the AI.
244
+ * It captures changes to superficial properties (name, description), type changes,
245
+ * constraint updates, and semantic alterations.
246
+ */
247
+ export interface AiDomainPropertyDelta {
248
+ key: string;
249
+ name?: string;
250
+ displayName?: string;
251
+ description?: string;
252
+ type?: DomainPropertyType;
253
+ constraints?: {
254
+ required?: boolean;
255
+ unique?: boolean;
256
+ index?: boolean;
257
+ primary?: boolean;
258
+ multiple?: boolean;
259
+ readOnly?: boolean;
260
+ writeOnly?: boolean;
261
+ };
262
+ deprecated?: boolean;
263
+ addedSemantics?: AiDomainSemantic[];
264
+ modifiedSemantics?: AiDomainSemantic[];
265
+ deletedSemanticIds?: SemanticType[];
266
+ schema?: PropertySchema;
267
+ }
268
+ /**
269
+ * Represents a targeted modification to an existing association generated by the AI.
270
+ * It captures updates to relationship cardinality, target entities, deletion rules,
271
+ * and applied semantics.
272
+ */
273
+ export interface AiDomainAssociationDelta {
274
+ key: string;
275
+ name?: string;
276
+ displayName?: string;
277
+ description?: string;
278
+ targets?: AssociationTarget[];
279
+ required?: boolean;
280
+ onDelete?: OnDeleteRule;
281
+ addedSemantics?: AiDomainSemantic[];
282
+ modifiedSemantics?: AiDomainSemantic[];
283
+ deletedSemanticIds?: SemanticType[];
284
+ }
285
+ /**
286
+ * An enriched, in-memory representation of a model's message that includes the globally
287
+ * parsed `AiDomainDelta` object.
288
+ * This is not stored directly in the datastore as-is; instead, the raw JSON text is stored,
289
+ * and this structure is assembled at runtime when the chat history is loaded into the UI.
290
+ */
291
+ export interface AiModelMessageWithDelta extends AiModelMessage {
292
+ /**
293
+ * The delta of the message, if any.
294
+ */
295
+ delta?: AiDomainDelta;
296
+ /**
297
+ * The reasoning of the delta.
298
+ * Format in markdown.
299
+ */
300
+ reasoning?: string;
301
+ }
302
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/modeling/ai/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAEhF;;;GAGG;AACH,oBAAY,IAAI;IACd;;OAEG;IACH,gBAAgB,qBAAqB;IACrC;;OAEG;IACH,MAAM,WAAW;IACjB;;OAEG;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,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAA;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,YAAY,CAAA;IAEvB,cAAc,CAAC,EAAE,gBAAgB,EAAE,CAAA;IACnC,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAA;IACtC,kBAAkB,CAAC,EAAE,YAAY,EAAE,CAAA;CACpC;AAED;;;;;GAKG;AACH,MAAM,WAAW,uBAAwB,SAAQ,cAAc;IAC7D;;OAEG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * A copy of the `Type` enum from the `@google/genai` package.
3
+ * It's here so we don't need to import the nodejs only package.
4
+ */
5
+ export var Type;
6
+ (function (Type) {
7
+ /**
8
+ * Not specified, should not be used.
9
+ */
10
+ Type["TYPE_UNSPECIFIED"] = "TYPE_UNSPECIFIED";
11
+ /**
12
+ * OpenAPI string type
13
+ */
14
+ Type["STRING"] = "STRING";
15
+ /**
16
+ * OpenAPI number type
17
+ */
18
+ Type["NUMBER"] = "NUMBER";
19
+ /**
20
+ * OpenAPI integer type
21
+ */
22
+ Type["INTEGER"] = "INTEGER";
23
+ /**
24
+ * OpenAPI boolean type
25
+ */
26
+ Type["BOOLEAN"] = "BOOLEAN";
27
+ /**
28
+ * OpenAPI array type
29
+ */
30
+ Type["ARRAY"] = "ARRAY";
31
+ /**
32
+ * OpenAPI object type
33
+ */
34
+ Type["OBJECT"] = "OBJECT";
35
+ /**
36
+ * Null type
37
+ */
38
+ Type["NULL"] = "NULL";
39
+ })(Type || (Type = {}));
40
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/modeling/ai/types.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,MAAM,CAAN,IAAY,IAiCX;AAjCD,WAAY,IAAI;IACd;;OAEG;IACH,6CAAqC,CAAA;IACrC;;OAEG;IACH,yBAAiB,CAAA;IACjB;;OAEG;IACH,yBAAiB,CAAA;IACjB;;OAEG;IACH,2BAAmB,CAAA;IACnB;;OAEG;IACH,2BAAmB,CAAA;IACnB;;OAEG;IACH,uBAAe,CAAA;IACf;;OAEG;IACH,yBAAiB,CAAA;IACjB;;OAEG;IACH,qBAAa,CAAA;AACf,CAAC,EAjCW,IAAI,KAAJ,IAAI,QAiCf","sourcesContent":["import type { IApiAssociationShape } from '../../amf/definitions/Shapes.js'\nimport type { Exception } from '../../exceptions/exception.js'\nimport type { AiSessionSchema } from '../../models/AiSession.js'\nimport type { DomainPropertyType } from '../DataFormat.js'\nimport type { OnDeleteRule } from '../index.js'\nimport { SemanticType } from '../Semantics.js'\nimport type { AssociationTarget, PropertySchema } from '../types.js'\nimport type { AiMessageSchema, AiModelMessage } from '../../models/AiMessage.js'\n\n/**\n * A copy of the `Type` enum from the `@google/genai` package.\n * It's here so we don't need to import the nodejs only package.\n */\nexport enum Type {\n /**\n * Not specified, should not be used.\n */\n TYPE_UNSPECIFIED = 'TYPE_UNSPECIFIED',\n /**\n * OpenAPI string type\n */\n STRING = 'STRING',\n /**\n * OpenAPI number type\n */\n NUMBER = 'NUMBER',\n /**\n * OpenAPI integer type\n */\n INTEGER = 'INTEGER',\n /**\n * OpenAPI boolean type\n */\n BOOLEAN = 'BOOLEAN',\n /**\n * OpenAPI array type\n */\n ARRAY = 'ARRAY',\n /**\n * OpenAPI object type\n */\n OBJECT = 'OBJECT',\n /**\n * Null type\n */\n NULL = 'NULL',\n}\n\n/**\n * A lightweight representation of the `DataDomain` used specifically for serializing\n * the current domain state and sending it as context to the AI endpoint.\n * It omits complex internal graph structures, including only essential keys, names,\n * descriptions, and the hierarchical structure of models and entities.\n */\nexport interface AiDataDomainSchema {\n key: string\n name: string\n models: AiDataModelSchema[]\n entities: AiDomainEntitySchema[]\n}\n\n/**\n * A stripped-down representation of a `DomainModel` sent to the AI as part of the\n * domain context. It provides the AI with the existing model hierarchy and descriptions.\n */\nexport interface AiDataModelSchema {\n key: string\n name?: string\n description?: string\n}\n\n/**\n * Represents a semantic annotation applied to an entity, property, or association\n * within the AI's understanding or response. It defines the \"meaning\" of a field\n * (e.g., \"Email\", \"Password\", \"Address\").\n */\nexport interface AiDomainSemantic {\n id: SemanticType\n config?: Record<string, unknown>\n}\n\n/**\n * Represents a full or partial entity schema as generated by the AI in its response delta.\n * It defines a new entity or updates to an existing one, including its properties,\n * associations, semantics, and tags. This is also used by the `get_entity_details` tool\n * to send detailed serialized entity information back to the AI.\n */\nexport interface AiDomainEntityResponseSchema {\n key: string\n modelKey: string\n name?: string\n displayName?: string\n description?: string\n tags?: string[]\n semantics?: AiDomainSemantic[]\n properties?: AiDomainProperty[]\n associations?: AiDomainAssociation[]\n}\n\n/**\n * A minimal representation of an entity used purely for context-setting when\n * sending the current domain structure to the AI. It excludes deeply nested\n * properties and associations to save token space.\n */\nexport interface AiDomainEntitySchema {\n key: string\n modelKey: string\n name?: string\n description?: string\n}\n\n/**\n * Represents a property definition generated by the AI. It maps the complex internal\n * domain property structure into a simpler, flat structure that the AI generates,\n * including data types, constraints, schema metadata, and semantics.\n */\nexport interface AiDomainProperty {\n key?: string\n name?: string\n displayName?: string\n description?: string\n type: DomainPropertyType\n constraints?: {\n required?: boolean\n unique?: boolean\n index?: boolean\n primary?: boolean\n multiple?: boolean\n readOnly?: boolean\n writeOnly?: boolean\n }\n deprecated?: boolean\n schema?: PropertySchema\n semantics?: AiDomainSemantic[]\n tags?: string[]\n}\n\n/**\n * Represents an association definition generated by the AI, linking an entity\n * to one or more target entities. It includes relationship rules (like onDelete)\n * and semantic annotations.\n */\nexport interface AiDomainAssociation {\n key: string\n name?: string\n displayName?: string\n description?: string\n targets: AssociationTarget[]\n required?: boolean\n multiple?: boolean\n onDelete?: OnDeleteRule\n semantics?: AiDomainSemantic[]\n schema?: IApiAssociationShape\n}\n\n/**\n * The core structure representing a set of modifications (a delta) proposed by the AI.\n * It contains arrays of models and entities to add, delete, or modify. The application\n * processes this delta to transition the data domain to the new requested state.\n */\nexport interface AiDomainDelta {\n /**\n * Models to add to the domain.\n */\n addedModels?: AiDataModelSchema[]\n /**\n * Keys of models to delete from the domain.\n */\n deletedModelKeys?: string[]\n /**\n * Models to modify in the domain.\n */\n modifiedModels?: AiDataModelSchema[]\n /**\n * Entities to add to the domain.\n */\n addedEntities?: AiDomainEntityResponseSchema[]\n /**\n * Keys of entities to delete from the domain.\n */\n deletedEntityKeys?: string[]\n /**\n * Entities to modify in the domain.\n */\n modifiedEntities?: AiDomainEntityDelta[]\n}\n\n/**\n * The expected JSON schema structure returned by the AI endpoint when performing\n * data domain manipulation. It includes the AI's step-by-step reasoning and the\n * actionable delta to be applied.\n */\nexport interface AiDomainDeltaResponse {\n /**\n * The LLM reasoning.\n */\n reasoning: string\n /**\n * Domain changes delta\n */\n delta?: AiDomainDelta\n}\n\n/**\n * Union type for progressive SSE stream chunks\n * received from the AI generation endpoint.\n */\nexport type AiStreamEvent =\n | { event: 'user-message'; data: AiMessageSchema }\n | { event: 'agent-message'; data: AiMessageSchema }\n | { event: 'thought-chunk'; data: string }\n | { event: 'text-chunk'; data: string }\n | { event: 'done'; data: AiMessageSchema }\n | { event: 'error'; data: Exception }\n | { event: 'session-updated'; data: AiSessionSchema }\n\n/**\n * Represents a targeted modification to an existing entity generated by the AI.\n * Instead of providing the full entity state, the AI provides explicit arrays\n * of properties, associations, and semantics to add, modify, or delete, enabling\n * precise, non-destructive updates.\n */\nexport interface AiDomainEntityDelta {\n key: string\n modelKey?: string // Provide to move the entity to a different model\n name?: string\n displayName?: string\n description?: string\n tags?: string[]\n // Entity semantics delta\n addedSemantics?: AiDomainSemantic[]\n modifiedSemantics?: AiDomainSemantic[]\n deletedSemanticIds?: SemanticType[]\n // Explicit deltas so the LLM doesn't have to list untouched properties\n addedProperties?: AiDomainProperty[]\n modifiedProperties?: AiDomainPropertyDelta[]\n deletedPropertyKeys?: string[]\n addedAssociations?: AiDomainAssociation[]\n modifiedAssociations?: AiDomainAssociationDelta[]\n deletedAssociationKeys?: string[]\n}\n\n/**\n * Represents a targeted modification to an existing property generated by the AI.\n * It captures changes to superficial properties (name, description), type changes,\n * constraint updates, and semantic alterations.\n */\nexport interface AiDomainPropertyDelta {\n key: string\n name?: string\n displayName?: string\n description?: string\n type?: DomainPropertyType\n constraints?: {\n required?: boolean\n unique?: boolean\n index?: boolean\n primary?: boolean\n multiple?: boolean\n readOnly?: boolean\n writeOnly?: boolean\n }\n deprecated?: boolean\n // Property semantics delta\n addedSemantics?: AiDomainSemantic[]\n modifiedSemantics?: AiDomainSemantic[]\n deletedSemanticIds?: SemanticType[]\n schema?: PropertySchema\n}\n\n/**\n * Represents a targeted modification to an existing association generated by the AI.\n * It captures updates to relationship cardinality, target entities, deletion rules,\n * and applied semantics.\n */\nexport interface AiDomainAssociationDelta {\n key: string\n name?: string\n displayName?: string\n description?: string\n targets?: AssociationTarget[]\n required?: boolean\n onDelete?: OnDeleteRule\n // Association semantics delta\n addedSemantics?: AiDomainSemantic[]\n modifiedSemantics?: AiDomainSemantic[]\n deletedSemanticIds?: SemanticType[]\n}\n\n/**\n * An enriched, in-memory representation of a model's message that includes the globally\n * parsed `AiDomainDelta` object.\n * This is not stored directly in the datastore as-is; instead, the raw JSON text is stored,\n * and this structure is assembled at runtime when the chat history is loaded into the UI.\n */\nexport interface AiModelMessageWithDelta extends AiModelMessage {\n /**\n * The delta of the message, if any.\n */\n delta?: AiDomainDelta\n /**\n * The reasoning of the delta.\n * Format in markdown.\n */\n reasoning?: string\n}\n"]}
@@ -0,0 +1,185 @@
1
+ import type { IDeletion } from './store/Deletion.js';
2
+ import { AiMessageKind } from './kinds.js';
3
+ import type { AiDomainDelta } from '../modeling/ai/types.js';
4
+ export type AiMessageRole = 'user' | 'model';
5
+ export type AiMessageState = 'loading' | 'complete' | 'error' | 'terminated';
6
+ /**
7
+ * The base interface representing a single message in the domain manipulation chat history.
8
+ * It tracks metadata like timestamps, the associated session, and the raw text content.
9
+ * See `AiUserMessage` and `AiModelMessage` for specific role implementations.
10
+ */
11
+ export interface AiMessageSchemaBase {
12
+ readonly kind: typeof AiMessageKind;
13
+ /**
14
+ * The datastore key of the message.
15
+ */
16
+ key: string;
17
+ /**
18
+ * The role of the message.
19
+ */
20
+ role: AiMessageRole;
21
+ /**
22
+ * The timestamp of when the message was created.
23
+ */
24
+ createdAt: number;
25
+ /**
26
+ * The timestamp of when the message was last updated.
27
+ */
28
+ updatedAt: number;
29
+ /**
30
+ * The datastore key of the session.
31
+ */
32
+ session: string;
33
+ /**
34
+ * The text of the message.
35
+ */
36
+ text: string;
37
+ /**
38
+ * Whether the message is deleted.
39
+ */
40
+ deleted?: boolean;
41
+ /**
42
+ * The information about the delete information.
43
+ * Always set when the `deleted` is true.
44
+ */
45
+ deletedInfo?: IDeletion;
46
+ }
47
+ /**
48
+ * The schema for a user message.
49
+ */
50
+ export interface AiUserMessageSchema extends AiMessageSchemaBase {
51
+ /**
52
+ * The role of the message.
53
+ */
54
+ role: 'user';
55
+ /**
56
+ * The state of the user message.
57
+ * Can only be `complete`.
58
+ */
59
+ state: 'complete';
60
+ /**
61
+ * The user utterance.
62
+ * Note, the actual message sent to the LLM may be different from the utterance
63
+ * as it has additional instructions and the domain context. However, we are not storing
64
+ * the full message in the datastore, only the utterance.
65
+ */
66
+ text: string;
67
+ }
68
+ /**
69
+ * The schema for a model message.
70
+ */
71
+ export interface AiModelMessageSchema extends AiMessageSchemaBase {
72
+ /**
73
+ * The role of the message.
74
+ */
75
+ role: 'model';
76
+ /**
77
+ * The full text of the message returned by the LLM.
78
+ * It is most likely a structured message that needs to be parsed
79
+ * to the corresponding message object.
80
+ */
81
+ text: string;
82
+ /**
83
+ * The state of the message.
84
+ * - loading: the message is being generated
85
+ * - complete: the message is complete
86
+ * - error: the message generation failed
87
+ * - terminated: the message generation was terminated by the user
88
+ */
89
+ state: AiMessageState;
90
+ /**
91
+ * Whether the message has been applied.
92
+ */
93
+ applied?: boolean;
94
+ /**
95
+ * The thoughts of the message.
96
+ */
97
+ thoughts?: string;
98
+ }
99
+ /**
100
+ * A union type representing any valid chat message in the AI session history.
101
+ */
102
+ export type AiMessageSchema = AiUserMessageSchema | AiModelMessageSchema;
103
+ /**
104
+ * The base class for all AI messages.
105
+ * It provides common functionality for all message types.
106
+ */
107
+ export declare abstract class AiMessageBase<T extends AiMessageSchemaBase = AiMessageSchemaBase> implements AiMessageSchemaBase {
108
+ /**
109
+ * The kind of the schema.
110
+ */
111
+ static get Kind(): typeof AiMessageKind;
112
+ /**
113
+ * The kind of the schema.
114
+ */
115
+ get kind(): typeof AiMessageKind;
116
+ key: string;
117
+ role: T['role'];
118
+ createdAt: number;
119
+ updatedAt: number;
120
+ session: string;
121
+ text: string;
122
+ deleted: boolean;
123
+ deletedInfo?: IDeletion;
124
+ protected static createBaseSchema(input: Partial<AiMessageSchemaBase>): Omit<AiMessageSchemaBase, 'role'>;
125
+ constructor(input: Partial<T> | undefined, role: T['role']);
126
+ toJSON(): T;
127
+ }
128
+ export declare class AiUserMessage extends AiMessageBase<AiUserMessageSchema> implements AiUserMessageSchema {
129
+ state: 'complete';
130
+ static createSchema(input: Partial<AiUserMessageSchema>): AiUserMessageSchema;
131
+ constructor(input?: Partial<AiUserMessageSchema>);
132
+ toJSON(): AiUserMessageSchema;
133
+ }
134
+ export declare class AiModelMessage extends AiMessageBase<AiModelMessageSchema> implements AiModelMessageSchema {
135
+ state: AiMessageState;
136
+ applied?: boolean;
137
+ thoughts: string;
138
+ /**
139
+ * The delta of the message, if any.
140
+ */
141
+ delta?: AiDomainDelta;
142
+ /**
143
+ * The reasoning of the delta.
144
+ * Format in markdown.
145
+ */
146
+ reasoning?: string;
147
+ static createSchema(input: Partial<AiModelMessageSchema>): AiModelMessageSchema;
148
+ constructor(input?: Partial<AiModelMessageSchema>);
149
+ toJSON(): AiModelMessageSchema;
150
+ /**
151
+ * Adds a thought to the message. Useful when streaming.
152
+ * @param thought The thought to add.
153
+ */
154
+ addThought(thought?: string): void;
155
+ /**
156
+ * Adds a text chunk to the message. Useful when streaming.
157
+ * @param text The text chunk to add.
158
+ */
159
+ addText(text?: string): void;
160
+ /**
161
+ * Processes the message.
162
+ * If the message is not valid JSON, it will throw an error.
163
+ * It sets the delta and reasoning fields, if found in the message.
164
+ */
165
+ processMessage(): void;
166
+ /**
167
+ * Processes the message safely.
168
+ * If the message is not valid JSON, it will be ignored.
169
+ */
170
+ processMessageSafe(): void;
171
+ /**
172
+ * Creates an empty model message. Useful when initializing LLM flow.
173
+ * @param session The session key.
174
+ * @returns An empty model message.
175
+ */
176
+ static createEmpty(session: string): AiModelMessage;
177
+ }
178
+ /**
179
+ * A union type representing any valid chat message in the AI session history.
180
+ */
181
+ export type AiMessage = AiUserMessage | AiModelMessage;
182
+ export declare const AiMessageFactory: {
183
+ fromSchema(schema: Partial<AiMessageSchema>): AiMessage;
184
+ };
185
+ //# sourceMappingURL=AiMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AiMessage.d.ts","sourceRoot":"","sources":["../../../src/models/AiMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAG5D,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,CAAA;AAC5C,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,YAAY,CAAA;AAE5E;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,OAAO,aAAa,CAAA;IACnC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,IAAI,EAAE,aAAa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