@ixo/editor 5.29.0 → 5.31.0

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.
@@ -7647,420 +7647,88 @@ var createUcanService = (config) => {
7647
7647
  };
7648
7648
  };
7649
7649
 
7650
- // src/core/lib/ucanDelegationStore.ts
7651
- var ROOT_DELEGATION_KEY = "__root__";
7652
- var STORE_VERSION_KEY = "__version__";
7653
- var CURRENT_VERSION = 2;
7654
- var isValidEntry = (value) => {
7655
- if (!value || typeof value !== "object") return false;
7656
- const entry = value;
7657
- return entry.v === CURRENT_VERSION && entry.data !== void 0;
7650
+ // src/core/lib/flowEngine/utils.ts
7651
+ var buildAuthzFromProps = (props) => {
7652
+ const linkedClaimCollectionId = typeof props.linkedClaimCollectionId === "string" ? props.linkedClaimCollectionId.trim() : "";
7653
+ const authz = {};
7654
+ if (linkedClaimCollectionId) {
7655
+ authz.linkedClaim = { collectionId: linkedClaimCollectionId };
7656
+ }
7657
+ return authz;
7658
7658
  };
7659
- var isReservedKey = (key) => key === ROOT_DELEGATION_KEY || key === STORE_VERSION_KEY;
7660
- var createUcanDelegationStore = (yMap) => {
7661
- const get = (cid) => {
7662
- if (isReservedKey(cid)) return null;
7663
- const raw = yMap.get(cid);
7664
- if (!raw) return null;
7665
- if (isValidEntry(raw)) return raw.data;
7666
- return null;
7667
- };
7668
- const set = (delegation) => {
7669
- const entry = { v: CURRENT_VERSION, data: delegation };
7670
- yMap.set(delegation.cid, entry);
7671
- };
7672
- const remove = (cid) => {
7673
- yMap.delete(cid);
7674
- };
7675
- const has = (cid) => {
7676
- return yMap.has(cid) && !isReservedKey(cid);
7677
- };
7678
- const getRoot = () => {
7679
- const rootCid = yMap.get(ROOT_DELEGATION_KEY);
7680
- if (!rootCid) return null;
7681
- return get(rootCid);
7682
- };
7683
- const setRootCid = (cid) => {
7684
- yMap.set(ROOT_DELEGATION_KEY, cid);
7685
- };
7686
- const getRootCid = () => {
7687
- return yMap.get(ROOT_DELEGATION_KEY) || null;
7688
- };
7689
- const getAll = () => {
7690
- const delegations = [];
7691
- yMap.forEach((value, key) => {
7692
- if (isReservedKey(key)) return;
7693
- if (isValidEntry(value)) {
7694
- delegations.push(value.data);
7695
- }
7696
- });
7697
- return delegations;
7698
- };
7699
- const getByAudience = (audienceDid) => {
7700
- return getAll().filter((d) => d.audienceDid === audienceDid);
7701
- };
7702
- const getByIssuer = (issuerDid) => {
7703
- return getAll().filter((d) => d.issuerDid === issuerDid);
7704
- };
7705
- const findByCapability = (can, withUri) => {
7706
- return getAll().filter(
7707
- (d) => d.capabilities.some((c) => {
7708
- if (c.can === can && c.with === withUri) return true;
7709
- if (c.can === "*" || c.can === "flow/*") return true;
7710
- if (c.can.endsWith("/*")) {
7711
- const prefix = c.can.slice(0, -1);
7712
- if (can.startsWith(prefix)) return true;
7713
- }
7714
- if (c.with === "*") return true;
7715
- if (c.with.endsWith("*")) {
7716
- const prefix = c.with.slice(0, -1);
7717
- if (withUri.startsWith(prefix)) return true;
7718
- }
7719
- return false;
7720
- })
7721
- );
7659
+ var buildFlowNodeFromBlock = (block) => {
7660
+ const base = {
7661
+ id: block.id,
7662
+ type: block.type,
7663
+ props: block.props || {}
7722
7664
  };
7665
+ const authz = buildAuthzFromProps(block.props || {});
7723
7666
  return {
7724
- get,
7725
- set,
7726
- remove,
7727
- has,
7728
- getRoot,
7729
- setRootCid,
7730
- getRootCid,
7731
- getAll,
7732
- getByAudience,
7733
- getByIssuer,
7734
- findByCapability
7667
+ ...base,
7668
+ ...authz
7735
7669
  };
7736
7670
  };
7737
- var createMemoryUcanDelegationStore = () => {
7738
- const store = /* @__PURE__ */ new Map();
7739
- const get = (cid) => {
7740
- if (isReservedKey(cid)) return null;
7741
- const raw = store.get(cid);
7742
- if (!raw) return null;
7743
- if (isValidEntry(raw)) return raw.data;
7744
- return null;
7745
- };
7746
- const set = (delegation) => {
7747
- const entry = { v: CURRENT_VERSION, data: delegation };
7748
- store.set(delegation.cid, entry);
7749
- };
7750
- const remove = (cid) => {
7751
- store.delete(cid);
7752
- };
7753
- const has = (cid) => {
7754
- return store.has(cid) && !isReservedKey(cid);
7755
- };
7756
- const getRoot = () => {
7757
- const rootCid = store.get(ROOT_DELEGATION_KEY);
7758
- if (!rootCid) return null;
7759
- return get(rootCid);
7760
- };
7761
- const setRootCid = (cid) => {
7762
- store.set(ROOT_DELEGATION_KEY, cid);
7763
- };
7764
- const getRootCid = () => {
7765
- return store.get(ROOT_DELEGATION_KEY) || null;
7766
- };
7767
- const getAll = () => {
7768
- const delegations = [];
7769
- store.forEach((value, key) => {
7770
- if (isReservedKey(key)) return;
7771
- if (isValidEntry(value)) {
7772
- delegations.push(value.data);
7773
- }
7774
- });
7775
- return delegations;
7776
- };
7777
- const getByAudience = (audienceDid) => {
7778
- return getAll().filter((d) => d.audienceDid === audienceDid);
7779
- };
7780
- const getByIssuer = (issuerDid) => {
7781
- return getAll().filter((d) => d.issuerDid === issuerDid);
7782
- };
7783
- const findByCapability = (can, withUri) => {
7784
- return getAll().filter(
7785
- (d) => d.capabilities.some((c) => {
7786
- if (c.can === can && c.with === withUri) return true;
7787
- if (c.can === "*" || c.can === "flow/*") return true;
7788
- if (c.can.endsWith("/*")) {
7789
- const prefix = c.can.slice(0, -1);
7790
- if (can.startsWith(prefix)) return true;
7791
- }
7792
- if (c.with === "*") return true;
7793
- if (c.with.endsWith("*")) {
7794
- const prefix = c.with.slice(0, -1);
7795
- if (withUri.startsWith(prefix)) return true;
7796
- }
7797
- return false;
7798
- })
7799
- );
7671
+
7672
+ // src/core/lib/flowEngine/runtime.ts
7673
+ var XERO_WORK_ITEMS_MAP_NAME = "xeroWorkItems";
7674
+ var XERO_CONNECTION_MAP_NAME = "xeroConnection";
7675
+ var ensureStateObject = (value) => {
7676
+ if (!value || typeof value !== "object") {
7677
+ return {};
7678
+ }
7679
+ return { ...value };
7680
+ };
7681
+ var createYMapManager = (map) => {
7682
+ return {
7683
+ get: (nodeId) => {
7684
+ const stored = map.get(nodeId);
7685
+ return ensureStateObject(stored);
7686
+ },
7687
+ update: (nodeId, updates) => {
7688
+ const current = ensureStateObject(map.get(nodeId));
7689
+ map.set(nodeId, { ...current, ...updates });
7690
+ }
7800
7691
  };
7692
+ };
7693
+ var createMemoryManager = () => {
7694
+ const memory = /* @__PURE__ */ new Map();
7801
7695
  return {
7802
- get,
7803
- set,
7804
- remove,
7805
- has,
7806
- getRoot,
7807
- setRootCid,
7808
- getRootCid,
7809
- getAll,
7810
- getByAudience,
7811
- getByIssuer,
7812
- findByCapability
7696
+ get: (nodeId) => ensureStateObject(memory.get(nodeId)),
7697
+ update: (nodeId, updates) => {
7698
+ const current = ensureStateObject(memory.get(nodeId));
7699
+ memory.set(nodeId, { ...current, ...updates });
7700
+ }
7813
7701
  };
7814
7702
  };
7815
-
7816
- // src/core/lib/invocationStore.ts
7817
- var createInvocationStore = (yMap) => {
7818
- const add = (invocation) => {
7819
- yMap.set(invocation.cid, invocation);
7820
- };
7821
- const get = (cid) => {
7822
- const raw = yMap.get(cid);
7823
- if (!raw || typeof raw !== "object") return null;
7824
- return raw;
7825
- };
7826
- const remove = (cid) => {
7827
- yMap.delete(cid);
7828
- };
7829
- const getAll = () => {
7830
- const invocations = [];
7831
- yMap.forEach((value) => {
7832
- if (value && typeof value === "object" && "cid" in value) {
7833
- invocations.push(value);
7834
- }
7835
- });
7836
- return invocations.sort((a, b) => b.executedAt - a.executedAt);
7837
- };
7838
- const getByInvoker = (invokerDid) => {
7839
- return getAll().filter((i) => i.invokerDid === invokerDid);
7840
- };
7841
- const getByFlow = (flowId) => {
7842
- return getAll().filter((i) => i.flowId === flowId);
7843
- };
7844
- const getByBlock = (flowId, blockId) => {
7845
- return getAll().filter((i) => i.flowId === flowId && i.blockId === blockId);
7846
- };
7847
- const getByCapability = (can, withUri) => {
7848
- return getAll().filter((i) => i.capability.can === can && i.capability.with === withUri);
7849
- };
7850
- const hasBeenInvoked = (cid) => {
7851
- return yMap.has(cid);
7852
- };
7853
- const getInDateRange = (startMs, endMs) => {
7854
- return getAll().filter((i) => i.executedAt >= startMs && i.executedAt <= endMs);
7855
- };
7856
- const getSuccessful = () => {
7857
- return getAll().filter((i) => i.result === "success");
7858
- };
7859
- const getFailures = () => {
7860
- return getAll().filter((i) => i.result === "failure");
7861
- };
7862
- const getPendingSubmission = () => {
7863
- return getAll().filter((i) => i.result === "success" && !i.transactionHash);
7864
- };
7865
- const markSubmitted = (cid, transactionHash) => {
7866
- const invocation = get(cid);
7867
- if (invocation) {
7868
- const updated = {
7869
- ...invocation,
7870
- transactionHash
7871
- };
7872
- yMap.set(cid, updated);
7873
- }
7874
- };
7875
- const getCount = () => {
7876
- return getAll().length;
7877
- };
7878
- const getCountByResult = () => {
7879
- const all = getAll();
7880
- return {
7881
- success: all.filter((i) => i.result === "success").length,
7882
- failure: all.filter((i) => i.result === "failure").length
7883
- };
7884
- };
7885
- return {
7886
- add,
7887
- get,
7888
- remove,
7889
- getAll,
7890
- getByInvoker,
7891
- getByFlow,
7892
- getByBlock,
7893
- getByCapability,
7894
- hasBeenInvoked,
7895
- getInDateRange,
7896
- getSuccessful,
7897
- getFailures,
7898
- getPendingSubmission,
7899
- markSubmitted,
7900
- getCount,
7901
- getCountByResult
7902
- };
7903
- };
7904
- var createMemoryInvocationStore = () => {
7905
- const store = /* @__PURE__ */ new Map();
7906
- const add = (invocation) => {
7907
- store.set(invocation.cid, invocation);
7908
- };
7909
- const get = (cid) => {
7910
- return store.get(cid) || null;
7911
- };
7912
- const remove = (cid) => {
7913
- store.delete(cid);
7914
- };
7915
- const getAll = () => {
7916
- const invocations = Array.from(store.values());
7917
- return invocations.sort((a, b) => b.executedAt - a.executedAt);
7918
- };
7919
- const getByInvoker = (invokerDid) => {
7920
- return getAll().filter((i) => i.invokerDid === invokerDid);
7921
- };
7922
- const getByFlow = (flowId) => {
7923
- return getAll().filter((i) => i.flowId === flowId);
7924
- };
7925
- const getByBlock = (flowId, blockId) => {
7926
- return getAll().filter((i) => i.flowId === flowId && i.blockId === blockId);
7927
- };
7928
- const getByCapability = (can, withUri) => {
7929
- return getAll().filter((i) => i.capability.can === can && i.capability.with === withUri);
7930
- };
7931
- const hasBeenInvoked = (cid) => {
7932
- return store.has(cid);
7933
- };
7934
- const getInDateRange = (startMs, endMs) => {
7935
- return getAll().filter((i) => i.executedAt >= startMs && i.executedAt <= endMs);
7936
- };
7937
- const getSuccessful = () => {
7938
- return getAll().filter((i) => i.result === "success");
7939
- };
7940
- const getFailures = () => {
7941
- return getAll().filter((i) => i.result === "failure");
7942
- };
7943
- const getPendingSubmission = () => {
7944
- return getAll().filter((i) => i.result === "success" && !i.transactionHash);
7945
- };
7946
- const markSubmitted = (cid, transactionHash) => {
7947
- const invocation = get(cid);
7948
- if (invocation) {
7949
- store.set(cid, { ...invocation, transactionHash });
7950
- }
7951
- };
7952
- const getCount = () => {
7953
- return store.size;
7954
- };
7955
- const getCountByResult = () => {
7956
- const all = getAll();
7957
- return {
7958
- success: all.filter((i) => i.result === "success").length,
7959
- failure: all.filter((i) => i.result === "failure").length
7960
- };
7961
- };
7962
- return {
7963
- add,
7964
- get,
7965
- remove,
7966
- getAll,
7967
- getByInvoker,
7968
- getByFlow,
7969
- getByBlock,
7970
- getByCapability,
7971
- hasBeenInvoked,
7972
- getInDateRange,
7973
- getSuccessful,
7974
- getFailures,
7975
- getPendingSubmission,
7976
- markSubmitted,
7977
- getCount,
7978
- getCountByResult
7979
- };
7980
- };
7981
-
7982
- // src/core/lib/flowEngine/utils.ts
7983
- var buildAuthzFromProps = (props) => {
7984
- const linkedClaimCollectionId = typeof props.linkedClaimCollectionId === "string" ? props.linkedClaimCollectionId.trim() : "";
7985
- const authz = {};
7986
- if (linkedClaimCollectionId) {
7987
- authz.linkedClaim = { collectionId: linkedClaimCollectionId };
7988
- }
7989
- return authz;
7990
- };
7991
- var buildFlowNodeFromBlock = (block) => {
7992
- const base = {
7993
- id: block.id,
7994
- type: block.type,
7995
- props: block.props || {}
7996
- };
7997
- const authz = buildAuthzFromProps(block.props || {});
7998
- return {
7999
- ...base,
8000
- ...authz
8001
- };
8002
- };
8003
-
8004
- // src/core/lib/flowEngine/runtime.ts
8005
- var XERO_WORK_ITEMS_MAP_NAME = "xeroWorkItems";
8006
- var XERO_CONNECTION_MAP_NAME = "xeroConnection";
8007
- var ensureStateObject = (value) => {
8008
- if (!value || typeof value !== "object") {
8009
- return {};
8010
- }
8011
- return { ...value };
8012
- };
8013
- var createYMapManager = (map) => {
8014
- return {
8015
- get: (nodeId) => {
8016
- const stored = map.get(nodeId);
8017
- return ensureStateObject(stored);
8018
- },
8019
- update: (nodeId, updates) => {
8020
- const current = ensureStateObject(map.get(nodeId));
8021
- map.set(nodeId, { ...current, ...updates });
8022
- }
8023
- };
8024
- };
8025
- var createMemoryManager = () => {
8026
- const memory = /* @__PURE__ */ new Map();
8027
- return {
8028
- get: (nodeId) => ensureStateObject(memory.get(nodeId)),
8029
- update: (nodeId, updates) => {
8030
- const current = ensureStateObject(memory.get(nodeId));
8031
- memory.set(nodeId, { ...current, ...updates });
8032
- }
8033
- };
8034
- };
8035
- var createRuntimeStateManager = (editor) => {
8036
- if (editor?._yRuntime) {
8037
- return createYMapManager(editor._yRuntime);
8038
- }
8039
- return createMemoryManager();
8040
- };
8041
- var createYDocRuntimeManager = (yDoc) => {
8042
- return createYMapManager(yDoc.getMap("runtime"));
8043
- };
8044
- function clearRuntimeForTemplateClone(yDoc) {
8045
- const runtime = yDoc.getMap("runtime");
8046
- const invocations = yDoc.getMap("invocations");
8047
- const pendingInvocations = yDoc.getMap("pendingInvocations");
8048
- const agentOutbox = yDoc.getMap("agentOutbox");
8049
- const agentLeases = yDoc.getMap("agentLeases");
8050
- const auditTrail = yDoc.getMap("auditTrail");
8051
- const xeroWorkItems = yDoc.getMap(XERO_WORK_ITEMS_MAP_NAME);
8052
- const xeroConnection = yDoc.getMap(XERO_CONNECTION_MAP_NAME);
8053
- yDoc.transact(() => {
8054
- runtime.forEach((_, key) => runtime.delete(key));
8055
- invocations.forEach((_, key) => invocations.delete(key));
8056
- pendingInvocations.forEach((_, key) => pendingInvocations.delete(key));
8057
- agentOutbox.forEach((_, key) => agentOutbox.delete(key));
8058
- agentLeases.forEach((_, key) => agentLeases.delete(key));
8059
- auditTrail.forEach((_, key) => auditTrail.delete(key));
8060
- xeroWorkItems.forEach((_, key) => xeroWorkItems.delete(key));
8061
- xeroConnection.forEach((_, key) => xeroConnection.delete(key));
8062
- });
8063
- }
7703
+ var createRuntimeStateManager = (editor) => {
7704
+ if (editor?._yRuntime) {
7705
+ return createYMapManager(editor._yRuntime);
7706
+ }
7707
+ return createMemoryManager();
7708
+ };
7709
+ var createYDocRuntimeManager = (yDoc) => {
7710
+ return createYMapManager(yDoc.getMap("runtime"));
7711
+ };
7712
+ function clearRuntimeForTemplateClone(yDoc) {
7713
+ const runtime = yDoc.getMap("runtime");
7714
+ const invocations = yDoc.getMap("invocations");
7715
+ const pendingInvocations = yDoc.getMap("pendingInvocations");
7716
+ const agentOutbox = yDoc.getMap("agentOutbox");
7717
+ const agentLeases = yDoc.getMap("agentLeases");
7718
+ const auditTrail = yDoc.getMap("auditTrail");
7719
+ const xeroWorkItems = yDoc.getMap(XERO_WORK_ITEMS_MAP_NAME);
7720
+ const xeroConnection = yDoc.getMap(XERO_CONNECTION_MAP_NAME);
7721
+ yDoc.transact(() => {
7722
+ runtime.forEach((_, key) => runtime.delete(key));
7723
+ invocations.forEach((_, key) => invocations.delete(key));
7724
+ pendingInvocations.forEach((_, key) => pendingInvocations.delete(key));
7725
+ agentOutbox.forEach((_, key) => agentOutbox.delete(key));
7726
+ agentLeases.forEach((_, key) => agentLeases.delete(key));
7727
+ auditTrail.forEach((_, key) => auditTrail.delete(key));
7728
+ xeroWorkItems.forEach((_, key) => xeroWorkItems.delete(key));
7729
+ xeroConnection.forEach((_, key) => xeroConnection.delete(key));
7730
+ });
7731
+ }
8064
7732
 
8065
7733
  // src/core/types/baseUcan.ts
8066
7734
  function isRuntimeRef(value) {
@@ -8703,105 +8371,437 @@ function processBarrierRunRecord(yDoc, sourceBlockId, record, barrierListenersBy
8703
8371
  pendingPayload: { ...existing, ...event.payload || {} }
8704
8372
  });
8705
8373
  }
8706
- const allSources = trigger.sources || [];
8707
- const currentState = readBarrierState(yDoc, listenerBlockId);
8708
- const requiredSources = allSources.filter((s) => s.optional !== true);
8709
- const gatingSources = requiredSources.length > 0 ? requiredSources : allSources;
8710
- const allFired = gatingSources.length > 0 && gatingSources.every((s) => currentState.some((e) => e.sourceBlockId === s.sourceBlockId && e.eventName === s.eventName));
8711
- if (!allFired) continue;
8712
- const assigneeDid = resolveAssignee(listenerBlock) || "unassigned";
8713
- const id = computeBarrierInvocationId(currentState, listenerBlockId);
8714
- const mergedPayload = mergeBarrierPayloads(currentState);
8715
- const inputs = parseInputs(listenerBlock);
8716
- const refSnapshots = snapshotInputRefs(inputs, getNodeOutput2);
8717
- const expiresAt = computeExpiry(listenerBlock, record.completedAt);
8718
- const invocation = {
8719
- id,
8720
- triggeringBlockId: sourceBlockId,
8721
- sourceRunId: record.runId,
8722
- eventName: `barrier:${allSources.map((s) => s.alias).join("+")}`,
8723
- eventIndex: 0,
8724
- payload: mergedPayload,
8725
- refSnapshots,
8726
- assigneeDid,
8727
- emittedAt: record.completedAt,
8728
- expiresAt
8374
+ const allSources = trigger.sources || [];
8375
+ const currentState = readBarrierState(yDoc, listenerBlockId);
8376
+ const requiredSources = allSources.filter((s) => s.optional !== true);
8377
+ const gatingSources = requiredSources.length > 0 ? requiredSources : allSources;
8378
+ const allFired = gatingSources.length > 0 && gatingSources.every((s) => currentState.some((e) => e.sourceBlockId === s.sourceBlockId && e.eventName === s.eventName));
8379
+ if (!allFired) continue;
8380
+ const assigneeDid = resolveAssignee(listenerBlock) || "unassigned";
8381
+ const id = computeBarrierInvocationId(currentState, listenerBlockId);
8382
+ const mergedPayload = mergeBarrierPayloads(currentState);
8383
+ const inputs = parseInputs(listenerBlock);
8384
+ const refSnapshots = snapshotInputRefs(inputs, getNodeOutput2);
8385
+ const expiresAt = computeExpiry(listenerBlock, record.completedAt);
8386
+ const invocation = {
8387
+ id,
8388
+ triggeringBlockId: sourceBlockId,
8389
+ sourceRunId: record.runId,
8390
+ eventName: `barrier:${allSources.map((s) => s.alias).join("+")}`,
8391
+ eventIndex: 0,
8392
+ payload: mergedPayload,
8393
+ refSnapshots,
8394
+ assigneeDid,
8395
+ emittedAt: record.completedAt,
8396
+ expiresAt
8397
+ };
8398
+ queuePendingInvocation(yDoc, listenerBlockId, invocation);
8399
+ clearBarrierState(yDoc, listenerBlockId);
8400
+ if (runtimeMap) {
8401
+ const prev = runtimeMap.get(listenerBlockId) || {};
8402
+ runtimeMap.set(listenerBlockId, {
8403
+ ...prev,
8404
+ pendingPayload: { ...mergedPayload, ...refSnapshots }
8405
+ });
8406
+ }
8407
+ }
8408
+ }
8409
+ }
8410
+ function parseTrigger(block) {
8411
+ const raw = block?.props?.trigger;
8412
+ if (!raw || typeof raw !== "string") return null;
8413
+ try {
8414
+ const parsed = JSON.parse(raw);
8415
+ if (parsed && typeof parsed === "object" && typeof parsed.type === "string") {
8416
+ return parsed;
8417
+ }
8418
+ } catch {
8419
+ }
8420
+ return null;
8421
+ }
8422
+ function parseInputs(block) {
8423
+ const raw = block?.props?.inputs;
8424
+ if (!raw || typeof raw !== "string") return {};
8425
+ try {
8426
+ const parsed = JSON.parse(raw);
8427
+ if (parsed && typeof parsed === "object") return parsed;
8428
+ } catch {
8429
+ }
8430
+ return {};
8431
+ }
8432
+ function resolveAssignee(block) {
8433
+ const raw = block?.props?.assignment;
8434
+ if (!raw) return void 0;
8435
+ try {
8436
+ const parsed = typeof raw === "string" ? JSON.parse(raw) : raw;
8437
+ const did = parsed?.assignedActor?.did;
8438
+ return typeof did === "string" && did.length > 0 ? did : void 0;
8439
+ } catch {
8440
+ return void 0;
8441
+ }
8442
+ }
8443
+ function computeExpiry(block, emittedAt) {
8444
+ const ttlAbsolute = block?.props?.ttlAbsoluteDueDate;
8445
+ if (typeof ttlAbsolute === "string" && ttlAbsolute) {
8446
+ return ttlAbsolute;
8447
+ }
8448
+ const ttlFromEnablement = block?.props?.ttlFromEnablement;
8449
+ if (typeof ttlFromEnablement === "string" && ttlFromEnablement) {
8450
+ const ms = parseIsoDurationToMs(ttlFromEnablement);
8451
+ if (ms != null) {
8452
+ return new Date(new Date(emittedAt).getTime() + ms).toISOString();
8453
+ }
8454
+ }
8455
+ return new Date(new Date(emittedAt).getTime() + 7 * 24 * 60 * 60 * 1e3).toISOString();
8456
+ }
8457
+ function parseIsoDurationToMs(duration) {
8458
+ const match = /^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/.exec(duration);
8459
+ if (!match) return null;
8460
+ const [, d, h, m, s] = match;
8461
+ let ms = 0;
8462
+ if (d) ms += parseInt(d, 10) * 24 * 60 * 60 * 1e3;
8463
+ if (h) ms += parseInt(h, 10) * 60 * 60 * 1e3;
8464
+ if (m) ms += parseInt(m, 10) * 60 * 1e3;
8465
+ if (s) ms += parseInt(s, 10) * 1e3;
8466
+ return ms;
8467
+ }
8468
+ function getActionForBlock(block) {
8469
+ const actionType = block?.props?.actionType;
8470
+ if (typeof actionType !== "string") return void 0;
8471
+ return getAction(actionType);
8472
+ }
8473
+
8474
+ // src/core/lib/ucanDelegationStore.ts
8475
+ var ROOT_DELEGATION_KEY = "__root__";
8476
+ var STORE_VERSION_KEY = "__version__";
8477
+ var CURRENT_VERSION = 2;
8478
+ var isValidEntry = (value) => {
8479
+ if (!value || typeof value !== "object") return false;
8480
+ const entry = value;
8481
+ return entry.v === CURRENT_VERSION && entry.data !== void 0;
8482
+ };
8483
+ var isReservedKey = (key) => key === ROOT_DELEGATION_KEY || key === STORE_VERSION_KEY;
8484
+ var createUcanDelegationStore = (yMap) => {
8485
+ const get = (cid) => {
8486
+ if (isReservedKey(cid)) return null;
8487
+ const raw = yMap.get(cid);
8488
+ if (!raw) return null;
8489
+ if (isValidEntry(raw)) return raw.data;
8490
+ return null;
8491
+ };
8492
+ const set = (delegation) => {
8493
+ const entry = { v: CURRENT_VERSION, data: delegation };
8494
+ yMap.set(delegation.cid, entry);
8495
+ };
8496
+ const remove = (cid) => {
8497
+ yMap.delete(cid);
8498
+ };
8499
+ const has = (cid) => {
8500
+ return yMap.has(cid) && !isReservedKey(cid);
8501
+ };
8502
+ const getRoot = () => {
8503
+ const rootCid = yMap.get(ROOT_DELEGATION_KEY);
8504
+ if (!rootCid) return null;
8505
+ return get(rootCid);
8506
+ };
8507
+ const setRootCid = (cid) => {
8508
+ yMap.set(ROOT_DELEGATION_KEY, cid);
8509
+ };
8510
+ const getRootCid = () => {
8511
+ return yMap.get(ROOT_DELEGATION_KEY) || null;
8512
+ };
8513
+ const getAll = () => {
8514
+ const delegations = [];
8515
+ yMap.forEach((value, key) => {
8516
+ if (isReservedKey(key)) return;
8517
+ if (isValidEntry(value)) {
8518
+ delegations.push(value.data);
8519
+ }
8520
+ });
8521
+ return delegations;
8522
+ };
8523
+ const getByAudience = (audienceDid) => {
8524
+ return getAll().filter((d) => d.audienceDid === audienceDid);
8525
+ };
8526
+ const getByIssuer = (issuerDid) => {
8527
+ return getAll().filter((d) => d.issuerDid === issuerDid);
8528
+ };
8529
+ const findByCapability = (can, withUri) => {
8530
+ return getAll().filter(
8531
+ (d) => d.capabilities.some((c) => {
8532
+ if (c.can === can && c.with === withUri) return true;
8533
+ if (c.can === "*" || c.can === "flow/*") return true;
8534
+ if (c.can.endsWith("/*")) {
8535
+ const prefix = c.can.slice(0, -1);
8536
+ if (can.startsWith(prefix)) return true;
8537
+ }
8538
+ if (c.with === "*") return true;
8539
+ if (c.with.endsWith("*")) {
8540
+ const prefix = c.with.slice(0, -1);
8541
+ if (withUri.startsWith(prefix)) return true;
8542
+ }
8543
+ return false;
8544
+ })
8545
+ );
8546
+ };
8547
+ return {
8548
+ get,
8549
+ set,
8550
+ remove,
8551
+ has,
8552
+ getRoot,
8553
+ setRootCid,
8554
+ getRootCid,
8555
+ getAll,
8556
+ getByAudience,
8557
+ getByIssuer,
8558
+ findByCapability
8559
+ };
8560
+ };
8561
+ var createMemoryUcanDelegationStore = () => {
8562
+ const store = /* @__PURE__ */ new Map();
8563
+ const get = (cid) => {
8564
+ if (isReservedKey(cid)) return null;
8565
+ const raw = store.get(cid);
8566
+ if (!raw) return null;
8567
+ if (isValidEntry(raw)) return raw.data;
8568
+ return null;
8569
+ };
8570
+ const set = (delegation) => {
8571
+ const entry = { v: CURRENT_VERSION, data: delegation };
8572
+ store.set(delegation.cid, entry);
8573
+ };
8574
+ const remove = (cid) => {
8575
+ store.delete(cid);
8576
+ };
8577
+ const has = (cid) => {
8578
+ return store.has(cid) && !isReservedKey(cid);
8579
+ };
8580
+ const getRoot = () => {
8581
+ const rootCid = store.get(ROOT_DELEGATION_KEY);
8582
+ if (!rootCid) return null;
8583
+ return get(rootCid);
8584
+ };
8585
+ const setRootCid = (cid) => {
8586
+ store.set(ROOT_DELEGATION_KEY, cid);
8587
+ };
8588
+ const getRootCid = () => {
8589
+ return store.get(ROOT_DELEGATION_KEY) || null;
8590
+ };
8591
+ const getAll = () => {
8592
+ const delegations = [];
8593
+ store.forEach((value, key) => {
8594
+ if (isReservedKey(key)) return;
8595
+ if (isValidEntry(value)) {
8596
+ delegations.push(value.data);
8597
+ }
8598
+ });
8599
+ return delegations;
8600
+ };
8601
+ const getByAudience = (audienceDid) => {
8602
+ return getAll().filter((d) => d.audienceDid === audienceDid);
8603
+ };
8604
+ const getByIssuer = (issuerDid) => {
8605
+ return getAll().filter((d) => d.issuerDid === issuerDid);
8606
+ };
8607
+ const findByCapability = (can, withUri) => {
8608
+ return getAll().filter(
8609
+ (d) => d.capabilities.some((c) => {
8610
+ if (c.can === can && c.with === withUri) return true;
8611
+ if (c.can === "*" || c.can === "flow/*") return true;
8612
+ if (c.can.endsWith("/*")) {
8613
+ const prefix = c.can.slice(0, -1);
8614
+ if (can.startsWith(prefix)) return true;
8615
+ }
8616
+ if (c.with === "*") return true;
8617
+ if (c.with.endsWith("*")) {
8618
+ const prefix = c.with.slice(0, -1);
8619
+ if (withUri.startsWith(prefix)) return true;
8620
+ }
8621
+ return false;
8622
+ })
8623
+ );
8624
+ };
8625
+ return {
8626
+ get,
8627
+ set,
8628
+ remove,
8629
+ has,
8630
+ getRoot,
8631
+ setRootCid,
8632
+ getRootCid,
8633
+ getAll,
8634
+ getByAudience,
8635
+ getByIssuer,
8636
+ findByCapability
8637
+ };
8638
+ };
8639
+
8640
+ // src/core/lib/invocationStore.ts
8641
+ var createInvocationStore = (yMap) => {
8642
+ const add = (invocation) => {
8643
+ yMap.set(invocation.cid, invocation);
8644
+ };
8645
+ const get = (cid) => {
8646
+ const raw = yMap.get(cid);
8647
+ if (!raw || typeof raw !== "object") return null;
8648
+ return raw;
8649
+ };
8650
+ const remove = (cid) => {
8651
+ yMap.delete(cid);
8652
+ };
8653
+ const getAll = () => {
8654
+ const invocations = [];
8655
+ yMap.forEach((value) => {
8656
+ if (value && typeof value === "object" && "cid" in value) {
8657
+ invocations.push(value);
8658
+ }
8659
+ });
8660
+ return invocations.sort((a, b) => b.executedAt - a.executedAt);
8661
+ };
8662
+ const getByInvoker = (invokerDid) => {
8663
+ return getAll().filter((i) => i.invokerDid === invokerDid);
8664
+ };
8665
+ const getByFlow = (flowId) => {
8666
+ return getAll().filter((i) => i.flowId === flowId);
8667
+ };
8668
+ const getByBlock = (flowId, blockId) => {
8669
+ return getAll().filter((i) => i.flowId === flowId && i.blockId === blockId);
8670
+ };
8671
+ const getByCapability = (can, withUri) => {
8672
+ return getAll().filter((i) => i.capability.can === can && i.capability.with === withUri);
8673
+ };
8674
+ const hasBeenInvoked = (cid) => {
8675
+ return yMap.has(cid);
8676
+ };
8677
+ const getInDateRange = (startMs, endMs) => {
8678
+ return getAll().filter((i) => i.executedAt >= startMs && i.executedAt <= endMs);
8679
+ };
8680
+ const getSuccessful = () => {
8681
+ return getAll().filter((i) => i.result === "success");
8682
+ };
8683
+ const getFailures = () => {
8684
+ return getAll().filter((i) => i.result === "failure");
8685
+ };
8686
+ const getPendingSubmission = () => {
8687
+ return getAll().filter((i) => i.result === "success" && !i.transactionHash);
8688
+ };
8689
+ const markSubmitted = (cid, transactionHash) => {
8690
+ const invocation = get(cid);
8691
+ if (invocation) {
8692
+ const updated = {
8693
+ ...invocation,
8694
+ transactionHash
8729
8695
  };
8730
- queuePendingInvocation(yDoc, listenerBlockId, invocation);
8731
- clearBarrierState(yDoc, listenerBlockId);
8732
- if (runtimeMap) {
8733
- const prev = runtimeMap.get(listenerBlockId) || {};
8734
- runtimeMap.set(listenerBlockId, {
8735
- ...prev,
8736
- pendingPayload: { ...mergedPayload, ...refSnapshots }
8737
- });
8738
- }
8739
- }
8740
- }
8741
- }
8742
- function parseTrigger(block) {
8743
- const raw = block?.props?.trigger;
8744
- if (!raw || typeof raw !== "string") return null;
8745
- try {
8746
- const parsed = JSON.parse(raw);
8747
- if (parsed && typeof parsed === "object" && typeof parsed.type === "string") {
8748
- return parsed;
8696
+ yMap.set(cid, updated);
8749
8697
  }
8750
- } catch {
8751
- }
8752
- return null;
8753
- }
8754
- function parseInputs(block) {
8755
- const raw = block?.props?.inputs;
8756
- if (!raw || typeof raw !== "string") return {};
8757
- try {
8758
- const parsed = JSON.parse(raw);
8759
- if (parsed && typeof parsed === "object") return parsed;
8760
- } catch {
8761
- }
8762
- return {};
8763
- }
8764
- function resolveAssignee(block) {
8765
- const raw = block?.props?.assignment;
8766
- if (!raw) return void 0;
8767
- try {
8768
- const parsed = typeof raw === "string" ? JSON.parse(raw) : raw;
8769
- const did = parsed?.assignedActor?.did;
8770
- return typeof did === "string" && did.length > 0 ? did : void 0;
8771
- } catch {
8772
- return void 0;
8773
- }
8774
- }
8775
- function computeExpiry(block, emittedAt) {
8776
- const ttlAbsolute = block?.props?.ttlAbsoluteDueDate;
8777
- if (typeof ttlAbsolute === "string" && ttlAbsolute) {
8778
- return ttlAbsolute;
8779
- }
8780
- const ttlFromEnablement = block?.props?.ttlFromEnablement;
8781
- if (typeof ttlFromEnablement === "string" && ttlFromEnablement) {
8782
- const ms = parseIsoDurationToMs(ttlFromEnablement);
8783
- if (ms != null) {
8784
- return new Date(new Date(emittedAt).getTime() + ms).toISOString();
8698
+ };
8699
+ const getCount = () => {
8700
+ return getAll().length;
8701
+ };
8702
+ const getCountByResult = () => {
8703
+ const all = getAll();
8704
+ return {
8705
+ success: all.filter((i) => i.result === "success").length,
8706
+ failure: all.filter((i) => i.result === "failure").length
8707
+ };
8708
+ };
8709
+ return {
8710
+ add,
8711
+ get,
8712
+ remove,
8713
+ getAll,
8714
+ getByInvoker,
8715
+ getByFlow,
8716
+ getByBlock,
8717
+ getByCapability,
8718
+ hasBeenInvoked,
8719
+ getInDateRange,
8720
+ getSuccessful,
8721
+ getFailures,
8722
+ getPendingSubmission,
8723
+ markSubmitted,
8724
+ getCount,
8725
+ getCountByResult
8726
+ };
8727
+ };
8728
+ var createMemoryInvocationStore = () => {
8729
+ const store = /* @__PURE__ */ new Map();
8730
+ const add = (invocation) => {
8731
+ store.set(invocation.cid, invocation);
8732
+ };
8733
+ const get = (cid) => {
8734
+ return store.get(cid) || null;
8735
+ };
8736
+ const remove = (cid) => {
8737
+ store.delete(cid);
8738
+ };
8739
+ const getAll = () => {
8740
+ const invocations = Array.from(store.values());
8741
+ return invocations.sort((a, b) => b.executedAt - a.executedAt);
8742
+ };
8743
+ const getByInvoker = (invokerDid) => {
8744
+ return getAll().filter((i) => i.invokerDid === invokerDid);
8745
+ };
8746
+ const getByFlow = (flowId) => {
8747
+ return getAll().filter((i) => i.flowId === flowId);
8748
+ };
8749
+ const getByBlock = (flowId, blockId) => {
8750
+ return getAll().filter((i) => i.flowId === flowId && i.blockId === blockId);
8751
+ };
8752
+ const getByCapability = (can, withUri) => {
8753
+ return getAll().filter((i) => i.capability.can === can && i.capability.with === withUri);
8754
+ };
8755
+ const hasBeenInvoked = (cid) => {
8756
+ return store.has(cid);
8757
+ };
8758
+ const getInDateRange = (startMs, endMs) => {
8759
+ return getAll().filter((i) => i.executedAt >= startMs && i.executedAt <= endMs);
8760
+ };
8761
+ const getSuccessful = () => {
8762
+ return getAll().filter((i) => i.result === "success");
8763
+ };
8764
+ const getFailures = () => {
8765
+ return getAll().filter((i) => i.result === "failure");
8766
+ };
8767
+ const getPendingSubmission = () => {
8768
+ return getAll().filter((i) => i.result === "success" && !i.transactionHash);
8769
+ };
8770
+ const markSubmitted = (cid, transactionHash) => {
8771
+ const invocation = get(cid);
8772
+ if (invocation) {
8773
+ store.set(cid, { ...invocation, transactionHash });
8785
8774
  }
8786
- }
8787
- return new Date(new Date(emittedAt).getTime() + 7 * 24 * 60 * 60 * 1e3).toISOString();
8788
- }
8789
- function parseIsoDurationToMs(duration) {
8790
- const match = /^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/.exec(duration);
8791
- if (!match) return null;
8792
- const [, d, h, m, s] = match;
8793
- let ms = 0;
8794
- if (d) ms += parseInt(d, 10) * 24 * 60 * 60 * 1e3;
8795
- if (h) ms += parseInt(h, 10) * 60 * 60 * 1e3;
8796
- if (m) ms += parseInt(m, 10) * 60 * 1e3;
8797
- if (s) ms += parseInt(s, 10) * 1e3;
8798
- return ms;
8799
- }
8800
- function getActionForBlock(block) {
8801
- const actionType = block?.props?.actionType;
8802
- if (typeof actionType !== "string") return void 0;
8803
- return getAction(actionType);
8804
- }
8775
+ };
8776
+ const getCount = () => {
8777
+ return store.size;
8778
+ };
8779
+ const getCountByResult = () => {
8780
+ const all = getAll();
8781
+ return {
8782
+ success: all.filter((i) => i.result === "success").length,
8783
+ failure: all.filter((i) => i.result === "failure").length
8784
+ };
8785
+ };
8786
+ return {
8787
+ add,
8788
+ get,
8789
+ remove,
8790
+ getAll,
8791
+ getByInvoker,
8792
+ getByFlow,
8793
+ getByBlock,
8794
+ getByCapability,
8795
+ hasBeenInvoked,
8796
+ getInDateRange,
8797
+ getSuccessful,
8798
+ getFailures,
8799
+ getPendingSubmission,
8800
+ markSubmitted,
8801
+ getCount,
8802
+ getCountByResult
8803
+ };
8804
+ };
8805
8805
 
8806
8806
  // src/core/lib/flowEngine/emitEvents.ts
8807
8807
  function writeRunRecordAndReconcile(editor, blockId, output, events, actorDid, detailsPatch = {}) {
@@ -10281,7 +10281,7 @@ function readFlow() {
10281
10281
  return readFlowFromEditor(activeEditor);
10282
10282
  }
10283
10283
  async function setupFlowFromBaseUcan(options) {
10284
- const { plan: rawPlan, roomId, matrixClient, creatorDid, docId, strategy = "full" } = options;
10284
+ const { plan: rawPlan, roomId, matrixClient, creatorDid, docId, templateId, strategy = "full" } = options;
10285
10285
  const plan = rawPlan.flowId ? rawPlan : { ...rawPlan, flowId: docId || roomId };
10286
10286
  const incomingCompiled = compileBaseUcanFlow(plan, { getActionByCan });
10287
10287
  const { yDoc, provider } = await connectToRoom(roomId, matrixClient);
@@ -10297,7 +10297,7 @@ async function setupFlowFromBaseUcan(options) {
10297
10297
  const runtime = yDoc.getMap("runtime");
10298
10298
  runtime.forEach((_, key) => runtime.delete(key));
10299
10299
  }
10300
- setRootMetadata(yDoc, root, plan, creatorDid, docId);
10300
+ setRootMetadata(yDoc, root, plan, creatorDid, docId, templateId);
10301
10301
  hydrateYDocFromCompiledFlow(yDoc, incomingCompiled);
10302
10302
  const runtimeMap = yDoc.getMap("runtime");
10303
10303
  initializeRuntime(runtimeMap, incomingCompiled);
@@ -10307,7 +10307,7 @@ async function setupFlowFromBaseUcan(options) {
10307
10307
  finalCompiled = incomingCompiled;
10308
10308
  } else {
10309
10309
  if (!existingFlow) {
10310
- setRootMetadata(yDoc, root, plan, creatorDid, docId);
10310
+ setRootMetadata(yDoc, root, plan, creatorDid, docId, templateId);
10311
10311
  hydrateYDocFromCompiledFlow(yDoc, incomingCompiled);
10312
10312
  const runtimeMap = yDoc.getMap("runtime");
10313
10313
  initializeRuntime(runtimeMap, incomingCompiled);
@@ -10377,7 +10377,7 @@ async function connectToRoom(roomId, matrixClient) {
10377
10377
  });
10378
10378
  return { yDoc, provider };
10379
10379
  }
10380
- function setRootMetadata(yDoc, root, plan, creatorDid, docId) {
10380
+ function setRootMetadata(yDoc, root, plan, creatorDid, docId, templateId) {
10381
10381
  yDoc.transact(() => {
10382
10382
  if (!root.get("@context")) root.set("@context", "https://ixo.world/flow/0.3");
10383
10383
  if (!root.get("_type")) root.set("_type", "ixo.flow.crdt");
@@ -10386,6 +10386,9 @@ function setRootMetadata(yDoc, root, plan, creatorDid, docId) {
10386
10386
  if (!root.get("createdAt")) root.set("createdAt", (/* @__PURE__ */ new Date()).toISOString());
10387
10387
  if (!root.get("createdBy")) root.set("createdBy", creatorDid);
10388
10388
  root.set("flowOwnerDid", creatorDid);
10389
+ if (templateId && !root.get("source_template_id")) {
10390
+ root.set("source_template_id", templateId);
10391
+ }
10389
10392
  const titleText = yDoc.getText("title");
10390
10393
  if (titleText.length === 0 && plan.title) {
10391
10394
  titleText.insert(0, plan.title);
@@ -11758,17 +11761,13 @@ export {
11758
11761
  formatCoin2 as formatCoin,
11759
11762
  formatCoinAmount,
11760
11763
  createUcanService,
11761
- createUcanDelegationStore,
11762
- createMemoryUcanDelegationStore,
11763
- createInvocationStore,
11764
- createMemoryInvocationStore,
11765
- LATEST_VERSION,
11766
11764
  buildAuthzFromProps,
11767
11765
  buildFlowNodeFromBlock,
11768
11766
  createRuntimeStateManager,
11769
11767
  clearRuntimeForTemplateClone,
11770
11768
  isRuntimeRef,
11771
11769
  resolveRuntimeRefs,
11770
+ LATEST_VERSION,
11772
11771
  isAuthorized,
11773
11772
  executeNode,
11774
11773
  RUN_RECORD_AUDIT_TYPE,
@@ -11788,6 +11787,10 @@ export {
11788
11787
  reconcileActionReadBack,
11789
11788
  buildActionRunInputs,
11790
11789
  executeActionBlock,
11790
+ createUcanDelegationStore,
11791
+ createMemoryUcanDelegationStore,
11792
+ createInvocationStore,
11793
+ createMemoryInvocationStore,
11791
11794
  writeRunRecordAndReconcile,
11792
11795
  compileBaseUcanFlow,
11793
11796
  readCompiledFlowFromYDoc,
@@ -11829,4 +11832,4 @@ export {
11829
11832
  executeQueuedFlowAgentCoreCommands,
11830
11833
  FlowAgentService
11831
11834
  };
11832
- //# sourceMappingURL=chunk-47XOPWSV.mjs.map
11835
+ //# sourceMappingURL=chunk-OP7EY4CE.mjs.map