@api-client/core 0.19.6 → 0.19.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/browser.d.ts +1 -1
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +1 -1
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +1 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +1 -1
- package/build/src/index.js.map +1 -1
- package/build/src/modeling/DomainProperty.d.ts +7 -0
- package/build/src/modeling/DomainProperty.d.ts.map +1 -1
- package/build/src/modeling/DomainProperty.js +10 -0
- package/build/src/modeling/DomainProperty.js.map +1 -1
- package/build/src/modeling/ai/message_parser.d.ts +1 -0
- package/build/src/modeling/ai/message_parser.d.ts.map +1 -1
- package/build/src/modeling/ai/message_parser.js +1 -0
- package/build/src/modeling/ai/message_parser.js.map +1 -1
- package/build/src/models/AiMessage.d.ts +41 -9
- package/build/src/models/AiMessage.d.ts.map +1 -1
- package/build/src/models/AiMessage.js +41 -14
- package/build/src/models/AiMessage.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +12 -12
- package/package.json +1 -1
- package/src/modeling/DomainProperty.ts +11 -0
- package/src/modeling/ai/message_parser.ts +1 -0
- package/src/models/AiMessage.ts +66 -19
- package/tests/unit/modeling/domain_property.spec.ts +38 -0
- package/tests/unit/models/AiMessage.spec.ts +32 -30
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomainProperty.js","sourceRoot":"","sources":["../../../src/modeling/DomainProperty.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,aAAa,EAA4B,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,QA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MAAM,CAAC,YAAY,EAAE,CAAA;YAC1B,OAAO,MAAM,CAAA;QACf,CAAC;;;SA7hBU,cAAc","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainPropertyKind } from '../models/kinds.js'\nimport { DomainElement, type DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { observed, retargetChange, toRaw } from '../decorators/observed.js'\nimport {\n type BinaryFormat,\n BinaryFormats,\n type DomainPropertyAttribute,\n DomainPropertyAttributes,\n type DomainPropertyFormat,\n DomainPropertyList,\n type DomainPropertyType,\n DomainPropertyTypes,\n type NumberFormat,\n NumberFormats,\n} from './DataFormat.js'\nimport { ShapeGenerator } from './amf/ShapeGenerator.js'\nimport type { PropertyBinding, PropertyBindings, PropertyWebBindings } from './Bindings.js'\nimport type { ModelValidationOptions } from '../models/types.js'\nimport type { DomainEntity } from './DomainEntity.js'\nimport type { IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport type { PropertySchema } from './types.js'\nimport { DataSemantics, isPropertySemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'\nimport { ApiSchemaGenerator } from '../amf/ApiSchemaGenerator.js'\nimport type { IShapeRenderOptions } from '../amf/shape/ShapeBase.js'\n\nexport interface DomainPropertySchema extends DomainElementSchema {\n kind: typeof DomainPropertyKind\n /**\n * The domain property description.\n */\n info: IThing\n /**\n * Wether the data property is required.\n */\n required?: boolean\n /**\n * Whether the data property allows multiple items.\n */\n multiple?: boolean\n /**\n * Whether this property describes a primary key of the entity.\n */\n primary?: boolean\n /**\n * Whether this property describes a unique property of the entity.\n * This is used to generate unique constraints in the database.\n */\n unique?: boolean\n /**\n * Whether this property describes an indexed property of the entity.\n */\n index?: boolean\n /**\n * Whether the property is read only in the schema.\n */\n readOnly?: boolean\n /**\n * Whether the property is write only in the schema.\n */\n writeOnly?: boolean\n /**\n * Whether this property is deprecated.\n */\n deprecated?: boolean\n /**\n * Optional general purpose tags for the UI.\n */\n tags?: string[]\n /**\n * The semantics applied to this property.\n * This is a list of applied semantics that can be used to\n * describe the property in more detail.\n */\n semantics?: AppliedDataSemantic[]\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers, but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n type: DomainPropertyType\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n schema?: PropertySchema\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n bindings?: PropertyBinding[]\n}\n\n/**\n * Represents a property within a data domain entity.\n *\n * A `DomainProperty` defines a single data element within a\n * `DomainEntity`. It specifies the data type, constraints,\n * and other metadata for a specific piece of information.\n *\n * **Key Features:**\n *\n * - **Data Type:** Defines the type of data the property\n * holds (e.g., string, number, boolean, date).\n * - **Constraints:** Supports defining constraints such as\n * minimum/maximum values, enum values, and default values.\n * - **Bindings:** Allows defining how the property is\n * represented in different formats (e.g., web APIs,\n * protocol buffers).\n * - **Metadata:** Supports metadata such as tags, semantics,\n * read-only/write-only status, and deprecation.\n * - **Schema:** Allows defining a general schema for the\n * property, which is propagated to all bindings.\n *\n * **Usage:**\n *\n * Use the `DomainEntity.addProperty` method to add a new property to an\n * entity. The property can be created using the constructor, but it\n * won't be added to the graph until you call the `addProperty` method.\n *\n * **Example:**\n *\n * ```typescript\n * const entity = domainModel.addEntity({ key: 'user' });\n * const property = entity.addProperty({\n * key: 'name',\n * type: 'string',\n * required: true,\n * schema: {\n * minimum: 3,\n * maximum: 50,\n * },\n * });\n * ```\n */\nexport class DomainProperty extends DomainElement {\n override kind: typeof DomainPropertyKind\n\n /**\n * The description of the domain property.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * Wether the data property is required.\n */\n @observed() accessor required: boolean | undefined\n\n /**\n * Whether the data property allows multiple items.\n */\n @observed() accessor multiple: boolean | undefined\n\n /**\n * Whether this property describes a primary key of the entity.\n */\n @observed() accessor primary: boolean | undefined\n\n /**\n * Whether this property describes a unique property of the entity.\n * This is used to generate unique constraints in the database.\n */\n @observed() accessor unique: boolean | undefined\n\n /**\n * Whether this property describes an indexed property of the entity.\n */\n @observed() accessor index: boolean | undefined\n\n /**\n * Whether the property is read only in the schema.\n */\n @observed() accessor readOnly: boolean | undefined\n\n /**\n * Whether the property is write only in the schema.\n */\n @observed() accessor writeOnly: boolean | undefined\n\n /**\n * Whether this property is deprecated.\n */\n @observed() accessor deprecated: boolean | undefined\n\n /**\n * Optional general purpose tags for the UI.\n *\n * Note to implementations, use the `addTag()` method as it propagates the \"tag\" value in the namespace.\n * Also, the tags property is excluded from the observer properties.\n * Changes to this property will not notify the observers.\n */\n @observed({ deep: true }) accessor tags: string[] = []\n\n /**\n * Semantics applied to this property.\n */\n @observed({ deep: true }) accessor semantics: AppliedDataSemantic[] = []\n\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n @observed() accessor type: DomainPropertyType = 'string'\n\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n @observed({ deep: true }) accessor schema: PropertySchema | undefined\n\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n @observed({ deep: true }) accessor bindings: PropertyBinding[] = []\n\n /**\n * Creates a full data model schema with defaults.\n *\n * @param input The partial data model schema.\n * @returns The data model schema.\n */\n static createSchema(input: Partial<DomainPropertySchema> = {}): DomainPropertySchema {\n const {\n key = nanoid(),\n multiple,\n required,\n type = DomainPropertyList.string,\n index,\n primary,\n unique,\n readOnly,\n writeOnly,\n tags,\n semantics,\n deprecated,\n schema,\n bindings,\n } = input\n if (typeof type === 'string') {\n if (!DomainPropertyTypes.includes(type as DomainPropertyType)) {\n throw new Error(`Invalid data property type ${type}`)\n }\n }\n const info = Thing.fromJSON(input.info, { name: 'new_property' }).toJSON()\n const result: DomainPropertySchema = {\n kind: DomainPropertyKind,\n key,\n info,\n type,\n }\n if (typeof multiple === 'boolean') {\n result.multiple = multiple\n }\n if (typeof required === 'boolean') {\n result.required = required\n }\n if (typeof index === 'boolean') {\n result.index = index\n }\n if (typeof primary === 'boolean') {\n result.primary = primary\n }\n if (typeof unique === 'boolean') {\n result.unique = unique\n }\n if (typeof readOnly === 'boolean') {\n result.readOnly = readOnly\n }\n if (typeof writeOnly === 'boolean') {\n result.writeOnly = writeOnly\n }\n if (typeof deprecated === 'boolean') {\n result.deprecated = deprecated\n }\n if (Array.isArray(tags)) {\n result.tags = [...tags]\n }\n if (Array.isArray(semantics)) {\n result.semantics = [...semantics]\n }\n if (schema) {\n result.schema = structuredClone(schema)\n }\n if (Array.isArray(bindings)) {\n result.bindings = bindings.map((i) => structuredClone(i))\n } else {\n result.bindings = []\n }\n return result\n }\n\n /**\n * The key of the parent entity.\n */\n protected parent: string\n\n /**\n * Creates a new domain property instance.\n * It does not add it to the graph.\n * You need to call the `addProperty` method of the graph or a data model to add it.\n *\n * Domain objects constructors shouldn't be used directly. Use methods\n * provided on the DataDomain class to create new objects.\n *\n * @param root A reference to the root DataDomain instance.\n * @param parent The key of the parent entity.\n * @param input The partial domain property schema.\n * @returns Created domain property instance.\n */\n constructor(root: DataDomain, parent: string, input: Partial<DomainPropertySchema> = {}) {\n const init = DomainProperty.createSchema(input)\n super(root, init.key)\n this.parent = parent\n this.kind = DomainPropertyKind\n this.info = new Thing(init.info)\n this.type = init.type\n\n if (typeof init.multiple === 'boolean') {\n this.multiple = init.multiple\n } else {\n this.multiple = undefined\n }\n if (typeof init.required === 'boolean') {\n this.required = init.required\n } else {\n this.required = undefined\n }\n if (typeof init.index === 'boolean') {\n this.index = init.index\n } else {\n this.index = undefined\n }\n if (typeof init.deprecated === 'boolean') {\n this.deprecated = init.deprecated\n } else {\n this.deprecated = undefined\n }\n if (typeof init.primary === 'boolean') {\n this.primary = init.primary\n } else {\n this.primary = undefined\n }\n if (typeof init.unique === 'boolean') {\n this.unique = init.unique\n } else {\n this.unique = undefined\n }\n if (typeof init.readOnly === 'boolean') {\n this.readOnly = init.readOnly\n } else {\n this.readOnly = undefined\n }\n if (typeof init.writeOnly === 'boolean') {\n this.writeOnly = init.writeOnly\n } else {\n this.writeOnly = undefined\n }\n if (Array.isArray(init.tags)) {\n this.tags = [...init.tags]\n } else {\n this.tags = []\n }\n if (Array.isArray(init.semantics)) {\n this.semantics = [...init.semantics]\n } else {\n this.semantics = []\n }\n if (init.schema) {\n this.schema = structuredClone(init.schema)\n } else {\n this.schema = undefined\n }\n if (Array.isArray(init.bindings)) {\n this.bindings = init.bindings.map((i) => structuredClone(i))\n } else {\n this.bindings = []\n }\n }\n\n /**\n * Checks whether the input is a valid definition of a domain property.\n *\n * @param input The input to validate.\n * @param options Validation options.\n * @returns true when the passed input is a valid definition of a domain property.\n */\n static validate(input: unknown, options: ModelValidationOptions = {}): boolean {\n if (!input || (typeof input !== 'object' && input !== null)) {\n return false\n }\n const typed = input as DomainPropertySchema\n if (options.strict && typed.kind !== DomainPropertyKind) {\n return false\n }\n return true\n }\n\n toJSON(): DomainPropertySchema {\n const result: DomainPropertySchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n type: this.type || DomainPropertyList.string,\n }\n if (typeof this.index === 'boolean') {\n result.index = this.index\n }\n if (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n if (typeof this.primary === 'boolean') {\n result.primary = this.primary\n }\n if (typeof this.unique === 'boolean') {\n result.unique = this.unique\n }\n if (typeof this.multiple === 'boolean') {\n result.multiple = this.multiple\n }\n if (typeof this.required === 'boolean') {\n result.required = this.required\n }\n if (typeof this.readOnly === 'boolean') {\n result.readOnly = this.readOnly\n }\n if (typeof this.writeOnly === 'boolean') {\n result.writeOnly = this.writeOnly\n }\n if (Array.isArray(this.tags) && this.tags.length) {\n result.tags = [...this.tags]\n }\n if (Array.isArray(this.semantics) && this.semantics.length) {\n result.semantics = toRaw(this, this.semantics)?.map((i) => structuredClone(i))\n }\n if (this.schema) {\n result.schema = structuredClone(toRaw(this, this.schema))\n }\n if (Array.isArray(this.bindings) && this.bindings.length) {\n result.bindings = toRaw(this, this.bindings)?.map((i) => structuredClone(i))\n }\n return result\n }\n\n /**\n * Removes this property from the parent entity.\n * It calls the `removeProperty()` method of the parent entity.\n */\n remove(): void {\n const parent = this.getParentInstance()\n parent?.removeProperty(this.key)\n }\n\n /**\n * Returns a parent data entity where this data property exist.\n */\n getParentInstance(): DomainEntity | undefined {\n return this.root.graph.node(this.parent) as DomainEntity | undefined\n }\n\n /**\n * Checks whether the passed value is one of the supported data types.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data types.\n */\n static isValidType(value: unknown): value is DomainPropertyType {\n if (typeof value !== 'string') {\n return false\n }\n return DomainPropertyTypes.includes(value as DomainPropertyType)\n }\n\n /**\n * Checks whether the passed value is one of the supported data property attributes.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data property attributes.\n */\n static isValidAttribute(value: unknown): value is DomainPropertyAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DomainPropertyAttributes.includes(value as DomainPropertyAttribute)\n }\n\n /**\n * Checks whether the passed value of one of the supported `format` values.\n *\n * @param value The value to test\n * @returns `true` when the value is one of the supported `format` values.\n */\n static isValidFormat(value: unknown): value is DomainPropertyFormat {\n if (value === undefined) {\n // It is the valid value.\n return true\n }\n if (typeof value !== 'string') {\n return false\n }\n if (NumberFormats.includes(value as NumberFormat)) {\n return true\n }\n if (BinaryFormats.includes(value as BinaryFormat)) {\n return true\n }\n return false\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n * @returns The schema object.\n */\n ensureSchema(): PropertySchema {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\n }\n\n /**\n * Creates if not existing and returns web bindings definition.\n * @returns The web binding definition\n */\n getWebBinding(): PropertyWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as PropertyBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as PropertyBinding\n this.bindings.push(object)\n }\n return object.schema as PropertyWebBindings\n }\n\n /**\n * Returns the schema value of the binding, if any was created.\n * @param type The type of the binding to read.\n * @returns The binding schema, if any\n */\n readBinding(type: 'web' | 'protobuf'): PropertyBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as PropertyBinding\n return item?.schema || undefined\n }\n\n /**\n * Creates a Property Shape of AMF.\n *\n * The property itself is auto-generated. If the `schema` is\n * defined then it is used as the `range` of the property.\n * Otherwise basic shape is generated for the range.\n *\n * This is a preferred way of reading the AMF shape as this\n * synchronizes changed data properties with the shape\n * definition.\n *\n * @returns AMF property shape definition.\n */\n toApiShape(): IApiPropertyShape {\n const serializer = new ShapeGenerator()\n return serializer.property(this)\n }\n\n /**\n * Generates an example value for this property based on its schema and type.\n *\n * This method converts the property to an AMF shape and then generates\n * an example value using the ApiSchemaGenerator. The generated example\n * respects the property's type, constraints, and any defined schema.\n *\n * @param mime The mime type of the example (e.g., 'application/json', 'application/xml').\n * @param opts Optional configuration for example generation.\n * @returns The generated example value.\n * @example\n * ```typescript\n * const example = property.toExample('application/json');\n * console.log(example);\n * ```\n */\n toExample(mime: string, opts: IShapeRenderOptions = {}): string | number | boolean | null | undefined {\n // TODO: add support for semantic extensions and generate example values based on them.\n const shape = this.toApiShape()\n if (!shape.range) {\n return undefined\n }\n const generator = new ApiSchemaGenerator(mime, {\n renderExamples: opts.renderExamples ?? true,\n renderMocked: opts.renderMocked ?? true,\n renderOptional: opts.renderOptional ?? true,\n selectedUnions: opts.selectedUnions,\n })\n return generator.generate(shape)\n }\n\n /**\n * Adds or updates a semantic to the property.\n * @param semantic The semantic to add to the property.\n * @throws Error if the semantic is not an property semantic.\n */\n addSemantic(semantic: AppliedDataSemantic): void {\n const sem = DataSemantics[semantic.id]\n if (!isPropertySemantic(sem)) {\n throw new Error(`Invalid semantic type: ${semantic.id}. Expected a property semantic.`)\n }\n const index = this.semantics.findIndex((s) => s.id === semantic.id)\n if (index >= 0) {\n this.semantics[index] = semantic\n } else {\n this.semantics.push(semantic)\n }\n this.domain.notifyChange()\n }\n\n /**\n * Removes a semantic from the property.\n * @param semanticId The ID of the semantic to remove.\n */\n removeSemantic(semanticId: SemanticType): void {\n const index = this.semantics.findIndex((s) => s.id === semanticId)\n if (index >= 0) {\n this.semantics.splice(index, 1)\n this.domain.notifyChange()\n }\n }\n\n /**\n * Checks if the property has a specific semantic.\n * @param semanticId The ID of the semantic to check.\n * @returns True if the semantic is present, false otherwise.\n */\n hasSemantic(semanticId: SemanticType): boolean {\n return this.semantics.some((s) => s.id === semanticId)\n }\n\n /**\n * Creates a duplicate of this domain property on the parent entity.\n * It places the duplicate on the parent entity right after the original property.\n */\n duplicate(): DomainProperty {\n const parent = this.getParentInstance()\n if (!parent) {\n throw new Error(`Cannot duplicate property ${this.key} as it has no parent entity.`)\n }\n const originalIndex = parent.fields.findIndex((f) => f.key === this.key)\n if (originalIndex === -1) {\n throw new Error(`Cannot duplicate property ${this.key} as it does not exist on the parent entity fields list.`)\n }\n const baseName = this.info.name || 'field'\n const newName = parent.generateUniqueName(baseName)\n\n // Making a copy and restoring it through the `addProperty()` method\n // scales better than copying it manually.\n const copy = this.toJSON() as Partial<DomainPropertySchema>\n\n // Delete properties that should not be copied\n delete copy.key\n delete copy.primary // Don't duplicate the primary key\n\n // Set the new name for the duplicated property\n if (copy.info) {\n copy.info.name = newName\n } else {\n copy.info = { name: newName }\n }\n const result = parent.addProperty(copy)\n\n // Move the duplicate to be right after the original\n const fromIndex = parent.fields.length - 1\n const duplicateField = parent.fields[fromIndex]\n parent.fields.splice(fromIndex, 1)\n parent.fields.splice(originalIndex + 1, 0, duplicateField)\n\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CAAC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAA;YAC1B,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;YAC/B,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;YAEvC,oDAAoD;YACpD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;YAC1C,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YAC/C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;YAClC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,CAAA;YAE1D,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;YAC1B,OAAO,MAAM,CAAA;QACf,CAAC;;;SAxiBU,cAAc","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainPropertyKind } from '../models/kinds.js'\nimport { DomainElement, type DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { observed, retargetChange, toRaw } from '../decorators/observed.js'\nimport {\n type BinaryFormat,\n BinaryFormats,\n type DomainPropertyAttribute,\n DomainPropertyAttributes,\n type DomainPropertyFormat,\n DomainPropertyList,\n type DomainPropertyType,\n DomainPropertyTypes,\n type NumberFormat,\n NumberFormats,\n} from './DataFormat.js'\nimport { ShapeGenerator } from './amf/ShapeGenerator.js'\nimport type { PropertyBinding, PropertyBindings, PropertyWebBindings } from './Bindings.js'\nimport type { ModelValidationOptions } from '../models/types.js'\nimport type { DomainEntity } from './DomainEntity.js'\nimport type { IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport type { PropertySchema } from './types.js'\nimport { DataSemantics, isPropertySemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'\nimport { ApiSchemaGenerator } from '../amf/ApiSchemaGenerator.js'\nimport type { IShapeRenderOptions } from '../amf/shape/ShapeBase.js'\n\nexport interface DomainPropertySchema extends DomainElementSchema {\n kind: typeof DomainPropertyKind\n /**\n * The domain property description.\n */\n info: IThing\n /**\n * Wether the data property is required.\n */\n required?: boolean\n /**\n * Whether the data property allows multiple items.\n */\n multiple?: boolean\n /**\n * Whether this property describes a primary key of the entity.\n */\n primary?: boolean\n /**\n * Whether this property describes a unique property of the entity.\n * This is used to generate unique constraints in the database.\n */\n unique?: boolean\n /**\n * Whether this property describes an indexed property of the entity.\n */\n index?: boolean\n /**\n * Whether the property is read only in the schema.\n */\n readOnly?: boolean\n /**\n * Whether the property is write only in the schema.\n */\n writeOnly?: boolean\n /**\n * Whether this property is deprecated.\n */\n deprecated?: boolean\n /**\n * Optional general purpose tags for the UI.\n */\n tags?: string[]\n /**\n * The semantics applied to this property.\n * This is a list of applied semantics that can be used to\n * describe the property in more detail.\n */\n semantics?: AppliedDataSemantic[]\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers, but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n type: DomainPropertyType\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n schema?: PropertySchema\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n bindings?: PropertyBinding[]\n}\n\n/**\n * Represents a property within a data domain entity.\n *\n * A `DomainProperty` defines a single data element within a\n * `DomainEntity`. It specifies the data type, constraints,\n * and other metadata for a specific piece of information.\n *\n * **Key Features:**\n *\n * - **Data Type:** Defines the type of data the property\n * holds (e.g., string, number, boolean, date).\n * - **Constraints:** Supports defining constraints such as\n * minimum/maximum values, enum values, and default values.\n * - **Bindings:** Allows defining how the property is\n * represented in different formats (e.g., web APIs,\n * protocol buffers).\n * - **Metadata:** Supports metadata such as tags, semantics,\n * read-only/write-only status, and deprecation.\n * - **Schema:** Allows defining a general schema for the\n * property, which is propagated to all bindings.\n *\n * **Usage:**\n *\n * Use the `DomainEntity.addProperty` method to add a new property to an\n * entity. The property can be created using the constructor, but it\n * won't be added to the graph until you call the `addProperty` method.\n *\n * **Example:**\n *\n * ```typescript\n * const entity = domainModel.addEntity({ key: 'user' });\n * const property = entity.addProperty({\n * key: 'name',\n * type: 'string',\n * required: true,\n * schema: {\n * minimum: 3,\n * maximum: 50,\n * },\n * });\n * ```\n */\nexport class DomainProperty extends DomainElement {\n override kind: typeof DomainPropertyKind\n\n /**\n * The description of the domain property.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * Wether the data property is required.\n */\n @observed() accessor required: boolean | undefined\n\n /**\n * Whether the data property allows multiple items.\n */\n @observed() accessor multiple: boolean | undefined\n\n /**\n * Whether this property describes a primary key of the entity.\n */\n @observed() accessor primary: boolean | undefined\n\n /**\n * Whether this property describes a unique property of the entity.\n * This is used to generate unique constraints in the database.\n */\n @observed() accessor unique: boolean | undefined\n\n /**\n * Whether this property describes an indexed property of the entity.\n */\n @observed() accessor index: boolean | undefined\n\n /**\n * Whether the property is read only in the schema.\n */\n @observed() accessor readOnly: boolean | undefined\n\n /**\n * Whether the property is write only in the schema.\n */\n @observed() accessor writeOnly: boolean | undefined\n\n /**\n * Whether this property is deprecated.\n */\n @observed() accessor deprecated: boolean | undefined\n\n /**\n * Optional general purpose tags for the UI.\n *\n * Note to implementations, use the `addTag()` method as it propagates the \"tag\" value in the namespace.\n * Also, the tags property is excluded from the observer properties.\n * Changes to this property will not notify the observers.\n */\n @observed({ deep: true }) accessor tags: string[] = []\n\n /**\n * Semantics applied to this property.\n */\n @observed({ deep: true }) accessor semantics: AppliedDataSemantic[] = []\n\n /**\n * The data type for this property.\n * Note, not all schemas support the same type. For example, defining `sint32`\n * works for protocol buffers but does not for JSON. In such case we use default\n * translation `sint32` -> `number`. Another way it to create\n * a derivative entity for specific schema to describe specific schema case.\n */\n @observed() accessor type: DomainPropertyType = 'string'\n\n /**\n * The general schema definition of this property.\n * This is propagated to all bindings (when they support these properties).\n */\n @observed({ deep: true }) accessor schema: PropertySchema | undefined\n\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n @observed({ deep: true }) accessor bindings: PropertyBinding[] = []\n\n /**\n * Creates a full data model schema with defaults.\n *\n * @param input The partial data model schema.\n * @returns The data model schema.\n */\n static createSchema(input: Partial<DomainPropertySchema> = {}): DomainPropertySchema {\n const {\n key = nanoid(),\n multiple,\n required,\n type = DomainPropertyList.string,\n index,\n primary,\n unique,\n readOnly,\n writeOnly,\n tags,\n semantics,\n deprecated,\n schema,\n bindings,\n } = input\n if (typeof type === 'string') {\n if (!DomainPropertyTypes.includes(type as DomainPropertyType)) {\n throw new Error(`Invalid data property type ${type}`)\n }\n }\n const info = Thing.fromJSON(input.info, { name: 'new_property' }).toJSON()\n const result: DomainPropertySchema = {\n kind: DomainPropertyKind,\n key,\n info,\n type,\n }\n if (typeof multiple === 'boolean') {\n result.multiple = multiple\n }\n if (typeof required === 'boolean') {\n result.required = required\n }\n if (typeof index === 'boolean') {\n result.index = index\n }\n if (typeof primary === 'boolean') {\n result.primary = primary\n }\n if (typeof unique === 'boolean') {\n result.unique = unique\n }\n if (typeof readOnly === 'boolean') {\n result.readOnly = readOnly\n }\n if (typeof writeOnly === 'boolean') {\n result.writeOnly = writeOnly\n }\n if (typeof deprecated === 'boolean') {\n result.deprecated = deprecated\n }\n if (Array.isArray(tags)) {\n result.tags = [...tags]\n }\n if (Array.isArray(semantics)) {\n result.semantics = [...semantics]\n }\n if (schema) {\n result.schema = structuredClone(schema)\n }\n if (Array.isArray(bindings)) {\n result.bindings = bindings.map((i) => structuredClone(i))\n } else {\n result.bindings = []\n }\n return result\n }\n\n /**\n * The key of the parent entity.\n */\n protected parent: string\n\n /**\n * Creates a new domain property instance.\n * It does not add it to the graph.\n * You need to call the `addProperty` method of the graph or a data model to add it.\n *\n * Domain objects constructors shouldn't be used directly. Use methods\n * provided on the DataDomain class to create new objects.\n *\n * @param root A reference to the root DataDomain instance.\n * @param parent The key of the parent entity.\n * @param input The partial domain property schema.\n * @returns Created domain property instance.\n */\n constructor(root: DataDomain, parent: string, input: Partial<DomainPropertySchema> = {}) {\n const init = DomainProperty.createSchema(input)\n super(root, init.key)\n this.parent = parent\n this.kind = DomainPropertyKind\n this.info = new Thing(init.info)\n this.type = init.type\n\n if (typeof init.multiple === 'boolean') {\n this.multiple = init.multiple\n } else {\n this.multiple = undefined\n }\n if (typeof init.required === 'boolean') {\n this.required = init.required\n } else {\n this.required = undefined\n }\n if (typeof init.index === 'boolean') {\n this.index = init.index\n } else {\n this.index = undefined\n }\n if (typeof init.deprecated === 'boolean') {\n this.deprecated = init.deprecated\n } else {\n this.deprecated = undefined\n }\n if (typeof init.primary === 'boolean') {\n this.primary = init.primary\n } else {\n this.primary = undefined\n }\n if (typeof init.unique === 'boolean') {\n this.unique = init.unique\n } else {\n this.unique = undefined\n }\n if (typeof init.readOnly === 'boolean') {\n this.readOnly = init.readOnly\n } else {\n this.readOnly = undefined\n }\n if (typeof init.writeOnly === 'boolean') {\n this.writeOnly = init.writeOnly\n } else {\n this.writeOnly = undefined\n }\n if (Array.isArray(init.tags)) {\n this.tags = [...init.tags]\n } else {\n this.tags = []\n }\n if (Array.isArray(init.semantics)) {\n this.semantics = [...init.semantics]\n } else {\n this.semantics = []\n }\n if (init.schema) {\n this.schema = structuredClone(init.schema)\n } else {\n this.schema = undefined\n }\n if (Array.isArray(init.bindings)) {\n this.bindings = init.bindings.map((i) => structuredClone(i))\n } else {\n this.bindings = []\n }\n }\n\n /**\n * Checks whether the input is a valid definition of a domain property.\n *\n * @param input The input to validate.\n * @param options Validation options.\n * @returns true when the passed input is a valid definition of a domain property.\n */\n static validate(input: unknown, options: ModelValidationOptions = {}): boolean {\n if (!input || (typeof input !== 'object' && input !== null)) {\n return false\n }\n const typed = input as DomainPropertySchema\n if (options.strict && typed.kind !== DomainPropertyKind) {\n return false\n }\n return true\n }\n\n toJSON(): DomainPropertySchema {\n const result: DomainPropertySchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n type: this.type || DomainPropertyList.string,\n }\n if (typeof this.index === 'boolean') {\n result.index = this.index\n }\n if (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n if (typeof this.primary === 'boolean') {\n result.primary = this.primary\n }\n if (typeof this.unique === 'boolean') {\n result.unique = this.unique\n }\n if (typeof this.multiple === 'boolean') {\n result.multiple = this.multiple\n }\n if (typeof this.required === 'boolean') {\n result.required = this.required\n }\n if (typeof this.readOnly === 'boolean') {\n result.readOnly = this.readOnly\n }\n if (typeof this.writeOnly === 'boolean') {\n result.writeOnly = this.writeOnly\n }\n if (Array.isArray(this.tags) && this.tags.length) {\n result.tags = [...this.tags]\n }\n if (Array.isArray(this.semantics) && this.semantics.length) {\n result.semantics = toRaw(this, this.semantics)?.map((i) => structuredClone(i))\n }\n if (this.schema) {\n result.schema = structuredClone(toRaw(this, this.schema))\n }\n if (Array.isArray(this.bindings) && this.bindings.length) {\n result.bindings = toRaw(this, this.bindings)?.map((i) => structuredClone(i))\n }\n return result\n }\n\n /**\n * Removes this property from the parent entity.\n * It calls the `removeProperty()` method of the parent entity.\n */\n remove(): void {\n const parent = this.getParentInstance()\n parent?.removeProperty(this.key)\n }\n\n /**\n * Returns a parent data entity where this data property exist.\n */\n getParentInstance(): DomainEntity | undefined {\n return this.root.graph.node(this.parent) as DomainEntity | undefined\n }\n\n /**\n * Checks whether the passed value is one of the supported data types.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data types.\n */\n static isValidType(value: unknown): value is DomainPropertyType {\n if (typeof value !== 'string') {\n return false\n }\n return DomainPropertyTypes.includes(value as DomainPropertyType)\n }\n\n /**\n * Checks whether the passed value is one of the supported data property attributes.\n * @param value The value to test\n * @returns True when the passed value is one of the supported data property attributes.\n */\n static isValidAttribute(value: unknown): value is DomainPropertyAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DomainPropertyAttributes.includes(value as DomainPropertyAttribute)\n }\n\n /**\n * Checks whether the passed value of one of the supported `format` values.\n *\n * @param value The value to test\n * @returns `true` when the value is one of the supported `format` values.\n */\n static isValidFormat(value: unknown): value is DomainPropertyFormat {\n if (value === undefined) {\n // It is the valid value.\n return true\n }\n if (typeof value !== 'string') {\n return false\n }\n if (NumberFormats.includes(value as NumberFormat)) {\n return true\n }\n if (BinaryFormats.includes(value as BinaryFormat)) {\n return true\n }\n return false\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n * @returns The schema object.\n */\n ensureSchema(): PropertySchema {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\n }\n\n /**\n * Creates if not existing and returns web bindings definition.\n * @returns The web binding definition\n */\n getWebBinding(): PropertyWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as PropertyBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as PropertyBinding\n this.bindings.push(object)\n }\n return object.schema as PropertyWebBindings\n }\n\n /**\n * Reads the web binding definition, if any.\n * Useful for reading binding data without mutating the model when the binding\n * is missing (unlike `getWebBinding()` which creates the binding when missing).\n * @returns The web binding definition, if any\n */\n readWebBinding(): PropertyWebBindings | undefined {\n const object = this.bindings.find((i) => i.type === 'web') as PropertyBinding | undefined\n return object?.schema as PropertyWebBindings | undefined\n }\n\n /**\n * Returns the schema value of the binding, if any was created.\n * @param type The type of the binding to read.\n * @returns The binding schema, if any\n */\n readBinding(type: 'web' | 'protobuf'): PropertyBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as PropertyBinding\n return item?.schema || undefined\n }\n\n /**\n * Creates a Property Shape of AMF.\n *\n * The property itself is auto-generated. If the `schema` is\n * defined then it is used as the `range` of the property.\n * Otherwise basic shape is generated for the range.\n *\n * This is a preferred way of reading the AMF shape as this\n * synchronizes changed data properties with the shape\n * definition.\n *\n * @returns AMF property shape definition.\n */\n toApiShape(): IApiPropertyShape {\n const serializer = new ShapeGenerator()\n return serializer.property(this)\n }\n\n /**\n * Generates an example value for this property based on its schema and type.\n *\n * This method converts the property to an AMF shape and then generates\n * an example value using the ApiSchemaGenerator. The generated example\n * respects the property's type, constraints, and any defined schema.\n *\n * @param mime The mime type of the example (e.g., 'application/json', 'application/xml').\n * @param opts Optional configuration for example generation.\n * @returns The generated example value.\n * @example\n * ```typescript\n * const example = property.toExample('application/json');\n * console.log(example);\n * ```\n */\n toExample(mime: string, opts: IShapeRenderOptions = {}): string | number | boolean | null | undefined {\n // TODO: add support for semantic extensions and generate example values based on them.\n const shape = this.toApiShape()\n if (!shape.range) {\n return undefined\n }\n const generator = new ApiSchemaGenerator(mime, {\n renderExamples: opts.renderExamples ?? true,\n renderMocked: opts.renderMocked ?? true,\n renderOptional: opts.renderOptional ?? true,\n selectedUnions: opts.selectedUnions,\n })\n return generator.generate(shape)\n }\n\n /**\n * Adds or updates a semantic to the property.\n * @param semantic The semantic to add to the property.\n * @throws Error if the semantic is not an property semantic.\n */\n addSemantic(semantic: AppliedDataSemantic): void {\n const sem = DataSemantics[semantic.id]\n if (!isPropertySemantic(sem)) {\n throw new Error(`Invalid semantic type: ${semantic.id}. Expected a property semantic.`)\n }\n const index = this.semantics.findIndex((s) => s.id === semantic.id)\n if (index >= 0) {\n this.semantics[index] = semantic\n } else {\n this.semantics.push(semantic)\n }\n this.domain.notifyChange()\n }\n\n /**\n * Removes a semantic from the property.\n * @param semanticId The ID of the semantic to remove.\n */\n removeSemantic(semanticId: SemanticType): void {\n const index = this.semantics.findIndex((s) => s.id === semanticId)\n if (index >= 0) {\n this.semantics.splice(index, 1)\n this.domain.notifyChange()\n }\n }\n\n /**\n * Checks if the property has a specific semantic.\n * @param semanticId The ID of the semantic to check.\n * @returns True if the semantic is present, false otherwise.\n */\n hasSemantic(semanticId: SemanticType): boolean {\n return this.semantics.some((s) => s.id === semanticId)\n }\n\n /**\n * Creates a duplicate of this domain property on the parent entity.\n * It places the duplicate on the parent entity right after the original property.\n */\n duplicate(): DomainProperty {\n const parent = this.getParentInstance()\n if (!parent) {\n throw new Error(`Cannot duplicate property ${this.key} as it has no parent entity.`)\n }\n const originalIndex = parent.fields.findIndex((f) => f.key === this.key)\n if (originalIndex === -1) {\n throw new Error(`Cannot duplicate property ${this.key} as it does not exist on the parent entity fields list.`)\n }\n const baseName = this.info.name || 'field'\n const newName = parent.generateUniqueName(baseName)\n\n // Making a copy and restoring it through the `addProperty()` method\n // scales better than copying it manually.\n const copy = this.toJSON() as Partial<DomainPropertySchema>\n\n // Delete properties that should not be copied\n delete copy.key\n delete copy.primary // Don't duplicate the primary key\n\n // Set the new name for the duplicated property\n if (copy.info) {\n copy.info.name = newName\n } else {\n copy.info = { name: newName }\n }\n const result = parent.addProperty(copy)\n\n // Move the duplicate to be right after the original\n const fromIndex = parent.fields.length - 1\n const duplicateField = parent.fields[fromIndex]\n parent.fields.splice(fromIndex, 1)\n parent.fields.splice(originalIndex + 1, 0, duplicateField)\n\n this.domain.notifyChange()\n return result\n }\n}\n"]}
|
|
@@ -10,6 +10,7 @@ import type { AiMessageSchema, AiUserMessage } from '../../models/AiMessage.js';
|
|
|
10
10
|
*
|
|
11
11
|
* @param msg The generic AI chat message.
|
|
12
12
|
* @returns The parsed in-memory wrapper context message.
|
|
13
|
+
* @deprecated Use `AiModelMessage.processMessageSafe` instead.
|
|
13
14
|
*/
|
|
14
15
|
export declare function parseAiChatMessage(msg: AiMessageSchema): AiUserMessage | AiModelMessageWithDelta;
|
|
15
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message_parser.d.ts","sourceRoot":"","sources":["../../../../src/modeling/ai/message_parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAG/E
|
|
1
|
+
{"version":3,"file":"message_parser.d.ts","sourceRoot":"","sources":["../../../../src/modeling/ai/message_parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAG/E;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,eAAe,GAAG,aAAa,GAAG,uBAAuB,CAoBhG;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAwDhE"}
|
|
@@ -9,6 +9,7 @@ import { DataDomainDelta } from './DataDomainDelta.js';
|
|
|
9
9
|
*
|
|
10
10
|
* @param msg The generic AI chat message.
|
|
11
11
|
* @returns The parsed in-memory wrapper context message.
|
|
12
|
+
* @deprecated Use `AiModelMessage.processMessageSafe` instead.
|
|
12
13
|
*/
|
|
13
14
|
export function parseAiChatMessage(msg) {
|
|
14
15
|
if (msg.role === 'user') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message_parser.js","sourceRoot":"","sources":["../../../../src/modeling/ai/message_parser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtD
|
|
1
|
+
{"version":3,"file":"message_parser.js","sourceRoot":"","sources":["../../../../src/modeling/ai/message_parser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAoB;IACrD,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACxB,OAAO,GAAoB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AC;aACrB,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;aACrB,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;aACrB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;aACpB,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAC3B,CAAC;AACH,CAAC","sourcesContent":["import type { AiModelMessageWithDelta } from './types.js'\nimport type { AiMessageSchema, AiUserMessage } from '../../models/AiMessage.js'\nimport { DataDomainDelta } from './DataDomainDelta.js'\n\n/**\n * Parses an incoming `AiMessage` and maps it directly into its runtime\n * representations `AiUserMessage` or `AiModelMessageWithDelta`.\n *\n * If the message is a model message, it attempts to parse the structured JSON\n * contents in `msg.text` and sets the `delta` field accordingly. The `text` field\n * is replaced with the reasoning text, or remains original if parsing fails/is omitted.\n *\n * @param msg The generic AI chat message.\n * @returns The parsed in-memory wrapper context message.\n * @deprecated Use `AiModelMessage.processMessageSafe` instead.\n */\nexport function parseAiChatMessage(msg: AiMessageSchema): AiUserMessage | AiModelMessageWithDelta {\n if (msg.role === 'user') {\n return msg as AiUserMessage\n }\n\n const modelMsg = { ...msg } as AiModelMessageWithDelta\n\n // Try to parse the delta structure\n if (modelMsg.state === 'complete' && modelMsg.text) {\n try {\n const parsedJSON = JSON.parse(modelMsg.text)\n modelMsg.delta = parsedJSON.delta ? DataDomainDelta.normalize(parsedJSON.delta) : undefined\n modelMsg.text = parsedJSON.reasoning || modelMsg.text\n } catch {\n // It might legitimately not be valid JSON yet if it crashed mid-stream,\n // fallback to retaining original shape.\n }\n }\n\n return modelMsg\n}\n\n/**\n * When a model response is generated it may contain the `reasoning` property. But because\n * that property might still be generated it might not be a valid JSON. This function checks\n * if the text contains reasoning and returns it if it does.\n * @param text The text to check.\n * @returns The reasoning string if it exists, otherwise undefined.\n */\nexport function detectReasoning(text: string): string | undefined {\n try {\n const parsedJSON = JSON.parse(text)\n return parsedJSON.reasoning\n } catch {\n // Continue below\n }\n\n const searchStr = '\"reasoning\"'\n const keyIndex = text.indexOf(searchStr)\n if (keyIndex === -1) {\n return undefined\n }\n\n const afterKey = text.substring(keyIndex + searchStr.length)\n const colonIndex = afterKey.indexOf(':')\n if (colonIndex === -1) {\n return undefined\n }\n\n const afterColon = afterKey.substring(colonIndex + 1)\n const quoteIndex = afterColon.indexOf('\"')\n if (quoteIndex === -1) {\n return undefined\n }\n\n const valueStr = afterColon.substring(quoteIndex + 1)\n let isEscaped = false\n let endIndex = -1\n\n for (let i = 0; i < valueStr.length; i++) {\n const char = valueStr[i]\n if (char === '\\\\' && !isEscaped) {\n isEscaped = true\n } else if (char === '\"' && !isEscaped) {\n endIndex = i\n break\n } else {\n isEscaped = false\n }\n }\n\n const extracted = endIndex !== -1 ? valueStr.substring(0, endIndex) : valueStr\n\n try {\n // Try to safely parse the literal string value.\n return JSON.parse('\"' + extracted + '\"')\n } catch {\n // string replace fallback\n return extracted\n .replace(/\\\\n/g, '\\n')\n .replace(/\\\\r/g, '\\r')\n .replace(/\\\\t/g, '\\t')\n .replace(/\\\\\"/g, '\"')\n .replace(/\\\\\\\\/g, '\\\\')\n }\n}\n"]}
|
|
@@ -131,16 +131,29 @@ export declare class AiUserMessage extends AiMessageBase<AiUserMessageSchema> im
|
|
|
131
131
|
constructor(input?: Partial<AiUserMessageSchema>);
|
|
132
132
|
toJSON(): AiUserMessageSchema;
|
|
133
133
|
}
|
|
134
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Model messages have the `text` that most likely is a structured JSON
|
|
136
|
+
* with the `delta` and `reasoning` properties. When an `AiModelMessage` is instantiated,
|
|
137
|
+
* it will try to parse the `text` into the `delta` and `reasoning` properties, leaving the
|
|
138
|
+
* `text` property unchanged.
|
|
139
|
+
*
|
|
140
|
+
* The delta object will be different for different models and different use cases.
|
|
141
|
+
* It is up to the model to define the delta object. However, the delta object should
|
|
142
|
+
* be normalized by each child class.
|
|
143
|
+
*
|
|
144
|
+
* @template D The type of the delta.
|
|
145
|
+
*/
|
|
146
|
+
export declare abstract class AiModelMessage<D = unknown> extends AiMessageBase<AiModelMessageSchema> implements AiModelMessageSchema {
|
|
147
|
+
#private;
|
|
135
148
|
state: AiMessageState;
|
|
136
149
|
applied?: boolean;
|
|
137
150
|
thoughts: string;
|
|
138
151
|
/**
|
|
139
|
-
* The delta
|
|
152
|
+
* The extracted delta from the message.
|
|
140
153
|
*/
|
|
141
|
-
delta?:
|
|
154
|
+
delta?: D;
|
|
142
155
|
/**
|
|
143
|
-
* The reasoning
|
|
156
|
+
* The extracted reasoning from the message.
|
|
144
157
|
* Format in markdown.
|
|
145
158
|
*/
|
|
146
159
|
reasoning?: string;
|
|
@@ -154,6 +167,8 @@ export declare class AiModelMessage extends AiMessageBase<AiModelMessageSchema>
|
|
|
154
167
|
addThought(thought?: string): void;
|
|
155
168
|
/**
|
|
156
169
|
* Adds a text chunk to the message. Useful when streaming.
|
|
170
|
+
*
|
|
171
|
+
* Note, this function progressively detects the reasoning on each chunk.
|
|
157
172
|
* @param text The text chunk to add.
|
|
158
173
|
*/
|
|
159
174
|
addText(text?: string): void;
|
|
@@ -168,18 +183,35 @@ export declare class AiModelMessage extends AiMessageBase<AiModelMessageSchema>
|
|
|
168
183
|
* If the message is not valid JSON, it will be ignored.
|
|
169
184
|
*/
|
|
170
185
|
processMessageSafe(): void;
|
|
186
|
+
/**
|
|
187
|
+
* Normalizes the delta to the final shape required by the system.
|
|
188
|
+
*
|
|
189
|
+
* Probabilistic models can produce deltas that are not always what the author expected.
|
|
190
|
+
* For example, the DataDomain delta has `modifiedEntities` property that sometimes is
|
|
191
|
+
* populated multiple times by the same entity. This should be normalized to a single
|
|
192
|
+
* operation so that the UI can correctly render the changes, without an expensive lookup
|
|
193
|
+
* operations. The author of the message model should predict these situations and handle
|
|
194
|
+
* them accordingly.
|
|
195
|
+
*
|
|
196
|
+
* @param delta The delta to normalize.
|
|
197
|
+
* @returns The normalized delta.
|
|
198
|
+
*/
|
|
199
|
+
abstract normalizeDelta(delta: D): D;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* A model message that contains a delta of type `AiDomainDelta`.
|
|
203
|
+
*/
|
|
204
|
+
export declare class AiModelDataDomainMessage extends AiModelMessage<AiDomainDelta> {
|
|
171
205
|
/**
|
|
172
206
|
* Creates an empty model message. Useful when initializing LLM flow.
|
|
173
207
|
* @param session The session key.
|
|
174
208
|
* @returns An empty model message.
|
|
175
209
|
*/
|
|
176
|
-
static createEmpty(session: string):
|
|
210
|
+
static createEmpty(session: string): AiModelDataDomainMessage;
|
|
211
|
+
normalizeDelta(delta: AiDomainDelta): AiDomainDelta;
|
|
177
212
|
}
|
|
178
213
|
/**
|
|
179
214
|
* A union type representing any valid chat message in the AI session history.
|
|
180
215
|
*/
|
|
181
|
-
export type AiMessage = AiUserMessage | AiModelMessage;
|
|
182
|
-
export declare const AiMessageFactory: {
|
|
183
|
-
fromSchema(schema: Partial<AiMessageSchema>): AiMessage;
|
|
184
|
-
};
|
|
216
|
+
export type AiMessage = AiUserMessage | AiModelMessage | AiModelDataDomainMessage;
|
|
185
217
|
//# sourceMappingURL=AiMessage.d.ts.map
|
|
@@ -1 +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;
|
|
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;AAI5D,MAAM,MAAM,aAAa,G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C,oBAAoB,CAAC,GAAG,oBAAoB;gBAWnE,KAAK,GAAE,OAAO,CAAC,oBAAoB,CAAM;IAQ5C,MAAM,IAAI,oBAAoB;IAYvC;;;OAGG;IACH,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAOlC;;;;;OAKG;IACH,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI;IAgB5B;;;;OAIG;IACH,cAAc,IAAI,IAAI;IActB;;;OAGG;IACH,kBAAkB,IAAI,IAAI;IAQ1B;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC;CACrC;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,cAAc,CAAC,aAAa,CAAC;IACzE;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,wBAAwB;IAOpD,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa;CAG7D;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,cAAc,GAAG,wBAAwB,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AiMessageKind } from './kinds.js';
|
|
2
2
|
import { nanoid } from '../nanoid.js';
|
|
3
3
|
import { DataDomainDelta } from '../modeling/ai/DataDomainDelta.js';
|
|
4
|
+
import { detectReasoning } from '../modeling/ai/message_parser.js';
|
|
4
5
|
/**
|
|
5
6
|
* The base class for all AI messages.
|
|
6
7
|
* It provides common functionality for all message types.
|
|
@@ -91,19 +92,32 @@ export class AiUserMessage extends AiMessageBase {
|
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Model messages have the `text` that most likely is a structured JSON
|
|
97
|
+
* with the `delta` and `reasoning` properties. When an `AiModelMessage` is instantiated,
|
|
98
|
+
* it will try to parse the `text` into the `delta` and `reasoning` properties, leaving the
|
|
99
|
+
* `text` property unchanged.
|
|
100
|
+
*
|
|
101
|
+
* The delta object will be different for different models and different use cases.
|
|
102
|
+
* It is up to the model to define the delta object. However, the delta object should
|
|
103
|
+
* be normalized by each child class.
|
|
104
|
+
*
|
|
105
|
+
* @template D The type of the delta.
|
|
106
|
+
*/
|
|
94
107
|
export class AiModelMessage extends AiMessageBase {
|
|
95
108
|
state;
|
|
96
109
|
applied;
|
|
97
110
|
thoughts;
|
|
98
111
|
/**
|
|
99
|
-
* The delta
|
|
112
|
+
* The extracted delta from the message.
|
|
100
113
|
*/
|
|
101
114
|
delta;
|
|
102
115
|
/**
|
|
103
|
-
* The reasoning
|
|
116
|
+
* The extracted reasoning from the message.
|
|
104
117
|
* Format in markdown.
|
|
105
118
|
*/
|
|
106
119
|
reasoning;
|
|
120
|
+
#reasoningEnded = false;
|
|
107
121
|
static createSchema(input) {
|
|
108
122
|
const base = AiMessageBase.createBaseSchema(input);
|
|
109
123
|
return {
|
|
@@ -119,6 +133,7 @@ export class AiModelMessage extends AiMessageBase {
|
|
|
119
133
|
this.state = input.state || 'loading';
|
|
120
134
|
this.applied = input.applied;
|
|
121
135
|
this.thoughts = input.thoughts || '';
|
|
136
|
+
this.processMessageSafe();
|
|
122
137
|
}
|
|
123
138
|
toJSON() {
|
|
124
139
|
const result = {
|
|
@@ -143,6 +158,8 @@ export class AiModelMessage extends AiMessageBase {
|
|
|
143
158
|
}
|
|
144
159
|
/**
|
|
145
160
|
* Adds a text chunk to the message. Useful when streaming.
|
|
161
|
+
*
|
|
162
|
+
* Note, this function progressively detects the reasoning on each chunk.
|
|
146
163
|
* @param text The text chunk to add.
|
|
147
164
|
*/
|
|
148
165
|
addText(text) {
|
|
@@ -150,6 +167,15 @@ export class AiModelMessage extends AiMessageBase {
|
|
|
150
167
|
return;
|
|
151
168
|
}
|
|
152
169
|
this.text += text;
|
|
170
|
+
if (this.#reasoningEnded) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const before = this.reasoning;
|
|
174
|
+
const after = detectReasoning(this.text);
|
|
175
|
+
if (after && after === before) {
|
|
176
|
+
this.#reasoningEnded = true;
|
|
177
|
+
}
|
|
178
|
+
this.reasoning = after;
|
|
153
179
|
}
|
|
154
180
|
/**
|
|
155
181
|
* Processes the message.
|
|
@@ -157,12 +183,13 @@ export class AiModelMessage extends AiMessageBase {
|
|
|
157
183
|
* It sets the delta and reasoning fields, if found in the message.
|
|
158
184
|
*/
|
|
159
185
|
processMessage() {
|
|
160
|
-
|
|
186
|
+
const { text } = this;
|
|
187
|
+
if (!text) {
|
|
161
188
|
return;
|
|
162
189
|
}
|
|
163
|
-
const parsed = JSON.parse(
|
|
190
|
+
const parsed = JSON.parse(text);
|
|
164
191
|
if (parsed.delta) {
|
|
165
|
-
this.delta =
|
|
192
|
+
this.delta = this.normalizeDelta(parsed.delta);
|
|
166
193
|
}
|
|
167
194
|
if (parsed.reasoning) {
|
|
168
195
|
this.reasoning = parsed.reasoning;
|
|
@@ -180,24 +207,24 @@ export class AiModelMessage extends AiMessageBase {
|
|
|
180
207
|
// do nothing
|
|
181
208
|
}
|
|
182
209
|
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* A model message that contains a delta of type `AiDomainDelta`.
|
|
213
|
+
*/
|
|
214
|
+
export class AiModelDataDomainMessage extends AiModelMessage {
|
|
183
215
|
/**
|
|
184
216
|
* Creates an empty model message. Useful when initializing LLM flow.
|
|
185
217
|
* @param session The session key.
|
|
186
218
|
* @returns An empty model message.
|
|
187
219
|
*/
|
|
188
220
|
static createEmpty(session) {
|
|
189
|
-
return new
|
|
221
|
+
return new AiModelDataDomainMessage({
|
|
190
222
|
session,
|
|
191
223
|
state: 'loading',
|
|
192
224
|
});
|
|
193
225
|
}
|
|
226
|
+
normalizeDelta(delta) {
|
|
227
|
+
return DataDomainDelta.normalize(delta);
|
|
228
|
+
}
|
|
194
229
|
}
|
|
195
|
-
export const AiMessageFactory = {
|
|
196
|
-
fromSchema(schema) {
|
|
197
|
-
if (schema.role === 'model') {
|
|
198
|
-
return new AiModelMessage(schema);
|
|
199
|
-
}
|
|
200
|
-
return new AiUserMessage(schema);
|
|
201
|
-
},
|
|
202
|
-
};
|
|
203
230
|
//# sourceMappingURL=AiMessage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiMessage.js","sourceRoot":"","sources":["../../../src/models/AiMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AA0GnE;;;GAGG;AACH,MAAM,OAAgB,aAAa;IAGjC;;OAEG;IACH,MAAM,KAAK,IAAI;QACb,OAAO,aAAa,CAAA;IACtB,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,aAAa,CAAA;IACtB,CAAC;IAED,GAAG,CAAQ;IACX,IAAI,CAAW;IACf,SAAS,CAAQ;IACjB,SAAS,CAAQ;IACjB,OAAO,CAAQ;IACf,IAAI,CAAQ;IACZ,OAAO,CAAS;IAChB,WAAW,CAAY;IAEb,MAAM,CAAC,gBAAgB,CAAC,KAAmC;QACnE,MAAM,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,EAAE,GAAG,KAAK,CAAA;QAClF,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;QAChE,CAAC;QACD,OAAO;YACL,GAAG;YACH,IAAI,EAAE,aAAa;YACnB,OAAO;YACP,IAAI;YACJ,SAAS;YACT,SAAS;SACV,CAAA;IACH,CAAC;IAED,YAAY,QAAoB,EAAE,EAAE,IAAe;QACjD,MAAM,IAAI,GAAG,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;Q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AAI,KAAK,OAAO,EAAE,CAAC;YAC5B,OAAO,IAAI,cAAc,CAAC,MAAuC,CAAC,CAAA;QACpE,CAAC;QACD,OAAO,IAAI,aAAa,CAAC,MAAsC,CAAC,CAAA;IAClE,CAAC;CACF,CAAA","sourcesContent":["import type { IDeletion } from './store/Deletion.js'\nimport { AiMessageKind } from './kinds.js'\nimport { nanoid } from '../nanoid.js'\nimport type { AiDomainDelta } from '../modeling/ai/types.js'\nimport { DataDomainDelta } from '../modeling/ai/DataDomainDelta.js'\n\nexport type AiMessageRole = 'user' | 'model'\nexport type AiMessageState = 'loading' | 'complete' | 'error' | 'terminated'\n\n/**\n * The base interface representing a single message in the domain manipulation chat history.\n * It tracks metadata like timestamps, the associated session, and the raw text content.\n * See `AiUserMessage` and `AiModelMessage` for specific role implementations.\n */\nexport interface AiMessageSchemaBase {\n readonly kind: typeof AiMessageKind\n /**\n * The datastore key of the message.\n */\n key: string\n /**\n * The role of the message.\n */\n role: AiMessageRole\n /**\n * The timestamp of when the message was created.\n */\n createdAt: number\n /**\n * The timestamp of when the message was last updated.\n */\n updatedAt: number\n /**\n * The datastore key of the session.\n */\n session: string\n /**\n * The text of the message.\n */\n text: string\n /**\n * Whether the message is deleted.\n */\n deleted?: boolean\n /**\n * The information about the delete information.\n * Always set when the `deleted` is true.\n */\n deletedInfo?: IDeletion\n}\n\n/**\n * The schema for a user message.\n */\nexport interface AiUserMessageSchema extends AiMessageSchemaBase {\n /**\n * The role of the message.\n */\n role: 'user'\n /**\n * The state of the user message.\n * Can only be `complete`.\n */\n state: 'complete'\n /**\n * The user utterance.\n * Note, the actual message sent to the LLM may be different from the utterance\n * as it has additional instructions and the domain context. However, we are not storing\n * the full message in the datastore, only the utterance.\n */\n text: string\n}\n\n/**\n * The schema for a model message.\n */\nexport interface AiModelMessageSchema extends AiMessageSchemaBase {\n /**\n * The role of the message.\n */\n role: 'model'\n /**\n * The full text of the message returned by the LLM.\n * It is most likely a structured message that needs to be parsed\n * to the corresponding message object.\n */\n text: string\n /**\n * The state of the message.\n * - loading: the message is being generated\n * - complete: the message is complete\n * - error: the message generation failed\n * - terminated: the message generation was terminated by the user\n */\n state: AiMessageState\n /**\n * Whether the message has been applied.\n */\n applied?: boolean\n /**\n * The thoughts of the message.\n */\n thoughts?: string\n}\n\n/**\n * A union type representing any valid chat message in the AI session history.\n */\nexport type AiMessageSchema = AiUserMessageSchema | AiModelMessageSchema\n\n/**\n * The base class for all AI messages.\n * It provides common functionality for all message types.\n */\nexport abstract class AiMessageBase<\n T extends AiMessageSchemaBase = AiMessageSchemaBase,\n> implements AiMessageSchemaBase {\n /**\n * The kind of the schema.\n */\n static get Kind(): typeof AiMessageKind {\n return AiMessageKind\n }\n\n /**\n * The kind of the schema.\n */\n get kind(): typeof AiMessageKind {\n return AiMessageKind\n }\n\n key: string\n role: T['role']\n createdAt: number\n updatedAt: number\n session: string\n text: string\n deleted: boolean\n deletedInfo?: IDeletion\n\n protected static createBaseSchema(input: Partial<AiMessageSchemaBase>): Omit<AiMessageSchemaBase, 'role'> {\n const { key = nanoid(), session, text = '', createdAt = 0, updatedAt = 0 } = input\n if (!session) {\n throw new Error('Session is required to create an AiMessage.')\n }\n return {\n key,\n kind: AiMessageKind,\n session,\n text,\n createdAt,\n updatedAt,\n }\n }\n\n constructor(input: Partial<T> = {}, role: T['role']) {\n const base = AiMessageBase.createBaseSchema(input)\n this.key = base.key\n this.role = role\n this.session = base.session\n this.text = base.text\n this.createdAt = base.createdAt\n this.updatedAt = base.updatedAt\n this.deleted = input.deleted || false\n this.deletedInfo = input.deletedInfo\n }\n\n toJSON(): T {\n const result = {\n kind: this.kind,\n key: this.key,\n role: this.role,\n session: this.session,\n text: this.text,\n createdAt: this.createdAt,\n updatedAt: this.updatedAt,\n }\n if (this.deleted && this.deletedInfo) {\n Object.assign(result, {\n deleted: this.deleted,\n deletedInfo: { ...this.deletedInfo },\n })\n }\n return result as unknown as T\n }\n}\n\nexport class AiUserMessage extends AiMessageBase<AiUserMessageSchema> implements AiUserMessageSchema {\n state: 'complete'\n\n static createSchema(input: Partial<AiUserMessageSchema>): AiUserMessageSchema {\n const base = AiMessageBase.createBaseSchema(input)\n return {\n ...base,\n role: 'user',\n state: 'complete',\n }\n }\n\n constructor(input: Partial<AiUserMessageSchema> = {}) {\n super(input, 'user')\n this.state = 'complete'\n }\n\n override toJSON(): AiUserMessageSchema {\n return {\n ...super.toJSON(),\n state: this.state,\n }\n }\n}\n\nexport class AiModelMessage extends AiMessageBase<AiModelMessageSchema> implements AiModelMessageSchema {\n state: AiMessageState\n applied?: boolean\n thoughts: string\n\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 static createSchema(input: Partial<AiModelMessageSchema>): AiModelMessageSchema {\n const base = AiMessageBase.createBaseSchema(input)\n return {\n ...base,\n role: 'model',\n state: input.state || 'loading',\n applied: input.applied,\n thoughts: input.thoughts || '',\n }\n }\n\n constructor(input: Partial<AiModelMessageSchema> = {}) {\n super(input, 'model')\n this.state = input.state || 'loading'\n this.applied = input.applied\n this.thoughts = input.thoughts || ''\n }\n\n override toJSON(): AiModelMessageSchema {\n const result: AiModelMessageSchema = {\n ...super.toJSON(),\n state: this.state,\n thoughts: this.thoughts,\n }\n if (this.applied !== undefined) {\n result.applied = this.applied\n }\n return result\n }\n\n /**\n * Adds a thought to the message. Useful when streaming.\n * @param thought The thought to add.\n */\n addThought(thought?: string): void {\n if (!thought) {\n return\n }\n this.thoughts += thought\n }\n\n /**\n * Adds a text chunk to the message. Useful when streaming.\n * @param text The text chunk to add.\n */\n addText(text?: string): void {\n if (!text) {\n return\n }\n this.text += text\n }\n\n /**\n * Processes the message.\n * If the message is not valid JSON, it will throw an error.\n * It sets the delta and reasoning fields, if found in the message.\n */\n processMessage(): void {\n if (!this.text) {\n return\n }\n const parsed = JSON.parse(this.text)\n if (parsed.delta) {\n this.delta = DataDomainDelta.normalize(parsed.delta)\n }\n if (parsed.reasoning) {\n this.reasoning = parsed.reasoning\n }\n }\n\n /**\n * Processes the message safely.\n * If the message is not valid JSON, it will be ignored.\n */\n processMessageSafe(): void {\n try {\n this.processMessage()\n } catch {\n // do nothing\n }\n }\n\n /**\n * Creates an empty model message. Useful when initializing LLM flow.\n * @param session The session key.\n * @returns An empty model message.\n */\n static createEmpty(session: string): AiModelMessage {\n return new AiModelMessage({\n session,\n state: 'loading',\n })\n }\n}\n\n/**\n * A union type representing any valid chat message in the AI session history.\n */\nexport type AiMessage = AiUserMessage | AiModelMessage\n\nexport const AiMessageFactory = {\n fromSchema(schema: Partial<AiMessageSchema>): AiMessage {\n if (schema.role === 'model') {\n return new AiModelMessage(schema as Partial<AiModelMessageSchema>)\n }\n return new AiUserMessage(schema as Partial<AiUserMessageSchema>)\n },\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AiMessage.js","sourceRoot":"","sources":["../../../src/models/AiMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AA0GlE;;;GAGG;AACH,MAAM,OAAgB,aAAa;IAGjC;;OAEG;IACH,MAAM,KAAK,IAAI;QACb,OAAO,aAAa,CAAA;IACtB,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,aAAa,CAAA;IACtB,CAAC;IAED,GAAG,CAAQ;IACX,IAAI,CAAW;IACf,SAAS,CAAQ;IACjB,SAAS,CAAQ;IACjB,OAAO,CAAQ;IACf,IAAI,CAAQ;IACZ,OAAO,CAAS;IAChB,WAAW,CAAY;IAEb,MAAM,CAAC,gBAAgB,CAAC,KAAmC;QACnE,MAAM,EAAE,GAAG,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE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CAAC;IAED;;;;OAIG;IACH,cAAc;QACZ,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;QACrB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAM;QACR,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC/B,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAChD,CAAC;QACD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QACnC,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,kBAAkB;QAChB,IAAI,CAAC;YACH,IAAI,CAAC,cAAc,EAAE,CAAA;QACvB,CAAC;QAAC,MAAM,CAAC;YACP,aAAa;QACf,CAAC;IACH,CAAC;CAgBF;AAED;;GAEG;AACH,MAAM,OAAO,wBAAyB,SAAQ,cAA6B;IACzE;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC,OAAe;QAChC,OAAO,IAAI,wBAAwB,CAAC;YAClC,OAAO;YACP,KAAK,EAAE,SAAS;SACjB,CAAC,CAAA;IACJ,CAAC;IAEQ,cAAc,CAAC,KAAoB;QAC1C,OAAO,eAAe,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACzC,CAAC;CACF","sourcesContent":["import type { IDeletion } from './store/Deletion.js'\nimport { AiMessageKind } from './kinds.js'\nimport { nanoid } from '../nanoid.js'\nimport type { AiDomainDelta } from '../modeling/ai/types.js'\nimport { DataDomainDelta } from '../modeling/ai/DataDomainDelta.js'\nimport { detectReasoning } from '../modeling/ai/message_parser.js'\n\nexport type AiMessageRole = 'user' | 'model'\nexport type AiMessageState = 'loading' | 'complete' | 'error' | 'terminated'\n\n/**\n * The base interface representing a single message in the domain manipulation chat history.\n * It tracks metadata like timestamps, the associated session, and the raw text content.\n * See `AiUserMessage` and `AiModelMessage` for specific role implementations.\n */\nexport interface AiMessageSchemaBase {\n readonly kind: typeof AiMessageKind\n /**\n * The datastore key of the message.\n */\n key: string\n /**\n * The role of the message.\n */\n role: AiMessageRole\n /**\n * The timestamp of when the message was created.\n */\n createdAt: number\n /**\n * The timestamp of when the message was last updated.\n */\n updatedAt: number\n /**\n * The datastore key of the session.\n */\n session: string\n /**\n * The text of the message.\n */\n text: string\n /**\n * Whether the message is deleted.\n */\n deleted?: boolean\n /**\n * The information about the delete information.\n * Always set when the `deleted` is true.\n */\n deletedInfo?: IDeletion\n}\n\n/**\n * The schema for a user message.\n */\nexport interface AiUserMessageSchema extends AiMessageSchemaBase {\n /**\n * The role of the message.\n */\n role: 'user'\n /**\n * The state of the user message.\n * Can only be `complete`.\n */\n state: 'complete'\n /**\n * The user utterance.\n * Note, the actual message sent to the LLM may be different from the utterance\n * as it has additional instructions and the domain context. However, we are not storing\n * the full message in the datastore, only the utterance.\n */\n text: string\n}\n\n/**\n * The schema for a model message.\n */\nexport interface AiModelMessageSchema extends AiMessageSchemaBase {\n /**\n * The role of the message.\n */\n role: 'model'\n /**\n * The full text of the message returned by the LLM.\n * It is most likely a structured message that needs to be parsed\n * to the corresponding message object.\n */\n text: string\n /**\n * The state of the message.\n * - loading: the message is being generated\n * - complete: the message is complete\n * - error: the message generation failed\n * - terminated: the message generation was terminated by the user\n */\n state: AiMessageState\n /**\n * Whether the message has been applied.\n */\n applied?: boolean\n /**\n * The thoughts of the message.\n */\n thoughts?: string\n}\n\n/**\n * A union type representing any valid chat message in the AI session history.\n */\nexport type AiMessageSchema = AiUserMessageSchema | AiModelMessageSchema\n\n/**\n * The base class for all AI messages.\n * It provides common functionality for all message types.\n */\nexport abstract class AiMessageBase<\n T extends AiMessageSchemaBase = AiMessageSchemaBase,\n> implements AiMessageSchemaBase {\n /**\n * The kind of the schema.\n */\n static get Kind(): typeof AiMessageKind {\n return AiMessageKind\n }\n\n /**\n * The kind of the schema.\n */\n get kind(): typeof AiMessageKind {\n return AiMessageKind\n }\n\n key: string\n role: T['role']\n createdAt: number\n updatedAt: number\n session: string\n text: string\n deleted: boolean\n deletedInfo?: IDeletion\n\n protected static createBaseSchema(input: Partial<AiMessageSchemaBase>): Omit<AiMessageSchemaBase, 'role'> {\n const { key = nanoid(), session, text = '', createdAt = 0, updatedAt = 0 } = input\n if (!session) {\n throw new Error('Session is required to create an AiMessage.')\n }\n return {\n key,\n kind: AiMessageKind,\n session,\n text,\n createdAt,\n updatedAt,\n }\n }\n\n constructor(input: Partial<T> = {}, role: T['role']) {\n const base = AiMessageBase.createBaseSchema(input)\n this.key = base.key\n this.role = role\n this.session = base.session\n this.text = base.text\n this.createdAt = base.createdAt\n this.updatedAt = base.updatedAt\n this.deleted = input.deleted || false\n this.deletedInfo = input.deletedInfo\n }\n\n toJSON(): T {\n const result = {\n kind: this.kind,\n key: this.key,\n role: this.role,\n session: this.session,\n text: this.text,\n createdAt: this.createdAt,\n updatedAt: this.updatedAt,\n }\n if (this.deleted && this.deletedInfo) {\n Object.assign(result, {\n deleted: this.deleted,\n deletedInfo: { ...this.deletedInfo },\n })\n }\n return result as unknown as T\n }\n}\n\nexport class AiUserMessage extends AiMessageBase<AiUserMessageSchema> implements AiUserMessageSchema {\n state: 'complete'\n\n static createSchema(input: Partial<AiUserMessageSchema>): AiUserMessageSchema {\n const base = AiMessageBase.createBaseSchema(input)\n return {\n ...base,\n role: 'user',\n state: 'complete',\n }\n }\n\n constructor(input: Partial<AiUserMessageSchema> = {}) {\n super(input, 'user')\n this.state = 'complete'\n }\n\n override toJSON(): AiUserMessageSchema {\n return {\n ...super.toJSON(),\n state: this.state,\n }\n }\n}\n\n/**\n * Model messages have the `text` that most likely is a structured JSON\n * with the `delta` and `reasoning` properties. When an `AiModelMessage` is instantiated,\n * it will try to parse the `text` into the `delta` and `reasoning` properties, leaving the\n * `text` property unchanged.\n *\n * The delta object will be different for different models and different use cases.\n * It is up to the model to define the delta object. However, the delta object should\n * be normalized by each child class.\n *\n * @template D The type of the delta.\n */\nexport abstract class AiModelMessage<D = unknown>\n extends AiMessageBase<AiModelMessageSchema>\n implements AiModelMessageSchema\n{\n state: AiMessageState\n applied?: boolean\n thoughts: string\n\n /**\n * The extracted delta from the message.\n */\n delta?: D\n\n /**\n * The extracted reasoning from the message.\n * Format in markdown.\n */\n reasoning?: string\n\n #reasoningEnded = false\n\n static createSchema(input: Partial<AiModelMessageSchema>): AiModelMessageSchema {\n const base = AiMessageBase.createBaseSchema(input)\n return {\n ...base,\n role: 'model',\n state: input.state || 'loading',\n applied: input.applied,\n thoughts: input.thoughts || '',\n }\n }\n\n constructor(input: Partial<AiModelMessageSchema> = {}) {\n super(input, 'model')\n this.state = input.state || 'loading'\n this.applied = input.applied\n this.thoughts = input.thoughts || ''\n this.processMessageSafe()\n }\n\n override toJSON(): AiModelMessageSchema {\n const result: AiModelMessageSchema = {\n ...super.toJSON(),\n state: this.state,\n thoughts: this.thoughts,\n }\n if (this.applied !== undefined) {\n result.applied = this.applied\n }\n return result\n }\n\n /**\n * Adds a thought to the message. Useful when streaming.\n * @param thought The thought to add.\n */\n addThought(thought?: string): void {\n if (!thought) {\n return\n }\n this.thoughts += thought\n }\n\n /**\n * Adds a text chunk to the message. Useful when streaming.\n *\n * Note, this function progressively detects the reasoning on each chunk.\n * @param text The text chunk to add.\n */\n addText(text?: string): void {\n if (!text) {\n return\n }\n this.text += text\n if (this.#reasoningEnded) {\n return\n }\n const before = this.reasoning\n const after = detectReasoning(this.text)\n if (after && after === before) {\n this.#reasoningEnded = true\n }\n this.reasoning = after\n }\n\n /**\n * Processes the message.\n * If the message is not valid JSON, it will throw an error.\n * It sets the delta and reasoning fields, if found in the message.\n */\n processMessage(): void {\n const { text } = this\n if (!text) {\n return\n }\n const parsed = JSON.parse(text)\n if (parsed.delta) {\n this.delta = this.normalizeDelta(parsed.delta)\n }\n if (parsed.reasoning) {\n this.reasoning = parsed.reasoning\n }\n }\n\n /**\n * Processes the message safely.\n * If the message is not valid JSON, it will be ignored.\n */\n processMessageSafe(): void {\n try {\n this.processMessage()\n } catch {\n // do nothing\n }\n }\n\n /**\n * Normalizes the delta to the final shape required by the system.\n *\n * Probabilistic models can produce deltas that are not always what the author expected.\n * For example, the DataDomain delta has `modifiedEntities` property that sometimes is\n * populated multiple times by the same entity. This should be normalized to a single\n * operation so that the UI can correctly render the changes, without an expensive lookup\n * operations. The author of the message model should predict these situations and handle\n * them accordingly.\n *\n * @param delta The delta to normalize.\n * @returns The normalized delta.\n */\n abstract normalizeDelta(delta: D): D\n}\n\n/**\n * A model message that contains a delta of type `AiDomainDelta`.\n */\nexport class AiModelDataDomainMessage extends AiModelMessage<AiDomainDelta> {\n /**\n * Creates an empty model message. Useful when initializing LLM flow.\n * @param session The session key.\n * @returns An empty model message.\n */\n static createEmpty(session: string): AiModelDataDomainMessage {\n return new AiModelDataDomainMessage({\n session,\n state: 'loading',\n })\n }\n\n override normalizeDelta(delta: AiDomainDelta): AiDomainDelta {\n return DataDomainDelta.normalize(delta)\n }\n}\n\n/**\n * A union type representing any valid chat message in the AI session history.\n */\nexport type AiMessage = AiUserMessage | AiModelMessage | AiModelDataDomainMessage\n"]}
|