@turbofy-ai/app-runtime 0.0.24 → 0.0.26

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/src/dsl.d.ts CHANGED
@@ -787,6 +787,17 @@ declare function blockTypeCopiesCode(): string;
787
787
  declare function blockConfigCode(blockTypeTableId: string): string;
788
788
  declare function blockNameCode(blockTypeTableId: string): string;
789
789
  declare function blockDynamicDataCode(blockTypeTableId: string): string;
790
+ declare const mcpServerDefinitionSchema: z.ZodObject<{
791
+ name: z.ZodString;
792
+ slug: z.ZodString;
793
+ description: z.ZodOptional<z.ZodString>;
794
+ handler: z.ZodObject<{
795
+ server: z.ZodObject<{
796
+ function: z.ZodString;
797
+ }, z.core.$strict>;
798
+ }, z.core.$strict>;
799
+ }, z.core.$strict>;
800
+ export type IMcpServerDefinition = z.infer<typeof mcpServerDefinitionSchema>;
790
801
  /** A JSON-serializable localization value. */
791
802
  export type LocalizationValue = string | number | boolean | null | LocalizationValue[] | {
792
803
  [key: string]: LocalizationValue;
@@ -2086,8 +2097,30 @@ export interface FlattenBlocksOptions {
2086
2097
  fallbackLocale?: string;
2087
2098
  }
2088
2099
  declare function flattenBlocks(blocks: IBlockDefinition[], opts?: FlattenBlocksOptions): IBlockOutput[];
2100
+ /**
2101
+ * One `slugConfig.paramsCollectionMap` entry. Code-created pages store the bare
2102
+ * table id; the dashboard stores `{ ofType: tableId }`.
2103
+ */
2104
+ export type PageParamCollectionMapping = string | IPageParamCollectionObject;
2105
+ export interface IPageParamCollectionObject {
2106
+ ofType: string;
2107
+ /** Legacy; push rejects it. Kept in the type so pull can surface it. */
2108
+ slugField?: string;
2109
+ [key: string]: unknown;
2110
+ }
2089
2111
  export interface IPageParamConfig {
2090
2112
  collection: IObjectTypeDeclaration;
2113
+ /**
2114
+ * How `slugConfig.paramsCollectionMap` stores this param. `"object"` writes
2115
+ * `{ ofType: <table id> }`, the form the dashboard's page settings save.
2116
+ * Omitted writes the bare table id. Pull sets it so a round trip is lossless.
2117
+ */
2118
+ mappingFormat?: "object";
2119
+ /**
2120
+ * Extra keys stored next to `ofType` in the object form. Requires
2121
+ * `mappingFormat: "object"`; pull emits it so unknown keys survive a push.
2122
+ */
2123
+ mappingExtras?: Record<string, unknown>;
2091
2124
  }
2092
2125
  export interface IPageOptions {
2093
2126
  id?: string;
@@ -2137,16 +2170,10 @@ export interface IPageDefinition {
2137
2170
  blocks: IBlockDefinition[];
2138
2171
  }
2139
2172
  export interface IPageSlugConfig {
2140
- paramsCollectionMap: Record<string, string | {
2141
- ofType: string;
2142
- slugField?: string;
2143
- }>;
2173
+ paramsCollectionMap: Record<string, PageParamCollectionMapping>;
2144
2174
  [locale: string]: {
2145
2175
  slug: string;
2146
- } | Record<string, string | {
2147
- ofType: string;
2148
- slugField?: string;
2149
- }>;
2176
+ } | Record<string, PageParamCollectionMapping>;
2150
2177
  }
2151
2178
  export interface IPageOutput {
2152
2179
  id?: string;
@@ -2216,6 +2243,8 @@ declare const CLOUD_FUNCTION_REFERENCE_PREFIX = "cloud-function:";
2216
2243
  declare const validateCloudFunctionName: (name: string) => void;
2217
2244
  declare const buildFunction: (definition: ICloudFunctionDefinition) => ICloudFunctionDefinition;
2218
2245
  declare const ref: (name: string) => string;
2246
+ export type IMcpServerOptions = IMcpServerDefinition;
2247
+ declare const buildServer: (options: IMcpServerOptions) => IMcpServerDefinition;
2219
2248
  export interface IJsParam {
2220
2249
  readonly __flowParam: "js";
2221
2250
  readonly code: string;
@@ -2462,6 +2491,9 @@ declare namespace appBuilder {
2462
2491
  declare namespace cloudFunctionBuilder {
2463
2492
  export { CLOUD_FUNCTION_REFERENCE_PREFIX, CloudFunctionRuntime, ICloudFunctionDefinition, buildFunction, ref, validateCloudFunctionName };
2464
2493
  }
2494
+ declare namespace mcpServerBuilder {
2495
+ export { IMcpServerDefinition, IMcpServerOptions, buildServer };
2496
+ }
2465
2497
 
2466
2498
  export {
2467
2499
  appBuilder,
@@ -2469,6 +2501,7 @@ export {
2469
2501
  dataBuilder,
2470
2502
  flowBuilder,
2471
2503
  macros,
2504
+ mcpServerBuilder,
2472
2505
  };
2473
2506
 
2474
2507
  export {};
package/dist/src/dsl.js CHANGED
@@ -15055,6 +15055,59 @@ function build(schema) {
15055
15055
  return finalSchema;
15056
15056
  }
15057
15057
 
15058
+ // ../declarations/src/mcp-servers/definition.ts
15059
+ var MCP_SERVER_SLUG_PATTERN = /^[a-z][a-z0-9-]{2,39}$/;
15060
+ var MCP_SERVER_FUNCTION_NAME_PATTERN = /^[a-z][a-z0-9-]{0,47}$/;
15061
+ var RESERVED_MCP_SERVER_SLUGS = /* @__PURE__ */ new Set([
15062
+ "admin",
15063
+ "alpha",
15064
+ "api",
15065
+ "app",
15066
+ "auth",
15067
+ "beta",
15068
+ "cdn",
15069
+ "console",
15070
+ "dev",
15071
+ "docs",
15072
+ "help",
15073
+ "mail",
15074
+ "mcp",
15075
+ "prod",
15076
+ "staging",
15077
+ "status",
15078
+ "support",
15079
+ "turbofy",
15080
+ "www"
15081
+ ]);
15082
+ var slugSchema = external_exports.string().regex(
15083
+ MCP_SERVER_SLUG_PATTERN,
15084
+ "Slug must be 3 to 40 lowercase letters, digits or hyphens and start with a letter"
15085
+ ).refine((slug) => !slug.endsWith("-"), "Slug cannot end with a hyphen").refine(
15086
+ (slug) => !RESERVED_MCP_SERVER_SLUGS.has(slug),
15087
+ "This slug is reserved"
15088
+ );
15089
+ var serverHandlerSchema = external_exports.object({
15090
+ server: external_exports.object({
15091
+ function: external_exports.string().regex(
15092
+ MCP_SERVER_FUNCTION_NAME_PATTERN,
15093
+ "Function name must be lowercase letters, digits or hyphens and start with a letter"
15094
+ )
15095
+ }).strict()
15096
+ }).strict();
15097
+ var mcpServerDefinitionSchema = external_exports.object({
15098
+ name: external_exports.string().trim().min(1).max(80),
15099
+ slug: slugSchema,
15100
+ description: external_exports.string().max(500).optional(),
15101
+ handler: serverHandlerSchema
15102
+ }).strict();
15103
+ var validateMcpServerDefinition = (input) => {
15104
+ const result = mcpServerDefinitionSchema.safeParse(input);
15105
+ if (result.success) return [];
15106
+ return result.error.issues.map(
15107
+ (issue2) => issue2.path.length > 0 ? `${issue2.path.join(".")}: ${issue2.message}` : issue2.message
15108
+ );
15109
+ };
15110
+
15058
15111
  // ../declarations/src/flows/schemas/branch.schema.ts
15059
15112
  var branchSchema = {
15060
15113
  params: external_exports.object({
@@ -16253,7 +16306,7 @@ var getFlowStepTargets = (step2) => {
16253
16306
  var getBranchOwnershipErrors = (declaration) => {
16254
16307
  const owners = /* @__PURE__ */ new Map();
16255
16308
  const errors = [];
16256
- const visit = (name, scope) => {
16309
+ const visit2 = (name, scope) => {
16257
16310
  const step2 = declaration.steps[name];
16258
16311
  if (!Object.hasOwn(declaration.steps, name)) return;
16259
16312
  const owner = JSON.stringify(scope);
@@ -16270,18 +16323,18 @@ var getBranchOwnershipErrors = (declaration) => {
16270
16323
  owners.set(name, owner);
16271
16324
  if (step2.type === "forEach" /* forEach */) {
16272
16325
  const body = getForEachBodyTarget(step2);
16273
- if (body !== null) visit(body, [...scope, name, body]);
16274
- if (step2.nextStep !== null) visit(step2.nextStep, scope);
16326
+ if (body !== null) visit2(body, [...scope, name, body]);
16327
+ if (step2.nextStep !== null) visit2(step2.nextStep, scope);
16275
16328
  return;
16276
16329
  }
16277
16330
  for (const target of getFlowStepTargets(step2)) {
16278
- visit(
16331
+ visit2(
16279
16332
  target,
16280
16333
  step2.type === "branch" /* branch */ ? [...scope, name, target] : scope
16281
16334
  );
16282
16335
  }
16283
16336
  };
16284
- if (declaration.startStep) visit(declaration.startStep, []);
16337
+ if (declaration.startStep) visit2(declaration.startStep, []);
16285
16338
  const names = Object.keys(declaration.steps);
16286
16339
  const targets = new Set(
16287
16340
  Object.values(declaration.steps).flatMap(getFlowStepTargets)
@@ -16290,7 +16343,7 @@ var getBranchOwnershipErrors = (declaration) => {
16290
16343
  ...names.filter((name2) => !targets.has(name2)),
16291
16344
  ...names
16292
16345
  ]) {
16293
- if (!owners.has(name)) visit(name, []);
16346
+ if (!owners.has(name)) visit2(name, []);
16294
16347
  }
16295
16348
  return errors;
16296
16349
  };
@@ -16324,7 +16377,7 @@ var getFlowCycleErrors = (declaration) => {
16324
16377
  const visiting = /* @__PURE__ */ new Set();
16325
16378
  const visited = /* @__PURE__ */ new Set();
16326
16379
  const errors = [];
16327
- const visit = (name) => {
16380
+ const visit2 = (name) => {
16328
16381
  if (visiting.has(name)) {
16329
16382
  errors.push({
16330
16383
  stepName: name,
@@ -16335,11 +16388,11 @@ var getFlowCycleErrors = (declaration) => {
16335
16388
  if (visited.has(name) || !Object.hasOwn(declaration.steps, name)) return;
16336
16389
  visiting.add(name);
16337
16390
  for (const target of getFlowStepTargets(declaration.steps[name]))
16338
- visit(target);
16391
+ visit2(target);
16339
16392
  visiting.delete(name);
16340
16393
  visited.add(name);
16341
16394
  };
16342
- for (const name of Object.keys(declaration.steps)) visit(name);
16395
+ for (const name of Object.keys(declaration.steps)) visit2(name);
16343
16396
  return errors;
16344
16397
  };
16345
16398
  var getFlowGraphErrors = (declaration) => [
@@ -22216,6 +22269,48 @@ function flattenBlocks(blocks, opts) {
22216
22269
  return result;
22217
22270
  }
22218
22271
 
22272
+ // ../dsl-builders/src/apps/json-safe.ts
22273
+ function assertJsonSafe(value, path = "value") {
22274
+ visit(value, path, /* @__PURE__ */ new Set());
22275
+ }
22276
+ function visit(value, path, ancestors) {
22277
+ if (value === null || typeof value === "boolean" || typeof value === "string") {
22278
+ return;
22279
+ }
22280
+ if (typeof value === "number") {
22281
+ if (!Number.isFinite(value)) {
22282
+ throw new Error(`${path} is not JSON-safe: ${String(value)}`);
22283
+ }
22284
+ return;
22285
+ }
22286
+ const isArray2 = Array.isArray(value);
22287
+ if (!isArray2 && !isPlainObject2(value)) {
22288
+ throw new Error(`${path} is not JSON-safe: ${typeof value}`);
22289
+ }
22290
+ if (ancestors.has(value)) {
22291
+ throw new Error(`${path} is not JSON-safe: circular reference`);
22292
+ }
22293
+ ancestors.add(value);
22294
+ if (isArray2) {
22295
+ for (let i = 0; i < value.length; i++) {
22296
+ if (!(i in value)) {
22297
+ throw new Error(`${path}[${i}] is not JSON-safe: array hole`);
22298
+ }
22299
+ visit(value[i], `${path}[${i}]`, ancestors);
22300
+ }
22301
+ } else {
22302
+ for (const [key, item] of Object.entries(value)) {
22303
+ visit(item, `${path}.${key}`, ancestors);
22304
+ }
22305
+ }
22306
+ ancestors.delete(value);
22307
+ }
22308
+ function isPlainObject2(value) {
22309
+ if (typeof value !== "object" || value === null) return false;
22310
+ const proto = Object.getPrototypeOf(value);
22311
+ return proto === Object.prototype || proto === null;
22312
+ }
22313
+
22219
22314
  // ../dsl-builders/src/apps/slug-validation.ts
22220
22315
  function assertNoLegacySlugField(mapping, pageName, paramName, collectionId) {
22221
22316
  if (!("slugField" in mapping)) return;
@@ -22226,6 +22321,12 @@ function assertNoLegacySlugField(mapping, pageName, paramName, collectionId) {
22226
22321
  }
22227
22322
 
22228
22323
  // ../dsl-builders/src/apps/pages.ts
22324
+ function toParamCollectionMapping(config2) {
22325
+ if (config2.mappingFormat !== "object") {
22326
+ return config2.collection.id;
22327
+ }
22328
+ return { ...config2.mappingExtras ?? {}, ofType: config2.collection.id };
22329
+ }
22229
22330
  function setPageVisibility(slugConfig, visibility) {
22230
22331
  if (visibility && visibility !== "public") {
22231
22332
  slugConfig.visibility = visibility;
@@ -22422,6 +22523,23 @@ function buildPages(pages, opts) {
22422
22523
  );
22423
22524
  }
22424
22525
  assertNoLegacySlugField(paramConfig, p.name, paramKey, collection.id);
22526
+ if (paramConfig.mappingExtras !== void 0) {
22527
+ if (paramConfig.mappingFormat !== "object") {
22528
+ throw new Error(
22529
+ `buildPages: page "${p.name}" param "${paramKey}" sets mappingExtras, which requires mappingFormat: "object"`
22530
+ );
22531
+ }
22532
+ assertJsonSafe(
22533
+ paramConfig.mappingExtras,
22534
+ `buildPages: page "${p.name}" param "${paramKey}" mappingExtras`
22535
+ );
22536
+ assertNoLegacySlugField(
22537
+ paramConfig.mappingExtras,
22538
+ p.name,
22539
+ paramKey,
22540
+ collection.id
22541
+ );
22542
+ }
22425
22543
  }
22426
22544
  }
22427
22545
  const locales = opts?.locales ?? (opts?.locale ? [opts.locale] : ["en"]);
@@ -22429,7 +22547,7 @@ function buildPages(pages, opts) {
22429
22547
  const mergedParams = collectMergedParams(p);
22430
22548
  const paramsCollectionMap = {};
22431
22549
  for (const [key, config2] of Object.entries(mergedParams)) {
22432
- paramsCollectionMap[key] = config2.collection.id;
22550
+ paramsCollectionMap[key] = toParamCollectionMapping(config2);
22433
22551
  }
22434
22552
  const slugConfig = { paramsCollectionMap };
22435
22553
  setPageVisibility(slugConfig, p.visibility);
@@ -22543,7 +22661,7 @@ function validatePageLocalizations(pages, supportedLocales) {
22543
22661
  }
22544
22662
  function validateBlockLocalizations(pages, supportedLocales) {
22545
22663
  const supported = new Set(supportedLocales);
22546
- const visit = (blocks, pageName) => {
22664
+ const visit2 = (blocks, pageName) => {
22547
22665
  for (const b of blocks) {
22548
22666
  if (b.localizations) {
22549
22667
  for (const locale of Object.keys(b.localizations)) {
@@ -22555,12 +22673,12 @@ function validateBlockLocalizations(pages, supportedLocales) {
22555
22673
  }
22556
22674
  }
22557
22675
  if (b.blocks.length > 0) {
22558
- visit(b.blocks, pageName);
22676
+ visit2(b.blocks, pageName);
22559
22677
  }
22560
22678
  }
22561
22679
  };
22562
22680
  for (const p of pages) {
22563
- visit(p.blocks, p.name);
22681
+ visit2(p.blocks, p.name);
22564
22682
  }
22565
22683
  }
22566
22684
 
@@ -22606,6 +22724,22 @@ var ref2 = (name) => {
22606
22724
  return `${CLOUD_FUNCTION_REFERENCE_PREFIX}${name}`;
22607
22725
  };
22608
22726
 
22727
+ // ../dsl-builders/src/mcp-servers/mcp-server-builder.ts
22728
+ var mcp_server_builder_exports = {};
22729
+ __export(mcp_server_builder_exports, {
22730
+ buildServer: () => buildServer
22731
+ });
22732
+ var buildServer = (options) => {
22733
+ const errors = validateMcpServerDefinition(options);
22734
+ if (errors.length > 0) {
22735
+ throw new Error(
22736
+ `MCP server "${options.slug}" is invalid:
22737
+ - ${errors.join("\n- ")}`
22738
+ );
22739
+ }
22740
+ return mcpServerDefinitionSchema.parse(options);
22741
+ };
22742
+
22609
22743
  // ../dsl-builders/src/flows/flow-builder.ts
22610
22744
  var flow_builder_exports = {};
22611
22745
  __export(flow_builder_exports, {
@@ -22644,7 +22778,7 @@ function isSecretParam(value) {
22644
22778
  function isFlowParamMarker(value) {
22645
22779
  return isJsParam(value) || isSecretParam(value);
22646
22780
  }
22647
- function isPlainObject2(value) {
22781
+ function isPlainObject3(value) {
22648
22782
  return typeof value === "object" && value !== null && !Array.isArray(value) && !isFlowParamMarker(value);
22649
22783
  }
22650
22784
  function containsMarker(value) {
@@ -22670,7 +22804,7 @@ function lowerParamValue(value, path) {
22670
22804
  }
22671
22805
  return { value, config: { type: "logic", language: "static" } };
22672
22806
  }
22673
- if (isPlainObject2(value)) {
22807
+ if (isPlainObject3(value)) {
22674
22808
  if (!containsMarker(value)) {
22675
22809
  return { value, config: { type: "logic", language: "static" } };
22676
22810
  }
@@ -22779,7 +22913,7 @@ function collectNonStaticPaths(paramsConfig, prefix = "") {
22779
22913
  }
22780
22914
  return paths;
22781
22915
  }
22782
- function walkSecretLeaves(params, paramsConfig, visit, prefix = "") {
22916
+ function walkSecretLeaves(params, paramsConfig, visit2, prefix = "") {
22783
22917
  if (!paramsConfig) return;
22784
22918
  for (const [key, config2] of Object.entries(paramsConfig)) {
22785
22919
  const path = prefix ? `${prefix}.${key}` : key;
@@ -22788,11 +22922,11 @@ function walkSecretLeaves(params, paramsConfig, visit, prefix = "") {
22788
22922
  walkSecretLeaves(
22789
22923
  value ?? {},
22790
22924
  config2.subParams,
22791
- visit,
22925
+ visit2,
22792
22926
  path
22793
22927
  );
22794
22928
  } else if (config2.type === "secret") {
22795
- visit(path, value);
22929
+ visit2(path, value);
22796
22930
  }
22797
22931
  }
22798
22932
  }
@@ -22866,12 +23000,12 @@ function tableIdsMatch(a, b) {
22866
23000
  }
22867
23001
  function collectReachableSteps(startStep, steps) {
22868
23002
  const reachable = /* @__PURE__ */ new Set();
22869
- const visit = (name) => {
23003
+ const visit2 = (name) => {
22870
23004
  if (reachable.has(name) || !Object.hasOwn(steps, name)) return;
22871
23005
  reachable.add(name);
22872
- getFlowStepTargets(steps[name]).forEach(visit);
23006
+ getFlowStepTargets(steps[name]).forEach(visit2);
22873
23007
  };
22874
- if (startStep !== null) visit(startStep);
23008
+ if (startStep !== null) visit2(startStep);
22875
23009
  return reachable;
22876
23010
  }
22877
23011
  function validateControlStep(step2, issue2, errors) {
@@ -23101,7 +23235,7 @@ function validateFlowGraph(flows) {
23101
23235
  const visiting = /* @__PURE__ */ new Set();
23102
23236
  const done = /* @__PURE__ */ new Set();
23103
23237
  const stack = [];
23104
- const visit = (id) => {
23238
+ const visit2 = (id) => {
23105
23239
  if (done.has(id)) return;
23106
23240
  visiting.add(id);
23107
23241
  stack.push(id);
@@ -23127,7 +23261,7 @@ function validateFlowGraph(flows) {
23127
23261
  continue;
23128
23262
  }
23129
23263
  if (!done.has(edge.toId)) {
23130
- visit(edge.toId);
23264
+ visit2(edge.toId);
23131
23265
  }
23132
23266
  }
23133
23267
  stack.pop();
@@ -23135,7 +23269,7 @@ function validateFlowGraph(flows) {
23135
23269
  done.add(id);
23136
23270
  };
23137
23271
  for (const flow of flows) {
23138
- visit(flow.id);
23272
+ visit2(flow.id);
23139
23273
  }
23140
23274
  return { errors, warnings: [] };
23141
23275
  }
@@ -23435,6 +23569,7 @@ export {
23435
23569
  dataSchemaDeclarationSchema,
23436
23570
  flow_builder_exports as flowBuilder,
23437
23571
  macros_exports as macros,
23572
+ mcp_server_builder_exports as mcpServerBuilder,
23438
23573
  validateFlow,
23439
23574
  validateFlowGraph,
23440
23575
  validateFlows
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbofy-ai/app-runtime",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {