d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
import type { CanonicalModeOverrides } from '@/lib/workflows/subblocks/visibility'
|
|
import {
|
|
type ForkRemapKind,
|
|
scanWorkflowReferences,
|
|
} from '@/ee/workspace-forking/lib/remap/remap-references'
|
|
import type { WorkflowState } from '@/stores/workflows/workflow/types'
|
|
|
|
/** A block reduced to what the reference scanner reads (incl. canonical context for detection). */
|
|
interface ScannerBlock {
|
|
id: string
|
|
name: string
|
|
type: string
|
|
subBlocks: unknown
|
|
canonicalModes?: CanonicalModeOverrides
|
|
}
|
|
|
|
/**
|
|
* Unique source ids of one remap kind referenced across a set of blocks - both top-level
|
|
* selectors and nested tool params. Used at fork/promote time to decide which KB documents
|
|
* a copy must create placeholders for (so their references remap to the copied doc instead
|
|
* of being cleared). The resolver is irrelevant here (every reference is detected regardless
|
|
* of mapping), so a null resolver is passed.
|
|
*/
|
|
export function collectReferencedResourceIds(
|
|
blocks: ScannerBlock[],
|
|
kind: ForkRemapKind
|
|
): Set<string> {
|
|
const ids = new Set<string>()
|
|
for (const reference of scanWorkflowReferences(blocks, () => null).references) {
|
|
if (reference.kind === kind) ids.add(reference.sourceId)
|
|
}
|
|
return ids
|
|
}
|
|
|
|
/**
|
|
* Map a workflow state's blocks to the `{ id, name, subBlocks }` shape the reference scanner
|
|
* consumes. Confines the `subBlocks as unknown` widening (the stored subblock record is opaque
|
|
* to the scanner, which re-narrows per subblock type) to one spot shared by every fork caller
|
|
* that scans a source workflow's references.
|
|
*/
|
|
export function toScannerBlocks(state: WorkflowState): ScannerBlock[] {
|
|
return Object.values(state.blocks).map((block) => ({
|
|
id: block.id,
|
|
name: block.name,
|
|
type: block.type,
|
|
subBlocks: block.subBlocks as unknown,
|
|
canonicalModes: block.data?.canonicalModes,
|
|
}))
|
|
}
|
|
|
|
/**
|
|
* Unique knowledge-document ids referenced across a set of source workflow states. Fork and
|
|
* promote use this to decide which KB documents a copy must pre-create placeholders for, so a
|
|
* `document-selector` reference remaps to the copied doc instead of being cleared.
|
|
*/
|
|
export function collectReferencedDocumentIds(states: Iterable<WorkflowState>): Set<string> {
|
|
const ids = new Set<string>()
|
|
for (const state of states) {
|
|
for (const docId of collectReferencedResourceIds(
|
|
toScannerBlocks(state),
|
|
'knowledge-document'
|
|
)) {
|
|
ids.add(docId)
|
|
}
|
|
}
|
|
return ids
|
|
}
|