Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/docs/content/docs/workflows/code/diagnostics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ Workspace source reports every workflow code above for the files of `workflows/<
| Code | Meaning |
| --- | --- |
| `E_SECRET_NAME` | A declared name outside the secret name format. |
| `E_SECRET_MISSING` | A workflow uses a declared secret the workspace holds no value for: it is held back. |
| `E_SECRET_MISSING` | A workflow reads a declared secret the workspace holds no value for: it is held back. The finding points at the first line that reads it, and replaces `W_ENV_UNKNOWN` for that name. |
| `W_SECRET_MISSING` | A declared secret the workspace holds no value for. |

#### Credentials (`credentials.ts`)
Expand All @@ -258,7 +258,7 @@ Workspace source reports every workflow code above for the files of `workflows/<
| `E_TABLE_TOO_MANY_COLUMNS` | More columns than a table may hold: a size limit, classed like `E_LIMIT_EXCEEDED`. |
| `E_TABLE_OPTIONS` | A select column without options, an option declared twice, or options on another type. |
| `E_TABLE_TYPE_CONVERSION` | A type change the stored cells cannot convert to. |
| `E_TABLE_FOLDER` | A table folder that does not exist in the workspace. |
| `E_TABLE_FOLDER` | A table folder that does not exist in the workspace. The hint creates each missing folder, parent first. |
| `E_TABLE_ROWS` | The declaration's `rows` or its `tables/<key>.rows.jsonl`: a bad mode or key column, a line that is not a row of declared columns, a managed row without its key or repeating one. |
| `I_TABLE_SEED_SKIPPED` | Seed rows declared for a table that already holds rows: only a new or empty table is seeded. |
| `I_TABLE_ROWS_UNKEYED` | Managed rows whose key cell is empty (a row the table's "add row" made and nobody keyed): no file line can name them, so a get leaves them out and an apply keeps them as they are. |
Expand Down Expand Up @@ -309,7 +309,7 @@ Workspace source reports every workflow code above for the files of `workflows/<
| `E_KB_DOC_NAME` | A document file name or type the knowledge base cannot hold. |
| `E_KB_DOC_EMPTY` | An empty document, which a knowledge base cannot index. |
| `E_KB_CHUNKING` | Chunking settings outside what a knowledge base accepts. |
| `E_KB_FOLDER` | A knowledge base folder that does not exist in the workspace. |
| `E_KB_FOLDER` | A knowledge base folder that does not exist in the workspace. The hint creates each missing folder, parent first. |
| `W_KB_DOC_UNCHECKED` | A stored document whose bytes this request had no budget left to download and compare. |
| `W_KB_DOC_FAILED` | Documents whose indexing failed: search does not find them until they are indexed again. |
| `I_KB_REEMBED` | How many documents the apply indexes (embeds) after it writes them. |
Expand Down Expand Up @@ -344,7 +344,7 @@ Workspace source reports every workflow code above for the files of `workflows/<
| `E_APPLY_REFUSED` | A change a child operation refused, with its message. |
| `E_APPLY_FAILED` | A write failed for a reason that is not the source's (logged on the server). |
| `E_PLAN_TOO_LARGE` | The apply would make more changes or touch more workflows than one request may. |
| `E_PLAN_REF_DELETED` | A declared resource references one this apply deletes. |
| `E_PLAN_REF_DELETED` | A declared resource references one this apply deletes. For an edited workflow, the finding points at the line that uses it. |
| `E_PLAN_REF_HELD` | A declared resource references one this apply holds back, so it is held back too. |
| `W_RESOURCE_IN_USE` | A resource this apply deletes is still used by stored workflows. |
| `W_TABLE_COLUMN_RENAMED_IN_USE` | A table column this apply renames is still written, filtered or sorted by its old name in a stored workflow's Table block, which the run then drops. |
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/workflows/code/directory.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ A resource's key is its file or folder name, and a workflow names it by that key

{/* workflow-code-docs:directory-kinds:begin — generated by `bun run generate:workflow-code-docs`; do not edit between markers */}

- `secrets.ts`: `export default defineSecrets({ NAME: { description? } })`, the workspace secrets workflows read, by name and description only (never a value: set one with `sim secrets set NAME --scope workspace`). A workflow: `env.NAME`; one using a declared secret the workspace has no value for is held back, and the rest apply.
- `secrets.ts`: `export default defineSecrets({ NAME: { description? } })`, the workspace secrets workflows read, by name and description only (never a value: set one with `sim secrets set NAME --scope workspace`). A workflow: `env.NAME`; one using a declared secret the workspace has no value for is held back, and the rest apply. A get prints only the secrets the workspace has a value for, so a declared secret without one stays only in your directory.
- `credentials.ts`: `export default defineCredentials({ <key>: { provider, name? } })`, binding each key to this workspace's credential for that provider (never a token): the one bound already, else the only one, else the one whose display name is `name`. A workflow: `credential('<key>')`; one using a key no credential binds to is held back, and the rest apply.
- `tools/<key>.ts` (`defineTool({ title, schema, code: codeFile('./<key>.js') })`) and its code in `tools/<key>.js`, where each schema parameter is a variable. Code holding a literal credential prints as `code: stored()`, which keeps the stored code. A workflow: `customTool('<key>')`.
- `skills/<key>.md`: a frontmatter block of `name` and `description`, then the content. A workflow: `skills: [skill('<key>')]` on an agent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function withPendingResources(

/**
* Every `(kind, key)` resource reference in a compiled model, for ident lookup, and the tool each
* MCP agent tool (`mcp(key).tool(name)`) names on its server.
* MCP agent tool (`mcp(key).tool(name)`) names on its server, each at `span`.
*/
function collectResourceKeys(
value: unknown,
Expand All @@ -85,7 +85,7 @@ function collectResourceKeys(
isResourceKind(record.kind) &&
typeof record.key === 'string'
) {
refs.push({ kind: record.kind, key: record.key })
refs.push({ kind: record.kind, key: record.key, ...(span ? { span } : {}) })
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
}
const tool = mcpToolReference(record)
if (tool) refs.push(span ? { ...tool, span } : tool)
Expand Down Expand Up @@ -163,10 +163,13 @@ export async function resolveSubmission(

const compiledKeys: SourceReference[] = []
for (const [key, block] of Object.entries(compiledWorkflow.blocks)) {
const span =
compiled.spans[encodeAnchor({ kind: 'param', block: key, param: 'tools' })] ??
compiled.spans[encodeAnchor({ kind: 'block', block: key })]
collectResourceKeys(block, compiledKeys, span)
const blockSpan = compiled.spans[encodeAnchor({ kind: 'block', block: key })]
const { params, ...rest } = block
for (const [param, value] of Object.entries(params)) {
const span = compiled.spans[encodeAnchor({ kind: 'param', block: key, param })] ?? blockSpan
collectResourceKeys(value, compiledKeys, span)
}
collectResourceKeys(rest, compiledKeys, blockSpan)
}
const storedResources = resources
const newKeys = compiledKeys.filter(({ kind, key }) => storedResources.toId(kind, key) === null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
CanonicalWorkflow,
CanonicalWorkflowMeta,
ChildResultFields,
EnvReference,
LockIdentity,
ResourceKeyResolver,
ResourceKind,
Expand Down Expand Up @@ -77,7 +78,7 @@ export interface SourceEvaluationInput {
*/
export interface SourceReference extends ResourceKeyRef {
member?: string
/** Where the entry file writes the reference, for an MCP tool: the agent's `tools`. */
/** Where the source writes the reference: the block param that holds it, else the block. */
span?: SourceSpan
}

Expand Down Expand Up @@ -133,8 +134,8 @@ export interface SourcePlan {
resources: ResourceKeyResolver
/** Every resource the submitted source names by key, as the compiler read it. */
references: SourceReference[]
/** Every env name the submitted source reads, as the compiler read it. */
envReferences: string[]
/** Every env name the submitted source reads, and where, as the compiler read it. */
envReferences: EnvReference[]
/** The child result fields the compile typed with, which every print of the plan types with. */
childResults?: ReadonlyMap<string, ChildResultFields>
}
Expand Down
8 changes: 7 additions & 1 deletion apps/sim/lib/workflows/application/source-pipeline/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export type SourceTarget =
export interface SourceLoads {
catalogGate?: Promise<CatalogGate>
envNames?: Promise<string[]>
/**
* The env names the workspace directory's `secrets.ts` declares, which a plan reads as known, as
* the offline check does: a workflow that reads one the workspace holds no value for is held
* back (`E_SECRET_MISSING`, at the read) rather than warned about (`W_ENV_UNKNOWN`).
*/
declaredEnvNames?: readonly string[]
/** The child workflows read to type their callers' results (`loadChildResults`). */
childResults?: ChildResultsMemo
/** The workflow folders the workspace source apply writes, which its callers are typed by. */
Expand Down Expand Up @@ -174,7 +180,7 @@ export async function loadSourceTarget(
storedCanonical.canonical,
storedCanonical.resources
),
envNames,
envNames: [...envNames, ...(loads.declaredEnvNames ?? [])],
scope,
}
})
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/lib/workflows/application/source-pipeline/plan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Principal } from '@sim/auth/principal'
import type {
BlockCatalog,
EnvReference,
ResourceKind,
SourceBase,
SourceFingerprint,
Expand Down Expand Up @@ -113,7 +114,7 @@ export interface SourcePlanSummary {
diff: SourceDiffSummary
/** What the source references, as the compiler read it; empty when it did not compile. */
references: readonly SourceReference[]
envReferences: readonly string[]
envReferences: readonly EnvReference[]
/** Whether a graph no-op still changes source meta (idents, order or comments). */
sourceMetaChanged: boolean
/** The workflow's name after the write; absent for a refusal. */
Expand Down
39 changes: 37 additions & 2 deletions apps/sim/lib/workspace-source/application/apply.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,36 @@ describe('workspace source apply', () => {
const taken = await refusal(
apply(workspaceId, { 'tables/other.ts': LEADS }, { kinds: ['table'], only: ['table'] })
)
expect(codes(taken.diagnostics)).toContain('E_NAME_TAKEN')
expect(taken.diagnostics).toContainEqual(
expect.objectContaining({
code: 'E_NAME_TAKEN',
file: 'tables/other.ts',
message:
'tables/other declares the table name "leads", which belongs to the table under key "leads".',
})
)
}
)

check(
'a missing nested table folder hints one create per missing level, parent first',
async () => {
const workspaceId = await newWorkspace()
const nested = LEADS.replace("name: 'leads',", "name: 'leads',\n folder: '/qa/sub',")

const refused = await refusal(
apply(workspaceId, { 'tables/leads.ts': nested }, { kinds: ['table'], only: ['table'] })
)

expect(refused.diagnostics).toEqual([
expect.objectContaining({
code: 'E_TABLE_FOLDER',
file: 'tables/leads.ts',
hint: expect.stringContaining(
'Create it first (`sim tables folders create "qa"`, then `sim tables folders create "qa/sub"`)'
),
}),
])
}
)

Expand Down Expand Up @@ -754,7 +783,13 @@ describe('workspace source apply', () => {
)

expect(codes(refused.diagnostics)).toEqual(['E_PLAN_REF_DELETED'])
expect(refused.diagnostics[0]).toMatchObject({ kind: 'workflow', key: 'ingest' })
const source = files['workflows/ingest/workflow.ts'].split('\n')
expect(refused.diagnostics[0]).toMatchObject({
kind: 'workflow',
key: 'ingest',
file: 'workflows/ingest/workflow.ts',
line: source.findIndex((line) => line.includes("'Save Lead'")) + 1,
})
expect(await tables(workspaceId)).toHaveLength(1)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,9 @@ export default workflow('Reader', {}, () => {
.filter((finding) => finding.severity === 'error')
.map((finding) => `${finding.code} ${finding.kind}:${finding.key}`)
).toEqual(['E_PLAN_REF_DELETED workflow:reader'])
expect(
refused.diagnostics.find((finding) => finding.code === 'E_PLAN_REF_DELETED')
).toMatchObject({ file: 'workflows/reader/workflow.ts', line: expect.any(Number) })
}
)
check(
Expand Down
Loading
Loading