paperclip-plugin-supermemory-otomatik 0.2.4 → 0.2.6

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/dist/worker.js CHANGED
@@ -44579,6 +44579,8 @@ var plugin = definePlugin({
44579
44579
  ctx.actions.register("memory-assignment-save", async (params, actionCtx) => {
44580
44580
  const companyId = actionCompany(params, actionCtx);
44581
44581
  const actorUserId = await ownerFor(ctx, companyId, actionCtx);
44582
+ const assignmentId = typeof params.assignmentId === "string" ? params.assignmentId.trim() : "";
44583
+ const previousAssignment = assignmentId ? await requireAssignment(ctx, companyId, assignmentId) : null;
44582
44584
  const scopeType = params.scopeType;
44583
44585
  const scopeId = typeof params.scopeId === "string" ? params.scopeId.trim() : "";
44584
44586
  const label2 = typeof params.label === "string" ? params.label.trim().slice(0, 180) : "";
@@ -44591,8 +44593,12 @@ var plugin = definePlugin({
44591
44593
  ]);
44592
44594
  if (!scope) throw new Error("L\u2019agente o progetto selezionato non appartiene a questa organizzazione.");
44593
44595
  if (authorizedAgents.some((agent) => !agent || agent.status === "terminated" || agent.status === "pending_approval")) throw new Error("Tutti gli agenti autorizzati devono essere attivi e appartenere a questa organizzazione.");
44594
- const namespace = assignmentNamespace(companyId, scopeType, scopeId);
44595
44596
  const externalId = `${scopeType}:${scopeId}`;
44597
+ const targetRows = await ctx.entities.list({ entityType: ASSIGNMENT_ENTITY, scopeKind: "company", scopeId: companyId, externalId, limit: 1 });
44598
+ if (targetRows[0] && targetRows[0].id !== previousAssignment?.id) {
44599
+ throw new Error("Questo agente o progetto ha gi\xE0 un\u2019assegnazione. Apri quella esistente per modificarla.");
44600
+ }
44601
+ const namespace = previousAssignment?.namespace ?? assignmentNamespace(companyId, scopeType, scopeId);
44596
44602
  const row = await ctx.entities.upsert({
44597
44603
  entityType: ASSIGNMENT_ENTITY,
44598
44604
  scopeKind: "company",
@@ -44602,6 +44608,40 @@ var plugin = definePlugin({
44602
44608
  status: "active",
44603
44609
  data: { companyId, scopeType, scopeId, label: label2, namespace, authorizedAgentIds, updatedBy: actorUserId, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }
44604
44610
  });
44611
+ if (previousAssignment && `${previousAssignment.scopeType}:${previousAssignment.scopeId}` !== externalId) {
44612
+ const previousRows = await ctx.entities.list({
44613
+ entityType: ASSIGNMENT_ENTITY,
44614
+ scopeKind: "company",
44615
+ scopeId: companyId,
44616
+ externalId: `${previousAssignment.scopeType}:${previousAssignment.scopeId}`,
44617
+ limit: 1
44618
+ });
44619
+ const previousRow = previousRows.find((candidate) => candidate.id === previousAssignment.id);
44620
+ if (previousRow) {
44621
+ await ctx.entities.upsert({
44622
+ entityType: ASSIGNMENT_ENTITY,
44623
+ scopeKind: "company",
44624
+ scopeId: companyId,
44625
+ externalId: `${previousAssignment.scopeType}:${previousAssignment.scopeId}`,
44626
+ title: previousRow.title ?? void 0,
44627
+ status: "disabled",
44628
+ data: { ...isRecord(previousRow.data) ? previousRow.data : {}, updatedBy: actorUserId, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }
44629
+ });
44630
+ }
44631
+ const documents = await ctx.entities.list({ entityType: DOCUMENT_ENTITY, scopeKind: "company", scopeId: companyId, limit: 500 });
44632
+ for (const document2 of documents) {
44633
+ if (!isRecord(document2.data) || document2.data.assignmentId !== previousAssignment.id) continue;
44634
+ await ctx.entities.upsert({
44635
+ entityType: DOCUMENT_ENTITY,
44636
+ scopeKind: "company",
44637
+ scopeId: companyId,
44638
+ externalId: document2.externalId ?? void 0,
44639
+ title: document2.title ?? void 0,
44640
+ status: document2.status ?? "active",
44641
+ data: { ...document2.data, assignmentId: row.id }
44642
+ });
44643
+ }
44644
+ }
44605
44645
  return assignmentFromEntity(row, companyId);
44606
44646
  });
44607
44647
  ctx.actions.register("memory-assignment-disable", async (params, actionCtx) => {