diff --git a/apps/sim/app/(landing)/components/home-structured-data/home-structured-data.tsx b/apps/sim/app/(landing)/components/home-structured-data/home-structured-data.tsx index ee4e2de2644..7b826d9b4bb 100644 --- a/apps/sim/app/(landing)/components/home-structured-data/home-structured-data.tsx +++ b/apps/sim/app/(landing)/components/home-structured-data/home-structured-data.tsx @@ -97,7 +97,7 @@ const HOME_JSON_LD = { '@id': `${SITE_URL}#software`, url: SITE_URL, name: 'Sim, The AI Workspace', - description: `Sim is the open-source AI workspace where companies build, distribute, and govern AI agents in one place. Teams build agents visually, conversationally, or with code across ${INTEGRATION_COUNT_LABEL} integrations and every major LLM, while administrators control model access, integration access, spend limits, and deployment. Trusted by over 100,000 builders. SOC2 compliant and self-hostable.`, + description: `Sim is the open-source AI workspace where companies build, distribute, and govern AI agents in one place. Teams build agents visually, conversationally, or with code across ${INTEGRATION_COUNT_LABEL} integrations and every major LLM, while administrators control model access, integration access, spend limits, and deployment. Trusted by over 100,000 builders. SOC 2 Type II audited and self-hostable.`, applicationCategory: 'BusinessApplication', applicationSubCategory: 'AI Workspace', operatingSystem: 'Web', diff --git a/apps/sim/app/(landing)/page.tsx b/apps/sim/app/(landing)/page.tsx index 3e418c53a51..8dbf31c57b5 100644 --- a/apps/sim/app/(landing)/page.tsx +++ b/apps/sim/app/(landing)/page.tsx @@ -15,7 +15,7 @@ export const metadata: Metadata = { }, description: HOME_PAGE_DESCRIPTION, keywords: - 'AI workspace, AI agent builder, AI agent workflow builder, build AI agents, visual workflow builder, open-source AI agent platform, AI agents, agentic workflows, LLM orchestration, AI automation, knowledge base, workflow builder, AI integrations, SOC2 compliant, enterprise AI', + 'AI workspace, AI agent builder, AI agent workflow builder, build AI agents, visual workflow builder, open-source AI agent platform, AI agents, agentic workflows, LLM orchestration, AI automation, knowledge base, workflow builder, AI integrations, SOC 2 Type II, enterprise AI', authors: [{ name: 'Sim' }], creator: 'Sim', publisher: 'Sim', diff --git a/apps/sim/app/layout.tsx b/apps/sim/app/layout.tsx index 1d3ca86f852..60c27ff04bd 100644 --- a/apps/sim/app/layout.tsx +++ b/apps/sim/app/layout.tsx @@ -42,7 +42,7 @@ export const viewport: Viewport = { ], } -const SUMMARY_FULL = `Sim is the open-source AI workspace where teams build, deploy, and manage AI agents. Connect ${INTEGRATION_COUNT_LABEL} integrations and every major LLM to create agents that automate real work — visually, conversationally, or with code. Trusted by over 100,000 builders — from startups to Fortune 500 companies. SOC2 compliant.` +const SUMMARY_FULL = `Sim is the open-source AI workspace where teams build, deploy, and manage AI agents. Connect ${INTEGRATION_COUNT_LABEL} integrations and every major LLM to create agents that automate real work — visually, conversationally, or with code. Trusted by over 100,000 builders — from startups to Fortune 500 companies. SOC 2 Type II audited.` const SUMMARY_SHORT = `Sim is the open-source AI workspace where teams build, deploy, and manage AI agents. Connect ${INTEGRATION_COUNT_LABEL} integrations and every major LLM to create agents that automate real work.` /** diff --git a/apps/sim/content/library/ai-agents-in-procurement/index.mdx b/apps/sim/content/library/ai-agents-in-procurement/index.mdx index 77a59da2d50..88e7063c623 100644 --- a/apps/sim/content/library/ai-agents-in-procurement/index.mdx +++ b/apps/sim/content/library/ai-agents-in-procurement/index.mdx @@ -246,7 +246,7 @@ Procurement teams should buy a pre-built agent for a narrow, standardized need a Sim is the open-source AI workspace where procurement and IT teams build agents visually, conversationally, or with code. As of November 2026, it connects [270+ integrations](https://www.sim.ai/pricing) including Salesforce, Slack, Gmail, databases, and ERP systems, without adopting a rigid suite. -As of November 2026, its governance options include real-time collaboration, role-based access control, self-hosting for data residency, bring-your-own-keys, and SOC2 compliance. If you're weighing platforms more broadly, [the best AI agent platforms in 2026](https://www.sim.ai/library/best-ai-agent-platforms-2026) compares the field. +As of November 2026, its governance options include real-time collaboration, role-based access control, self-hosting for data residency, bring-your-own-keys, and a completed SOC 2 Type II audit. If you're weighing platforms more broadly, [the best AI agent platforms in 2026](https://www.sim.ai/library/best-ai-agent-platforms-2026) compares the field. ## What are the key differences between Sim and n8n for procurement agents? diff --git a/apps/sim/content/library/ai-agents-vs-rpa/index.mdx b/apps/sim/content/library/ai-agents-vs-rpa/index.mdx index 19ee482098d..28ea47661f7 100644 --- a/apps/sim/content/library/ai-agents-vs-rpa/index.mdx +++ b/apps/sim/content/library/ai-agents-vs-rpa/index.mdx @@ -205,7 +205,7 @@ AI agents aren't a universal upgrade. They can come with real costs and constrai Implementation cost. Building, testing, and deploying AI agents can take months. The engineering lift can be heavier, and you need people who understand both the AI stack and the business process. -> If you're building the agent layer and want to skip the months of custom orchestration engineering, Sim's visual workflow builder lets you design, deploy, and connect AI agent workflows to your existing systems and RPA bots through a drag-and-drop interface with [270+ integrations](https://www.sim.ai/pricing). Sim is SOC 2 compliant and built for teams that want to move fast without sacrificing governance. +> If you're building the agent layer and want to skip the months of custom orchestration engineering, Sim's visual workflow builder lets you design, deploy, and connect AI agent workflows to your existing systems and RPA bots through a drag-and-drop interface with [270+ integrations](https://www.sim.ai/pricing). Sim has completed a SOC 2 Type II audit covering the Security criterion and is built for teams that want to move fast without sacrificing governance. Probabilistic outputs. AI agents don't produce the same answer every time. They produce the best answer given their training and context. For most knowledge work, that's fine or even preferable. For compliance-critical workflows where regulators expect 100% deterministic, auditable outputs, probabilistic reasoning introduces risk that needs governance around it. diff --git a/apps/sim/content/library/best-relay-app-alternatives-2026/index.mdx b/apps/sim/content/library/best-relay-app-alternatives-2026/index.mdx index 7ac898becb8..889c581e9fa 100644 --- a/apps/sim/content/library/best-relay-app-alternatives-2026/index.mdx +++ b/apps/sim/content/library/best-relay-app-alternatives-2026/index.mdx @@ -62,7 +62,7 @@ Data lives inside Sim rather than in a separate service you have to wire up. Nat Real-time multiplayer lets more than one person edit the same workflow at once, the way you'd edit a shared document. If your Relay setup was maintained by a small team, you keep that collaborative build model instead of dropping back to one editor at a time. -For larger deployments, Sim offers SSO and SAML, bring-your-own-key so you use your own model provider credentials and billing, SOC 2 Type II compliance, and an Admin API for provisioning and governance. That path exists if you need to justify the tool to a security team or manage many users, and it's the same product, not a separate enterprise fork. +For larger deployments, Sim offers SSO and SAML, bring-your-own-key so you use your own model provider credentials and billing, a SOC 2 Type II report covering the Security criterion, and an Admin API for provisioning and governance. That path exists if you need to justify the tool to a security team or manage many users, and it's the same product, not a separate enterprise fork. Here is the honest tradeoff. Sim's library of pre-built, third-party integrations is smaller than what n8n or Zapier ship today. If your Relay workflows lean on a long tail of niche SaaS connectors, you'll hit some that Sim doesn't have out of the box yet, and you'll cover the gap with a generic HTTP or API block instead of a one-click node. For workflows built on common services and AI steps, you won't notice. For a handful of obscure apps, you will, and it's worth checking your connector list before you commit. diff --git a/apps/sim/lib/compare/data/sim.ts b/apps/sim/lib/compare/data/sim.ts index f17235155a0..8042dfd74e7 100644 --- a/apps/sim/lib/compare/data/sim.ts +++ b/apps/sim/lib/compare/data/sim.ts @@ -845,8 +845,8 @@ export const simProfile: CompetitorProfile = { }, security: { soc2: { - value: 'Yes: SOC2 compliant', - shortValue: 'SOC2 compliant', + value: 'Yes: SOC 2 Type II audit completed, covering the Security criterion', + shortValue: 'SOC 2 Type II audited (Security)', confidence: 'verified', sources: [ { @@ -924,10 +924,10 @@ export const simProfile: CompetitorProfile = { ], }, additionalCompliance: { - value: 'SOC2', + value: 'SOC 2 Type II (Security criterion); ISO 27001 certification in progress', detail: - 'Self-hosting is the primary lever Sim offers for data-residency-sensitive compliance needs beyond SOC2, rather than additional certifications.', - shortValue: 'SOC2', + 'Self-hosting is the primary lever Sim offers for data-residency-sensitive compliance needs beyond SOC 2, rather than additional certifications.', + shortValue: 'SOC 2 Type II; ISO 27001 in progress', confidence: 'estimated', sources: [ { diff --git a/apps/sim/lib/workflows/code/catalog/build.ts b/apps/sim/lib/workflows/code/catalog/build.ts index 4ec0f448af6..e6bb82c0648 100644 --- a/apps/sim/lib/workflows/code/catalog/build.ts +++ b/apps/sim/lib/workflows/code/catalog/build.ts @@ -9,7 +9,7 @@ import { type ExpandedBlockCatalog, stableStringify, } from '@sim/workflow-code' -import { SDK_MAJOR } from '@sim/workflow-sdk/codegen' +import { SDK_MAJOR } from '@sim/workflow-code/sdk' import { containerBlock, projectBlock, projectTrigger } from '@/lib/workflows/code/catalog/project' import { operationOptions, diff --git a/apps/sim/lib/workflows/code/catalog/project.ts b/apps/sim/lib/workflows/code/catalog/project.ts index dea97e87dcc..43fc4a102b5 100644 --- a/apps/sim/lib/workflows/code/catalog/project.ts +++ b/apps/sim/lib/workflows/code/catalog/project.ts @@ -522,10 +522,9 @@ function projectEffects( const effect = blockEffect(block) if (effect === undefined) return {} if (effect === 'read' || !operationTools) return { effect } - const access = new Set(block.tools.access) const operationEffects: NonNullable = {} for (const [operation, toolId] of operationTools) { - const operationEffect = access.has(toolId) ? accessIdEffect(toolId) : 'write' + const operationEffect = accessIdEffect(toolId) if (operationEffect !== effect) operationEffects[operation] = operationEffect } return Object.keys(operationEffects).length > 0 ? { effect, operationEffects } : { effect } diff --git a/apps/sim/lib/workflows/code/real-catalog.test.ts b/apps/sim/lib/workflows/code/real-catalog.test.ts index 751ff55deb4..257fab9e2d8 100644 --- a/apps/sim/lib/workflows/code/real-catalog.test.ts +++ b/apps/sim/lib/workflows/code/real-catalog.test.ts @@ -114,7 +114,7 @@ describe('canonicalize and codegen over the real block catalog', () => { ? undefined : block?.operationOutputs?.[builder.operation] if (!builder || !block || !returned) return [] - const produced = builderProducedOutputs(catalog, block, builder) + const { outputs: produced } = builderProducedOutputs(catalog, block, builder) return returned.names .filter((name) => Object.hasOwn(block.outputs, name) && !Object.hasOwn(produced, name)) .map((name) => `${key}.${name}`) diff --git a/apps/sim/lib/workflows/editing/engine.ts b/apps/sim/lib/workflows/editing/engine.ts index e0f7a4adab8..0e9380318c5 100644 --- a/apps/sim/lib/workflows/editing/engine.ts +++ b/apps/sim/lib/workflows/editing/engine.ts @@ -528,13 +528,11 @@ function removeInvalidScopeEdges( }) } - if (dropped.length > 0) { - logger.info('Removed invalid workflow edges', { - refused: refusedEdgeIds.length, - removed: removedEdges.length, - reasons: dropped.map(({ reason }) => reason), - }) - } + logger.info('Removed invalid workflow edges', { + refused: refusedEdgeIds.length, + removed: removedEdges.length, + reasons: dropped.map(({ reason }) => reason), + }) return { refusedEdgeIds, removedEdges } } diff --git a/apps/sim/lib/workflows/executor/execution-status.test.ts b/apps/sim/lib/workflows/executor/execution-status.test.ts index dafe18d2991..d7a41e77d88 100644 --- a/apps/sim/lib/workflows/executor/execution-status.test.ts +++ b/apps/sim/lib/workflows/executor/execution-status.test.ts @@ -813,59 +813,6 @@ describe('getWorkflowExecutionStatus once a pause has settled', () => { }) }) -describe('getProjectedWorkflowExecutionStatus overrides of a dry run logged before they were named', () => { - beforeEach(() => { - resetDbChainMock() - mockGetJob.mockResolvedValue(null) - }) - - it("keeps a child's blocks and the mocks read from another run, as a rerun names them", async () => { - queueTableRows(schemaMock.workflowExecutionLogs, [ - { - executionId: 'execution-1', - workflowId: 'workflow-1', - workspaceId: 'workspace-1', - status: 'failed', - level: 'error', - trigger: 'test', - startedAt: new Date('2026-08-05T12:00:00.000Z'), - endedAt: new Date('2026-08-05T12:00:01.000Z'), - totalDurationMs: 1000, - executionData: {}, - costTotal: null, - }, - ]) - queueTableRows(schemaMock.resumeQueue, []) - queueTableRows(schemaMock.pausedExecutions, []) - mockMaterializeForDisplayWithBlockOutputs.mockResolvedValueOnce({ - executionData: { - error: 'boom', - trigger: { - data: { - dryRun: { - allowBlocks: ['send'], - mockedBlocks: ['lookup'], - childAllowBlocks: [{ workflowId: 'child-1', blockId: 'notify' }], - childMockedBlocks: [{ workflowId: 'child-1', blockId: 'fetch' }], - mocksFrom: { runId: 'execution-0', blockIds: ['classify'] }, - }, - }, - }, - }, - blockOutputs: new Map(), - placeholderBlockIds: new Set(), - }) - - const projected = await getProjectedWorkflowExecutionStatus(input) - - expect(projected?.overrides).toEqual({ - allow: ['send', 'child-1.notify'], - mocks: ['lookup', 'child-1.fetch'], - mocksFrom: { runId: 'execution-0', blocks: ['classify'] }, - }) - }) -}) - describe('readPausedRunPoints cap', () => { beforeEach(() => { resetDbChainMock() diff --git a/apps/sim/lib/workflows/executor/execution-status.ts b/apps/sim/lib/workflows/executor/execution-status.ts index ee47ff3f3ed..514a238790c 100644 --- a/apps/sim/lib/workflows/executor/execution-status.ts +++ b/apps/sim/lib/workflows/executor/execution-status.ts @@ -7,7 +7,6 @@ import { } from '@sim/db/schema' import { compareStrings } from '@sim/utils/string' import { and, eq, inArray, sql } from 'drizzle-orm' -import { z } from 'zod' import { v2RunOverridesSchema } from '@/lib/api/contracts/v2/workflows' import type { WorkflowExecutionStatusResponse } from '@/lib/api/contracts/workflows' import { getJobQueue } from '@/lib/core/async-jobs' @@ -49,7 +48,7 @@ type LogStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' interface ExecutionDataShape { finalOutput?: unknown traceSpans?: unknown - trigger?: { data?: { overrides?: unknown; dryRun?: unknown; placeholdersRecorded?: unknown } } + trigger?: { data?: { overrides?: unknown; placeholdersRecorded?: unknown } } } function resolvePath(value: unknown, path: string[]): unknown { @@ -660,40 +659,14 @@ async function readWorkflowExecutionStatus( } } -const legacyChildBlockSchema = z.object({ workflowId: z.string(), blockId: z.string() }) - -/** - * The only other shape a log holds overrides in: a dry run logged before they were named - * `overrides` listed its own blocks by id, a child's apart with its workflow id, and the blocks - * mocked from another run under `blockIds`. - */ -const legacyDryRunSchema = z.object({ - allowBlocks: z.array(z.string()), - mockedBlocks: z.array(z.string()), - childAllowBlocks: z.array(legacyChildBlockSchema).optional(), - childMockedBlocks: z.array(legacyChildBlockSchema).optional(), - mocksFrom: z.object({ runId: z.string(), blockIds: z.array(z.string()) }).optional(), -}) - /** * A dry run's overrides from its log's trigger, recovered with the rest of the execution data - * however it was stored, a log written before they were named `overrides` included; null for a - * test run that recorded none (a workflow test) or a record not in either shape. + * however it was stored; null for a test run that recorded none (a workflow test) or a record + * not in that shape. */ function readOverrides(executionData: ExecutionDataShape | null): RunOverrides | null { - const data = executionData?.trigger?.data - const parsed = v2RunOverridesSchema.safeParse(data?.overrides) - if (parsed.success) return parsed.data - const legacy = legacyDryRunSchema.safeParse(data?.dryRun) - if (!legacy.success) return null - const { allowBlocks, mockedBlocks, childAllowBlocks, childMockedBlocks, mocksFrom } = legacy.data - const childSelector = ({ workflowId, blockId }: { workflowId: string; blockId: string }) => - `${workflowId}.${blockId}` - return { - allow: [...allowBlocks, ...(childAllowBlocks ?? []).map(childSelector)], - mocks: [...mockedBlocks, ...(childMockedBlocks ?? []).map(childSelector)], - ...(mocksFrom ? { mocksFrom: { runId: mocksFrom.runId, blocks: mocksFrom.blockIds } } : {}), - } + const parsed = v2RunOverridesSchema.safeParse(executionData?.trigger?.data?.overrides) + return parsed.success ? parsed.data : null } /** diff --git a/packages/sim-cli/README.md b/packages/sim-cli/README.md index 417455883e4..d45b92ec052 100644 --- a/packages/sim-cli/README.md +++ b/packages/sim-cli/README.md @@ -339,7 +339,7 @@ sim workflows source get --dir ./support-triage # write workflow. sim workflows source check --dir ./support-triage # compile offline, no request sim workflows source status --dir ./support-triage # your edits, server changes, next step sim workflows source diff --dir ./support-triage # your edits as a unified diff -sim workflows source apply --dir ./support-triage --dry # run every check a save runs +sim workflows source apply --dir ./support-triage --dry # run every check a save runs sim workflows source apply --dir ./support-triage --yes # save the draft (never deploys) ``` diff --git a/packages/sim-cli/src/commands/protocol/source-check.ts b/packages/sim-cli/src/commands/protocol/source-check.ts index c2286f258bf..46fead8936e 100644 --- a/packages/sim-cli/src/commands/protocol/source-check.ts +++ b/packages/sim-cli/src/commands/protocol/source-check.ts @@ -66,13 +66,7 @@ import { } from './source-tree' import { type TypeCheck, typeCheck } from './source-types' import { type Diagnostic, findingsOutput } from './source-ui' -import { - blockDigest, - compiledWithChildResults, - readStoredBlockDigests, - readStoredEdges, - readStoredUntypedFields, -} from './stored-edges' +import { blockDigest, compiledWithChildResults, readStoredRecord } from './stored-edges' import { lockRecoveryHint, readSourceFiles, resourceNodes } from './workflow-dir' import { type DeclaredColumn, @@ -473,13 +467,16 @@ async function compileWorkflowDir( const lockText = await readSourceText(dir, SOURCE_LOCK_FILE) const parsedLock = lockText === null ? null : parseWorkflowLock(lockText) const lock = parsedLock?.lock - const [files, storedEdges, storedBlocks, storedUntypedFields, printedWith] = await Promise.all([ + const [files, stored, printedWith] = await Promise.all([ readSourceFiles(dir, lock ?? null), - readStoredEdges(dir), - readStoredBlockDigests(dir), - readStoredUntypedFields(dir), + readStoredRecord(dir), cachedSourceCatalog(dir), ]) + const { + edges: storedEdges, + blockDigests: storedBlocks, + untypedJsonFields: storedUntypedFields, + } = stored const catalog = printedWith ?? workspaceCatalog // Compiled against another catalog than the source was printed with, a field may store a // reference differently with no edit, so the record says nothing of what the edit changed. diff --git a/packages/sim-cli/src/commands/protocol/source-primer.ts b/packages/sim-cli/src/commands/protocol/source-primer.ts index a15beb12d1a..f70c7639558 100644 --- a/packages/sim-cli/src/commands/protocol/source-primer.ts +++ b/packages/sim-cli/src/commands/protocol/source-primer.ts @@ -5,13 +5,8 @@ */ import type { BlockCatalog } from '@sim/workflow-code' import { SOURCE_BASE_FILE, SOURCE_ENTRY_FILE, SOURCE_LOCK_FILE } from '@sim/workflow-code/limits' -import { SDK_SPECIAL_BUILDERS } from '@sim/workflow-code/sdk' -import { - builderSnippet, - describeBuilder, - referencedBuilders, - SDK_MAJOR, -} from '@sim/workflow-sdk/codegen' +import { SDK_MAJOR, SDK_SPECIAL_BUILDERS } from '@sim/workflow-code/sdk' +import { builderSnippet, describeBuilder, referencedBuilders } from '@sim/workflow-sdk/codegen' import { RATE_LIMITED_EXIT_CODE, SOURCE_BUSY_EXIT_CODE, diff --git a/packages/sim-cli/src/commands/protocol/source-tree.ts b/packages/sim-cli/src/commands/protocol/source-tree.ts index 2a634c36d10..e741411aa23 100644 --- a/packages/sim-cli/src/commands/protocol/source-tree.ts +++ b/packages/sim-cli/src/commands/protocol/source-tree.ts @@ -13,6 +13,7 @@ import { escapeRegExp } from '@sim/utils/string' import type { BlockCatalog } from '@sim/workflow-code' import { catalogBlock } from '@sim/workflow-code/catalog/view' import { SOURCE_BASE_FILE } from '@sim/workflow-code/limits' +import { SDK_MAJOR } from '@sim/workflow-code/sdk' import { COOKBOOK_EXAMPLES, CORE_DTS, @@ -23,7 +24,6 @@ import { generateWorkspaceTypes, referencedBlockTypes, SDK_INDEX_FILE, - SDK_MAJOR, SDK_MODELS_FILE, sdkIndexHeader, type WorkspaceManifest, diff --git a/packages/sim-cli/src/commands/protocol/stored-edges.ts b/packages/sim-cli/src/commands/protocol/stored-edges.ts index 980eaab9ae0..b7bab5a0591 100644 --- a/packages/sim-cli/src/commands/protocol/stored-edges.ts +++ b/packages/sim-cli/src/commands/protocol/stored-edges.ts @@ -215,9 +215,10 @@ export interface WorkflowFolderRecords { * call by the result fields of the folder it calls, resolved through chains * ({@link resolveChildResults}), as a check types it. A workflow holding a type the workspace * catalog lacks was printed with its own catalog: one not cached yet is fetched, once per - * distinct hash, and cached, so an offline check compiles that folder against it too. The records are a cache fill, never part of the write: a - * catalog fetch that fails skips the folders printed with that catalog (named in `unrecorded`) - * rather than failing a write the server already committed. + * distinct hash, and cached, so an offline check compiles that folder against it too. The + * records are a cache fill, never part of the write: a catalog fetch that fails skips the folders + * printed with that catalog (named in `unrecorded`) rather than failing a write the server already + * committed. */ export async function workflowFolderRecords( client: OperationClient<'getSourceCatalog'>, @@ -325,38 +326,39 @@ async function currentRecord(dir: string): Promise> { : {} } -/** - * The stored edges recorded for the base `dir` holds now, or `undefined` when none are: no - * record, one another base wrote, or a malformed one. - */ -export async function readStoredEdges(dir: string): Promise { - const { edges } = await currentRecord(dir) - return Array.isArray(edges) && edges.every(isStoredEdge) ? edges : undefined +/** What the stored-edges record of the base a workflow folder holds now says. */ +interface StoredRecord { + /** The stored edges, or `undefined` when none are recorded or the record is malformed. */ + edges: StoredEdgeRef[] | undefined + /** + * The digest of each block of the printed source the record was written from, by key (see + * {@link storedEdgesWrite}); `undefined` when the record names no blocks or a malformed one. + */ + blockDigests: ReadonlyMap | undefined + /** + * The JSON fields holding untyped references (see {@link storedEdgesWrite}), or `undefined` when + * none are recorded or the record is malformed. + */ + untypedJsonFields: UntypedJsonField[] | undefined } /** - * The JSON fields holding untyped references recorded for the base `dir` holds now (see - * {@link storedEdgesWrite}), or `undefined` when none are: no record, one another base wrote, or - * a malformed one. + * The stored-edges record of the base `dir` holds now, read once. Every part is `undefined` when + * there is no record, or one another base wrote. */ -export async function readStoredUntypedFields( - dir: string -): Promise { - const { untypedJsonFields } = await currentRecord(dir) - return Array.isArray(untypedJsonFields) && untypedJsonFields.every(isUntypedJsonField) - ? untypedJsonFields - : undefined +export async function readStoredRecord(dir: string): Promise { + const { edges, blocks, untypedJsonFields } = await currentRecord(dir) + return { + edges: Array.isArray(edges) && edges.every(isStoredEdge) ? edges : undefined, + blockDigests: blockDigestsOf(blocks), + untypedJsonFields: + Array.isArray(untypedJsonFields) && untypedJsonFields.every(isUntypedJsonField) + ? untypedJsonFields + : undefined, + } } -/** - * The digest of each block of the printed source the record of the base `dir` holds now was - * written from, by key (see {@link storedEdgesWrite}); `undefined` when there is no such record or - * it records no blocks. - */ -export async function readStoredBlockDigests( - dir: string -): Promise | undefined> { - const { blocks } = await currentRecord(dir) +function blockDigestsOf(blocks: unknown): ReadonlyMap | undefined { if (!isRecordLike(blocks)) return undefined const digests = new Map() for (const [key, value] of Object.entries(blocks)) { diff --git a/packages/sim-cli/src/commands/protocol/workflow-dir.ts b/packages/sim-cli/src/commands/protocol/workflow-dir.ts index ff4d648a681..3b80d4d67af 100644 --- a/packages/sim-cli/src/commands/protocol/workflow-dir.ts +++ b/packages/sim-cli/src/commands/protocol/workflow-dir.ts @@ -16,7 +16,8 @@ import { SOURCE_ENTRY_FILE, SOURCE_LOCK_FILE, } from '@sim/workflow-code/limits' -import { SDK_GUIDE_FILE, SDK_MAJOR, SOURCE_COMPILER_OPTIONS } from '@sim/workflow-sdk/codegen' +import { SDK_MAJOR } from '@sim/workflow-code/sdk' +import { SDK_GUIDE_FILE, SOURCE_COMPILER_OPTIONS } from '@sim/workflow-sdk/codegen' import { SOURCE_PLANNED_EXIT_CODE, SOURCE_STALE_EXIT_CODE } from '../../exit-codes' import type { ApplyWorkflowSourceBody, GetWorkflowSourceResponse } from '../../generated/v2-api' import type { OperationClient } from '../../runtime/called-operations' diff --git a/packages/sim-cli/src/commands/protocol/workflow-source-get.ts b/packages/sim-cli/src/commands/protocol/workflow-source-get.ts index e91ca0e1dd3..855f0923d6b 100644 --- a/packages/sim-cli/src/commands/protocol/workflow-source-get.ts +++ b/packages/sim-cli/src/commands/protocol/workflow-source-get.ts @@ -62,9 +62,9 @@ async function assertNoLocalEdits(dir: string, source: PrintedSource): Promise command.name() === 'get') diff --git a/packages/sim-cli/src/commands/protocol/workflow-source-params.ts b/packages/sim-cli/src/commands/protocol/workflow-source-params.ts index 9847a95445f..6108fd23e78 100644 --- a/packages/sim-cli/src/commands/protocol/workflow-source-params.ts +++ b/packages/sim-cli/src/commands/protocol/workflow-source-params.ts @@ -19,12 +19,12 @@ const PARAMS_HELP = ` Prints a builder in brief (an example call, the required params with types, the optional ones by name, the gate field that picks which others apply, and the outputs), from the block catalog the last get, create or check cached. --full prints every param with its type, enum, default and doc. -A legacy builder names the one that replaces it. No request is made. is the dotted builder path as source writes it: table.upsertRow, -agent, trigger.schedule, slack.sendMessage (slack.tool.sendMessage names the same builder). A -namespace (gmail, trigger.gmail) lists its builders; a block type prints the builder written for -it (function is fn) or lists them (table_v2); a construct core.d.ts declares (loop, parallel, t, -env) prints its declaration. Run it from a workflow or workspace source directory, -or pass --dir. +A legacy builder names the one that replaces it. No request is made. + is the dotted builder path as source writes it: table.upsertRow, agent, trigger.schedule, +slack.sendMessage (slack.tool.sendMessage names the same builder). A namespace (gmail, +trigger.gmail) lists its builders; a block type prints the builder written for it (function is fn) +or lists them (table_v2); a construct core.d.ts declares (loop, parallel, t, env) prints its +declaration. Run it from a workflow or workspace source directory, or pass --dir. Exit codes: 0 printed; 1 no builder or namespace of that name (the closest one is named), or no cached catalog (run a get once).` diff --git a/packages/sim-cli/src/commands/protocol/workspace-source-dir.ts b/packages/sim-cli/src/commands/protocol/workspace-source-dir.ts index d4833a561bd..be0e7166b59 100644 --- a/packages/sim-cli/src/commands/protocol/workspace-source-dir.ts +++ b/packages/sim-cli/src/commands/protocol/workspace-source-dir.ts @@ -9,8 +9,8 @@ import { mapWithConcurrency } from '@sim/utils/concurrency' import { compareStrings } from '@sim/utils/string' import type { ChildResultFields, WorkflowInput } from '@sim/workflow-code' import { SOURCE_CODE_DIR, SOURCE_ENTRY_FILE, SOURCE_LOCK_FILE } from '@sim/workflow-code/limits' +import { SDK_MAJOR } from '@sim/workflow-code/sdk' import { - SDK_MAJOR, SOURCE_COMPILER_OPTIONS, WORKSPACE_COOKBOOK, WORKSPACE_SDK_DTS, diff --git a/packages/workflow-code/src/catalog/activity.ts b/packages/workflow-code/src/catalog/activity.ts index 90e685ee42c..ad9cd3bacfc 100644 --- a/packages/workflow-code/src/catalog/activity.ts +++ b/packages/workflow-code/src/catalog/activity.ts @@ -148,7 +148,7 @@ export function errorOutputOf( * its block's first. Compile checks output paths and SDK codegen types a builder's outputs by * this one call, so a path compile accepts is one the SDK types. */ -export function builderOutputSchemas( +function builderOutputSchemas( catalog: BlockCatalog, block: CatalogBlock, builder: CatalogBuilder | undefined @@ -162,29 +162,33 @@ export function builderOutputSchemas( /** * The outputs a block declared through `builder` produces: {@link builderOutputSchemas}, narrowed * to the names its operation's tool returns when the catalog records them (`operationOutputs`), - * as SDK codegen types them, so `table.queryRows` has `rows` and never the `row` of the insert - * operations. An operation the catalog records nothing for, a block with no `operationOutputs`, - * and a trigger keep every output: an output's `condition` is not read, since block conditions - * can disagree with the tools behind them. + * so `table.queryRows` has `rows` and never the `row` of the insert operations, with the names + * among them that may be `null`. Compile and SDK codegen both read outputs here. An operation the + * catalog records nothing for, a block with no `operationOutputs`, and a trigger keep every + * output: an output's `condition` is not read, since block conditions can disagree with the tools + * behind them. */ export function builderProducedOutputs( catalog: BlockCatalog, block: CatalogBlock, builder: CatalogBuilder | undefined -): Record { +): { outputs: Record; nullable: ReadonlySet } { const outputs = builderOutputSchemas(catalog, block, builder) const operation = builder?.operation const returned = operation !== undefined && !builder?.triggerMode && outputs === block.outputs ? getOwn(block.operationOutputs ?? {}, operation) : undefined - if (!returned) return outputs - return Object.fromEntries( - returned.names.flatMap((name) => { - const output = getOwn(outputs, name) - return output ? [[name, output] as const] : [] - }) - ) + if (!returned) return { outputs, nullable: new Set() } + return { + outputs: Object.fromEntries( + returned.names.flatMap((name) => { + const output = getOwn(outputs, name) + return output ? [[name, output] as const] : [] + }) + ), + nullable: new Set(returned.nullable ?? []), + } } /** diff --git a/packages/workflow-code/src/compile/function-returns.ts b/packages/workflow-code/src/compile/function-returns.ts index 42b558a4007..48861ee399b 100644 --- a/packages/workflow-code/src/compile/function-returns.ts +++ b/packages/workflow-code/src/compile/function-returns.ts @@ -488,12 +488,13 @@ function readReturns(code: string): ReturnedKinds | null { if (returns.length === 0) return null const inference = new Inference(collectBindings(program)) const whole = wholeKind(program, returns, inference) - const objects = returns.filter((argument) => argument?.type === 'ObjectExpression') + const objects = returns.filter( + (argument): argument is ObjectExpression => argument?.type === 'ObjectExpression' + ) const kinds = new Map() if (objects.length !== returns.length) return { whole, fields: kinds } let agreed: Map | null = null for (const argument of objects) { - if (argument?.type !== 'ObjectExpression') continue const fields = returnedFields(argument, inference) if (agreed === null) { agreed = fields diff --git a/packages/workflow-code/src/compile/values.ts b/packages/workflow-code/src/compile/values.ts index 6cca726aad4..9f8f1b7475b 100644 --- a/packages/workflow-code/src/compile/values.ts +++ b/packages/workflow-code/src/compile/values.ts @@ -829,7 +829,7 @@ function checkOutputPath( // Table rows only refine the element type of `rows`/`row`; the outputs themselves are static. if (!block || (block.dynamicOutputs && block.dynamicOutputs.source !== 'tableRows')) return const builder = target.builder.kind === 'catalog' ? target.builder.builder : undefined - const outputs = builderProducedOutputs(ctx.catalog, block, builder) + const { outputs } = builderProducedOutputs(ctx.catalog, block, builder) if (outputKnown(outputs, segments)) return const errorOutput = errorOutputOf(block, segments) if (errorOutput) { @@ -920,7 +920,7 @@ export function checkDynamicOutputRefs( const [first] = segments if (fields === null || first?.kind !== 'name' || fields.includes(first.name)) continue const builder = target.builder.kind === 'catalog' ? target.builder.builder : undefined - const outputs = builderProducedOutputs(ctx.catalog, block, builder) + const { outputs } = builderProducedOutputs(ctx.catalog, block, builder) if (outputKnown(outputs, segments)) continue const errorOutput = errorOutputOf(block, segments) if (errorOutput) { diff --git a/packages/workflow-code/src/index.ts b/packages/workflow-code/src/index.ts index 3539821e7eb..395bdb81e50 100644 --- a/packages/workflow-code/src/index.ts +++ b/packages/workflow-code/src/index.ts @@ -3,7 +3,6 @@ export { babelErrorShape, babelMessage } from './babel' export { type CanonicalizeResult, canonicalize, canonicalizeUnderLock } from './canonicalize' export { toolModes } from './canonicalize/modes' export { - builderOutputSchemas, builderProducedOutputs, executableInactiveParams, } from './catalog/activity' diff --git a/packages/workflow-code/src/responds.test.ts b/packages/workflow-code/src/responds.test.ts new file mode 100644 index 00000000000..dfa522b799b --- /dev/null +++ b/packages/workflow-code/src/responds.test.ts @@ -0,0 +1,36 @@ +import { describe, expect, it } from 'vitest' +import type { CanonicalBlock } from './model' +import { calledWorkflowKey } from './responds' + +function blockNaming(type: string, workflowKey: string): CanonicalBlock { + return { + key: 'call', + name: 'Call', + type, + parent: null, + enabled: true, + locked: false, + triggerMode: false, + advancedMode: false, + errorPort: true, + retry: null, + params: { + workflowId: { + kind: 'value', + value: { $sim: 'resource', kind: 'workflow', key: workflowKey }, + }, + }, + modes: {}, + } +} + +describe('calledWorkflowKey', () => { + it('names the child of a block that runs one', () => { + expect(calledWorkflowKey(blockNaming('workflow_input', 'billing'))).toBe('billing') + expect(calledWorkflowKey(blockNaming('workflow', 'billing'))).toBe('billing') + }) + + it('is null for a block that names a workflow it never runs', () => { + expect(calledWorkflowKey(blockNaming('deployments', 'billing'))).toBeNull() + }) +}) diff --git a/packages/workflow-code/src/responds.ts b/packages/workflow-code/src/responds.ts index 547ef075817..ced095f7a50 100644 --- a/packages/workflow-code/src/responds.ts +++ b/packages/workflow-code/src/responds.ts @@ -126,8 +126,15 @@ export function childResultFields( return fields } +/** + * The block types that run a workflow as a child. Another block may name a workflow in its + * `workflowId` (Deployments deploys or promotes one) without calling it. + */ +const CHILD_WORKFLOW_BLOCK_TYPES: ReadonlySet = new Set(['workflow', 'workflow_input']) + /** The key of the workflow `block` runs as a child (its `workflowId` names one), else `null`. */ export function calledWorkflowKey(block: CanonicalBlock): string | null { + if (!CHILD_WORKFLOW_BLOCK_TYPES.has(block.type)) return null const param = getOwn(block.params, 'workflowId') const child = param?.kind === 'value' ? param.value : undefined return isResource(child, 'workflow') ? child.key : null diff --git a/packages/workflow-sdk/src/codegen/generate.ts b/packages/workflow-sdk/src/codegen/generate.ts index ceb7de6eb43..55f5308f086 100644 --- a/packages/workflow-sdk/src/codegen/generate.ts +++ b/packages/workflow-sdk/src/codegen/generate.ts @@ -17,8 +17,8 @@ */ import { compareStrings } from '@sim/utils/string' -import type { BlockCatalog, CatalogBlock, CatalogOutput, CatalogSubBlock } from '@sim/workflow-code' -import { builderOutputSchemas, printKey, quoteString } from '@sim/workflow-code' +import type { BlockCatalog, CatalogBlock, CatalogSubBlock } from '@sim/workflow-code' +import { builderProducedOutputs, printKey, quoteString } from '@sim/workflow-code' import { type EditorDefault, subBlockEditorDefault } from '@sim/workflow-code/catalog/defaults' import { builderPins, @@ -262,31 +262,6 @@ export interface BuilderTypes { facts: ParamFacts } -/** - * The outputs of an operation builder whose tool the catalog records (`operationOutputs`): only - * those the tool returns, and which of them may be `null`. - */ -function operationOutputs( - block: CatalogBlock, - entry: BuilderEntry, - outputs: Record -): { outputs: Record; nullable: ReadonlySet } { - const operation = entry.builder.operation - const byOperation = block.operationOutputs - const returned = - operation !== undefined && - !entry.builder.triggerMode && - outputs === block.outputs && - byOperation && - Object.hasOwn(byOperation, operation) - ? byOperation[operation] - : undefined - if (!returned) return { outputs, nullable: new Set() } - const picked: Record = {} - for (const name of returned.names) if (Object.hasOwn(outputs, name)) picked[name] = outputs[name] - return { outputs: picked, nullable: new Set(returned.nullable ?? []) } -} - /** The label of `operation` in the block's operation dropdown, if it has one. */ export function operationLabel(block: CatalogBlock, operation: string): string | undefined { const dropdown = block.subBlocks.find((subBlock) => subBlock.id === 'operation') @@ -483,11 +458,7 @@ export function builderTypes(catalog: BlockCatalog, entry: BuilderEntry): Builde `sdk codegen: builder \`${entry.key}\` names unknown block type \`${entry.builder.type}\`` ) } - const { outputs, nullable } = operationOutputs( - block, - entry, - builderOutputSchemas(catalog, block, entry.builder) - ) + const { outputs, nullable } = builderProducedOutputs(catalog, block, entry.builder) const spec = block.dynamicOutputs ?? null const plan = spec && !entry.special ? dynamicOutputPlan(spec, outputs, entry.builder.operation) : null diff --git a/packages/workflow-sdk/src/codegen/index.ts b/packages/workflow-sdk/src/codegen/index.ts index 8cc93fb21a5..6b76de6386a 100644 --- a/packages/workflow-sdk/src/codegen/index.ts +++ b/packages/workflow-sdk/src/codegen/index.ts @@ -1,4 +1,3 @@ -export { SDK_MAJOR } from '@sim/workflow-code/sdk' export { COOKBOOK_EXAMPLES } from './cookbook-text.generated' export { CORE_DTS } from './core-text.generated' export { @@ -21,7 +20,6 @@ export { type BuilderLookup, type BuilderReference, builderSnippet, - type CompactBuilderReference, compactBuilder, describeBuilder, lookupBuilder, diff --git a/packages/workflow-sdk/src/codegen/reference.test.ts b/packages/workflow-sdk/src/codegen/reference.test.ts index 6f0f16e99cf..392e6fea2de 100644 --- a/packages/workflow-sdk/src/codegen/reference.test.ts +++ b/packages/workflow-sdk/src/codegen/reference.test.ts @@ -12,9 +12,9 @@ const CATALOG = JSON.parse( ) as BlockCatalog describe('builder reference', () => { - it('says table.upsertRow replaces the row, and names update builders that exist', () => { + it("names only update builders that exist in table.upsertRow's doc", () => { const upsert = describeBuilder(CATALOG, 'table.upsertRow') - expect(upsert?.doc).toContain('Replaces the matched row') + expect(upsert?.doc).toMatch(/`table\.\w+`/) for (const [, name] of upsert?.doc?.matchAll(/`(table\.\w+)`/g) ?? []) { expect(describeBuilder(CATALOG, name), name).not.toBeNull() } diff --git a/scripts/sync-workflow-code-docs.ts b/scripts/sync-workflow-code-docs.ts index 4c8f21f9e2a..88249074c26 100644 --- a/scripts/sync-workflow-code-docs.ts +++ b/scripts/sync-workflow-code-docs.ts @@ -280,11 +280,7 @@ function buildDiagnostics(errors: string[]): string { const workflowMeaning = new Map( workflowRows.flatMap((row) => row.codes.map((code) => [code, row.meaning])) ) - for (const [what, documented, exported] of [ - ['SYNTAX.md Diagnostics', [...workflowMeaning.keys()], DIAGNOSTIC_CODES], - ] as const) { - errors.push(...codeDiff(what, documented, exported)) - } + errors.push(...codeDiff('SYNTAX.md Diagnostics', [...workflowMeaning.keys()], DIAGNOSTIC_CODES)) const { groups: workspace, undocumented } = parseWorkspaceDiagnostics() if (undocumented.length)