Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H-2206, H-2242: Support entities with multiple types in frontend, everywhere else #5312

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2515612
typos
CiaranMn Sep 20, 2024
174189f
update @blockprotocol/graph for multi-type entities
CiaranMn Sep 20, 2024
af127ad
update @local/hash-graph-types and @local/hash-graph-sdk for multi-tyโ€ฆ
CiaranMn Sep 20, 2024
c7a7e2f
update @local/hash-subgraph and @local/hash-isomorphic-utils for multโ€ฆ
CiaranMn Sep 20, 2024
a85e4cc
regenerate system types for multi-type entities
CiaranMn Sep 20, 2024
82135a7
mostly update @apps/hash-api for multi-type entities
CiaranMn Sep 20, 2024
514072d
update @apps/hash-integration-worker for multi-type entities
CiaranMn Sep 20, 2024
2e12afa
mostly update @local/hash-backend-utils for multi-type entities
CiaranMn Sep 20, 2024
27da66e
update GraphQL schema for multi-type entities
CiaranMn Sep 20, 2024
fe5046d
type weaks in @local/hash-graph-sdk|types
CiaranMn Sep 20, 2024
6c73e11
update isPageEntityTypeId -> includesPageEntityTypeId
CiaranMn Sep 20, 2024
2c85511
wip: update frontend for multi-type entities
CiaranMn Sep 20, 2024
c316bd6
more updates to frontend for multitype entities
CiaranMn Sep 23, 2024
194a093
update AI worker for multi-type entities
CiaranMn Sep 25, 2024
4393abe
update tests for multi-type entities
CiaranMn Sep 25, 2024
1385ced
misc updates for multi-type entities
CiaranMn Sep 25, 2024
95c7790
lint fixes
CiaranMn Sep 25, 2024
8e4cded
add UI for showing / adding / removing multiple types on an entity
CiaranMn Sep 25, 2024
5f8a39e
wip: update change modal
CiaranMn Sep 27, 2024
2ce276d
more FE multitype entities changes
CiaranMn Sep 27, 2024
99763af
handle showing multiple link types on link entity
CiaranMn Sep 30, 2024
c32f696
bug fixes in entities table rendering
CiaranMn Sep 30, 2024
54dc286
prevent changing entity types before the entity is created
CiaranMn Sep 30, 2024
24d52b2
Merge branch 'main' into cm/multi-type-entities
CiaranMn Sep 30, 2024
233d25f
Merge branch 'main' into cm/multi-type-entities
CiaranMn Oct 4, 2024
b5d0835
bug / lint fixes. todo comments
CiaranMn Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ blocks/**/.env
**/dist
**/build
**/target
**/pkg

# vscode config
**/.vscode/settings.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const inferEntitiesFromContentAction: FlowActionActivity = async ({

return {
localEntityId: localIdToEntityId[proposal.entityId]!,
entityTypeId: entityTypeId as VersionedUrl,
entityTypeIds: [entityTypeId as VersionedUrl],
claims: {
isObjectOf: [],
isSubjectOf: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ export const persistEntitiesAction: FlowActionActivity = async ({ inputs }) => {
*/
const entitiesWithDependenciesSortedLast = proposedEntities.toSorted(
(a, b) => {
const isAFileEntity = fileEntityTypeIds.includes(a.entityTypeId);
const isBFileEntity = fileEntityTypeIds.includes(b.entityTypeId);
const isAFileEntity = a.entityTypeIds.some((entityTypeId) =>
fileEntityTypeIds.includes(entityTypeId),
);
const isBFileEntity = b.entityTypeIds.some((entityTypeId) =>
fileEntityTypeIds.includes(entityTypeId),
);
if (isAFileEntity && !isBFileEntity) {
return -1;
} else if (isBFileEntity && !isAFileEntity) {
Expand Down Expand Up @@ -75,7 +79,7 @@ export const persistEntitiesAction: FlowActionActivity = async ({ inputs }) => {
for (const unresolvedEntity of entitiesWithDependenciesSortedLast) {
const {
claims,
entityTypeId,
entityTypeIds,
localEntityId,
properties,
provenance,
Expand All @@ -86,7 +90,7 @@ export const persistEntitiesAction: FlowActionActivity = async ({ inputs }) => {

const entityWithResolvedLinks: ProposedEntityWithResolvedLinks = {
claims,
entityTypeId,
entityTypeIds,
localEntityId,
properties,
propertyMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const persistEntityAction: FlowActionActivity = async ({ inputs }) => {
const createEditionAsDraft = draft ?? false;

const {
entityTypeId,
entityTypeIds,
localEntityId,
claims,
properties,
Expand All @@ -80,7 +80,7 @@ export const persistEntityAction: FlowActionActivity = async ({ inputs }) => {
CreateEntityParameters,
"relationships" | "ownedById" | "draft" | "linkData"
> & { linkData: Entity["linkData"] } = {
entityTypeId,
entityTypeIds,
properties: mergePropertyObjectAndMetadata(properties, propertyMetadata),
linkData,
provenance,
Expand Down Expand Up @@ -114,7 +114,9 @@ export const persistEntityAction: FlowActionActivity = async ({ inputs }) => {
* by looking up the entity type's parents in the graph, rather than
* relying on a hardcoded value.
*/
const isFileEntity = fileEntityTypeIds.includes(entityTypeId);
const isFileEntity = entityTypeIds.some((entityTypeId) =>
fileEntityTypeIds.includes(entityTypeId),
);

const fileUrl = isFileEntity
? (properties as Partial<FileProperties>)[
Expand All @@ -134,7 +136,7 @@ export const persistEntityAction: FlowActionActivity = async ({ inputs }) => {
url: fileUrl,
propertyMetadata,
provenance,
entityTypeId,
entityTypeIds,
});

if (getFileEntityFromUrlStatus.status !== "ok") {
Expand Down Expand Up @@ -305,12 +307,15 @@ export const persistEntityAction: FlowActionActivity = async ({ inputs }) => {
includeDrafts: draft,
});

const entityTypeId =
`https://hash.ai/@hash/types/entity-type/${linkType}/v/1` as const;

return LinkEntity.create<T extends "has-subject" ? HasSubject : HasObject>(
graphApiClient,
{ actorId: webBotActorId },
{
draft,
entityTypeId: `https://hash.ai/@hash/types/entity-type/${linkType}/v/1`,
entityTypeIds: [entityTypeId],
ownedById: webId,
provenance: {
...claim.metadata.provenance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const persistFlowActivity = async (
await Entity.create<FlowRun>(graphApiClient, userAuthentication, {
ownedById: webId,
entityUuid: flowRunId,
entityTypeId: systemEntityTypes.flowRun.entityTypeId,
entityTypeIds: [systemEntityTypes.flowRun.entityTypeId],
properties: flowRunProperties,
provenance,
draft: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ const parseAndResolveCoordinatorInputs = async (params: {
graphApiClient,
entityTypeIds: [
...entityTypeIds!,
...(existingEntities?.map(({ metadata }) => metadata.entityTypeId) ?? []),
...(existingEntities?.flatMap(({ metadata }) => metadata.entityTypeIds) ??
[]),
].filter((entityTypeId, index, all) => all.indexOf(entityTypeId) === index),
actorId: userAuthentication.actorId,
});
Expand Down Expand Up @@ -502,7 +503,7 @@ export const runCoordinatingAgent: FlowActionActivity<{
*/
propertyMetadata: { value: {} },
provenance: fileEditionProvenance,
entityTypeId,
entityTypeIds: [entityTypeId],
localEntityId: entityIdFromComponents(
webId,
generateUuid() as EntityUuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ export const generateProgressReport = (params: {
.map((proposedEntity) =>
simplifyProposedEntityForLlmConsumption({
proposedEntity,
entityType:
allDereferencedEntityTypesById[proposedEntity.entityTypeId]!,
entityTypes: proposedEntity.entityTypeIds.map(
(entityTypeId) => allDereferencedEntityTypesById[entityTypeId]!,
),
}),
)
.join("\n")}
Expand All @@ -69,8 +70,9 @@ export const generateProgressReport = (params: {
.map((proposedLink) =>
simplifyProposedEntityForLlmConsumption({
proposedEntity: proposedLink,
entityType:
allDereferencedEntityTypesById[proposedLink.entityTypeId]!,
entityTypes: proposedLink.entityTypeIds.map(
(entityTypeId) => allDereferencedEntityTypesById[entityTypeId]!,
),
}),
)
.join("\n")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export const processCompleteToolCall = ({

const missingEntityTypes = input.entityTypes.filter(
({ $id }) =>
!submittedEntities.some(({ entityTypeId }) => entityTypeId === $id),
!submittedEntities.some(({ entityTypeIds }) =>
entityTypeIds.includes($id),
),
);

if (missingEntityTypes.length > 0) {
Expand All @@ -99,7 +101,9 @@ export const processCompleteToolCall = ({

const missingLinkEntityTypes = input.linkEntityTypes?.filter(
({ $id }) =>
!submittedEntities.some(({ entityTypeId }) => entityTypeId === $id),
!submittedEntities.some(({ entityTypeIds }) =>
entityTypeIds.includes($id),
),
);

if (missingLinkEntityTypes && missingLinkEntityTypes.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { simplifyEntity } from "../../../shared/simplify-entity.js";

export type ExistingEntitySummary = {
entityId: EntityId;
entityTypeId: VersionedUrl;
entityTypeIds: [VersionedUrl, ...VersionedUrl[]];
name: string;
summary: string;
};
Expand Down Expand Up @@ -142,7 +142,7 @@ export const summarizeExistingEntities = async (params: {

validEntitySummaries.push({
entityId: existingEntity.metadata.recordId.entityId,
entityTypeId: existingEntity.metadata.entityTypeId,
entityTypeIds: existingEntity.metadata.entityTypeIds,
name,
summary,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ const generateUserMessage = (
<Entities>
Here is the information about entities you have already gathered:
${JSON.stringify(
entitySummaries.map(({ localId, name, summary, entityTypeId }) => {
entitySummaries.map(({ localId, name, summary, entityTypeIds }) => {
const claimsAboutEntity = claimsGathered.filter(
(claim) => claim.subjectEntityLocalId === localId,
);

return {
name,
summary,
entityType: entityTypeId,
entityTypes: entityTypeIds,
claims: JSON.stringify(
claimsAboutEntity.map(simplifyClaimForLlmConsumption),
),
Expand Down
Loading
Loading