sim 2.3.0-preview.329.1 → 2.3.0-preview.331.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/protocol/workspace-source-dir.d.ts +3 -1
- package/dist/index.js +50 -25
- package/dist/runtime.js +50 -25
- package/package.json +1 -1
|
@@ -15,7 +15,9 @@ export declare const WORKSPACE_TREE: SourceTreeProfile;
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function localDeclarations(files: Readonly<Record<string, string>>): LocalDeclarations;
|
|
17
17
|
/** A table column as a workflow's row writes name it. */
|
|
18
|
-
interface DeclaredColumn {
|
|
18
|
+
export interface DeclaredColumn {
|
|
19
|
+
/** Its key in `tables/<key>.ts`, which differs from the name row writes use once `name` is set. */
|
|
20
|
+
key: string;
|
|
19
21
|
/** The option names of a `select` column. */
|
|
20
22
|
options?: readonly string[];
|
|
21
23
|
/** A `select` column whose cells hold several options. */
|
package/dist/index.js
CHANGED
|
@@ -23754,7 +23754,7 @@ class SimClient {
|
|
|
23754
23754
|
this.resolveCredential(options.auth);
|
|
23755
23755
|
const workspaceId = explicit ?? this.profile.workspaceId;
|
|
23756
23756
|
if (!workspaceId) {
|
|
23757
|
-
throw new SimApiError(`No workspace set for profile "${this.profile.name}". Pass
|
|
23757
|
+
throw new SimApiError(`No workspace set for profile "${this.profile.name}". Pass -w <workspaceId>, set SIM_WORKSPACE, or run: sim configure --profile ${this.profile.name} --set-workspace <id>`, 0);
|
|
23758
23758
|
}
|
|
23759
23759
|
return workspaceId;
|
|
23760
23760
|
}
|
|
@@ -35174,12 +35174,14 @@ Inputs:
|
|
|
35174
35174
|
manualTableId; a string goes to the typed field). Add the type it answers with: \`blocks get
|
|
35175
35175
|
table\` answers table_v2, and an add of legacy table is refused.
|
|
35176
35176
|
conditions (condition): [{"title":"if","value":"<start.n> > 3"},{"title":"else if","value":"…"},
|
|
35177
|
-
{"title":"else","value":""}]; the last entry is the else
|
|
35177
|
+
{"title":"else","value":""}]; the last entry is the else. Each entry's id comes from its
|
|
35178
|
+
position (<block id>-if, <block id>-else-if-0, …, <block id>-else): an id you pass is replaced.
|
|
35178
35179
|
inputFormat (Start): [{"name":"email","type":"string"}]; types string, number, boolean,
|
|
35179
35180
|
object, array, file[]; an optional default "value" as text.
|
|
35180
35181
|
Block settings, beside inputs in an add's or edit's params:
|
|
35181
35182
|
"retry":{"enabled":true,"maxTries":3,"waitBetweenTriesMs":1000} retries a failed block; null
|
|
35182
|
-
clears it.
|
|
35183
|
+
clears it. An api block's retries input repeats the request after a timeout, reset, 429 or
|
|
35184
|
+
5xx, not when the host does not resolve or refuses the connection; "retry" covers that.
|
|
35183
35185
|
Outputs:
|
|
35184
35186
|
A block that fails outputs {"error":"<message>"}: connect its error handle and read
|
|
35185
35187
|
<name.error> there (without one, the run fails). A Workflow block's result is the child's
|
|
@@ -37997,7 +37999,7 @@ async function coerce(raw, field, flag, flagName) {
|
|
|
37997
37999
|
return encodeFolderPath(raw);
|
|
37998
38000
|
return raw;
|
|
37999
38001
|
}
|
|
38000
|
-
var NO_WORKSPACE_FALLBACK = "No workspace set. Pass
|
|
38002
|
+
var NO_WORKSPACE_FALLBACK = "No workspace set. Pass -w <workspaceId>, set SIM_WORKSPACE, or run: sim configure --set-workspace <id>";
|
|
38001
38003
|
function asQueryValue(value) {
|
|
38002
38004
|
if (value === null || value === undefined)
|
|
38003
38005
|
return;
|
|
@@ -38492,6 +38494,14 @@ function foldOtherSpellings(operation, commandSpec, flags) {
|
|
|
38492
38494
|
}
|
|
38493
38495
|
}
|
|
38494
38496
|
}
|
|
38497
|
+
function withSearchedWorkspace(error, profile) {
|
|
38498
|
+
if (!(error instanceof SimApiError) || error.status !== 404 || !profile.workspaceId)
|
|
38499
|
+
return error;
|
|
38500
|
+
const source = profile.sources.workspaceId;
|
|
38501
|
+
const from = source === "env" ? ", from SIM_WORKSPACE; pass -w <workspaceId> to search another" : source === "config" ? `, the workspace of profile "${safeOneLine(profile.name)}"; pass -w <workspaceId> or set SIM_WORKSPACE to search another` : "";
|
|
38502
|
+
const searched = `searched workspace ${safeOneLine(profile.workspaceId)}${from}`;
|
|
38503
|
+
return new SimApiError(`${error.message} (${searched})`, error.status, error.code, error.details, error.exitCode, error.requestId);
|
|
38504
|
+
}
|
|
38495
38505
|
async function executeOperation(operation, commandSpec, operationSpec, invocation) {
|
|
38496
38506
|
const host = invocation[invocation.length - 1];
|
|
38497
38507
|
const inheritedFlags = host.optsWithGlobals();
|
|
@@ -38575,6 +38585,8 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
|
|
|
38575
38585
|
if (cursor && rows.length < limit)
|
|
38576
38586
|
progress.advance(rows.length);
|
|
38577
38587
|
} while (cursor && rows.length < limit);
|
|
38588
|
+
} catch (error) {
|
|
38589
|
+
throw needsWorkspace ? withSearchedWorkspace(error, profile) : error;
|
|
38578
38590
|
} finally {
|
|
38579
38591
|
progress.finish();
|
|
38580
38592
|
}
|
|
@@ -38600,7 +38612,7 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
|
|
|
38600
38612
|
reconciliation: "Find the operation using this requestId, or retry identical inputs with the same requestId."
|
|
38601
38613
|
}, failure.exitCode, failure.requestId);
|
|
38602
38614
|
}
|
|
38603
|
-
throw error;
|
|
38615
|
+
throw needsWorkspace ? withSearchedWorkspace(error, profile) : error;
|
|
38604
38616
|
}
|
|
38605
38617
|
let payload = result?.data ?? result;
|
|
38606
38618
|
if (commandSpec.workspaceOperation && (Boolean(request.body?.requestId) || requestFlags.wait === true || payload && typeof payload === "object" && ("operationId" in payload))) {
|
|
@@ -40745,7 +40757,8 @@ export default workflow('Cookbook', { description: 'One example of each common b
|
|
|
40745
40757
|
})
|
|
40746
40758
|
// Upsert: updates the row whose conflictColumn (a unique column, by name) matches data, else
|
|
40747
40759
|
// inserts one, so a second run for the same order updates it. table.insertRow takes the same
|
|
40748
|
-
// data without conflictColumn and adds a row every run.
|
|
40760
|
+
// data without conflictColumn and adds a row every run. data is keyed by column name: a column
|
|
40761
|
+
// declared as \`phone: column.string({ name: 'mobile' })\` is written as { mobile: ... }.
|
|
40749
40762
|
const save = table.upsertRow('Save Order', {
|
|
40750
40763
|
tableId: table('orders'),
|
|
40751
40764
|
data: { orderId: start.orderId, status: 'open' },
|
|
@@ -51459,13 +51472,14 @@ function dynamicOutputPlan(spec, outputs, operation) {
|
|
|
51459
51472
|
var RUNTIME_SEMANTICS = [
|
|
51460
51473
|
"## How it runs",
|
|
51461
51474
|
"",
|
|
51462
|
-
"- **Two retries, nested.** An `api` block's `retries`, `retryDelayMs` and `retryMaxDelayMs` repeat the HTTP request inside one run of the block: only after a timeout, a connection reset, a 429 or a 5xx, only for GET, HEAD, PUT and DELETE unless `retryNonIdempotent: true`, with jittered exponential backoff capped at `retryMaxDelayMs` (a `Retry-After` beyond the cap ends the retries). `meta.retry` (`{ enabled, maxTries, waitBetweenTriesMs }`) reruns the whole block, request retries included, after any failure but a stop or a failed child workflow; `maxTries` counts every try. So `retries: 2` under `maxTries: 3` sends up to 9 requests. Only the last try's failure reaches `onError`. Triggers and `human` never retry.",
|
|
51475
|
+
"- **Two retries, nested.** An `api` block's `retries`, `retryDelayMs` and `retryMaxDelayMs` repeat the HTTP request inside one run of the block: only after a timeout, a connection reset, a 429 or a 5xx (a host that does not resolve or refuses the connection fails at once), only for GET, HEAD, PUT and DELETE unless `retryNonIdempotent: true`, with jittered exponential backoff capped at `retryMaxDelayMs` (a `Retry-After` beyond the cap ends the retries). `meta.retry` (`{ enabled, maxTries, waitBetweenTriesMs }`) reruns the whole block, request retries included, after any failure but a stop or a failed child workflow; `maxTries` counts every try. So `retries: 2` under `maxTries: 3` sends up to 9 requests. Only the last try's failure reaches `onError`. Triggers and `human` never retry.",
|
|
51463
51476
|
"- **`onError`.** `x.onError(y)` makes a failure of `x` an output, `{ error: '<message>' }`, and runs `y` instead of `x`'s other targets; the run goes on. `y` reads the message as `x.error` (only a block with an `onError` edge has it). In a loop or parallel body (`y` must be in the same body) the iteration ends normally and the loop moves to the next item, with that error output as `x`'s entry for the iteration. Without `onError`, a failure in any iteration fails the run and stops the loop.",
|
|
51464
51477
|
"- **Joins run once.** A block with several incoming edges runs once, after every one of them has fired or been ruled out (a condition or router branch not taken, the normal edge of a block that failed into `onError`). `a.to(join)`, `b.to(join)`, `c.to(join)` wait for all three; behind a condition only the taken branch fires, and the join runs once after it. A block never runs once per incoming branch. A reference to a block that did not run (on the branch not taken) resolves empty: `null` as a whole value, in function code or in a condition, `''` inside text.",
|
|
51465
51478
|
"- **Loop and parallel results.** `x.results` holds one entry per iteration (a parallel: per branch), and each entry is the list of outputs of the body blocks that ran in it, in the order they finished. With one block in the body its output is `x.results[i][0]`; `x.results.flat()` lists every output.",
|
|
51466
51479
|
"- **Outputs in function code.** In `fn` code, `${a.content}` inside js`` is not spliced in as text: it becomes an expression that evaluates to the output's value, a string as a string and an object as an object. Write it where an expression goes (`const reply = ${a.content}`, `[${a.content}, ${b.content}]`) and never wrap it in quotes. Written inside a JavaScript string or template literal it splices in as JSON, quotes included (`'Hi ${a.content}'` gives `Hi \"hello\"`). Python code works the same way.",
|
|
51467
51480
|
"- **Child workflows.** `const c = runWorkflow('C', { workflowId: childWorkflow('k'), inputMapping })` outputs the child's run as `c.result`: the output of the first `response` block the child reaches, `{ data, status, headers }` (a field of its `body` is `c.result.data.field`), or, with no `response` block, the output of the last block it ran. `c.result` is untyped: wrap a value that should become text in `t`. A deployed run of the parent (API, webhook, schedule, chat) runs the child's deployed version and fails while the child is not deployed; a run from the editor runs the child's draft. A failed child fails `c` (`c.onError(...)` catches it).",
|
|
51468
51481
|
"- **MCP headers** (`mcp/<key>.ts`). A header value is plain text in which `{{NAME}}` names an env variable anywhere (`Authorization: 'Bearer {{GITHUB_TOKEN}}'`), `env.NAME` for a whole value, or `stored()` to keep the value the server holds. A `t` template or a template literal with `${}` is refused. A credential header (`Authorization`, `Cookie`, or a name with `key`, `token`, `secret`, `auth`, `password`, `session`, `signature` or `credential`) holds nothing but an optional scheme word (`Bearer`, `Basic`, `Token`, `Bot`, `ApiKey`) and `{{NAME}}` references (`E_MCP_LITERAL_SECRET`). The variables resolve when the server connects, from the personal and workspace env (the workspace value wins); a missing one fails the connection.",
|
|
51482
|
+
"- **Table rows are keyed by column name.** A Table block's `data` (and `conflictColumn`, and a filter's `field`) names each column by its name: its key in `tables/<key>.ts`, or the `name` set there (`phone: column.string({ name: 'mobile' })` is written `{ mobile: … }`). A key naming no column is dropped from the row at run time; `check` and `apply` warn on it (`W_TABLE_UNKNOWN_COLUMN`). A table's `rows.jsonl` is the exception: it is keyed by column key.",
|
|
51469
51483
|
"- **MCP tool names are checked late.** `mcp('k').tool('name')` is type-checked only when `workspace.d.ts` lists that server's tools; a server that could not be listed, or one declared but not yet applied, takes any name. `sim workflows source check` and `sim workflows source apply` do not check tool names (the apply checks only that the server exists). `sim workspaces source apply` checks the tools of each workflow it changes against the server's live listing (`E_MCP_TOOL_UNKNOWN`, or `W_MCP_TOOLS_UNCHECKED` when it cannot list the server). Otherwise a wrong name surfaces at run time: the agent block fails before the model runs, `MCP operation \"name\" is missing or not permitted`.",
|
|
51470
51484
|
""
|
|
51471
51485
|
];
|
|
@@ -52488,7 +52502,8 @@ Write like a person, not a policy. Lead with the answer, then the one detail tha
|
|
|
52488
52502
|
import { column, defineTable } from '@sim/workflow-sdk/workspace'
|
|
52489
52503
|
|
|
52490
52504
|
// tables/<key>.ts: the key (\`orders\`) is how a workflow names it: table('orders'). Its rows stay
|
|
52491
|
-
// out of source (see plans.ts to opt in). To rename a column keep its key and set \`name
|
|
52505
|
+
// out of source (see plans.ts to opt in). To rename a column keep its key and set \`name\`: a
|
|
52506
|
+
// workflow's row data (\`data\`, \`conflictColumn\`, filters) names a column by that name, not its key.
|
|
52492
52507
|
export default defineTable({
|
|
52493
52508
|
name: 'orders',
|
|
52494
52509
|
description: 'Order questions the support workflow answered',
|
|
@@ -56653,14 +56668,14 @@ var WORKFLOW_PRIMER = `# Sim workflow source: primer
|
|
|
56653
56668
|
- **Deploy**: apply saves a draft; \`apply --deploy\` also deploys it, or \`sim workflows deploy <workflowId>\` publishes the saved draft later.
|
|
56654
56669
|
${sharedRules("sim workflows source")}
|
|
56655
56670
|
`;
|
|
56656
|
-
var WORKSPACE_RENAMES = " A column: change its `name`, keep its key (cells stay)
|
|
56671
|
+
var WORKSPACE_RENAMES = " A column: change its `name`, keep its key (cells stay). Table blocks (`data`, `conflictColumn`, filters) use the name, not the key, and keep old names (`W_TABLE_COLUMN_RENAMED_IN_USE`). A file's key never changes (`E_KEY_RENAMED`): rename by `name`.";
|
|
56657
56672
|
var WORKSPACE_PRIMER = `# Sim workspace source: primer
|
|
56658
56673
|
|
|
56659
|
-
This directory is a Sim workspace as files (\`tables/\`, \`workflows/<key>/workflow.ts\`, …);
|
|
56674
|
+
This directory is a Sim workspace as files (\`tables/\`, \`workflows/<key>/workflow.ts\`, …); nothing in it runs. Commands read the workspace id from \`${SOURCE_BASE_FILE}\`; run them from this directory.
|
|
56660
56675
|
|
|
56661
56676
|
**Edit loop**: edit the files → \`sim workspaces source check --dir .\` (offline; refreshes \`workspace.d.ts\` and \`tsconfig.json\`) → \`${typecheckCommand()}\` → \`sim workspaces source apply --dir . --dry-run\` → \`--yes\`. Rerun each step until it exits 0. Apply rewrites the directory from what it stored: read a file again before the next edit.
|
|
56662
56677
|
|
|
56663
|
-
- **Deletes**: a removed file (a resource this directory managed), table column, workflow block or
|
|
56678
|
+
- **Deletes**: a removed file (a resource this directory managed), table column, workflow block or variable is deleted only with \`apply --allow-delete\` and cannot be undone. A kind is managed only when its folder exists.
|
|
56664
56679
|
- **Deploy**: \`deployments/<workflow key>.ts\` (\`defineDeployment({ live: 'draft' })\`) deploys that workflow on apply, which prints its webhook URLs; without one, apply never deploys.
|
|
56665
56680
|
- **Promote** (dev → prod): \`sim workspaces source apply --dir . --to <workspaceId> --dry-run\`, then \`--yes\`.
|
|
56666
56681
|
- **Exit ${SOURCE_HELD_EXIT_CODE}**: written in part; changes using an unset secret or unbound credential were held back: set it, apply again.
|
|
@@ -59798,14 +59813,14 @@ function isCurrencyMarkerLetters(letters) {
|
|
|
59798
59813
|
return !SCALE_SUFFIX.test(upper);
|
|
59799
59814
|
return supportedCurrencyCodes.has(upper);
|
|
59800
59815
|
}
|
|
59801
|
-
var CURRENCY_MARKER_PREFIX =
|
|
59802
|
-
var CURRENCY_MARKER_SUFFIX = /
|
|
59816
|
+
var CURRENCY_MARKER_PREFIX = /^\s*(?:([+-])\s*)?(?:\p{Sc}\p{L}{0,3}|(\p{L}{1,3})(\p{Sc})?)\s*/u;
|
|
59817
|
+
var CURRENCY_MARKER_SUFFIX = /(?:\p{Sc}\p{L}{0,3}|(\p{L}{1,3})(\p{Sc})?)\.?$/u;
|
|
59803
59818
|
function isStrippableMarker(letters, symbol) {
|
|
59804
59819
|
if (letters === undefined || symbol !== undefined)
|
|
59805
59820
|
return true;
|
|
59806
59821
|
return isCurrencyMarkerLetters(letters);
|
|
59807
59822
|
}
|
|
59808
|
-
var AMOUNT_SHAPE = /^[+-]?[
|
|
59823
|
+
var AMOUNT_SHAPE = /^[+-]?[.,]*\d[\d.,]*$/;
|
|
59809
59824
|
function hasValidGrouping(text, separator) {
|
|
59810
59825
|
const groups = text.split(separator);
|
|
59811
59826
|
if (groups.length === 1)
|
|
@@ -59866,15 +59881,15 @@ function parseCurrencyInput(raw, currencyCode) {
|
|
|
59866
59881
|
if (!isStrippableMarker(letters, symbol))
|
|
59867
59882
|
return match;
|
|
59868
59883
|
hadMarker = true;
|
|
59869
|
-
return sign;
|
|
59884
|
+
return sign ?? "";
|
|
59870
59885
|
});
|
|
59871
|
-
const withoutMarkers = withoutPrefix.replace(CURRENCY_MARKER_SUFFIX, (match, letters, symbol) => {
|
|
59886
|
+
const withoutMarkers = withoutPrefix.trimEnd().replace(CURRENCY_MARKER_SUFFIX, (match, letters, symbol) => {
|
|
59872
59887
|
if (!isStrippableMarker(letters, symbol))
|
|
59873
59888
|
return match;
|
|
59874
59889
|
hadMarker = true;
|
|
59875
59890
|
return "";
|
|
59876
59891
|
});
|
|
59877
|
-
const cleaned = withoutMarkers.replace(/[\s\
|
|
59892
|
+
const cleaned = withoutMarkers.replace(/[\s\u2019']/gu, "");
|
|
59878
59893
|
if (!AMOUNT_SHAPE.test(cleaned))
|
|
59879
59894
|
return null;
|
|
59880
59895
|
const signed = /^[+-]/.test(cleaned);
|
|
@@ -64405,6 +64420,7 @@ function declaredColumns(decl) {
|
|
|
64405
64420
|
return new Map(Object.entries(decl.columns).map(([columnKey, column]) => [
|
|
64406
64421
|
columnName(columnKey, column),
|
|
64407
64422
|
{
|
|
64423
|
+
key: columnKey,
|
|
64408
64424
|
...column.options ? { options: column.options } : {},
|
|
64409
64425
|
...column.multiple ? { multiple: true } : {}
|
|
64410
64426
|
}
|
|
@@ -64789,6 +64805,22 @@ function childResultFindings(workflow, declarations) {
|
|
|
64789
64805
|
}
|
|
64790
64806
|
return findings;
|
|
64791
64807
|
}
|
|
64808
|
+
function unknownColumnFinding(table, columns, field, block, param) {
|
|
64809
|
+
const finding = { code: "W_TABLE_UNKNOWN_COLUMN", severity: "warning", block, param };
|
|
64810
|
+
const renamed = [...columns].find(([, column]) => column.key === field)?.[0];
|
|
64811
|
+
if (renamed) {
|
|
64812
|
+
return {
|
|
64813
|
+
...finding,
|
|
64814
|
+
message: `${param} writes ${field}, the key of column "${renamed}" of table "${table}": row data is keyed by column name, so the run drops it.`,
|
|
64815
|
+
hint: `Did you mean ${renamed}?`
|
|
64816
|
+
};
|
|
64817
|
+
}
|
|
64818
|
+
return {
|
|
64819
|
+
...finding,
|
|
64820
|
+
message: `${param} writes ${field}, which is not a column of table "${table}"; the run drops it.`,
|
|
64821
|
+
hint: `${didYouMean(field, columns.keys()) ?? ""} Columns: ${listed2(columns.keys())}.`.trimStart()
|
|
64822
|
+
};
|
|
64823
|
+
}
|
|
64792
64824
|
function declarationFindings(workflow, declarations) {
|
|
64793
64825
|
const findings = [];
|
|
64794
64826
|
for (const [block, canonical] of Object.entries(workflow.blocks)) {
|
|
@@ -64830,14 +64862,7 @@ function declarationFindings(workflow, declarations) {
|
|
|
64830
64862
|
for (const [field, cell] of Object.entries(row)) {
|
|
64831
64863
|
const column = columns.get(field);
|
|
64832
64864
|
if (!column) {
|
|
64833
|
-
findings.push(
|
|
64834
|
-
code: "W_TABLE_UNKNOWN_COLUMN",
|
|
64835
|
-
severity: "warning",
|
|
64836
|
-
message: `${param} writes ${field}, which is not a column of table "${table}"; the run drops it.`,
|
|
64837
|
-
hint: `${didYouMean(field, columns.keys()) ?? ""} Columns: ${listed2(columns.keys())}.`.trimStart(),
|
|
64838
|
-
block,
|
|
64839
|
-
param
|
|
64840
|
-
});
|
|
64865
|
+
findings.push(unknownColumnFinding(table, columns, field, block, param));
|
|
64841
64866
|
continue;
|
|
64842
64867
|
}
|
|
64843
64868
|
const { options } = column;
|
package/dist/runtime.js
CHANGED
|
@@ -20273,7 +20273,7 @@ class SimClient {
|
|
|
20273
20273
|
this.resolveCredential(options.auth);
|
|
20274
20274
|
const workspaceId = explicit ?? this.profile.workspaceId;
|
|
20275
20275
|
if (!workspaceId) {
|
|
20276
|
-
throw new SimApiError(`No workspace set for profile "${this.profile.name}". Pass
|
|
20276
|
+
throw new SimApiError(`No workspace set for profile "${this.profile.name}". Pass -w <workspaceId>, set SIM_WORKSPACE, or run: sim configure --profile ${this.profile.name} --set-workspace <id>`, 0);
|
|
20277
20277
|
}
|
|
20278
20278
|
return workspaceId;
|
|
20279
20279
|
}
|
|
@@ -35223,12 +35223,14 @@ Inputs:
|
|
|
35223
35223
|
manualTableId; a string goes to the typed field). Add the type it answers with: \`blocks get
|
|
35224
35224
|
table\` answers table_v2, and an add of legacy table is refused.
|
|
35225
35225
|
conditions (condition): [{"title":"if","value":"<start.n> > 3"},{"title":"else if","value":"…"},
|
|
35226
|
-
{"title":"else","value":""}]; the last entry is the else
|
|
35226
|
+
{"title":"else","value":""}]; the last entry is the else. Each entry's id comes from its
|
|
35227
|
+
position (<block id>-if, <block id>-else-if-0, …, <block id>-else): an id you pass is replaced.
|
|
35227
35228
|
inputFormat (Start): [{"name":"email","type":"string"}]; types string, number, boolean,
|
|
35228
35229
|
object, array, file[]; an optional default "value" as text.
|
|
35229
35230
|
Block settings, beside inputs in an add's or edit's params:
|
|
35230
35231
|
"retry":{"enabled":true,"maxTries":3,"waitBetweenTriesMs":1000} retries a failed block; null
|
|
35231
|
-
clears it.
|
|
35232
|
+
clears it. An api block's retries input repeats the request after a timeout, reset, 429 or
|
|
35233
|
+
5xx, not when the host does not resolve or refuses the connection; "retry" covers that.
|
|
35232
35234
|
Outputs:
|
|
35233
35235
|
A block that fails outputs {"error":"<message>"}: connect its error handle and read
|
|
35234
35236
|
<name.error> there (without one, the run fails). A Workflow block's result is the child's
|
|
@@ -38046,7 +38048,7 @@ async function coerce(raw, field, flag, flagName) {
|
|
|
38046
38048
|
return encodeFolderPath(raw);
|
|
38047
38049
|
return raw;
|
|
38048
38050
|
}
|
|
38049
|
-
var NO_WORKSPACE_FALLBACK = "No workspace set. Pass
|
|
38051
|
+
var NO_WORKSPACE_FALLBACK = "No workspace set. Pass -w <workspaceId>, set SIM_WORKSPACE, or run: sim configure --set-workspace <id>";
|
|
38050
38052
|
function asQueryValue(value) {
|
|
38051
38053
|
if (value === null || value === undefined)
|
|
38052
38054
|
return;
|
|
@@ -38541,6 +38543,14 @@ function foldOtherSpellings(operation, commandSpec, flags) {
|
|
|
38541
38543
|
}
|
|
38542
38544
|
}
|
|
38543
38545
|
}
|
|
38546
|
+
function withSearchedWorkspace(error, profile) {
|
|
38547
|
+
if (!(error instanceof SimApiError) || error.status !== 404 || !profile.workspaceId)
|
|
38548
|
+
return error;
|
|
38549
|
+
const source = profile.sources.workspaceId;
|
|
38550
|
+
const from = source === "env" ? ", from SIM_WORKSPACE; pass -w <workspaceId> to search another" : source === "config" ? `, the workspace of profile "${safeOneLine(profile.name)}"; pass -w <workspaceId> or set SIM_WORKSPACE to search another` : "";
|
|
38551
|
+
const searched = `searched workspace ${safeOneLine(profile.workspaceId)}${from}`;
|
|
38552
|
+
return new SimApiError(`${error.message} (${searched})`, error.status, error.code, error.details, error.exitCode, error.requestId);
|
|
38553
|
+
}
|
|
38544
38554
|
async function executeOperation(operation, commandSpec, operationSpec, invocation) {
|
|
38545
38555
|
const host = invocation[invocation.length - 1];
|
|
38546
38556
|
const inheritedFlags = host.optsWithGlobals();
|
|
@@ -38624,6 +38634,8 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
|
|
|
38624
38634
|
if (cursor && rows.length < limit)
|
|
38625
38635
|
progress.advance(rows.length);
|
|
38626
38636
|
} while (cursor && rows.length < limit);
|
|
38637
|
+
} catch (error) {
|
|
38638
|
+
throw needsWorkspace ? withSearchedWorkspace(error, profile) : error;
|
|
38627
38639
|
} finally {
|
|
38628
38640
|
progress.finish();
|
|
38629
38641
|
}
|
|
@@ -38649,7 +38661,7 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
|
|
|
38649
38661
|
reconciliation: "Find the operation using this requestId, or retry identical inputs with the same requestId."
|
|
38650
38662
|
}, failure.exitCode, failure.requestId);
|
|
38651
38663
|
}
|
|
38652
|
-
throw error;
|
|
38664
|
+
throw needsWorkspace ? withSearchedWorkspace(error, profile) : error;
|
|
38653
38665
|
}
|
|
38654
38666
|
let payload = result?.data ?? result;
|
|
38655
38667
|
if (commandSpec.workspaceOperation && (Boolean(request.body?.requestId) || requestFlags.wait === true || payload && typeof payload === "object" && ("operationId" in payload))) {
|
|
@@ -40794,7 +40806,8 @@ export default workflow('Cookbook', { description: 'One example of each common b
|
|
|
40794
40806
|
})
|
|
40795
40807
|
// Upsert: updates the row whose conflictColumn (a unique column, by name) matches data, else
|
|
40796
40808
|
// inserts one, so a second run for the same order updates it. table.insertRow takes the same
|
|
40797
|
-
// data without conflictColumn and adds a row every run.
|
|
40809
|
+
// data without conflictColumn and adds a row every run. data is keyed by column name: a column
|
|
40810
|
+
// declared as \`phone: column.string({ name: 'mobile' })\` is written as { mobile: ... }.
|
|
40798
40811
|
const save = table.upsertRow('Save Order', {
|
|
40799
40812
|
tableId: table('orders'),
|
|
40800
40813
|
data: { orderId: start.orderId, status: 'open' },
|
|
@@ -51508,13 +51521,14 @@ function dynamicOutputPlan(spec, outputs, operation) {
|
|
|
51508
51521
|
var RUNTIME_SEMANTICS = [
|
|
51509
51522
|
"## How it runs",
|
|
51510
51523
|
"",
|
|
51511
|
-
"- **Two retries, nested.** An `api` block's `retries`, `retryDelayMs` and `retryMaxDelayMs` repeat the HTTP request inside one run of the block: only after a timeout, a connection reset, a 429 or a 5xx, only for GET, HEAD, PUT and DELETE unless `retryNonIdempotent: true`, with jittered exponential backoff capped at `retryMaxDelayMs` (a `Retry-After` beyond the cap ends the retries). `meta.retry` (`{ enabled, maxTries, waitBetweenTriesMs }`) reruns the whole block, request retries included, after any failure but a stop or a failed child workflow; `maxTries` counts every try. So `retries: 2` under `maxTries: 3` sends up to 9 requests. Only the last try's failure reaches `onError`. Triggers and `human` never retry.",
|
|
51524
|
+
"- **Two retries, nested.** An `api` block's `retries`, `retryDelayMs` and `retryMaxDelayMs` repeat the HTTP request inside one run of the block: only after a timeout, a connection reset, a 429 or a 5xx (a host that does not resolve or refuses the connection fails at once), only for GET, HEAD, PUT and DELETE unless `retryNonIdempotent: true`, with jittered exponential backoff capped at `retryMaxDelayMs` (a `Retry-After` beyond the cap ends the retries). `meta.retry` (`{ enabled, maxTries, waitBetweenTriesMs }`) reruns the whole block, request retries included, after any failure but a stop or a failed child workflow; `maxTries` counts every try. So `retries: 2` under `maxTries: 3` sends up to 9 requests. Only the last try's failure reaches `onError`. Triggers and `human` never retry.",
|
|
51512
51525
|
"- **`onError`.** `x.onError(y)` makes a failure of `x` an output, `{ error: '<message>' }`, and runs `y` instead of `x`'s other targets; the run goes on. `y` reads the message as `x.error` (only a block with an `onError` edge has it). In a loop or parallel body (`y` must be in the same body) the iteration ends normally and the loop moves to the next item, with that error output as `x`'s entry for the iteration. Without `onError`, a failure in any iteration fails the run and stops the loop.",
|
|
51513
51526
|
"- **Joins run once.** A block with several incoming edges runs once, after every one of them has fired or been ruled out (a condition or router branch not taken, the normal edge of a block that failed into `onError`). `a.to(join)`, `b.to(join)`, `c.to(join)` wait for all three; behind a condition only the taken branch fires, and the join runs once after it. A block never runs once per incoming branch. A reference to a block that did not run (on the branch not taken) resolves empty: `null` as a whole value, in function code or in a condition, `''` inside text.",
|
|
51514
51527
|
"- **Loop and parallel results.** `x.results` holds one entry per iteration (a parallel: per branch), and each entry is the list of outputs of the body blocks that ran in it, in the order they finished. With one block in the body its output is `x.results[i][0]`; `x.results.flat()` lists every output.",
|
|
51515
51528
|
"- **Outputs in function code.** In `fn` code, `${a.content}` inside js`` is not spliced in as text: it becomes an expression that evaluates to the output's value, a string as a string and an object as an object. Write it where an expression goes (`const reply = ${a.content}`, `[${a.content}, ${b.content}]`) and never wrap it in quotes. Written inside a JavaScript string or template literal it splices in as JSON, quotes included (`'Hi ${a.content}'` gives `Hi \"hello\"`). Python code works the same way.",
|
|
51516
51529
|
"- **Child workflows.** `const c = runWorkflow('C', { workflowId: childWorkflow('k'), inputMapping })` outputs the child's run as `c.result`: the output of the first `response` block the child reaches, `{ data, status, headers }` (a field of its `body` is `c.result.data.field`), or, with no `response` block, the output of the last block it ran. `c.result` is untyped: wrap a value that should become text in `t`. A deployed run of the parent (API, webhook, schedule, chat) runs the child's deployed version and fails while the child is not deployed; a run from the editor runs the child's draft. A failed child fails `c` (`c.onError(...)` catches it).",
|
|
51517
51530
|
"- **MCP headers** (`mcp/<key>.ts`). A header value is plain text in which `{{NAME}}` names an env variable anywhere (`Authorization: 'Bearer {{GITHUB_TOKEN}}'`), `env.NAME` for a whole value, or `stored()` to keep the value the server holds. A `t` template or a template literal with `${}` is refused. A credential header (`Authorization`, `Cookie`, or a name with `key`, `token`, `secret`, `auth`, `password`, `session`, `signature` or `credential`) holds nothing but an optional scheme word (`Bearer`, `Basic`, `Token`, `Bot`, `ApiKey`) and `{{NAME}}` references (`E_MCP_LITERAL_SECRET`). The variables resolve when the server connects, from the personal and workspace env (the workspace value wins); a missing one fails the connection.",
|
|
51531
|
+
"- **Table rows are keyed by column name.** A Table block's `data` (and `conflictColumn`, and a filter's `field`) names each column by its name: its key in `tables/<key>.ts`, or the `name` set there (`phone: column.string({ name: 'mobile' })` is written `{ mobile: … }`). A key naming no column is dropped from the row at run time; `check` and `apply` warn on it (`W_TABLE_UNKNOWN_COLUMN`). A table's `rows.jsonl` is the exception: it is keyed by column key.",
|
|
51518
51532
|
"- **MCP tool names are checked late.** `mcp('k').tool('name')` is type-checked only when `workspace.d.ts` lists that server's tools; a server that could not be listed, or one declared but not yet applied, takes any name. `sim workflows source check` and `sim workflows source apply` do not check tool names (the apply checks only that the server exists). `sim workspaces source apply` checks the tools of each workflow it changes against the server's live listing (`E_MCP_TOOL_UNKNOWN`, or `W_MCP_TOOLS_UNCHECKED` when it cannot list the server). Otherwise a wrong name surfaces at run time: the agent block fails before the model runs, `MCP operation \"name\" is missing or not permitted`.",
|
|
51519
51533
|
""
|
|
51520
51534
|
];
|
|
@@ -52537,7 +52551,8 @@ Write like a person, not a policy. Lead with the answer, then the one detail tha
|
|
|
52537
52551
|
import { column, defineTable } from '@sim/workflow-sdk/workspace'
|
|
52538
52552
|
|
|
52539
52553
|
// tables/<key>.ts: the key (\`orders\`) is how a workflow names it: table('orders'). Its rows stay
|
|
52540
|
-
// out of source (see plans.ts to opt in). To rename a column keep its key and set \`name
|
|
52554
|
+
// out of source (see plans.ts to opt in). To rename a column keep its key and set \`name\`: a
|
|
52555
|
+
// workflow's row data (\`data\`, \`conflictColumn\`, filters) names a column by that name, not its key.
|
|
52541
52556
|
export default defineTable({
|
|
52542
52557
|
name: 'orders',
|
|
52543
52558
|
description: 'Order questions the support workflow answered',
|
|
@@ -56702,14 +56717,14 @@ var WORKFLOW_PRIMER = `# Sim workflow source: primer
|
|
|
56702
56717
|
- **Deploy**: apply saves a draft; \`apply --deploy\` also deploys it, or \`sim workflows deploy <workflowId>\` publishes the saved draft later.
|
|
56703
56718
|
${sharedRules("sim workflows source")}
|
|
56704
56719
|
`;
|
|
56705
|
-
var WORKSPACE_RENAMES = " A column: change its `name`, keep its key (cells stay)
|
|
56720
|
+
var WORKSPACE_RENAMES = " A column: change its `name`, keep its key (cells stay). Table blocks (`data`, `conflictColumn`, filters) use the name, not the key, and keep old names (`W_TABLE_COLUMN_RENAMED_IN_USE`). A file's key never changes (`E_KEY_RENAMED`): rename by `name`.";
|
|
56706
56721
|
var WORKSPACE_PRIMER = `# Sim workspace source: primer
|
|
56707
56722
|
|
|
56708
|
-
This directory is a Sim workspace as files (\`tables/\`, \`workflows/<key>/workflow.ts\`, …);
|
|
56723
|
+
This directory is a Sim workspace as files (\`tables/\`, \`workflows/<key>/workflow.ts\`, …); nothing in it runs. Commands read the workspace id from \`${SOURCE_BASE_FILE}\`; run them from this directory.
|
|
56709
56724
|
|
|
56710
56725
|
**Edit loop**: edit the files → \`sim workspaces source check --dir .\` (offline; refreshes \`workspace.d.ts\` and \`tsconfig.json\`) → \`${typecheckCommand()}\` → \`sim workspaces source apply --dir . --dry-run\` → \`--yes\`. Rerun each step until it exits 0. Apply rewrites the directory from what it stored: read a file again before the next edit.
|
|
56711
56726
|
|
|
56712
|
-
- **Deletes**: a removed file (a resource this directory managed), table column, workflow block or
|
|
56727
|
+
- **Deletes**: a removed file (a resource this directory managed), table column, workflow block or variable is deleted only with \`apply --allow-delete\` and cannot be undone. A kind is managed only when its folder exists.
|
|
56713
56728
|
- **Deploy**: \`deployments/<workflow key>.ts\` (\`defineDeployment({ live: 'draft' })\`) deploys that workflow on apply, which prints its webhook URLs; without one, apply never deploys.
|
|
56714
56729
|
- **Promote** (dev → prod): \`sim workspaces source apply --dir . --to <workspaceId> --dry-run\`, then \`--yes\`.
|
|
56715
56730
|
- **Exit ${SOURCE_HELD_EXIT_CODE}**: written in part; changes using an unset secret or unbound credential were held back: set it, apply again.
|
|
@@ -59847,14 +59862,14 @@ function isCurrencyMarkerLetters(letters) {
|
|
|
59847
59862
|
return !SCALE_SUFFIX.test(upper);
|
|
59848
59863
|
return supportedCurrencyCodes.has(upper);
|
|
59849
59864
|
}
|
|
59850
|
-
var CURRENCY_MARKER_PREFIX =
|
|
59851
|
-
var CURRENCY_MARKER_SUFFIX = /
|
|
59865
|
+
var CURRENCY_MARKER_PREFIX = /^\s*(?:([+-])\s*)?(?:\p{Sc}\p{L}{0,3}|(\p{L}{1,3})(\p{Sc})?)\s*/u;
|
|
59866
|
+
var CURRENCY_MARKER_SUFFIX = /(?:\p{Sc}\p{L}{0,3}|(\p{L}{1,3})(\p{Sc})?)\.?$/u;
|
|
59852
59867
|
function isStrippableMarker(letters, symbol) {
|
|
59853
59868
|
if (letters === undefined || symbol !== undefined)
|
|
59854
59869
|
return true;
|
|
59855
59870
|
return isCurrencyMarkerLetters(letters);
|
|
59856
59871
|
}
|
|
59857
|
-
var AMOUNT_SHAPE = /^[+-]?[
|
|
59872
|
+
var AMOUNT_SHAPE = /^[+-]?[.,]*\d[\d.,]*$/;
|
|
59858
59873
|
function hasValidGrouping(text, separator) {
|
|
59859
59874
|
const groups = text.split(separator);
|
|
59860
59875
|
if (groups.length === 1)
|
|
@@ -59915,15 +59930,15 @@ function parseCurrencyInput(raw, currencyCode) {
|
|
|
59915
59930
|
if (!isStrippableMarker(letters, symbol))
|
|
59916
59931
|
return match;
|
|
59917
59932
|
hadMarker = true;
|
|
59918
|
-
return sign;
|
|
59933
|
+
return sign ?? "";
|
|
59919
59934
|
});
|
|
59920
|
-
const withoutMarkers = withoutPrefix.replace(CURRENCY_MARKER_SUFFIX, (match, letters, symbol) => {
|
|
59935
|
+
const withoutMarkers = withoutPrefix.trimEnd().replace(CURRENCY_MARKER_SUFFIX, (match, letters, symbol) => {
|
|
59921
59936
|
if (!isStrippableMarker(letters, symbol))
|
|
59922
59937
|
return match;
|
|
59923
59938
|
hadMarker = true;
|
|
59924
59939
|
return "";
|
|
59925
59940
|
});
|
|
59926
|
-
const cleaned = withoutMarkers.replace(/[\s\
|
|
59941
|
+
const cleaned = withoutMarkers.replace(/[\s\u2019']/gu, "");
|
|
59927
59942
|
if (!AMOUNT_SHAPE.test(cleaned))
|
|
59928
59943
|
return null;
|
|
59929
59944
|
const signed = /^[+-]/.test(cleaned);
|
|
@@ -64454,6 +64469,7 @@ function declaredColumns(decl) {
|
|
|
64454
64469
|
return new Map(Object.entries(decl.columns).map(([columnKey, column]) => [
|
|
64455
64470
|
columnName(columnKey, column),
|
|
64456
64471
|
{
|
|
64472
|
+
key: columnKey,
|
|
64457
64473
|
...column.options ? { options: column.options } : {},
|
|
64458
64474
|
...column.multiple ? { multiple: true } : {}
|
|
64459
64475
|
}
|
|
@@ -64838,6 +64854,22 @@ function childResultFindings(workflow, declarations) {
|
|
|
64838
64854
|
}
|
|
64839
64855
|
return findings;
|
|
64840
64856
|
}
|
|
64857
|
+
function unknownColumnFinding(table, columns, field, block, param) {
|
|
64858
|
+
const finding = { code: "W_TABLE_UNKNOWN_COLUMN", severity: "warning", block, param };
|
|
64859
|
+
const renamed = [...columns].find(([, column]) => column.key === field)?.[0];
|
|
64860
|
+
if (renamed) {
|
|
64861
|
+
return {
|
|
64862
|
+
...finding,
|
|
64863
|
+
message: `${param} writes ${field}, the key of column "${renamed}" of table "${table}": row data is keyed by column name, so the run drops it.`,
|
|
64864
|
+
hint: `Did you mean ${renamed}?`
|
|
64865
|
+
};
|
|
64866
|
+
}
|
|
64867
|
+
return {
|
|
64868
|
+
...finding,
|
|
64869
|
+
message: `${param} writes ${field}, which is not a column of table "${table}"; the run drops it.`,
|
|
64870
|
+
hint: `${didYouMean(field, columns.keys()) ?? ""} Columns: ${listed2(columns.keys())}.`.trimStart()
|
|
64871
|
+
};
|
|
64872
|
+
}
|
|
64841
64873
|
function declarationFindings(workflow, declarations) {
|
|
64842
64874
|
const findings = [];
|
|
64843
64875
|
for (const [block, canonical] of Object.entries(workflow.blocks)) {
|
|
@@ -64879,14 +64911,7 @@ function declarationFindings(workflow, declarations) {
|
|
|
64879
64911
|
for (const [field, cell] of Object.entries(row)) {
|
|
64880
64912
|
const column = columns.get(field);
|
|
64881
64913
|
if (!column) {
|
|
64882
|
-
findings.push(
|
|
64883
|
-
code: "W_TABLE_UNKNOWN_COLUMN",
|
|
64884
|
-
severity: "warning",
|
|
64885
|
-
message: `${param} writes ${field}, which is not a column of table "${table}"; the run drops it.`,
|
|
64886
|
-
hint: `${didYouMean(field, columns.keys()) ?? ""} Columns: ${listed2(columns.keys())}.`.trimStart(),
|
|
64887
|
-
block,
|
|
64888
|
-
param
|
|
64889
|
-
});
|
|
64914
|
+
findings.push(unknownColumnFinding(table, columns, field, block, param));
|
|
64890
64915
|
continue;
|
|
64891
64916
|
}
|
|
64892
64917
|
const { options } = column;
|