diff --git a/apps/hash-ai-worker-ts/README.md b/apps/hash-ai-worker-ts/README.md index fd9d5ee4767..c5b73a43c03 100644 --- a/apps/hash-ai-worker-ts/README.md +++ b/apps/hash-ai-worker-ts/README.md @@ -25,6 +25,7 @@ The service uses the following environment variables: ### Run the worker +- To use actions which require Google Cloud Platform, you must run `gcloud auth application-default login` before starting the worker. - Ensure the environment variables above are set, either in `.env.local` or in your shell. - Install dependencies: - `yarn` diff --git a/apps/hash-ai-worker-ts/package.json b/apps/hash-ai-worker-ts/package.json index e78a761becc..b1c9872955e 100644 --- a/apps/hash-ai-worker-ts/package.json +++ b/apps/hash-ai-worker-ts/package.json @@ -38,6 +38,7 @@ "start:healthcheck": "wait-on --timeout 120000 http-get://localhost:4100/health", "start:test": "NODE_ENV=test NODE_OPTIONS=--max-old-space-size=2048 node ./dist/main.js", "start:test:healthcheck": "wait-on --timeout 120000 http-get://localhost:4100/health", + "temporal:clean": "temporal workflow terminate --query \"TaskQueue='ai'\" --reason=\"Batch terminate from CLI\"", "test:unit": "vitest --run --exclude \"**/*.ai.test.ts\"" }, "dependencies": { diff --git a/apps/hash-ai-worker-ts/src/activities/flow-activities/persist-entities-action.ts b/apps/hash-ai-worker-ts/src/activities/flow-activities/persist-entities-action.ts index b2207393867..668d04b4010 100644 --- a/apps/hash-ai-worker-ts/src/activities/flow-activities/persist-entities-action.ts +++ b/apps/hash-ai-worker-ts/src/activities/flow-activities/persist-entities-action.ts @@ -191,7 +191,9 @@ export const persistEntitiesAction: FlowActionActivity = async ({ inputs }) => { if (!output) { failedEntitiesByLocalId[unresolvedEntity.localEntityId] = { proposedEntity: unresolvedEntity, - message: `No outputs returned when attempting to persist entity`, + message: + persistedEntityOutputs.message ?? + `No outputs returned when attempting to persist entity`, }; continue; } diff --git a/apps/hash-ai-worker-ts/src/activities/flow-activities/persist-entity-action.ts b/apps/hash-ai-worker-ts/src/activities/flow-activities/persist-entity-action.ts index 12123beae1c..1968d38bd18 100644 --- a/apps/hash-ai-worker-ts/src/activities/flow-activities/persist-entity-action.ts +++ b/apps/hash-ai-worker-ts/src/activities/flow-activities/persist-entity-action.ts @@ -185,21 +185,26 @@ export const persistEntityAction: FlowActionActivity = async ({ inputs }) => { }); /** - * In practice we don't reassign existingEntity anywhere below it doesn't harm to make sure it will always + * In practice we don't reassign matchedEntityUpdate anywhere below it doesn't harm to make sure it will always * be the same thing in the backOff function. */ - const stableReferenceToExistingEntity = - matchedEntityUpdate.existingEntity; + const stableReferenceToMatchedEntity = matchedEntityUpdate; entity = await backOff( () => - stableReferenceToExistingEntity.patch( + stableReferenceToMatchedEntity.existingEntity.patch( graphApiClient, { actorId: webBotActorId }, { - ...entityValues, + entityTypeIds: + stableReferenceToMatchedEntity.newValues.entityTypeIds, draft: existingEntityIsDraft ? true : createEditionAsDraft, propertyPatches: patchOperations, + provenance: { + ...entityValues.provenance, + sources: + stableReferenceToMatchedEntity.newValues.editionSources, + }, }, ), { diff --git a/apps/hash-ai-worker-ts/src/activities/shared/find-existing-entity.ts b/apps/hash-ai-worker-ts/src/activities/shared/find-existing-entity.ts index 83645c89449..359744b389b 100644 --- a/apps/hash-ai-worker-ts/src/activities/shared/find-existing-entity.ts +++ b/apps/hash-ai-worker-ts/src/activities/shared/find-existing-entity.ts @@ -217,14 +217,13 @@ export const findExistingEntity = async ({ }, ], }, - limit: 3, temporalAxes: currentTimeInstantTemporalAxes, includeDrafts, }) .then(({ data: response }) => - response.entities.map((entity) => - mapGraphApiEntityToEntity(entity, actorId), - ), + response.entities + .slice(0, 3) + .map((entity) => mapGraphApiEntityToEntity(entity, actorId)), ); } @@ -253,14 +252,13 @@ export const findExistingEntity = async ({ }, ], }, - limit: 3, temporalAxes: currentTimeInstantTemporalAxes, includeDrafts, }) .then(({ data: response }) => - response.entities.map((entity) => - mapGraphApiEntityToEntity(entity, actorId), - ), + response.entities + .slice(0, 3) + .map((entity) => mapGraphApiEntityToEntity(entity, actorId)), ); } } @@ -309,7 +307,10 @@ export const findExistingLinkEntity = async ({ { equal: [{ path: ["archived"] }, { parameter: false }] }, { any: proposedEntity.entityTypeIds.map((entityTypeId) => ({ - equal: [{ path: ["versionedUrl"] }, { parameter: entityTypeId }], + equal: [ + { path: ["type", "versionedUrl"] }, + { parameter: entityTypeId }, + ], })), }, {