Classes
Methods
# addContradictionInPlace(investigation, contradiction) → {Partial.<IInvestigation>}
Adds a contradiction to a specific field in an investigation.
Parameters:
| Name | Type | Description |
|---|---|---|
investigation |
Partial.<IInvestigation>
|
The investigation object to update. |
contradiction |
IContradictionInput
|
The details of the contradiction to add. |
- If the field is not found in the investigation.
Error
- The investigation object with the updated contradiction.
Partial.<IInvestigation>
# async cloneInvestigation(investigationId) → {Promise.<IInvestigation>}
Clones the current investigation by adding a "copy_N" postfix to its identifier.
Parameters:
| Name | Type | Description |
|---|---|---|
investigationId |
string
|
The ID of the current investigation to clone. |
- If an error occurs during the cloning process.
Error
- The cloned investigation object.
Promise.<IInvestigation>
# async createInvestigation(createDto) → {Promise.<IInvestigation>}
Creates a new investigation.
Parameters:
| Name | Type | Description |
|---|---|---|
createDto |
ICreateInvestigationDto
|
The data required to create the investigation. |
- The created investigation.
Promise.<IInvestigation>
# async deleteInvestigationById(investigationId) → {Promise.<IDeleteInvestigationByIdResponse>}
Permanently deletes an investigation and its related chat history.
Parameters:
| Name | Type | Description |
|---|---|---|
investigationId |
string
|
The ID of the investigation to delete. |
- If an error occurs during the deletion process.
Error
- An object summarizing the deletion status of the investigation and related chats.
Promise.<IDeleteInvestigationByIdResponse>
# deleteInvestigationData(investigation) → {IInvestigation}
Deletes the data of a given investigation.
Parameters:
| Name | Type | Description |
|---|---|---|
investigation |
IInvestigation
|
The investigation to clear. |
- If an error occurs during the deletion process.
Error
- The investigation object with its values emptied.
IInvestigation
# async ensureInvestigationAuthor(investigationId, authorId) → {Promise.<(IInvestigation|null)>}
Ensures that the author of a given investigation is set.
If the investigation exists and does not already have a valid author, this method sets the author
to the provided authorId and updates the dateModified field.
Parameters:
| Name | Type | Description |
|---|---|---|
investigationId |
string
|
The ID of the investigation to check. |
authorId |
Types.ObjectId
|
The ObjectId of the author to set. |
If there is an error during the process of fetching or saving the investigation.
Error
- The updated investigation object, or
nullif the investigation does not exist or already has a valid author.
Promise.<(IInvestigation|null)>
# async generateInvestigation(message, history, investigationMetadata) → {Promise.<(IAssistantInvestigationFormat|null)>}
Generates an entire investigation based on the provided metadata. If the investigation is not found, it throws an error.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string
|
The user's message from which the lesson must be detected. |
history |
FormattedHistory
|
The chat history between the user and the assistant. |
investigationMetadata |
string
|
The metadata of the investigation. |
- If the investigation is not found.
Error
- The generated investigation.
Promise.<(IAssistantInvestigationFormat|null)>
# async generateInvestigationObjects(message, history, investigationMetadata, investigation) → {Promise.<(IAssistantInvestigationFormat|null)>}
Generates objects of investigation based on the provided metadata and plain investigation. If the objects are not found, it throws an error.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string
|
The user's message from which the lesson must be detected. |
history |
string
|
The chat history between the user and the assistant. |
investigationMetadata |
string
|
The metadata of the investigation. |
investigation |
string
|
The plain investigation without steps and objects with yaml format. |
- If the objects are not found.
Error
- The generated objects of the provided investigation.
Promise.<(IAssistantInvestigationFormat|null)>
# async generateInvestigationSteps(message, history, investigationMetadata, investigation) → {Promise.<(IAssistantInvestigationFormat|null)>}
Generates steps of investigation based on the provided metadata and the provided investigation. If the steps are not found, it throws an error.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string
|
The user's message from which the lesson must be detected. |
history |
string
|
The chat history between the user and the assistant. |
investigationMetadata |
string
|
The metadata of the investigation. |
investigation |
string
|
The provided investigation without steps with yaml format. |
- If the steps are not found.
Error
- The generated steps of the provided investigation.
Promise.<(IAssistantInvestigationFormat|null)>
# async generateInvestigationWithoutStepsAndObjects(message, history, investigationMetadata) → {Promise.<(IAssistantInvestigationFormat|null)>}
Generates an investigation without steps and objects based on the provided metadata. If the investigation is not found, it throws an error.
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string
|
The user's message from which the lesson must be detected. |
history |
string
|
The chat history between the user and the assistant. |
investigationMetadata |
string
|
The metadata of the investigation. |
- If the investigation is not found.
Error
- The generated investigation without steps and objects.
Promise.<(IAssistantInvestigationFormat|null)>
# async getFieldHistory(investigationId, fieldPath, limit) → {Promise.<{fieldPath: string, history: Array.<unknown>, totalCount: number}>}
Gets the history for a specific field in an investigation.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
investigationId |
string
|
The ID of the investigation. |
|
fieldPath |
string
|
The path to the field (e.g., "title", "steps.0.title", "objects.0.name"). |
|
limit |
number
|
50 | Maximum number of history entries to return (default: 50). |
If the investigation is not found.
Error
The field history.
Promise.<{fieldPath: string, history: Array.<unknown>, totalCount: number}>
# async getInvestigationById(investigationId) → {Promise.<IInvestigation>}
Retrieves a single investigation by its ID.
Parameters:
| Name | Type | Description |
|---|---|---|
investigationId |
string
|
The ID of the investigation to retrieve. |
If the investigation is not found.
Error
- The investigation data.
Promise.<IInvestigation>
# async getInvestigationVersions(investigationId, limit) → {Promise.<IInvestigationVersionListResponse>}
Gets the versions of an investigation.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
investigationId |
string
|
The ID of the investigation. |
|
limit |
number
|
20 | The number of versions to return (default: 20). |
If the investigation is not found.
Error
- The investigation versions.
Promise.<IInvestigationVersionListResponse>
# async getInvestigations(searchDto) → {Promise.<IInvestigationListResponseDto>}
Retrieves investigations with pagination, grouped by curriculum.
Parameters:
| Name | Type | Description |
|---|---|---|
searchDto |
IInvestigationSearchDto
|
The search and pagination parameters. |
- The paginated investigations grouped by curriculum.
Promise.<IInvestigationListResponseDto>
# async redoInvestigation(investigationId) → {Promise.<IInvestigation>}
Redo investigation - increment currentVersionIndex and return investigation at that version
Parameters:
| Name | Type | Description |
|---|---|---|
investigationId |
string
|
The ID of the investigation. |
If the investigation is not found or if the index is out of bounds.
Error
- The investigation at the new index.
Promise.<IInvestigation>
# async regenerateOtherFields(investigationId, fieldName, updatedBy, historyopt) → {Promise.<IInvestigation>}
Regenerates other fields in an investigation based on a specific field. This operation uses a 3-step process: text fields → objects → steps.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
investigationId |
string
|
The ID of the investigation to update. |
||
fieldName |
string
|
The name of the field to base regeneration on (e.g., "title", "curriculum", "objectives"). |
||
updatedBy |
Types.ObjectId
|
null
|
null | The user making the change (optional). |
|
history |
string
|
<optional> |
- | Chat history in YAML format (optional, defaults to "-"). |
If the investigation is not found or the field is invalid.
Error
- The updated investigation.
Promise.<IInvestigation>
# async regenerateOtherFieldsObjects(fieldName, fieldValue, investigation, investigationMetadata, historyopt, contradictionInfoopt) → {Promise.<(IAssistantInvestigationFormat|null)>}
Regenerates objects based on regenerated text fields. This is Step 2 of the 3-step regeneration process.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
fieldName |
string
|
The name of the field to base regeneration on. |
||
fieldValue |
string
|
The value of the field to base regeneration on. |
||
investigation |
string
|
The regenerated investigation from Step 1 (YAML format). |
||
investigationMetadata |
string
|
The metadata/guide in YAML format. |
||
history |
string
|
<optional> |
- | Chat history in YAML format (optional, defaults to "-"). |
contradictionInfo |
object
|
<optional> |
Optional contradiction information. |
|
contradictionReason |
string
|
null
|
<optional> |
Reason for contradiction. |
|
targetFieldName |
string
|
null
|
<optional> |
Target field name for contradiction. |
|
isContradicting |
boolean
|
<optional> |
Whether the field is contradicting. |
If the prompt is not found or regeneration fails.
Error
- The regenerated objects only.
Promise.<(IAssistantInvestigationFormat|null)>
# async regenerateOtherFieldsSteps(fieldName, fieldValue, investigation, investigationMetadata, historyopt, contradictionInfoopt) → {Promise.<(IAssistantInvestigationFormat|null)>}
Regenerates steps based on regenerated text fields and objects. This is Step 3 of the 3-step regeneration process.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
fieldName |
string
|
The name of the field to base regeneration on. |
||
fieldValue |
string
|
The value of the field to base regeneration on. |
||
investigation |
string
|
The regenerated investigation from Step 1 + Step 2 (YAML format). |
||
investigationMetadata |
string
|
The metadata/guide in YAML format. |
||
history |
string
|
<optional> |
- | Chat history in YAML format (optional, defaults to "-"). |
contradictionInfo |
object
|
<optional> |
Optional contradiction information. |
|
contradictionReason |
string
|
null
|
<optional> |
Reason for contradiction. |
|
targetFieldName |
string
|
null
|
<optional> |
Target field name for contradiction. |
|
isContradicting |
boolean
|
<optional> |
Whether the field is contradicting. |
If the prompt is not found or regeneration fails.
Error
- The regenerated steps only.
Promise.<(IAssistantInvestigationFormat|null)>
# async regenerateOtherFieldsWithoutStepsAndObjects(fieldName, fieldValue, investigation, investigationMetadata, historyopt, contradictionInfoopt) → {Promise.<(IAssistantInvestigationFormat|null)>}
Regenerates text fields (without steps and objects) based on a specific field value. This is Step 1 of the 3-step regeneration process.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
fieldName |
string
|
The name of the field to base regeneration on. |
||
fieldValue |
string
|
The value of the field to base regeneration on. |
||
investigation |
string
|
The current investigation in YAML format. |
||
investigationMetadata |
string
|
The metadata/guide in YAML format. |
||
history |
string
|
<optional> |
- | Chat history in YAML format (optional, defaults to "-"). |
contradictionInfo |
object
|
<optional> |
Optional contradiction information. |
|
contradictionReason |
string
|
null
|
<optional> |
Reason for contradiction. |
|
targetFieldName |
string
|
null
|
<optional> |
Target field name for contradiction. |
|
isContradicting |
boolean
|
<optional> |
Whether the field is contradicting. |
If the prompt is not found or regeneration fails.
Error
- The regenerated text fields only.
Promise.<(IAssistantInvestigationFormat|null)>
# removeAiGeneratedValues(obj)
Recursively sets all aiGeneratedValue fields to null.
This method is schema-agnostic and works regardless of changes to the investigation structure.
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
Record.<string, unknown>
|
The object whose |
# async undoInvestigation(investigationId) → {Promise.<IInvestigation>}
Undo investigation - decrement currentVersionIndex and return investigation at that version
Parameters:
| Name | Type | Description |
|---|---|---|
investigationId |
string
|
The ID of the investigation. |
If the investigation is not found or if the index is out of bounds.
Error
- The investigation at the new index.
Promise.<IInvestigation>
# async updateInvestigation(investigationId, updateData, obj) → {Promise.<IUpdateInvestigationResponse>}
Updates an investigation using the new API format.
Parameters:
| Name | Type | Description |
|---|---|---|
investigationId |
string
|
The ID of the investigation to update. |
updateData |
IUpdateInvestigationDto
|
The update data in the new format, including string/number fields and step updates. |
obj |
object
|
Optional object used to determine if the update data should be built from scratch. |
needsBuildUpdate |
boolean
|
Whether the update data should be built from scratch. |
updatedBy |
Types.ObjectId
|
null
|
The user making the change (optional). |
isAiGenerated |
boolean
|
Whether this update is AI-generated (default: false). |
skipVersioning |
boolean
|
Whether to skip versioning (default: false). |
If the investigation is not found or is locked.
Error
- The result of the update operation.
Promise.<IUpdateInvestigationResponse>
# async updateInvestigationByVersion(oldInvestigation, investigation, userId, isUserChangeExist) → {Promise.<IInvestigation>}
Updates investigation by adding new version.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
oldInvestigation |
IInvestigation
|
The latest investigation version. |
|
investigation |
IInvestigation
|
The entire investigation model. |
|
userId |
ObjectId
|
null
|
The ID of the user. |
|
isUserChangeExist |
boolean
|
false | Whether the change was made by the user (true) or AI (false). Defaults to false. |
- If an error occurs during the update process.
Error
- An investigation updated with new version.
Promise.<IInvestigation>