@xano/sdk 1.0.0
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/CHANGELOG.md +788 -0
- package/LICENSE +21 -0
- package/README.md +541 -0
- package/dist/.build-fingerprint +1 -0
- package/dist/agent-file-refresh-ZEMK33AX.js +38 -0
- package/dist/answer-shape-K67TAAPY.js +33 -0
- package/dist/backend-dir-2U53CIAL.js +39 -0
- package/dist/backend-slot-7QXW2QYC.js +28 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +255 -0
- package/dist/branch-NCRNWQBQ.js +61 -0
- package/dist/branch-commands-ACIRCEQJ.js +79 -0
- package/dist/bundle.d.ts +223 -0
- package/dist/bundle.js +153 -0
- package/dist/capture-WAXPD7DR.js +41 -0
- package/dist/chunk-27GWNP2I.js +23 -0
- package/dist/chunk-2CMJZDCL.js +177 -0
- package/dist/chunk-2EZ3ZJZZ.js +302 -0
- package/dist/chunk-2GNFDZA2.js +390 -0
- package/dist/chunk-2MNLRIOX.js +11 -0
- package/dist/chunk-2TFRR6JV.js +104 -0
- package/dist/chunk-2ZUEE4EK.js +408 -0
- package/dist/chunk-36JUQZVQ.js +22 -0
- package/dist/chunk-3DRXWLJ5.js +83 -0
- package/dist/chunk-3JDU4VRL.js +137 -0
- package/dist/chunk-3KZCLN4Z.js +241 -0
- package/dist/chunk-3LDULPRE.js +168 -0
- package/dist/chunk-3M4LFYNQ.js +111 -0
- package/dist/chunk-3XI5CTUE.js +22 -0
- package/dist/chunk-3YW23UFH.js +50 -0
- package/dist/chunk-45UIT5T2.js +862 -0
- package/dist/chunk-4BW2SG2N.js +46 -0
- package/dist/chunk-4KHEMC32.js +79 -0
- package/dist/chunk-4POWHT2K.js +321 -0
- package/dist/chunk-4Q2GN7NW.js +192 -0
- package/dist/chunk-5A2PLKZB.js +70 -0
- package/dist/chunk-5FBYXK5P.js +159 -0
- package/dist/chunk-5HVXPTU4.js +323 -0
- package/dist/chunk-5QU2P5CA.js +304 -0
- package/dist/chunk-5V5XU32D.js +191 -0
- package/dist/chunk-5ZSO4T2G.js +10 -0
- package/dist/chunk-622HUCZT.js +10 -0
- package/dist/chunk-65HWOMGV.js +177 -0
- package/dist/chunk-6ELFRN3P.js +365 -0
- package/dist/chunk-6HO3NCSJ.js +1055 -0
- package/dist/chunk-6IUMKYWI.js +457 -0
- package/dist/chunk-6KEB3C3U.js +65 -0
- package/dist/chunk-6MR5TI5V.js +987 -0
- package/dist/chunk-6NNTNXN7.js +157 -0
- package/dist/chunk-6PBR37LN.js +97 -0
- package/dist/chunk-6QXLMMT3.js +155 -0
- package/dist/chunk-6ZGJCBZS.js +224 -0
- package/dist/chunk-73IVBKMA.js +250 -0
- package/dist/chunk-7G3CTU7I.js +286 -0
- package/dist/chunk-A3UDOZB6.js +222 -0
- package/dist/chunk-A6E77GDW.js +85 -0
- package/dist/chunk-AHJWCYQO.js +660 -0
- package/dist/chunk-AKNCFVKZ.js +36 -0
- package/dist/chunk-AM4FKL4J.js +237 -0
- package/dist/chunk-AN6BL47T.js +26 -0
- package/dist/chunk-AOSYVMUS.js +147 -0
- package/dist/chunk-APWXY5SL.js +182 -0
- package/dist/chunk-AWEIIR2U.js +218 -0
- package/dist/chunk-AWQ7BQTQ.js +73 -0
- package/dist/chunk-BAUZOWGX.js +393 -0
- package/dist/chunk-BHACRS6R.js +940 -0
- package/dist/chunk-BWPNT55T.js +680 -0
- package/dist/chunk-C6RIMRU4.js +187 -0
- package/dist/chunk-CGVQZXYG.js +263 -0
- package/dist/chunk-CIMQZRRE.js +162 -0
- package/dist/chunk-CJHQKJU4.js +113 -0
- package/dist/chunk-CTMO46PK.js +1897 -0
- package/dist/chunk-D53J55C5.js +106 -0
- package/dist/chunk-D7VGG3WS.js +90 -0
- package/dist/chunk-DAD3ONIS.js +245 -0
- package/dist/chunk-DGWHAVRG.js +162 -0
- package/dist/chunk-DX4QR4B2.js +483 -0
- package/dist/chunk-EHP3WPEG.js +21 -0
- package/dist/chunk-ELP2HMXC.js +432 -0
- package/dist/chunk-ERVIASGL.js +21 -0
- package/dist/chunk-ET4Y4XCB.js +865 -0
- package/dist/chunk-ETO6LGLD.js +4750 -0
- package/dist/chunk-EUUUMY7J.js +24 -0
- package/dist/chunk-FQJ2TTHP.js +218 -0
- package/dist/chunk-FQOF7E2E.js +133 -0
- package/dist/chunk-FWD7AL6N.js +21 -0
- package/dist/chunk-FXFV3KU6.js +138 -0
- package/dist/chunk-FXRQOWTE.js +171 -0
- package/dist/chunk-G554NZNI.js +210 -0
- package/dist/chunk-GSGDWJB5.js +13 -0
- package/dist/chunk-H2V3N23D.js +66 -0
- package/dist/chunk-H5C7MBCR.js +159 -0
- package/dist/chunk-HHN734BU.js +371 -0
- package/dist/chunk-HRVBLCVJ.js +243 -0
- package/dist/chunk-HVRUQXGD.js +1264 -0
- package/dist/chunk-I4F5TCJH.js +130 -0
- package/dist/chunk-IDOTCMDV.js +57 -0
- package/dist/chunk-IGOLHKWF.js +427 -0
- package/dist/chunk-JGE7CAWB.js +148 -0
- package/dist/chunk-JTUKLCXS.js +92 -0
- package/dist/chunk-JZGVVJSI.js +66 -0
- package/dist/chunk-K4WX6UUU.js +923 -0
- package/dist/chunk-K5BBGTYZ.js +217 -0
- package/dist/chunk-K6RXBGUB.js +427 -0
- package/dist/chunk-KTSDSD36.js +165 -0
- package/dist/chunk-L5JYN3NM.js +1038 -0
- package/dist/chunk-LIEOKXKD.js +354 -0
- package/dist/chunk-LLNZGEFK.js +51 -0
- package/dist/chunk-LPECSJ2J.js +55 -0
- package/dist/chunk-LQCMKAJ7.js +413 -0
- package/dist/chunk-LRN4ZJCQ.js +1145 -0
- package/dist/chunk-MJ4ZVHKN.js +17 -0
- package/dist/chunk-MXHSQOC4.js +3061 -0
- package/dist/chunk-N5GKCWE5.js +367 -0
- package/dist/chunk-NA3PXMEF.js +10 -0
- package/dist/chunk-NAQDMEHV.js +76 -0
- package/dist/chunk-NWKXM5RD.js +109 -0
- package/dist/chunk-NZOWWHU5.js +196 -0
- package/dist/chunk-OHX6MIUZ.js +184 -0
- package/dist/chunk-OOXWYAA4.js +15 -0
- package/dist/chunk-OPHB5ORL.js +1990 -0
- package/dist/chunk-OXA6PSZT.js +1725 -0
- package/dist/chunk-P2HAGF6H.js +73 -0
- package/dist/chunk-PTHVMXZI.js +3036 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-Q325JKYB.js +189 -0
- package/dist/chunk-Q7DGTQ5G.js +255 -0
- package/dist/chunk-QCNYHBL7.js +601 -0
- package/dist/chunk-QO6BVGS5.js +145 -0
- package/dist/chunk-QXTKSOFI.js +76 -0
- package/dist/chunk-ROY4YAEQ.js +66 -0
- package/dist/chunk-RTJRZFFY.js +447 -0
- package/dist/chunk-SAVJUS2X.js +128 -0
- package/dist/chunk-SFLHVCKX.js +173 -0
- package/dist/chunk-STSFNCY4.js +127 -0
- package/dist/chunk-SWBF2LTK.js +170 -0
- package/dist/chunk-T5KELPAR.js +109 -0
- package/dist/chunk-TFFGOFVZ.js +1481 -0
- package/dist/chunk-TLHIFK4M.js +256 -0
- package/dist/chunk-TLQE7ZN3.js +156 -0
- package/dist/chunk-TPHWJ7UG.js +1981 -0
- package/dist/chunk-TRJCALW3.js +291 -0
- package/dist/chunk-TTEIYD5P.js +133 -0
- package/dist/chunk-U64O2MXY.js +407 -0
- package/dist/chunk-UCQ2VUTG.js +630 -0
- package/dist/chunk-UTI5G6OJ.js +44 -0
- package/dist/chunk-UVHDMMIP.js +188 -0
- package/dist/chunk-UZ6QQWJT.js +120 -0
- package/dist/chunk-VAX3UZOY.js +686 -0
- package/dist/chunk-W3HBUKFO.js +57 -0
- package/dist/chunk-WKQLGKCL.js +2823 -0
- package/dist/chunk-WQFNASK4.js +560 -0
- package/dist/chunk-WRBKLYSJ.js +224 -0
- package/dist/chunk-WTPZRR4I.js +17 -0
- package/dist/chunk-WZDJ2LLX.js +2385 -0
- package/dist/chunk-X2NL4KUO.js +14 -0
- package/dist/chunk-X4DVXBFY.js +38 -0
- package/dist/chunk-X677DMZM.js +7050 -0
- package/dist/chunk-XBKMWY7F.js +612 -0
- package/dist/chunk-XNCP4KYO.js +78 -0
- package/dist/chunk-XVBGLISP.js +35 -0
- package/dist/chunk-XW6KISBB.js +1192 -0
- package/dist/chunk-YGZHHAAB.js +8156 -0
- package/dist/chunk-YHEFQUQB.js +186 -0
- package/dist/chunk-YLDALTWZ.js +653 -0
- package/dist/chunk-YU4HSQW7.js +229 -0
- package/dist/chunk-ZDPP6RKB.js +27 -0
- package/dist/chunk-ZFDZKNGG.js +194 -0
- package/dist/chunk-ZIY7RNUT.js +49 -0
- package/dist/chunk-ZYJP6BOO.js +30 -0
- package/dist/cli.d.ts +1111 -0
- package/dist/cli.js +165 -0
- package/dist/codegen-command-VR2GWR6C.js +173 -0
- package/dist/codegen.d.ts +115 -0
- package/dist/codegen.js +19 -0
- package/dist/commands-GJMJ4XYZ.js +76 -0
- package/dist/completion-ZQLO6PB6.js +738 -0
- package/dist/config-MBYGCAFK.js +136 -0
- package/dist/deploy-command-JVZPWHMK.js +180 -0
- package/dist/deploy-source-3W45CXMP.js +81 -0
- package/dist/dev-env-sync-HN44K4D5.js +188 -0
- package/dist/diagnostics-UEAAHWVF.js +30 -0
- package/dist/display-name-hint-ABBPVQIR.js +46 -0
- package/dist/emit-CyhBDxli.d.ts +7007 -0
- package/dist/env-example-refresh-ET5HMMDW.js +126 -0
- package/dist/env-pull-command-TNMNB3CV.js +323 -0
- package/dist/env-target-O4HRKTGZ.js +40 -0
- package/dist/env-var-command-ZIRDCAZA.js +427 -0
- package/dist/ephemeral-P7F3PMAD.js +54 -0
- package/dist/ephemeral-command-CLJJKOFT.js +592 -0
- package/dist/ephemeral-state-PYCBSOGX.js +61 -0
- package/dist/file-lock-PT74GWYW.js +10 -0
- package/dist/generate-command-AYEOLA26.js +510 -0
- package/dist/gitignore-3SJ3WNRG.js +51 -0
- package/dist/guards-4EBNCZDC.js +162 -0
- package/dist/hosted-file-PSHJB3HX.js +28 -0
- package/dist/impersonate-command-5JAS3WSV.js +152 -0
- package/dist/import-EQSFU6JC.js +19 -0
- package/dist/index.d.ts +5470 -0
- package/dist/index.js +371 -0
- package/dist/init-command-X2FR4UAK.js +125 -0
- package/dist/init-modules-RY7UHAOL.js +50 -0
- package/dist/init-web-M4YZSZK6.js +42 -0
- package/dist/internal.d.ts +179 -0
- package/dist/internal.js +2634 -0
- package/dist/io-RC56QSN5.js +26 -0
- package/dist/keep-data-merge-7MPLVAVI.js +1119 -0
- package/dist/lambda-config-reconcile-OUZ4OYAB.js +116 -0
- package/dist/landed-753YLJ5H.js +40 -0
- package/dist/landing-record-SU52SKXU.js +61 -0
- package/dist/live-diff-YONW2VI3.js +65 -0
- package/dist/local-engine-choice-CH5X3W7E.js +79 -0
- package/dist/local-engine-command-Z3OL7VOD.js +766 -0
- package/dist/local-engine-config-5U3SC434.js +39 -0
- package/dist/local-engine-deploy-PCQ4SNPB.js +39 -0
- package/dist/local-engine-process-EHTE5LLU.js +63 -0
- package/dist/local-engine-state-A4FTRFAF.js +32 -0
- package/dist/local-engine-update-check-6L645VBL.js +162 -0
- package/dist/lock-MRRHW5GS.js +87 -0
- package/dist/lock-commands-2QG25HL7.js +963 -0
- package/dist/login-command-QPYRWOXZ.js +538 -0
- package/dist/logout-command-WOIQLDP6.js +56 -0
- package/dist/loop-ALIZLOSX.js +191 -0
- package/dist/marketplace-command-K5YL42NO.js +977 -0
- package/dist/marketplace-resolve-LY32JES5.js +40 -0
- package/dist/meta-client-YXGPW53C.js +244 -0
- package/dist/module-manifest-JFGHU2TC.js +38 -0
- package/dist/near-key.d.ts +13 -0
- package/dist/near-key.js +8 -0
- package/dist/node.d.ts +95 -0
- package/dist/node.js +969 -0
- package/dist/operation-outcome-TZSESNC7.js +51 -0
- package/dist/output-target-AL3I44GG.js +47 -0
- package/dist/package-manager-PRAHUSCN.js +34 -0
- package/dist/plan-disclosure-6G4MLZKD.js +114 -0
- package/dist/plugin-contributions-WRNY5ABG.js +28 -0
- package/dist/plugin-prompt-4VA3B4FF.js +20 -0
- package/dist/plugin-questions-JTSYA74Q.js +24 -0
- package/dist/plugin.d.ts +396 -0
- package/dist/plugin.js +1 -0
- package/dist/preflight-command-2T5Z36MI.js +321 -0
- package/dist/profile-command-AH3PIM4X.js +800 -0
- package/dist/profile-pointer-GRWJU3YD.js +31 -0
- package/dist/profile-select-74TRDEPD.js +23 -0
- package/dist/project-dependency-KSH63ODT.js +35 -0
- package/dist/project-sdk-REPPOIBD.js +24 -0
- package/dist/promote-command-PCWT5N6S.js +140 -0
- package/dist/prompt-II3F3LND.js +27 -0
- package/dist/publish-command-TTDUUJI5.js +414 -0
- package/dist/pull-command-VBO7C4S3.js +161 -0
- package/dist/pull-superseded-GJWLG7XO.js +20 -0
- package/dist/release-command-N4ZPKMHR.js +146 -0
- package/dist/release-ns-command-3KFDMZ6G.js +1745 -0
- package/dist/response-HlXahv4K.d.ts +925 -0
- package/dist/retry-command-AS5EVREX.js +34 -0
- package/dist/routes-manifest-SNWUVBT6.js +43 -0
- package/dist/runtime-XETHVF33.js +14 -0
- package/dist/scaffold.d.ts +1911 -0
- package/dist/scaffold.js +107 -0
- package/dist/secrets-file-LVZD6IIM.js +56 -0
- package/dist/secrets-fill-command-TTCPSVXN.js +218 -0
- package/dist/seed-VU7C3QYS.js +46 -0
- package/dist/sent-writes-N7X4OVXT.js +22 -0
- package/dist/source-resolve-S2XA3XZF.js +83 -0
- package/dist/static-host-B2Y6AG3W.js +352 -0
- package/dist/status-command-RUDXTF7I.js +554 -0
- package/dist/store-6VNCD4D7.js +20 -0
- package/dist/store-ARM6VMO5.js +98 -0
- package/dist/store-DuYfzKlW.d.ts +3144 -0
- package/dist/suggest-6FOOYKHG.js +12 -0
- package/dist/sveltekit.d.ts +154 -0
- package/dist/sveltekit.js +109 -0
- package/dist/sync-contributions-UCEROO26.js +415 -0
- package/dist/table-ENAVMITR.js +42 -0
- package/dist/tables-command-GUPXXSB5.js +156 -0
- package/dist/tenant-IIHPOHGP.js +42 -0
- package/dist/tenant-command-D5HGI2X4.js +965 -0
- package/dist/test-command-TIKZMDPZ.js +476 -0
- package/dist/tests-BGGIOK3L.js +26 -0
- package/dist/token-NICJUTMT.js +72 -0
- package/dist/toolchain-hooks-GHKLUJOH.js +96 -0
- package/dist/toolchain-modules-5EAZUONB.js +24 -0
- package/dist/tracked-backend-EIBUMDZA.js +80 -0
- package/dist/update-check-2W2NLDTC.js +136 -0
- package/dist/upgrade-command-QHNFWM7O.js +531 -0
- package/dist/verify-rollout-DRCK5TDD.js +61 -0
- package/dist/whoami-command-STGINTXH.js +51 -0
- package/dist/workspace-2CLHU2LK.js +93 -0
- package/dist/workspace-binding-56PIIPCP.js +54 -0
- package/dist/workspace-command-JEXQETJD.js +535 -0
- package/dist/workspace-env-F2RFMSC5.js +70 -0
- package/dist/workspace-export-OJSH2HIW.js +21 -0
- package/dist/writable-VA7OISSK.js +25 -0
- package/dist/xano-ICFUSPFR.js +42 -0
- package/dist/xanosdk-import-GN42TO2B.js +56 -0
- package/dist/xanosdk-project-S6DXJONQ.js +41 -0
- package/dist/xdo-CxDr2Q1C.d.ts +1371 -0
- package/guides/README.md +33 -0
- package/guides/authoring.md +921 -0
- package/guides/cli.md +401 -0
- package/guides/codegen.md +177 -0
- package/guides/codes.md +404 -0
- package/guides/coverage.md +74 -0
- package/guides/deploying.md +1525 -0
- package/guides/environment.md +400 -0
- package/guides/marketplace.md +415 -0
- package/guides/module-contract.md +558 -0
- package/guides/object-kinds.md +433 -0
- package/guides/project-structure.md +43 -0
- package/guides/scaffold.md +351 -0
- package/guides/typed-frontend.md +242 -0
- package/llms/client.md +63 -0
- package/llms/errors.md +56 -0
- package/llms/fields.md +176 -0
- package/llms/filters.md +183 -0
- package/llms/kinds-agent-mcp.md +30 -0
- package/llms/kinds-core.md +100 -0
- package/llms/kinds-knowledge.md +20 -0
- package/llms/kinds-realtime.md +76 -0
- package/llms/lambda.md +94 -0
- package/llms/legacy.md +44 -0
- package/llms/lock.md +40 -0
- package/llms/object-kinds.md +34 -0
- package/llms/statements-calls.md +62 -0
- package/llms/statements-catalog.md +320 -0
- package/llms/statements-data.md +66 -0
- package/llms/statements-runtime.md +68 -0
- package/llms/tests.md +59 -0
- package/llms/toolchain.md +16 -0
- package/llms/triggers.md +36 -0
- package/llms/values.md +29 -0
- package/llms-full.txt +2085 -0
- package/llms.txt +493 -0
- package/manifest.json +11224 -0
- package/package.json +162 -0
- package/types/lambda-globals.d.ts +129 -0
|
@@ -0,0 +1,3061 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertPathParamInputs,
|
|
3
|
+
defaultCache,
|
|
4
|
+
encodeResponse,
|
|
5
|
+
encodeTests,
|
|
6
|
+
fillPathParams,
|
|
7
|
+
parsePathParams,
|
|
8
|
+
queryKind,
|
|
9
|
+
warnUnboundReturn
|
|
10
|
+
} from "./chunk-6IUMKYWI.js";
|
|
11
|
+
import {
|
|
12
|
+
workspaceKind
|
|
13
|
+
} from "./chunk-2CMJZDCL.js";
|
|
14
|
+
import {
|
|
15
|
+
Xano,
|
|
16
|
+
encodeMcpOauth,
|
|
17
|
+
refuseUnknown,
|
|
18
|
+
standaloneDefKind
|
|
19
|
+
} from "./chunk-CTMO46PK.js";
|
|
20
|
+
import {
|
|
21
|
+
resolveAuthRef
|
|
22
|
+
} from "./chunk-ZDPP6RKB.js";
|
|
23
|
+
import {
|
|
24
|
+
obj
|
|
25
|
+
} from "./chunk-K5BBGTYZ.js";
|
|
26
|
+
import {
|
|
27
|
+
GENERATED_SPECS,
|
|
28
|
+
apiGroupKind,
|
|
29
|
+
assertSslConsistency,
|
|
30
|
+
coerceBool,
|
|
31
|
+
coerceHeaders,
|
|
32
|
+
coerceHttpFields,
|
|
33
|
+
coerceInt,
|
|
34
|
+
coerceObj,
|
|
35
|
+
coerceScalar,
|
|
36
|
+
coerceText,
|
|
37
|
+
dbAdd,
|
|
38
|
+
dbAddOrEdit,
|
|
39
|
+
dbBulkAdd,
|
|
40
|
+
dbBulkDelete,
|
|
41
|
+
dbBulkPatch,
|
|
42
|
+
dbBulkUpdate,
|
|
43
|
+
dbDel,
|
|
44
|
+
dbDirectQuery,
|
|
45
|
+
dbEdit,
|
|
46
|
+
dbExternalQuery,
|
|
47
|
+
dbGet,
|
|
48
|
+
dbHas,
|
|
49
|
+
dbIncrement,
|
|
50
|
+
dbPatch,
|
|
51
|
+
dbQuery,
|
|
52
|
+
dbSchema,
|
|
53
|
+
dbTransaction,
|
|
54
|
+
dbTruncate,
|
|
55
|
+
declaredServicePorts,
|
|
56
|
+
encodeEval,
|
|
57
|
+
encodeFromSpec,
|
|
58
|
+
encodeSearch,
|
|
59
|
+
encodeSort,
|
|
60
|
+
generated,
|
|
61
|
+
isIgnored,
|
|
62
|
+
isValue,
|
|
63
|
+
microserviceKind,
|
|
64
|
+
noteMicroserviceHandleHost,
|
|
65
|
+
noteToolsetTarget,
|
|
66
|
+
precondition,
|
|
67
|
+
qualifyAggregateEvals,
|
|
68
|
+
registerSpec,
|
|
69
|
+
resolveEnumValue,
|
|
70
|
+
throwError
|
|
71
|
+
} from "./chunk-YGZHHAAB.js";
|
|
72
|
+
import {
|
|
73
|
+
assertCanonical,
|
|
74
|
+
assertStoredName,
|
|
75
|
+
buildMiddlewareBlock,
|
|
76
|
+
clear,
|
|
77
|
+
encodeContainerHistory,
|
|
78
|
+
encodeHistory
|
|
79
|
+
} from "./chunk-5V5XU32D.js";
|
|
80
|
+
import {
|
|
81
|
+
assertKnownKeys,
|
|
82
|
+
conditional,
|
|
83
|
+
encodeExpression,
|
|
84
|
+
encodeRuntimeCondition,
|
|
85
|
+
tableKind
|
|
86
|
+
} from "./chunk-HVRUQXGD.js";
|
|
87
|
+
import {
|
|
88
|
+
brandDef
|
|
89
|
+
} from "./chunk-ERVIASGL.js";
|
|
90
|
+
import {
|
|
91
|
+
assertDefShape,
|
|
92
|
+
emptyMiddleware,
|
|
93
|
+
encodeTags,
|
|
94
|
+
registerKind,
|
|
95
|
+
resolveMockKeys
|
|
96
|
+
} from "./chunk-4POWHT2K.js";
|
|
97
|
+
import {
|
|
98
|
+
nearestKey
|
|
99
|
+
} from "./chunk-WTPZRR4I.js";
|
|
100
|
+
import {
|
|
101
|
+
emitDiagnostic
|
|
102
|
+
} from "./chunk-2EZ3ZJZZ.js";
|
|
103
|
+
import {
|
|
104
|
+
lockKey
|
|
105
|
+
} from "./chunk-6MR5TI5V.js";
|
|
106
|
+
import {
|
|
107
|
+
HOSTED_FILE_SCHEME,
|
|
108
|
+
isHostedFile,
|
|
109
|
+
pendingHostedSrc
|
|
110
|
+
} from "./chunk-XNCP4KYO.js";
|
|
111
|
+
import {
|
|
112
|
+
ANNOTATION_KEYS,
|
|
113
|
+
OPTION_KEYS,
|
|
114
|
+
annotate,
|
|
115
|
+
encodeStack,
|
|
116
|
+
encodeStatement,
|
|
117
|
+
isRegisteredStatement,
|
|
118
|
+
registerFactoryPaths,
|
|
119
|
+
registerStatement
|
|
120
|
+
} from "./chunk-YU4HSQW7.js";
|
|
121
|
+
import {
|
|
122
|
+
impliedInputs,
|
|
123
|
+
isTriggerObjType
|
|
124
|
+
} from "./chunk-G554NZNI.js";
|
|
125
|
+
import {
|
|
126
|
+
encodeInput
|
|
127
|
+
} from "./chunk-N5GKCWE5.js";
|
|
128
|
+
import {
|
|
129
|
+
barePatternRefusal,
|
|
130
|
+
c,
|
|
131
|
+
inp,
|
|
132
|
+
isTaggedValue,
|
|
133
|
+
ref,
|
|
134
|
+
reversedOperandRefusal
|
|
135
|
+
} from "./chunk-OXA6PSZT.js";
|
|
136
|
+
import {
|
|
137
|
+
deriveGuid,
|
|
138
|
+
noteHandleRef,
|
|
139
|
+
realtimeChannelSeedName,
|
|
140
|
+
realtimeMessageSeedName,
|
|
141
|
+
resolveQueryRef,
|
|
142
|
+
resolveRef
|
|
143
|
+
} from "./chunk-NZOWWHU5.js";
|
|
144
|
+
import {
|
|
145
|
+
getLockedCanonical
|
|
146
|
+
} from "./chunk-4BW2SG2N.js";
|
|
147
|
+
import {
|
|
148
|
+
argsOrEmpty,
|
|
149
|
+
assertArg,
|
|
150
|
+
assertNewVarName,
|
|
151
|
+
assertStatements,
|
|
152
|
+
assertValueArg,
|
|
153
|
+
assertVarName,
|
|
154
|
+
describeArg,
|
|
155
|
+
describeEntry,
|
|
156
|
+
isRecordArg,
|
|
157
|
+
isTaggedArg,
|
|
158
|
+
presentValueArg
|
|
159
|
+
} from "./chunk-CIMQZRRE.js";
|
|
160
|
+
|
|
161
|
+
// src/statements/set-var.ts
|
|
162
|
+
var SET_VAR = "mvp:set_var";
|
|
163
|
+
var UPDATE_VAR = "mvp:update_var";
|
|
164
|
+
function setVar(as, value, a) {
|
|
165
|
+
assertNewVarName("s.set_var", as);
|
|
166
|
+
assertValueArg("s.set_var", "value", value);
|
|
167
|
+
assertKnownKeys(`Statement "s.set_var": options`, a, OPTION_KEYS);
|
|
168
|
+
return annotate(
|
|
169
|
+
{
|
|
170
|
+
name: SET_VAR,
|
|
171
|
+
as,
|
|
172
|
+
context: { value: value.value, tag: value.tag, filters: value.filters }
|
|
173
|
+
},
|
|
174
|
+
a
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
function updateVar(name, value, a) {
|
|
178
|
+
assertVarName("s.update_var", name);
|
|
179
|
+
assertValueArg("s.update_var", "value", value);
|
|
180
|
+
assertKnownKeys(`Statement "s.update_var": options`, a, ANNOTATION_KEYS);
|
|
181
|
+
return annotate(
|
|
182
|
+
{
|
|
183
|
+
name: UPDATE_VAR,
|
|
184
|
+
context: { name, value: value.value, tag: value.tag, filters: value.filters },
|
|
185
|
+
output: { filters: [] }
|
|
186
|
+
},
|
|
187
|
+
a
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
registerStatement(SET_VAR, setVar);
|
|
191
|
+
registerStatement(UPDATE_VAR, updateVar);
|
|
192
|
+
|
|
193
|
+
// src/statements/special/control-flow.ts
|
|
194
|
+
function asValue(arg) {
|
|
195
|
+
return "tag" in arg ? arg : arg.value;
|
|
196
|
+
}
|
|
197
|
+
function valueContext(statement, arg) {
|
|
198
|
+
assertArg(statement, "value", arg);
|
|
199
|
+
const value = arg !== null && (typeof arg === "object" || typeof arg === "function") ? asValue(arg) : void 0;
|
|
200
|
+
if (value === null || typeof value !== "object" && typeof value !== "function" || typeof value.tag !== "string") {
|
|
201
|
+
throw new Error(
|
|
202
|
+
`Statement "${statement}": argument "value" must be a value (\`c.*\`, \`ref()\`, \`inp()\`, \u2026) \u2014 got ${describeEntry(arg)}.`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
return { value: value.value, tag: value.tag, filters: value.filters };
|
|
206
|
+
}
|
|
207
|
+
function returnValue(value, a) {
|
|
208
|
+
const context = valueContext("s.return", value);
|
|
209
|
+
assertKnownKeys(`Statement "s.return": options`, a, ANNOTATION_KEYS);
|
|
210
|
+
return annotate({ name: "mvp:return", context }, a);
|
|
211
|
+
}
|
|
212
|
+
function die(value, a) {
|
|
213
|
+
const context = valueContext("s.debug.stop", value);
|
|
214
|
+
assertKnownKeys(`Statement "s.debug.stop": options`, a, ANNOTATION_KEYS);
|
|
215
|
+
return annotate({ name: "mvp:die", context }, a);
|
|
216
|
+
}
|
|
217
|
+
function debugLog(value, a) {
|
|
218
|
+
const context = valueContext("s.debug.log", value);
|
|
219
|
+
assertKnownKeys(`Statement "s.debug.log": options`, a, ANNOTATION_KEYS);
|
|
220
|
+
return annotate({ name: "mvp:debug_log", context }, a);
|
|
221
|
+
}
|
|
222
|
+
function foreachBreak(a) {
|
|
223
|
+
assertKnownKeys(`Statement "s.foreach_break"`, a, ANNOTATION_KEYS);
|
|
224
|
+
return annotate({ name: "mvp:foreach_break", context: {} }, a);
|
|
225
|
+
}
|
|
226
|
+
function foreachContinue(a) {
|
|
227
|
+
assertKnownKeys(`Statement "s.foreach_continue"`, a, ANNOTATION_KEYS);
|
|
228
|
+
return annotate({ name: "mvp:foreach_continue", context: {} }, a);
|
|
229
|
+
}
|
|
230
|
+
function foreachRemove(a) {
|
|
231
|
+
assertKnownKeys(`Statement "s.foreach_remove"`, a, ANNOTATION_KEYS);
|
|
232
|
+
return annotate({ name: "mvp:foreach_remove", context: {} }, a);
|
|
233
|
+
}
|
|
234
|
+
registerStatement("mvp:return", returnValue);
|
|
235
|
+
registerStatement("mvp:die", die);
|
|
236
|
+
registerStatement("mvp:debug_log", debugLog);
|
|
237
|
+
registerStatement("mvp:foreach_break", foreachBreak);
|
|
238
|
+
registerStatement("mvp:foreach_continue", foreachContinue);
|
|
239
|
+
registerStatement("mvp:foreach_remove", foreachRemove);
|
|
240
|
+
|
|
241
|
+
// src/statements/special/loops.ts
|
|
242
|
+
function valueFields(v) {
|
|
243
|
+
return { value: v.value, tag: v.tag, filters: v.filters };
|
|
244
|
+
}
|
|
245
|
+
function run(body) {
|
|
246
|
+
return body.map(encodeStatement);
|
|
247
|
+
}
|
|
248
|
+
var FOR_KEYS = /* @__PURE__ */ Object.keys({ as: 1, count: 1, body: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
249
|
+
function forLoop(args) {
|
|
250
|
+
args = argsOrEmpty(args);
|
|
251
|
+
assertKnownKeys(`Statement "s.for"`, args, FOR_KEYS);
|
|
252
|
+
assertArg("s.for", "as", args.as);
|
|
253
|
+
assertNewVarName("s.for", args.as, "as");
|
|
254
|
+
assertValueArg("s.for", "count", args.count);
|
|
255
|
+
assertStatements("s.for", "body", args.body);
|
|
256
|
+
return annotate({
|
|
257
|
+
name: "mvp:for",
|
|
258
|
+
context: { as: args.as, cnt: valueFields(args.count), run: run(args.body) },
|
|
259
|
+
input: []
|
|
260
|
+
}, args);
|
|
261
|
+
}
|
|
262
|
+
var FOREACH_KEYS = /* @__PURE__ */ Object.keys({ as: 1, list: 1, body: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
263
|
+
function foreachLoop(args) {
|
|
264
|
+
args = argsOrEmpty(args);
|
|
265
|
+
assertKnownKeys(`Statement "s.foreach"`, args, FOREACH_KEYS);
|
|
266
|
+
assertArg("s.foreach", "as", args.as);
|
|
267
|
+
assertNewVarName("s.foreach", args.as, "as");
|
|
268
|
+
assertValueArg("s.foreach", "list", args.list);
|
|
269
|
+
assertStatements("s.foreach", "body", args.body);
|
|
270
|
+
return annotate({
|
|
271
|
+
name: "mvp:foreach",
|
|
272
|
+
context: { as: args.as, list: valueFields(args.list), run: run(args.body) },
|
|
273
|
+
input: []
|
|
274
|
+
}, args);
|
|
275
|
+
}
|
|
276
|
+
var WHILE_KEYS = /* @__PURE__ */ Object.keys({ when: 1, body: 1, disabled: 1, description: 1, mock: 1 });
|
|
277
|
+
function whileLoop(args) {
|
|
278
|
+
args = argsOrEmpty(args);
|
|
279
|
+
assertKnownKeys(`Statement "s.while"`, args, WHILE_KEYS);
|
|
280
|
+
assertArg("s.while", "when", args.when);
|
|
281
|
+
assertStatements("s.while", "body", args.body);
|
|
282
|
+
return annotate({
|
|
283
|
+
name: "mvp:while",
|
|
284
|
+
context: { expr: encodeRuntimeCondition(args.when, "s.while `when`"), run: run(args.body) },
|
|
285
|
+
input: []
|
|
286
|
+
}, args);
|
|
287
|
+
}
|
|
288
|
+
function group(body, a) {
|
|
289
|
+
assertStatements("s.group", "body", body);
|
|
290
|
+
assertKnownKeys(`Statement "s.group": options`, a, ANNOTATION_KEYS);
|
|
291
|
+
return annotate({ name: "mvp:group", context: { run: run(body) }, input: [] }, a);
|
|
292
|
+
}
|
|
293
|
+
registerStatement("mvp:for", forLoop);
|
|
294
|
+
registerStatement("mvp:foreach", foreachLoop);
|
|
295
|
+
registerStatement("mvp:while", whileLoop);
|
|
296
|
+
registerStatement("mvp:group", group);
|
|
297
|
+
|
|
298
|
+
// src/statements/special/branch.ts
|
|
299
|
+
function valueFields2(v) {
|
|
300
|
+
return { value: v.value, tag: v.tag, filters: v.filters };
|
|
301
|
+
}
|
|
302
|
+
function run2(body) {
|
|
303
|
+
return body.map(encodeStatement);
|
|
304
|
+
}
|
|
305
|
+
var SWITCH_CASE_KEYS = /* @__PURE__ */ Object.keys({ when: 1, body: 1, break: 1, disabled: 1, description: 1, mock: 1 });
|
|
306
|
+
function switchCase(args, where = "") {
|
|
307
|
+
args = argsOrEmpty(args);
|
|
308
|
+
assertKnownKeys(`Statement "s.switch"${where === "" ? "" : `: argument "${where.slice(0, -1)}"`}`, args, SWITCH_CASE_KEYS);
|
|
309
|
+
assertValueArg("s.switch", `${where}when`, args.when);
|
|
310
|
+
assertStatements("s.switch", `${where}body`, args.body);
|
|
311
|
+
const context = { value: valueFields2(args.when) };
|
|
312
|
+
if (args.break !== void 0) {
|
|
313
|
+
context.break = args.break;
|
|
314
|
+
}
|
|
315
|
+
context.if = { run: run2(args.body) };
|
|
316
|
+
return annotate({ name: "mvp:switch_case", context, input: [] }, args);
|
|
317
|
+
}
|
|
318
|
+
var SWITCH_KEYS = /* @__PURE__ */ Object.keys({ on: 1, cases: 1, default: 1, disabled: 1, description: 1, mock: 1 });
|
|
319
|
+
function switchStatement(args) {
|
|
320
|
+
args = argsOrEmpty(args);
|
|
321
|
+
assertKnownKeys(`Statement "s.switch"`, args, SWITCH_KEYS);
|
|
322
|
+
assertValueArg("s.switch", "on", args.on);
|
|
323
|
+
assertArg("s.switch", "cases", args.cases);
|
|
324
|
+
if (!Array.isArray(args.cases)) {
|
|
325
|
+
throw new Error(`Statement "s.switch": argument "cases" must be an array of { when, body } cases \u2014 got ${describeEntry(args.cases)}.`);
|
|
326
|
+
}
|
|
327
|
+
if (args.default !== void 0 && args.default !== null) assertStatements("s.switch", "default", args.default);
|
|
328
|
+
return annotate({
|
|
329
|
+
name: "mvp:switch",
|
|
330
|
+
context: {
|
|
331
|
+
value: valueFields2(args.on),
|
|
332
|
+
elif: {
|
|
333
|
+
run: args.cases.map((c2, i) => {
|
|
334
|
+
if (c2 === null || typeof c2 !== "object") {
|
|
335
|
+
throw new Error(
|
|
336
|
+
`Statement "s.switch": argument "cases[${i}]" must be a { when, body } case \u2014 got ${describeEntry(c2)}.`
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
return encodeStatement(switchCase(c2, `cases[${i}].`));
|
|
340
|
+
})
|
|
341
|
+
},
|
|
342
|
+
else: { run: run2(args.default ?? []) }
|
|
343
|
+
},
|
|
344
|
+
input: []
|
|
345
|
+
}, args);
|
|
346
|
+
}
|
|
347
|
+
function tryCatch(args) {
|
|
348
|
+
return tryCatchStatement(argsOrEmpty(args));
|
|
349
|
+
}
|
|
350
|
+
var TRY_CATCH_KEYS = /* @__PURE__ */ Object.keys({ try: 1, catch: 1, finally: 1, disabled: 1, description: 1, mock: 1 });
|
|
351
|
+
function tryCatchStatement(args) {
|
|
352
|
+
assertKnownKeys(`Statement "s.try_catch"`, args, TRY_CATCH_KEYS);
|
|
353
|
+
assertStatements("s.try_catch", "try", args.try);
|
|
354
|
+
if (args.catch !== void 0 && args.catch !== null) assertStatements("s.try_catch", "catch", args.catch);
|
|
355
|
+
if (args.finally !== void 0 && args.finally !== null) assertStatements("s.try_catch", "finally", args.finally);
|
|
356
|
+
return annotate({
|
|
357
|
+
name: "mvp:try_catch",
|
|
358
|
+
context: {
|
|
359
|
+
if: { run: run2(args.try) },
|
|
360
|
+
else: { run: run2(args.catch ?? []) },
|
|
361
|
+
then: { run: run2(args.finally ?? []) }
|
|
362
|
+
},
|
|
363
|
+
input: []
|
|
364
|
+
}, args);
|
|
365
|
+
}
|
|
366
|
+
registerStatement("mvp:switch", switchStatement);
|
|
367
|
+
registerStatement("mvp:switch_case", switchCase);
|
|
368
|
+
registerStatement("mvp:try_catch", tryCatch);
|
|
369
|
+
|
|
370
|
+
// src/statements/special/async-runtime.ts
|
|
371
|
+
function encodeAsyncRuntime(runtime) {
|
|
372
|
+
if (!runtime) return void 0;
|
|
373
|
+
if (runtime.mode !== "async-dedicated") return { mode: runtime.mode };
|
|
374
|
+
return {
|
|
375
|
+
mode: runtime.mode,
|
|
376
|
+
cpu: runtime.cpu ?? "",
|
|
377
|
+
memory: runtime.memory ?? "",
|
|
378
|
+
timeout: runtime.timeout === void 0 ? "" : String(runtime.timeout),
|
|
379
|
+
max_retry: runtime.maxRetry === void 0 ? "" : String(runtime.maxRetry)
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// src/statements/special/calls.ts
|
|
384
|
+
function vf(v) {
|
|
385
|
+
return { value: v.value, tag: v.tag, filters: v.filters };
|
|
386
|
+
}
|
|
387
|
+
function encodeCallInput(input, statement, field2 = "input") {
|
|
388
|
+
if (input === void 0 || input === null) return [];
|
|
389
|
+
if (typeof input !== "object" || Array.isArray(input) || isTaggedValue(input)) {
|
|
390
|
+
throw new Error(
|
|
391
|
+
`Statement "${statement}": argument "${field2}" must be a { name: value } record \u2014 got ${describeEntry(input)}.`
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
return Object.entries(input).filter(([, v]) => v !== void 0).map(([name, v]) => ({ name, ...vf(coerceScalar(v)), ...isIgnored(v) ? { ignore: true } : {} }));
|
|
395
|
+
}
|
|
396
|
+
function fnId(fn) {
|
|
397
|
+
return fn === null ? "" : resolveRef("function", fn, `Statement "s.function.run": argument "fn"`);
|
|
398
|
+
}
|
|
399
|
+
var FUNCTION_RUN_KEYS = /* @__PURE__ */ Object.keys({ fn: 1, as: 1, input: 1, runtime: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
400
|
+
function functionRun(args) {
|
|
401
|
+
args = argsOrEmpty(args);
|
|
402
|
+
assertKnownKeys(`Statement "s.function.run"`, args, FUNCTION_RUN_KEYS);
|
|
403
|
+
assertArg("s.function.run", "fn", args.fn, { nullable: true });
|
|
404
|
+
return annotate({
|
|
405
|
+
name: "mvp:function",
|
|
406
|
+
context: { function: { id: fnId(args.fn) } },
|
|
407
|
+
as: args.as,
|
|
408
|
+
input: encodeCallInput(args.input, "s.function.run"),
|
|
409
|
+
runtime: encodeAsyncRuntime(args.runtime)
|
|
410
|
+
}, args);
|
|
411
|
+
}
|
|
412
|
+
var FUNCTION_CALL_KEYS = /* @__PURE__ */ Object.keys({ fn: 1, as: 1, input: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
413
|
+
function functionCall(args) {
|
|
414
|
+
args = argsOrEmpty(args);
|
|
415
|
+
assertKnownKeys(`Statement "s.function.call"`, args, FUNCTION_CALL_KEYS);
|
|
416
|
+
assertArg("s.function.call", "fn", args.fn);
|
|
417
|
+
return annotate({
|
|
418
|
+
name: "mvp:workspace_run_function",
|
|
419
|
+
context: { id: resolveRef("function", args.fn, `Statement "s.function.call": argument "fn"`) },
|
|
420
|
+
as: args.as,
|
|
421
|
+
input: encodeCallInput(args.input, "s.function.call")
|
|
422
|
+
}, args);
|
|
423
|
+
}
|
|
424
|
+
function deliveredName(name) {
|
|
425
|
+
return name.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join("-");
|
|
426
|
+
}
|
|
427
|
+
function asDelivered(headers) {
|
|
428
|
+
if (headers === void 0 || headers === null) return void 0;
|
|
429
|
+
if (isTaggedValue(headers) || typeof headers !== "object") return headers;
|
|
430
|
+
if (Array.isArray(headers)) {
|
|
431
|
+
return headers.map((line) => {
|
|
432
|
+
if (typeof line !== "string") return line;
|
|
433
|
+
const colon = line.indexOf(":");
|
|
434
|
+
return colon === -1 ? line : deliveredName(line.slice(0, colon)) + line.slice(colon);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
const delivered = {};
|
|
438
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
439
|
+
const as = deliveredName(name);
|
|
440
|
+
if (Object.hasOwn(delivered, as)) {
|
|
441
|
+
throw new Error(
|
|
442
|
+
`Statement "s.api.call": headers name "${as}" twice (as ${JSON.stringify(name)} and another spelling) \u2014 a real request delivers both under that one name, so only one can reach the endpoint.`
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
delivered[as] = value;
|
|
446
|
+
}
|
|
447
|
+
return delivered;
|
|
448
|
+
}
|
|
449
|
+
var API_CALL_KEYS = /* @__PURE__ */ Object.keys({ api: 1, query: 1, as: 1, input: 1, headers: 1, auth: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
450
|
+
function apiCall(args) {
|
|
451
|
+
args = argsOrEmpty(args);
|
|
452
|
+
assertKnownKeys(`Statement "s.api.call"`, args, API_CALL_KEYS);
|
|
453
|
+
if (args.query !== void 0 && args.api === void 0) {
|
|
454
|
+
throw new Error(`Statement "s.api.call": the endpoint goes in \`api\`, not \`query\` \u2014 s.api.call({ api: myQuery, \u2026 }).`);
|
|
455
|
+
}
|
|
456
|
+
assertArg("s.api.call", "api", args.api);
|
|
457
|
+
const context = { id: resolveQueryRef(args.api, `Statement "s.api.call": argument "api"`) };
|
|
458
|
+
const headers = coerceHeaders(asDelivered(args.headers), `Statement "s.api.call": argument "headers"`);
|
|
459
|
+
if (headers) context.headers = vf(headers);
|
|
460
|
+
if (args.auth !== void 0 && args.auth !== null) {
|
|
461
|
+
const auth = args.auth;
|
|
462
|
+
const token = isRecordArg(auth) ? auth.token : void 0;
|
|
463
|
+
if (!isRecordArg(auth) || typeof token !== "string" && !isTaggedArg(token)) {
|
|
464
|
+
throw new Error(
|
|
465
|
+
`Statement "s.api.call": argument "auth" must be { token, ignoreExpiration? } with token a string or a tagged value \u2014 got ${isRecordArg(auth) ? `token ${describeEntry(token)}` : describeEntry(auth)}.`
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
context.token = typeof args.auth.token === "string" ? args.auth.token : vf(args.auth.token);
|
|
469
|
+
if (args.auth.ignoreExpiration) context.token_ignore_expiration = true;
|
|
470
|
+
}
|
|
471
|
+
return annotate({
|
|
472
|
+
name: "mvp:workspace_run_endpoint",
|
|
473
|
+
context,
|
|
474
|
+
as: args.as,
|
|
475
|
+
input: encodeCallInput(args.input, "s.api.call")
|
|
476
|
+
}, args);
|
|
477
|
+
}
|
|
478
|
+
var TASK_CALL_KEYS = /* @__PURE__ */ Object.keys({ task: 1, as: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
479
|
+
function taskCall(args) {
|
|
480
|
+
args = argsOrEmpty(args);
|
|
481
|
+
assertKnownKeys(`Statement "s.task.call"`, args, TASK_CALL_KEYS);
|
|
482
|
+
assertArg("s.task.call", "task", args.task);
|
|
483
|
+
return annotate({
|
|
484
|
+
name: "mvp:workspace_run_task",
|
|
485
|
+
context: { id: resolveRef("task", args.task, `Statement "s.task.call": argument "task"`) },
|
|
486
|
+
as: args.as,
|
|
487
|
+
input: []
|
|
488
|
+
}, args);
|
|
489
|
+
}
|
|
490
|
+
var TOOL_CALL_KEYS = /* @__PURE__ */ Object.keys({ tool: 1, as: 1, input: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
491
|
+
function toolCall(args) {
|
|
492
|
+
args = argsOrEmpty(args);
|
|
493
|
+
assertKnownKeys(`Statement "s.tool.call"`, args, TOOL_CALL_KEYS);
|
|
494
|
+
assertArg("s.tool.call", "tool", args.tool);
|
|
495
|
+
return annotate({
|
|
496
|
+
name: "mvp:workspace_run_tool",
|
|
497
|
+
context: { id: resolveRef("tool", args.tool, `Statement "s.tool.call": argument "tool"`) },
|
|
498
|
+
as: args.as,
|
|
499
|
+
input: encodeCallInput(args.input, "s.tool.call")
|
|
500
|
+
}, args);
|
|
501
|
+
}
|
|
502
|
+
var TRIGGER_CALL_KEYS = /* @__PURE__ */ Object.keys({ trigger: 1, as: 1, input: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
503
|
+
function triggerCall(args) {
|
|
504
|
+
args = argsOrEmpty(args);
|
|
505
|
+
assertKnownKeys(`Statement "s.trigger.call"`, args, TRIGGER_CALL_KEYS);
|
|
506
|
+
assertArg("s.trigger.call", "trigger", args.trigger);
|
|
507
|
+
return annotate({
|
|
508
|
+
name: "mvp:workspace_run_trigger",
|
|
509
|
+
context: { id: resolveRef("trigger", args.trigger, `Statement "s.trigger.call": argument "trigger"`) },
|
|
510
|
+
as: args.as,
|
|
511
|
+
input: encodeCallInput(args.input, "s.trigger.call")
|
|
512
|
+
}, args);
|
|
513
|
+
}
|
|
514
|
+
var MIDDLEWARE_CALL_KEYS = /* @__PURE__ */ Object.keys({ middleware: 1, as: 1, input: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
515
|
+
function middlewareCall(args) {
|
|
516
|
+
args = argsOrEmpty(args);
|
|
517
|
+
assertKnownKeys(`Statement "s.middleware.call"`, args, MIDDLEWARE_CALL_KEYS);
|
|
518
|
+
assertArg("s.middleware.call", "middleware", args.middleware);
|
|
519
|
+
return annotate({
|
|
520
|
+
name: "mvp:workspace_run_middleware",
|
|
521
|
+
context: { id: resolveRef("middleware", args.middleware, `Statement "s.middleware.call": argument "middleware"`) },
|
|
522
|
+
as: args.as,
|
|
523
|
+
input: encodeCallInput(args.input, "s.middleware.call")
|
|
524
|
+
}, args);
|
|
525
|
+
}
|
|
526
|
+
var ADDON_CALL_KEYS = /* @__PURE__ */ Object.keys({ addon: 1, as: 1, input: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
527
|
+
function addonCall(args) {
|
|
528
|
+
args = argsOrEmpty(args);
|
|
529
|
+
assertKnownKeys(`Statement "s.addon.call"`, args, ADDON_CALL_KEYS);
|
|
530
|
+
assertArg("s.addon.call", "addon", args.addon);
|
|
531
|
+
return annotate({
|
|
532
|
+
name: "mvp:workspace_run_addon",
|
|
533
|
+
context: { id: resolveRef("addon", args.addon, `Statement "s.addon.call": argument "addon"`) },
|
|
534
|
+
as: args.as,
|
|
535
|
+
input: encodeCallInput(args.input, "s.addon.call")
|
|
536
|
+
}, args);
|
|
537
|
+
}
|
|
538
|
+
function refuseDerivedIdentity(statement, args) {
|
|
539
|
+
const legacy = args;
|
|
540
|
+
if (legacy.action === void 0 && legacy.package === void 0) return;
|
|
541
|
+
throw new Error(
|
|
542
|
+
`Statement "${statement}": \`action\`/\`package\` named an action and let the SDK derive its id. An action is a third-party package installed onto the instance, so its id is assigned at install and cannot be derived from a name \u2014 a derived one addresses nothing. Pass the installed id instead: \`actionId\` for action.call, or \`traceId\`/\`versionId\`/\`slug\` for action.package.call. Read them off an existing call in a pulled workspace.`
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
var ACTION_CALL_KEYS = /* @__PURE__ */ Object.keys({ actionId: 1, as: 1, input: 1, registry: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
546
|
+
function actionCall(args) {
|
|
547
|
+
args = argsOrEmpty(args);
|
|
548
|
+
refuseDerivedIdentity("s.action.call", args);
|
|
549
|
+
assertKnownKeys(`Statement "s.action.call"`, args, ACTION_CALL_KEYS);
|
|
550
|
+
assertArg("s.action.call", "actionId", args.actionId);
|
|
551
|
+
return annotate({
|
|
552
|
+
name: "mvp:action",
|
|
553
|
+
context: { run_version: { id: args.actionId } },
|
|
554
|
+
as: args.as,
|
|
555
|
+
input: encodeCallInput(args.input, "s.action.call"),
|
|
556
|
+
settings_registry: encodeCallInput(args.registry, "s.action.call", "registry")
|
|
557
|
+
}, args);
|
|
558
|
+
}
|
|
559
|
+
var ACTION_PACKAGE_CALL_KEYS = /* @__PURE__ */ Object.keys({ traceId: 1, versionId: 1, slug: 1, as: 1, input: 1, registry: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
560
|
+
function actionPackageCall(args) {
|
|
561
|
+
args = argsOrEmpty(args);
|
|
562
|
+
refuseDerivedIdentity("s.action.package.call", args);
|
|
563
|
+
assertKnownKeys(`Statement "s.action.package.call"`, args, ACTION_PACKAGE_CALL_KEYS);
|
|
564
|
+
assertArg("s.action.package.call", "traceId", args.traceId);
|
|
565
|
+
assertArg("s.action.package.call", "versionId", args.versionId);
|
|
566
|
+
assertArg("s.action.package.call", "slug", args.slug);
|
|
567
|
+
return annotate({
|
|
568
|
+
name: "mvp:action_package",
|
|
569
|
+
context: {
|
|
570
|
+
action: { trace_id: args.traceId },
|
|
571
|
+
package: { slug: args.slug },
|
|
572
|
+
package_version: { id: args.versionId }
|
|
573
|
+
},
|
|
574
|
+
as: args.as,
|
|
575
|
+
input: encodeCallInput(args.input, "s.action.package.call"),
|
|
576
|
+
settings_registry: encodeCallInput(args.registry, "s.action.package.call", "registry")
|
|
577
|
+
}, args);
|
|
578
|
+
}
|
|
579
|
+
var WORKFLOW_TEST_CALL_KEYS = /* @__PURE__ */ Object.keys({ workflowTest: 1, as: 1, datasource: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
580
|
+
function workflowTestCall(args) {
|
|
581
|
+
args = argsOrEmpty(args);
|
|
582
|
+
assertKnownKeys(`Statement "s.workflow_test.call"`, args, WORKFLOW_TEST_CALL_KEYS);
|
|
583
|
+
assertArg("s.workflow_test.call", "workflowTest", args.workflowTest);
|
|
584
|
+
return annotate({
|
|
585
|
+
name: "mvp:workspace_run_workflow_test",
|
|
586
|
+
context: {
|
|
587
|
+
datasource: args.datasource ?? "",
|
|
588
|
+
id: resolveRef("workflow_test", args.workflowTest, `Statement "s.workflow_test.call": argument "workflowTest"`)
|
|
589
|
+
},
|
|
590
|
+
as: args.as,
|
|
591
|
+
input: []
|
|
592
|
+
}, args);
|
|
593
|
+
}
|
|
594
|
+
registerStatement("mvp:function", functionRun);
|
|
595
|
+
registerStatement("mvp:action", actionCall);
|
|
596
|
+
registerStatement("mvp:action_package", actionPackageCall);
|
|
597
|
+
registerStatement("mvp:workspace_run_workflow_test", workflowTestCall);
|
|
598
|
+
registerStatement("mvp:workspace_run_function", functionCall);
|
|
599
|
+
registerStatement("mvp:workspace_run_endpoint", apiCall);
|
|
600
|
+
registerStatement("mvp:workspace_run_task", taskCall);
|
|
601
|
+
registerStatement("mvp:workspace_run_tool", toolCall);
|
|
602
|
+
registerStatement("mvp:workspace_run_trigger", triggerCall);
|
|
603
|
+
registerStatement("mvp:workspace_run_middleware", middlewareCall);
|
|
604
|
+
registerStatement("mvp:workspace_run_addon", addonCall);
|
|
605
|
+
|
|
606
|
+
// src/statements/special/input-enums.ts
|
|
607
|
+
var SPECIAL_INPUT_ENUMS = {
|
|
608
|
+
"mvp:get_input": { encoding: ["json", "yaml", "x-www-form-urlencoded", "none"] },
|
|
609
|
+
"mvp:cloud_job": { template: ["micro", "small", "medium", "large", "xlarge"] },
|
|
610
|
+
"mvp:call_agent": { version: ["v4", "v5"] }
|
|
611
|
+
};
|
|
612
|
+
function specialEnumValue(stored, statement, field2, input, provided, note) {
|
|
613
|
+
const values = SPECIAL_INPUT_ENUMS[stored][input];
|
|
614
|
+
if (typeof provided !== "string") presentValueArg(statement, field2, provided);
|
|
615
|
+
try {
|
|
616
|
+
return resolveEnumValue(statement, field2, values, provided);
|
|
617
|
+
} catch (err) {
|
|
618
|
+
if (note !== void 0 && err instanceof Error) err.message = `${err.message} ${note}`;
|
|
619
|
+
throw err;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// src/statements/special/ai-cloud.ts
|
|
624
|
+
function vf2(v) {
|
|
625
|
+
return { value: v.value, tag: v.tag, filters: v.filters };
|
|
626
|
+
}
|
|
627
|
+
var AI_AGENT_RUN_KEYS = /* @__PURE__ */ Object.keys({ agent: 1, as: 1, args: 1, allowToolExecution: 1, version: 1, runtime: 1, resultShape: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
628
|
+
function aiAgentRun(a) {
|
|
629
|
+
a = argsOrEmpty(a);
|
|
630
|
+
assertKnownKeys(`Statement "s.ai.agent.run"`, a, AI_AGENT_RUN_KEYS);
|
|
631
|
+
assertArg("s.ai.agent.run", "agent", a.agent);
|
|
632
|
+
const input = [];
|
|
633
|
+
if (a.args !== void 0 && a.args !== null) {
|
|
634
|
+
if (!isTaggedValue(a.args) && (typeof a.args !== "object" || Array.isArray(a.args))) {
|
|
635
|
+
throw new Error(
|
|
636
|
+
`Statement "s.ai.agent.run": argument "args" must be a { name: value } record or a tagged value \u2014 got ${describeEntry(a.args)}.`
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
const argsValue = isTaggedValue(a.args) ? a.args : obj(a.args);
|
|
640
|
+
input.push({ name: "args", ...vf2(argsValue) });
|
|
641
|
+
}
|
|
642
|
+
if (presentValueArg("s.ai.agent.run", "allowToolExecution", a.allowToolExecution))
|
|
643
|
+
input.push({ name: "allow_tool_execution", ...vf2(a.allowToolExecution) });
|
|
644
|
+
if (a.version !== void 0 && a.version !== null) {
|
|
645
|
+
input.push({ name: "version", ...vf2(specialEnumValue("mvp:call_agent", "s.ai.agent.run", "version", "version", a.version)) });
|
|
646
|
+
}
|
|
647
|
+
const stmt = {
|
|
648
|
+
name: "mvp:call_agent",
|
|
649
|
+
context: { toolset: { id: resolveRef("toolset", a.agent, `Statement "s.ai.agent.run": argument "agent"`, "agent") } },
|
|
650
|
+
as: a.as ?? "",
|
|
651
|
+
input
|
|
652
|
+
};
|
|
653
|
+
const runtime = encodeAsyncRuntime(a.runtime);
|
|
654
|
+
if (runtime) stmt.runtime = runtime;
|
|
655
|
+
return annotate(stmt, a);
|
|
656
|
+
}
|
|
657
|
+
var CLOUD_JOB_KEYS = /* @__PURE__ */ Object.keys({ as: 1, image: 1, command: 1, args: 1, secret: 1, template: 1, await: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
658
|
+
function cloudJob(a) {
|
|
659
|
+
a = argsOrEmpty(a);
|
|
660
|
+
assertKnownKeys(`Statement "s.cloud.job"`, a, CLOUD_JOB_KEYS);
|
|
661
|
+
assertValueArg("s.cloud.job", "image", a.image);
|
|
662
|
+
assertValueArg("s.cloud.job", "command", a.command);
|
|
663
|
+
const input = [];
|
|
664
|
+
input.push({ name: "image", ...vf2(a.image) });
|
|
665
|
+
input.push({ name: "command", ...vf2(a.command) });
|
|
666
|
+
if (presentValueArg("s.cloud.job", "args", a.args)) input.push({ name: "args", ...vf2(a.args) });
|
|
667
|
+
if (presentValueArg("s.cloud.job", "secret", a.secret)) input.push({ name: "secret", ...vf2(a.secret) });
|
|
668
|
+
if (a.template !== void 0 && a.template !== null) {
|
|
669
|
+
input.push({ name: "template", ...vf2(specialEnumValue("mvp:cloud_job", "s.cloud.job", "template", "template", a.template)) });
|
|
670
|
+
}
|
|
671
|
+
if (presentValueArg("s.cloud.job", "await", a.await)) input.push({ name: "await", ...vf2(a.await) });
|
|
672
|
+
return annotate({ name: "mvp:cloud_job", context: {}, as: a.as ?? "", input }, a);
|
|
673
|
+
}
|
|
674
|
+
var CLOUD_JOB_AWAIT_KEYS = /* @__PURE__ */ Object.keys({ as: 1, ids: 1, timeout: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
675
|
+
function cloudJobAwait(a) {
|
|
676
|
+
a = argsOrEmpty(a);
|
|
677
|
+
assertKnownKeys(`Statement "s.cloud.job.await"`, a, CLOUD_JOB_AWAIT_KEYS);
|
|
678
|
+
assertValueArg("s.cloud.job.await", "ids", a.ids);
|
|
679
|
+
assertValueArg("s.cloud.job.await", "timeout", a.timeout);
|
|
680
|
+
return annotate({
|
|
681
|
+
name: "mvp:cloud_job_await",
|
|
682
|
+
context: {},
|
|
683
|
+
as: a.as ?? "",
|
|
684
|
+
input: [
|
|
685
|
+
{ name: "ids", ...vf2(a.ids) },
|
|
686
|
+
{ name: "timeout", ...vf2(a.timeout) }
|
|
687
|
+
]
|
|
688
|
+
}, a);
|
|
689
|
+
}
|
|
690
|
+
var CLOUD_JOB_STATUS_KEYS = /* @__PURE__ */ Object.keys({ as: 1, id: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
691
|
+
function cloudJobStatus(a) {
|
|
692
|
+
a = argsOrEmpty(a);
|
|
693
|
+
assertKnownKeys(`Statement "s.cloud.job.status"`, a, CLOUD_JOB_STATUS_KEYS);
|
|
694
|
+
assertValueArg("s.cloud.job.status", "id", a.id);
|
|
695
|
+
return annotate({
|
|
696
|
+
name: "mvp:cloud_job_status",
|
|
697
|
+
context: {},
|
|
698
|
+
as: a.as ?? "",
|
|
699
|
+
input: [{ name: "id", ...vf2(a.id) }]
|
|
700
|
+
}, a);
|
|
701
|
+
}
|
|
702
|
+
registerStatement("mvp:call_agent", aiAgentRun);
|
|
703
|
+
registerStatement("mvp:cloud_job", cloudJob);
|
|
704
|
+
registerStatement("mvp:cloud_job_await", cloudJobAwait);
|
|
705
|
+
registerStatement("mvp:cloud_job_status", cloudJobStatus);
|
|
706
|
+
|
|
707
|
+
// src/statements/special/misc.ts
|
|
708
|
+
function vf3(v) {
|
|
709
|
+
return { value: v.value, tag: v.tag, filters: v.filters };
|
|
710
|
+
}
|
|
711
|
+
function isTransformRecord(t) {
|
|
712
|
+
return !isTaggedValue(t) && !Array.isArray(t);
|
|
713
|
+
}
|
|
714
|
+
function assertArrayMapTransform(t) {
|
|
715
|
+
const where = 'Statement "s.array.map": argument "transform"';
|
|
716
|
+
if (isTaggedValue(t)) return;
|
|
717
|
+
if (Array.isArray(t)) {
|
|
718
|
+
t.forEach((pair, i) => {
|
|
719
|
+
const ok = typeof pair === "object" && pair !== null && isTaggedValue(pair.key) && isTaggedValue(pair.value);
|
|
720
|
+
if (!ok) {
|
|
721
|
+
throw new Error(`${where.slice(0, -1)}[${i}]" must be a { key, value } pair of tagged values \u2014 got ${describeEntry(pair)}.`);
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
if (typeof t !== "object" || t === null) {
|
|
727
|
+
throw new Error(
|
|
728
|
+
`${where} must be a tagged value, a { key: value } record, or a list of { key, value } pairs \u2014 got ${describeEntry(t)}.`
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
for (const [key, value] of Object.entries(t)) {
|
|
732
|
+
if (!isTaggedValue(value)) {
|
|
733
|
+
throw new Error(`${where.slice(0, -1)}.${key}" must be a tagged value (\`c.*\`, \`ref()\`, \u2026) \u2014 got ${describeEntry(value)}.`);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
var ARRAY_MAP_KEYS = /* @__PURE__ */ Object.keys({ source: 1, as: 1, transform: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
738
|
+
function arrayMap(a) {
|
|
739
|
+
a = argsOrEmpty(a);
|
|
740
|
+
assertKnownKeys(`Statement "s.array.map"`, a, ARRAY_MAP_KEYS);
|
|
741
|
+
assertValueArg("s.array.map", "source", a.source);
|
|
742
|
+
const context = { output_type: "value", collection: vf3(a.source) };
|
|
743
|
+
if (a.transform !== void 0 && a.transform !== null) {
|
|
744
|
+
assertArrayMapTransform(a.transform);
|
|
745
|
+
const pairs = isTransformRecord(a.transform) ? Object.entries(a.transform).map(([key, value]) => ({ key: c.text(key), value })) : Array.isArray(a.transform) ? a.transform : void 0;
|
|
746
|
+
if (pairs) {
|
|
747
|
+
if (pairs.length === 0) {
|
|
748
|
+
throw new Error(
|
|
749
|
+
"Statement \"s.array.map\": an object `transform` needs at least one key \u2014 the engine's object branch iterates `transform_object` and an empty one maps every item to `{}`. Pass a record of values (`{ id: ref('$this') }`), a list of `{ key, value }` pairs, or a single value for the scalar form."
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
context.output_type = "object";
|
|
753
|
+
context.transform_object = pairs.map(({ key, value }) => ({
|
|
754
|
+
attribute_key: vf3(key),
|
|
755
|
+
attribute_value: vf3(value)
|
|
756
|
+
}));
|
|
757
|
+
} else {
|
|
758
|
+
context.transform_value = vf3(a.transform);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return annotate({ name: "mvp:array_map", context, as: a.as ?? "", input: [] }, a);
|
|
762
|
+
}
|
|
763
|
+
var ARRAY_UNION_KEYS = /* @__PURE__ */ Object.keys({ source: 1, with: 1, as: 1, transform: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
764
|
+
function arrayUnion(a) {
|
|
765
|
+
a = argsOrEmpty(a);
|
|
766
|
+
assertKnownKeys(`Statement "s.array.union"`, a, ARRAY_UNION_KEYS);
|
|
767
|
+
assertValueArg("s.array.union", "source", a.source);
|
|
768
|
+
assertValueArg("s.array.union", "with", a.with);
|
|
769
|
+
const context = { left: vf3(a.source), right: vf3(a.with) };
|
|
770
|
+
if (presentValueArg("s.array.union", "transform", a.transform)) context.transform_value = vf3(a.transform);
|
|
771
|
+
return annotate({ name: "mvp:array_union", context, as: a.as ?? "", input: [] }, a);
|
|
772
|
+
}
|
|
773
|
+
function comment(text = "", a) {
|
|
774
|
+
if (typeof text !== "string") {
|
|
775
|
+
throw new Error(`Statement "s.comment": argument "text" must be the comment as a string \u2014 got ${describeEntry(text)}.`);
|
|
776
|
+
}
|
|
777
|
+
assertKnownKeys(`Statement "s.comment": options`, a, ANNOTATION_KEYS);
|
|
778
|
+
return annotate({ name: "mvp:comment", description: text, context: {}, input: [] }, a);
|
|
779
|
+
}
|
|
780
|
+
var GET_RAW_INPUT_KEYS = /* @__PURE__ */ Object.keys({ as: 1, encoding: 1, excludeMiddleware: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
781
|
+
function getRawInput(a = {}) {
|
|
782
|
+
a = argsOrEmpty(a);
|
|
783
|
+
assertKnownKeys(`Statement "s.util.get_raw_input"`, a, GET_RAW_INPUT_KEYS);
|
|
784
|
+
return annotate({
|
|
785
|
+
name: "mvp:get_input",
|
|
786
|
+
context: {},
|
|
787
|
+
as: a.as ?? "",
|
|
788
|
+
// Both entries are `?=` optionals in the engine schema (`encoding?=json`,
|
|
789
|
+
// `exclude_middleware_modification?=false`) and Xano's editor writes neither
|
|
790
|
+
// for a plain body capture — so they are emitted only when authored.
|
|
791
|
+
input: [
|
|
792
|
+
...a.encoding !== void 0 && a.encoding !== null ? [{ name: "encoding", ...vf3(specialEnumValue(
|
|
793
|
+
"mvp:get_input",
|
|
794
|
+
"s.util.get_raw_input",
|
|
795
|
+
"encoding",
|
|
796
|
+
"encoding",
|
|
797
|
+
a.encoding,
|
|
798
|
+
'`"none"` binds the body\'s bytes as one string \u2014 what a signature check over the raw body needs.'
|
|
799
|
+
)) }] : [],
|
|
800
|
+
...presentValueArg("s.util.get_raw_input", "excludeMiddleware", a.excludeMiddleware) ? [{ name: "exclude_middleware_modification", ...vf3(a.excludeMiddleware) }] : []
|
|
801
|
+
]
|
|
802
|
+
}, a);
|
|
803
|
+
}
|
|
804
|
+
function postProcess(body, a) {
|
|
805
|
+
assertStatements("s.util.post_process", "body", body);
|
|
806
|
+
assertKnownKeys(`Statement "s.util.post_process": options`, a, ANNOTATION_KEYS);
|
|
807
|
+
return annotate(
|
|
808
|
+
{ name: "mvp:post_process", context: { run: body.map(encodeStatement) }, input: [] },
|
|
809
|
+
a
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
var REALTIME_EVENT_KEYS = /* @__PURE__ */ Object.keys({ channel: 1, data: 1, authTable: 1, authId: 1, disabled: 1, description: 1, mock: 1 });
|
|
813
|
+
function realtimeEvent(a) {
|
|
814
|
+
a = argsOrEmpty(a);
|
|
815
|
+
assertKnownKeys(`Statement "s.api.realtime_event"`, a, REALTIME_EVENT_KEYS);
|
|
816
|
+
assertValueArg("s.api.realtime_event", "channel", a.channel);
|
|
817
|
+
assertValueArg("s.api.realtime_event", "data", a.data);
|
|
818
|
+
assertValueArg("s.api.realtime_event", "authId", a.authId);
|
|
819
|
+
const auth = { row_id: vf3(a.authId) };
|
|
820
|
+
if (a.authTable !== void 0 && a.authTable !== null)
|
|
821
|
+
auth.dbo_id = resolveRef("dbo", a.authTable, `Statement "s.api.realtime_event": argument "authTable"`);
|
|
822
|
+
return annotate({
|
|
823
|
+
name: "mvp:realtime_event",
|
|
824
|
+
context: { channel: vf3(a.channel), data: vf3(a.data), auth },
|
|
825
|
+
input: []
|
|
826
|
+
}, a);
|
|
827
|
+
}
|
|
828
|
+
var REALTIME_PUBLISH_KEYS = /* @__PURE__ */ Object.keys({ server: 1, channel: 1, data: 1, message: 1, authTable: 1, authId: 1, disabled: 1, description: 1, mock: 1 });
|
|
829
|
+
function realtimePublish(a) {
|
|
830
|
+
a = argsOrEmpty(a);
|
|
831
|
+
assertKnownKeys(`Statement "s.realtime.publish"`, a, REALTIME_PUBLISH_KEYS);
|
|
832
|
+
const server = publishServerValue(a.server);
|
|
833
|
+
const channel = typeof a.channel === "string" ? c.text(a.channel) : a.channel;
|
|
834
|
+
if (!channel || channel.value === "") {
|
|
835
|
+
throw new Error(
|
|
836
|
+
'Statement "s.realtime.publish": required argument "channel" is missing \u2014 the filled-in channel path to publish onto (use `realtimeChannel().getChannel({\u2026})`).'
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
assertValueArg("s.realtime.publish", "channel", channel);
|
|
840
|
+
assertFilledChannel(channel);
|
|
841
|
+
assertValueArg("s.realtime.publish", "data", a.data);
|
|
842
|
+
const context = {
|
|
843
|
+
realtime_server: server,
|
|
844
|
+
channel: vf3(channel),
|
|
845
|
+
data: vf3(a.data)
|
|
846
|
+
};
|
|
847
|
+
if (a.message !== void 0 && a.message !== null) {
|
|
848
|
+
assertValueArg("s.realtime.publish", "message", a.message);
|
|
849
|
+
context.message = vf3(a.message);
|
|
850
|
+
}
|
|
851
|
+
const auth = {};
|
|
852
|
+
if (a.authTable !== void 0 && a.authTable !== null)
|
|
853
|
+
auth.dbo_id = resolveRef("dbo", a.authTable, `Statement "s.realtime.publish": argument "authTable"`);
|
|
854
|
+
if (a.authId !== void 0 && a.authId !== null) {
|
|
855
|
+
assertValueArg("s.realtime.publish", "authId", a.authId);
|
|
856
|
+
auth.row_id = vf3(a.authId);
|
|
857
|
+
}
|
|
858
|
+
if (Object.keys(auth).length > 0) context.auth = auth;
|
|
859
|
+
return annotate({ name: "mvp:realtime_publish", context, input: [] }, a);
|
|
860
|
+
}
|
|
861
|
+
function assertFilledChannel(channel) {
|
|
862
|
+
if (!channel.tag.startsWith("const")) return;
|
|
863
|
+
if (typeof channel.value !== "string" || !/[{}]/.test(channel.value)) return;
|
|
864
|
+
throw new Error(
|
|
865
|
+
`Statement "s.realtime.publish": \`channel\` is "${channel.value}", which is still a TEMPLATE \u2014 its {param} was never filled in, so this publishes onto a path no client can join, and the engine swallows the miss silently. Fill it in with \`channel.getChannel({ \u2026 })\` (e.g. \`c.text(rooms.getChannel({ room_id: 42 }))\`), or build the path at runtime from a \`ref\`/\`inp\`.`
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
function publishServerValue(server) {
|
|
869
|
+
if (typeof server === "string") {
|
|
870
|
+
if (server === "") throw new Error(`Statement "s.realtime.publish": required argument "server" is missing \u2014 the owning realtime server's name.`);
|
|
871
|
+
return { value: server, tag: "const", filters: [] };
|
|
872
|
+
}
|
|
873
|
+
if (server && typeof server === "object" && "tag" in server) return vf3(server);
|
|
874
|
+
const name = server && typeof server === "object" ? server.name : void 0;
|
|
875
|
+
if (!name) {
|
|
876
|
+
throw new Error(
|
|
877
|
+
'Statement "s.realtime.publish": required argument "server" is missing \u2014 pass the `realtimeServer()` handle, its name, or a value naming it.'
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
return { value: name, tag: "const", filters: [] };
|
|
881
|
+
}
|
|
882
|
+
var CREATE_AUTH_TOKEN_KEYS = /* @__PURE__ */ Object.keys({ table: 1, id: 1, extras: 1, expiration: 1, as: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
883
|
+
function createAuthToken(a) {
|
|
884
|
+
a = argsOrEmpty(a);
|
|
885
|
+
assertKnownKeys(`Statement "s.security.create_auth_token"`, a, CREATE_AUTH_TOKEN_KEYS);
|
|
886
|
+
assertValueArg("s.security.create_auth_token", "id", a.id);
|
|
887
|
+
assertArg("s.security.create_auth_token", "table", a.table, { nullable: true });
|
|
888
|
+
const extras = typeof a.extras === "object" && a.extras !== null && !Array.isArray(a.extras) && !isTaggedValue(a.extras) ? obj(a.extras) : a.extras;
|
|
889
|
+
return annotate({
|
|
890
|
+
name: "mvp:create_auth",
|
|
891
|
+
context: {},
|
|
892
|
+
as: a.as ?? "",
|
|
893
|
+
// Entry order and optionality come straight from the engine's own input
|
|
894
|
+
// schema — `id`, `dbtable`, `extras?={}`, `expiration?=86400`. Xano's editor
|
|
895
|
+
// writes this shape, so this is what a pulled workspace has.
|
|
896
|
+
input: [
|
|
897
|
+
{ name: "id", ...vf3(a.id) },
|
|
898
|
+
{
|
|
899
|
+
name: "dbtable",
|
|
900
|
+
value: a.table === null ? "" : resolveRef("dbo", a.table, `Statement "s.security.create_auth_token": argument "table"`),
|
|
901
|
+
tag: "const",
|
|
902
|
+
filters: []
|
|
903
|
+
},
|
|
904
|
+
...presentValueArg("s.security.create_auth_token", "extras", extras) ? [{ name: "extras", ...vf3(extras) }] : [],
|
|
905
|
+
...presentValueArg("s.security.create_auth_token", "expiration", a.expiration) ? [{ name: "expiration", ...vf3(a.expiration) }] : []
|
|
906
|
+
]
|
|
907
|
+
}, a);
|
|
908
|
+
}
|
|
909
|
+
var EXPECT_TO_THROW_KEYS = /* @__PURE__ */ Object.keys({ body: 1, exception: 1, disabled: 1, description: 1, mock: 1 });
|
|
910
|
+
function expectToThrow(a) {
|
|
911
|
+
a = argsOrEmpty(a);
|
|
912
|
+
assertKnownKeys(`Statement "s.expect.to_throw"`, a, EXPECT_TO_THROW_KEYS);
|
|
913
|
+
assertStatements("s.expect.to_throw", "body", a.body);
|
|
914
|
+
const context = { run: a.body.map(encodeStatement) };
|
|
915
|
+
if (presentValueArg("s.expect.to_throw", "exception", a.exception)) context.value1 = vf3(a.exception);
|
|
916
|
+
return annotate({ name: "mvp:test_expect_to_throw", context, input: [] }, a);
|
|
917
|
+
}
|
|
918
|
+
var EXPECT_TO_MATCH_KEYS = /* @__PURE__ */ Object.keys({ expr: 1, value: 1, disabled: 1, description: 1, mock: 1 });
|
|
919
|
+
function expectToMatch(a = {}) {
|
|
920
|
+
a = argsOrEmpty(a);
|
|
921
|
+
assertKnownKeys(`Statement "s.expect.to_match"`, a, EXPECT_TO_MATCH_KEYS);
|
|
922
|
+
if (a.value !== void 0 && a.value !== null) assertValueArg("s.expect.to_match", "value", a.value);
|
|
923
|
+
if (a.expr !== void 0 && a.expr !== null) assertValueArg("s.expect.to_match", "expr", a.expr);
|
|
924
|
+
const reversed = reversedOperandRefusal(a.value, a.expr);
|
|
925
|
+
if (reversed) {
|
|
926
|
+
throw new Error(
|
|
927
|
+
`Statement "s.expect.to_match": ${reversed} \u2014 \`expr\` is the value under test and \`value\` is the pattern.`
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
if (a.value) {
|
|
931
|
+
const refusal = barePatternRefusal(a.value);
|
|
932
|
+
if (refusal) throw new Error(`Statement "s.expect.to_match": ${refusal}.`);
|
|
933
|
+
}
|
|
934
|
+
return generated.expect.to_match(a);
|
|
935
|
+
}
|
|
936
|
+
registerStatement("mvp:array_map", arrayMap);
|
|
937
|
+
registerStatement("mvp:array_union", arrayUnion);
|
|
938
|
+
registerStatement("mvp:comment", comment);
|
|
939
|
+
registerStatement("mvp:get_input", getRawInput);
|
|
940
|
+
registerStatement("mvp:post_process", postProcess);
|
|
941
|
+
registerStatement("mvp:realtime_event", realtimeEvent);
|
|
942
|
+
registerStatement("mvp:realtime_publish", realtimePublish);
|
|
943
|
+
registerStatement("mvp:create_auth", createAuthToken);
|
|
944
|
+
registerStatement("mvp:test_expect_to_throw", expectToThrow);
|
|
945
|
+
|
|
946
|
+
// src/statements/special/ip-lookup.ts
|
|
947
|
+
var IP_LOOKUP_KEYS = /* @__PURE__ */ Object.keys({ value: 1, as: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
948
|
+
function ipLookup(a) {
|
|
949
|
+
a = argsOrEmpty(a);
|
|
950
|
+
assertKnownKeys(`Statement "s.util.ip_lookup"`, a, IP_LOOKUP_KEYS);
|
|
951
|
+
return generated.util.ip_lookup({
|
|
952
|
+
as: a.as,
|
|
953
|
+
value: a.value,
|
|
954
|
+
disabled: a.disabled,
|
|
955
|
+
description: a.description,
|
|
956
|
+
asFilters: a.asFilters,
|
|
957
|
+
// Read off the authored object at runtime; the generated arg type omits it.
|
|
958
|
+
...{ mock: a.mock }
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// src/statements/generated/catalog.ts
|
|
963
|
+
for (const spec2 of GENERATED_SPECS) {
|
|
964
|
+
if (!isRegisteredStatement(spec2.name)) registerSpec(spec2);
|
|
965
|
+
}
|
|
966
|
+
var specByName = new Map(GENERATED_SPECS.map((s2) => [s2.name, s2]));
|
|
967
|
+
function spec(name) {
|
|
968
|
+
const s2 = specByName.get(name);
|
|
969
|
+
if (!s2) throw new Error(`Generated catalog is missing expected statement "${name}".`);
|
|
970
|
+
return s2;
|
|
971
|
+
}
|
|
972
|
+
function mutation(name) {
|
|
973
|
+
const s2 = spec(name);
|
|
974
|
+
return (varName, value) => encodeFromSpec(s2, { name: varName, value });
|
|
975
|
+
}
|
|
976
|
+
function objectOp(name) {
|
|
977
|
+
const s2 = spec(name);
|
|
978
|
+
return (as, value) => encodeFromSpec(s2, { as, value });
|
|
979
|
+
}
|
|
980
|
+
var mathAdd = mutation("mvp:math_add");
|
|
981
|
+
var mathSub = mutation("mvp:math_sub");
|
|
982
|
+
var mathMul = mutation("mvp:math_mul");
|
|
983
|
+
var mathDiv = mutation("mvp:math_div");
|
|
984
|
+
var bitwiseAnd = mutation("mvp:bitwise_and");
|
|
985
|
+
var bitwiseOr = mutation("mvp:bitwise_or");
|
|
986
|
+
var bitwiseXor = mutation("mvp:bitwise_xor");
|
|
987
|
+
var textAppend = mutation("mvp:text_append");
|
|
988
|
+
var textPrepend = mutation("mvp:text_prepend");
|
|
989
|
+
var objectKeys = objectOp("mvp:object_keys");
|
|
990
|
+
var objectValues = objectOp("mvp:object_values");
|
|
991
|
+
var objectEntries = objectOp("mvp:object_entries");
|
|
992
|
+
var GENERATED_STATEMENT_NAMES = GENERATED_SPECS.map((s2) => s2.name);
|
|
993
|
+
|
|
994
|
+
// src/statements/special/api-request.ts
|
|
995
|
+
var API_REQUEST_KEYS = /* @__PURE__ */ Object.keys({ as: 1, url: 1, output: 1, method: 1, params: 1, headers: 1, timeout: 1, follow_location: 1, verify_host: 1, verify_peer: 1, ca_certificate: 1, certificate: 1, certificate_pass: 1, private_key: 1, private_key_pass: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
996
|
+
function apiRequest(a) {
|
|
997
|
+
a = argsOrEmpty(a);
|
|
998
|
+
assertKnownKeys(`Statement "s.api.request"`, a, API_REQUEST_KEYS);
|
|
999
|
+
assertSslConsistency('Statement "s.api.request"', a);
|
|
1000
|
+
return generated.api.request({
|
|
1001
|
+
as: a.as,
|
|
1002
|
+
url: coerceText(a.url, `Statement "s.api.request": argument "url"`),
|
|
1003
|
+
...coerceHttpFields(a),
|
|
1004
|
+
disabled: a.disabled,
|
|
1005
|
+
description: a.description,
|
|
1006
|
+
output: a.output,
|
|
1007
|
+
asFilters: a.asFilters,
|
|
1008
|
+
// Read off the authored object at runtime; the generated arg type omits it.
|
|
1009
|
+
...{ mock: a.mock }
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
var STREAM_FROM_REQUEST_KEYS = /* @__PURE__ */ Object.keys({ as: 1, url: 1, method: 1, params: 1, headers: 1, timeout: 1, follow_location: 1, verify_host: 1, verify_peer: 1, ca_certificate: 1, certificate: 1, certificate_pass: 1, private_key: 1, private_key_pass: 1, disabled: 1, description: 1, mock: 1 });
|
|
1013
|
+
function streamFromRequest(a) {
|
|
1014
|
+
a = argsOrEmpty(a);
|
|
1015
|
+
assertKnownKeys(`Statement "s.stream.from_request"`, a, STREAM_FROM_REQUEST_KEYS);
|
|
1016
|
+
assertSslConsistency('Statement "s.stream.from_request"', a);
|
|
1017
|
+
return annotate(generated.stream.from_request({
|
|
1018
|
+
as: a.as,
|
|
1019
|
+
url: coerceText(a.url, `Statement "s.stream.from_request": argument "url"`),
|
|
1020
|
+
...coerceHttpFields(a, "s.stream.from_request")
|
|
1021
|
+
}), a);
|
|
1022
|
+
}
|
|
1023
|
+
var WEBFLOW_REQUEST_KEYS = [.../* @__PURE__ */ Object.keys({ as: 1, path: 1, method: 1, params: 1, timeout: 1, follow_location: 1, verify_host: 1, verify_peer: 1, ca_certificate: 1, certificate: 1, certificate_pass: 1, private_key: 1, private_key_pass: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 }), "headers"];
|
|
1024
|
+
function webflowRequest(a) {
|
|
1025
|
+
a = argsOrEmpty(a);
|
|
1026
|
+
assertKnownKeys(`Statement "s.webflow.request"`, a, WEBFLOW_REQUEST_KEYS);
|
|
1027
|
+
assertSslConsistency('Statement "s.webflow.request"', a);
|
|
1028
|
+
return generated.webflow.request({
|
|
1029
|
+
as: a.as,
|
|
1030
|
+
path: coerceText(a.path, `Statement "s.webflow.request": argument "path"`),
|
|
1031
|
+
...coerceHttpFields(a, "s.webflow.request"),
|
|
1032
|
+
disabled: a.disabled,
|
|
1033
|
+
description: a.description,
|
|
1034
|
+
asFilters: a.asFilters,
|
|
1035
|
+
// Read off the authored object at runtime; the generated arg type omits it.
|
|
1036
|
+
...{ mock: a.mock }
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// src/statements/special/microservice.ts
|
|
1041
|
+
function resolveMicroserviceHost(host, port) {
|
|
1042
|
+
if (isValue(host)) {
|
|
1043
|
+
if (port !== void 0) {
|
|
1044
|
+
const v = host;
|
|
1045
|
+
const literal = typeof v.tag === "string" && v.tag.startsWith("const") && typeof v.value === "string" && !v.filters?.length;
|
|
1046
|
+
throw new Error(
|
|
1047
|
+
literal ? `Statement "s.microservice.request": \`port\` is not joined onto a \`c.text(...)\` \`host\`. Pass the name as a plain string (\`host: ${JSON.stringify(v.value)}, port: ${String(port)}\`), or spell the port in the text (\`c.text("${String(v.value)}:${String(port)}")\`).` : 'Statement "s.microservice.request": `port` cannot be joined onto a dynamic `host` at build time. Build the joined `"name:port"` string in the value itself instead.'
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
return host;
|
|
1051
|
+
}
|
|
1052
|
+
if (typeof host === "string") {
|
|
1053
|
+
if (port !== void 0 && host.includes(":")) {
|
|
1054
|
+
throw new Error(
|
|
1055
|
+
`Statement "s.microservice.request": \`host\` already carries a port ("${host}"), so \`port: ${String(port)}\` is ambiguous. Pass the port once \u2014 either joined into \`host\` or as \`port\`.`
|
|
1056
|
+
);
|
|
1057
|
+
}
|
|
1058
|
+
return port === void 0 ? host : `${host}:${port}`;
|
|
1059
|
+
}
|
|
1060
|
+
return defHost(host, port);
|
|
1061
|
+
}
|
|
1062
|
+
function defHost(host, port) {
|
|
1063
|
+
const declared = declaredServicePorts(host);
|
|
1064
|
+
if (port !== void 0) {
|
|
1065
|
+
if (declared.length > 0 && !declared.includes(String(port))) {
|
|
1066
|
+
throw new Error(
|
|
1067
|
+
`Statement "s.microservice.request": microservice "${host.name}" does not expose port ${String(port)}. It declares: ${declared.join(", ")}.`
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
return `${host.name}:${port}`;
|
|
1071
|
+
}
|
|
1072
|
+
if (declared.length === 1) return `${host.name}:${declared[0]}`;
|
|
1073
|
+
if (declared.length === 0) return host.name;
|
|
1074
|
+
throw new Error(
|
|
1075
|
+
`Statement "s.microservice.request": microservice "${host.name}" declares ${declared.length} ports (${declared.join(", ")}), so \`port\` is required to pick one.`
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
var MICROSERVICE_DEFAULTS = {
|
|
1079
|
+
method: "GET",
|
|
1080
|
+
params: {},
|
|
1081
|
+
headers: [],
|
|
1082
|
+
timeout: 10,
|
|
1083
|
+
follow_location: true
|
|
1084
|
+
};
|
|
1085
|
+
var MICROSERVICE_KEYS = /* @__PURE__ */ Object.keys({ as: 1, host: 1, port: 1, path: 1, method: 1, params: 1, headers: 1, timeout: 1, follow_location: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
1086
|
+
function microserviceRequest(a) {
|
|
1087
|
+
a = argsOrEmpty(a);
|
|
1088
|
+
assertKnownKeys(`Statement "s.microservice.request"`, a, MICROSERVICE_KEYS);
|
|
1089
|
+
assertArg("s.microservice.request", "host", a.host);
|
|
1090
|
+
assertArg("s.microservice.request", "path", a.path);
|
|
1091
|
+
const statement = generated.microservice.request({
|
|
1092
|
+
as: a.as,
|
|
1093
|
+
host: coerceText(resolveMicroserviceHost(a.host, a.port), `Statement "s.microservice.request": argument "host"`),
|
|
1094
|
+
path: coerceText(a.path, `Statement "s.microservice.request": argument "path"`),
|
|
1095
|
+
// `??` (not `||`) so an explicit `false`/`0`/`""` is honored, not defaulted.
|
|
1096
|
+
method: coerceText(a.method ?? MICROSERVICE_DEFAULTS.method, `Statement "s.microservice.request": argument "method"`),
|
|
1097
|
+
params: coerceObj(a.params ?? MICROSERVICE_DEFAULTS.params, `Statement "s.microservice.request": argument "params"`),
|
|
1098
|
+
headers: coerceHeaders(a.headers ?? MICROSERVICE_DEFAULTS.headers, `Statement "s.microservice.request": argument "headers"`),
|
|
1099
|
+
timeout: coerceInt(a.timeout ?? MICROSERVICE_DEFAULTS.timeout, `Statement "s.microservice.request": argument "timeout"`),
|
|
1100
|
+
follow_location: coerceBool(a.follow_location ?? MICROSERVICE_DEFAULTS.follow_location, `Statement "s.microservice.request": argument "follow_location"`),
|
|
1101
|
+
disabled: a.disabled,
|
|
1102
|
+
description: a.description,
|
|
1103
|
+
asFilters: a.asFilters,
|
|
1104
|
+
// Read off the authored object at runtime; the generated arg type omits it.
|
|
1105
|
+
...{ mock: a.mock }
|
|
1106
|
+
});
|
|
1107
|
+
const host = a.host;
|
|
1108
|
+
if (host !== null && typeof host === "object" && !isValue(host)) noteMicroserviceHandleHost(statement, host.name);
|
|
1109
|
+
return statement;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// src/statements/special/closed-sets.ts
|
|
1113
|
+
var STORAGE_ACCESS = ["public", "private"];
|
|
1114
|
+
var HEADER_DUPLICATES = ["replace", "append"];
|
|
1115
|
+
function assertClosed(factory, field2, values, got) {
|
|
1116
|
+
if (got === void 0 || typeof got === "string" && values.includes(got)) return;
|
|
1117
|
+
throw new Error(
|
|
1118
|
+
`Statement "${factory}": argument "${field2}" accepts only ${values.map((v) => JSON.stringify(v)).join(" | ")} \u2014 got ${typeof got === "string" ? JSON.stringify(got) : String(got)}.`
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
function field(a, key) {
|
|
1122
|
+
return a !== null && typeof a === "object" ? a[key] : void 0;
|
|
1123
|
+
}
|
|
1124
|
+
function createAttachment(a) {
|
|
1125
|
+
assertClosed("s.storage.create_attachment", "access", STORAGE_ACCESS, field(a, "access"));
|
|
1126
|
+
return generated.storage.create_attachment(a);
|
|
1127
|
+
}
|
|
1128
|
+
function createAudio(a) {
|
|
1129
|
+
assertClosed("s.storage.create_audio", "access", STORAGE_ACCESS, field(a, "access"));
|
|
1130
|
+
return generated.storage.create_audio(a);
|
|
1131
|
+
}
|
|
1132
|
+
function createImage(a) {
|
|
1133
|
+
assertClosed("s.storage.create_image", "access", STORAGE_ACCESS, field(a, "access"));
|
|
1134
|
+
return generated.storage.create_image(a);
|
|
1135
|
+
}
|
|
1136
|
+
function createVideo(a) {
|
|
1137
|
+
assertClosed("s.storage.create_video", "access", STORAGE_ACCESS, field(a, "access"));
|
|
1138
|
+
return generated.storage.create_video(a);
|
|
1139
|
+
}
|
|
1140
|
+
function setHeader(a) {
|
|
1141
|
+
assertClosed("s.util.set_header", "duplicates", HEADER_DUPLICATES, field(a, "duplicates"));
|
|
1142
|
+
return generated.util.set_header(a);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// src/statements/special/lambda-args.ts
|
|
1146
|
+
function lambda(a) {
|
|
1147
|
+
if (a !== null && typeof a === "object" && a.capture !== void 0) {
|
|
1148
|
+
throw new Error(
|
|
1149
|
+
'Statement "s.lambda": `capture` is not a field of s.lambda \u2014 it is an option of lam.fn: `code: lam.fn(fn, { capture: { \u2026 } })`.'
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
return generated.lambda(a);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
// src/statements/special/mcp.ts
|
|
1156
|
+
function vf4(v) {
|
|
1157
|
+
return { value: v.value, tag: v.tag, filters: v.filters };
|
|
1158
|
+
}
|
|
1159
|
+
var FORM_TYPES = ["text", "email", "date", "int", "decimal", "bool", "enum"];
|
|
1160
|
+
function assertFormField(field2) {
|
|
1161
|
+
const at = `Statement "s.mcp.elicit": \`input.${field2.name}\``;
|
|
1162
|
+
const list = field2.style?.type === "list";
|
|
1163
|
+
if (field2.type === "password" || field2.sensitive === true) {
|
|
1164
|
+
throw new Error(`${at}: a form must not collect secrets (the MCP spec forbids it), so a password or sensitive field is refused.`);
|
|
1165
|
+
}
|
|
1166
|
+
if (Array.isArray(field2.children) && field2.children.length > 0) {
|
|
1167
|
+
throw new Error(`${at}: nested objects are not supported \u2014 an MCP form is a flat set of fields.`);
|
|
1168
|
+
}
|
|
1169
|
+
if (!FORM_TYPES.includes(field2.type)) {
|
|
1170
|
+
throw new Error(`${at}: "${field2.type}" cannot be asked in an MCP form. Use one of ${FORM_TYPES.join(", ")}.`);
|
|
1171
|
+
}
|
|
1172
|
+
if (list && field2.type !== "enum") {
|
|
1173
|
+
throw new Error(`${at}: only an enum may be a list (a multi-select) in an MCP form.`);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
var MCP_ELICIT_KEYS = /* @__PURE__ */ Object.keys({ key: 1, message: 1, input: 1, as: 1, asFilters: 1, disabled: 1, description: 1, mock: 1 });
|
|
1177
|
+
function mcpElicit(a) {
|
|
1178
|
+
a = argsOrEmpty(a);
|
|
1179
|
+
assertKnownKeys(`Statement "s.mcp.elicit"`, a, MCP_ELICIT_KEYS);
|
|
1180
|
+
const key = typeof a.key === "string" ? c.text(a.key) : a.key;
|
|
1181
|
+
const message = typeof a.message === "string" ? c.text(a.message) : a.message;
|
|
1182
|
+
assertValueArg("s.mcp.elicit", "key", key);
|
|
1183
|
+
if (key.tag === "const" && key.value === "") {
|
|
1184
|
+
throw new Error(`Statement "s.mcp.elicit": \`key\` is empty. Give each elicit a short stable name, unique in the stack.`);
|
|
1185
|
+
}
|
|
1186
|
+
assertValueArg("s.mcp.elicit", "message", message);
|
|
1187
|
+
const fields = a.input ?? {};
|
|
1188
|
+
if (typeof fields !== "object" || fields === null || Array.isArray(fields)) {
|
|
1189
|
+
throw new Error(
|
|
1190
|
+
`Statement "s.mcp.elicit": argument "input" must be a { field: input.*() } record \u2014 got ${describeArg(fields)}.`
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
const schema = Object.entries(fields).map(([name, d]) => {
|
|
1194
|
+
if (typeof d !== "object" || d === null || typeof d.type !== "string") {
|
|
1195
|
+
throw new Error(`Statement "s.mcp.elicit": \`input.${name}\` must be an input descriptor (\`input.text()\`, \u2026) \u2014 got ${describeArg(d)}.`);
|
|
1196
|
+
}
|
|
1197
|
+
const { market_item: _marketItem, ...field2 } = encodeInput(name, d);
|
|
1198
|
+
return field2;
|
|
1199
|
+
});
|
|
1200
|
+
for (const field2 of schema) assertFormField(field2);
|
|
1201
|
+
return annotate(
|
|
1202
|
+
{
|
|
1203
|
+
name: "mvp:mcp_elicit",
|
|
1204
|
+
as: a.as ?? "",
|
|
1205
|
+
context: { schema },
|
|
1206
|
+
// Entry order is the engine's own: `key`, then `message`.
|
|
1207
|
+
input: [
|
|
1208
|
+
{ name: "key", ...vf4(key) },
|
|
1209
|
+
{ name: "message", ...vf4(message) }
|
|
1210
|
+
]
|
|
1211
|
+
},
|
|
1212
|
+
a
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
registerStatement("mvp:mcp_elicit", mcpElicit);
|
|
1216
|
+
|
|
1217
|
+
// src/statements/s.ts
|
|
1218
|
+
var externalQuery = (engine) => ({
|
|
1219
|
+
direct_query: (a) => dbExternalQuery({ ...a, engine })
|
|
1220
|
+
});
|
|
1221
|
+
var cloudJobNs = Object.assign(cloudJob, { await: cloudJobAwait, status: cloudJobStatus });
|
|
1222
|
+
var s = {
|
|
1223
|
+
...generated,
|
|
1224
|
+
// Typed overrides of generated factories: `precondition` narrows `error_type`
|
|
1225
|
+
// to the status-bearing enum, and `throw` documents that it returns HTTP 200
|
|
1226
|
+
// (use `precondition` for a status-observable rejection).
|
|
1227
|
+
precondition,
|
|
1228
|
+
throw: throwError,
|
|
1229
|
+
// Typed refusal of `capture`, which belongs to `lam.fn` — the bare TS2353 the
|
|
1230
|
+
// generated factory produced implied dropping the field rather than moving
|
|
1231
|
+
// the body. Same bytes.
|
|
1232
|
+
lambda,
|
|
1233
|
+
// Hand-authored specials (not in the codegen'd catalog).
|
|
1234
|
+
set_var: setVar,
|
|
1235
|
+
update_var: updateVar,
|
|
1236
|
+
conditional,
|
|
1237
|
+
comment,
|
|
1238
|
+
for: forLoop,
|
|
1239
|
+
foreach: foreachLoop,
|
|
1240
|
+
while: whileLoop,
|
|
1241
|
+
group,
|
|
1242
|
+
switch: switchStatement,
|
|
1243
|
+
try_catch: tryCatch,
|
|
1244
|
+
return: returnValue,
|
|
1245
|
+
foreach_break: foreachBreak,
|
|
1246
|
+
foreach_continue: foreachContinue,
|
|
1247
|
+
foreach_remove: foreachRemove,
|
|
1248
|
+
// Call family — invoke another workspace object. `api.call`/`api.realtime_event`
|
|
1249
|
+
// merge into the generated `api` namespace; the rest are new namespaces.
|
|
1250
|
+
// `api.request` (and `stream.from_request`/`webflow.request`/`microservice.request`
|
|
1251
|
+
// below) are typed hand-authored overrides of their generated factories.
|
|
1252
|
+
function: { run: functionRun, call: functionCall },
|
|
1253
|
+
action: { call: actionCall, package: { call: actionPackageCall } },
|
|
1254
|
+
workflow_test: { call: workflowTestCall },
|
|
1255
|
+
api: { ...generated.api, call: apiCall, realtime_event: realtimeEvent, request: apiRequest },
|
|
1256
|
+
// Microservices are a top-level feature: the `microservice()` def and the
|
|
1257
|
+
// statement that calls one live side by side. The override is load-bearing —
|
|
1258
|
+
// `...generated` above already exposes the RAW generated factory here, and it
|
|
1259
|
+
// has none of the defaulting that lets a call name only `host` and `path`.
|
|
1260
|
+
microservice: { ...generated.microservice, request: microserviceRequest },
|
|
1261
|
+
// `realtime.publish` is the CURRENT-layer send statement (`api.realtime_event` is the
|
|
1262
|
+
// superseded one); `get_session` beside it is generated.
|
|
1263
|
+
realtime: { ...generated.realtime, publish: realtimePublish },
|
|
1264
|
+
stream: { ...generated.stream, from_request: streamFromRequest },
|
|
1265
|
+
webflow: { ...generated.webflow, request: webflowRequest },
|
|
1266
|
+
task: { call: taskCall },
|
|
1267
|
+
tool: { call: toolCall },
|
|
1268
|
+
// MCP server stacks (tool / prompt / resource): ask the client's user mid-call,
|
|
1269
|
+
// and report progress (generated). `oauth` is the MCP sign-in hand-off a
|
|
1270
|
+
// login page's stack runs (generated; `export()` checks revoke's one-of target).
|
|
1271
|
+
mcp: { ...generated.mcp, elicit: mcpElicit },
|
|
1272
|
+
trigger: { call: triggerCall },
|
|
1273
|
+
middleware: { call: middlewareCall },
|
|
1274
|
+
addon: { call: addonCall },
|
|
1275
|
+
// Database family — merges into the generated `db` namespace.
|
|
1276
|
+
db: {
|
|
1277
|
+
...generated.db,
|
|
1278
|
+
add: dbAdd,
|
|
1279
|
+
edit: dbEdit,
|
|
1280
|
+
add_or_edit: dbAddOrEdit,
|
|
1281
|
+
get: dbGet,
|
|
1282
|
+
del: dbDel,
|
|
1283
|
+
has: dbHas,
|
|
1284
|
+
patch: dbPatch,
|
|
1285
|
+
truncate: dbTruncate,
|
|
1286
|
+
schema: dbSchema,
|
|
1287
|
+
direct_query: dbDirectQuery,
|
|
1288
|
+
query: dbQuery,
|
|
1289
|
+
increment: dbIncrement,
|
|
1290
|
+
transaction: dbTransaction,
|
|
1291
|
+
bulk: { add: dbBulkAdd, delete: dbBulkDelete, patch: dbBulkPatch, update: dbBulkUpdate },
|
|
1292
|
+
external: {
|
|
1293
|
+
mssql: externalQuery("mssql"),
|
|
1294
|
+
mysql: externalQuery("mysql"),
|
|
1295
|
+
oracle: externalQuery("oracle"),
|
|
1296
|
+
postgres: externalQuery("postgres"),
|
|
1297
|
+
snowflake: externalQuery("snowflake")
|
|
1298
|
+
}
|
|
1299
|
+
},
|
|
1300
|
+
// AI agent + cloud jobs.
|
|
1301
|
+
ai: { ...generated.ai, agent: { run: aiAgentRun } },
|
|
1302
|
+
cloud: { ...generated.cloud, job: cloudJobNs },
|
|
1303
|
+
// Array map/union, expect.to_throw, auth-token, raw-input/post-process merge
|
|
1304
|
+
// into their generated namespaces.
|
|
1305
|
+
array: {
|
|
1306
|
+
...generated.array,
|
|
1307
|
+
map: arrayMap,
|
|
1308
|
+
union: arrayUnion,
|
|
1309
|
+
// Typed overrides of the generated factories: same bytes, plus the element
|
|
1310
|
+
// an accumulator gains, which `InferResponse` reads off the list it traces.
|
|
1311
|
+
push: generated.array.push,
|
|
1312
|
+
unshift: generated.array.unshift,
|
|
1313
|
+
merge: generated.array.merge
|
|
1314
|
+
},
|
|
1315
|
+
expect: { ...generated.expect, to_throw: expectToThrow, to_match: expectToMatch },
|
|
1316
|
+
security: { ...generated.security, create_auth_token: createAuthToken, create_uuid: generated.security.create_uuid },
|
|
1317
|
+
// The generated factory, typed: `object.keys` always binds a list of the
|
|
1318
|
+
// object's key names, so `ref("<as>")` traces to `string[]`, not `unknown`.
|
|
1319
|
+
object: { ...generated.object, keys: generated.object.keys },
|
|
1320
|
+
util: {
|
|
1321
|
+
...generated.util,
|
|
1322
|
+
get_raw_input: getRawInput,
|
|
1323
|
+
get_input: getRawInput,
|
|
1324
|
+
post_process: postProcess,
|
|
1325
|
+
// Typed override of the generated factory: same bytes, plus the nested
|
|
1326
|
+
// result shape a `ref` into the bound var has no other way to learn.
|
|
1327
|
+
ip_lookup: ipLookup,
|
|
1328
|
+
// `duplicates` is a closed set the codegen ships as a bare `string`.
|
|
1329
|
+
set_header: setHeader
|
|
1330
|
+
},
|
|
1331
|
+
// `access` is a closed set the codegen ships as a bare `string`, and it
|
|
1332
|
+
// defaults to `public` — a misspelled `"private"` would serve the file to
|
|
1333
|
+
// the world with no compile-time signal.
|
|
1334
|
+
storage: {
|
|
1335
|
+
...generated.storage,
|
|
1336
|
+
create_attachment: createAttachment,
|
|
1337
|
+
create_audio: createAudio,
|
|
1338
|
+
create_image: createImage,
|
|
1339
|
+
create_video: createVideo
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
registerFactoryPaths(s, "s");
|
|
1343
|
+
function registerAllStatements() {
|
|
1344
|
+
registerFactoryPaths(s, "s");
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
// src/kinds/realtime-channel.ts
|
|
1348
|
+
function realtimeServerRefName(context, server) {
|
|
1349
|
+
const name = typeof server === "string" ? server : server?.name;
|
|
1350
|
+
if (!name) {
|
|
1351
|
+
throw new Error(`${context}: \`server\` is required \u2014 a channel path is unique only within its realtime server.`);
|
|
1352
|
+
}
|
|
1353
|
+
return name;
|
|
1354
|
+
}
|
|
1355
|
+
function resolveRealtimeServerRef(context, server) {
|
|
1356
|
+
if (typeof server !== "string" && server?.guid) return server.guid;
|
|
1357
|
+
return deriveGuid("realtime_server", realtimeServerRefName(context, server));
|
|
1358
|
+
}
|
|
1359
|
+
function encodeRealtimeChannel(def) {
|
|
1360
|
+
if (!def.name) throw new Error("realtimeChannel: `name` is required (the channel path).");
|
|
1361
|
+
const context = `realtimeChannel "${def.name}"`;
|
|
1362
|
+
assertChannelPathParams(def);
|
|
1363
|
+
return {
|
|
1364
|
+
name: def.name,
|
|
1365
|
+
description: def.description ?? "",
|
|
1366
|
+
active: def.active ?? true,
|
|
1367
|
+
server: { id: resolveRealtimeServerRef(context, def.server) },
|
|
1368
|
+
input: Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d)),
|
|
1369
|
+
anonymous_clients: def.anonymousClients ?? false,
|
|
1370
|
+
presence: def.presence ?? false,
|
|
1371
|
+
publish: {
|
|
1372
|
+
who: def.publish?.who ?? "nobody",
|
|
1373
|
+
direct: def.publish?.direct ?? false
|
|
1374
|
+
},
|
|
1375
|
+
conversation: {
|
|
1376
|
+
enabled: def.conversation?.enabled ?? false,
|
|
1377
|
+
limit: def.conversation?.limit ?? 0,
|
|
1378
|
+
ttl: def.conversation?.ttl ?? 0
|
|
1379
|
+
},
|
|
1380
|
+
delivery: {
|
|
1381
|
+
guarantee: def.delivery?.guarantee ?? "at_most_once",
|
|
1382
|
+
per_recipient: def.delivery?.perRecipient ?? false
|
|
1383
|
+
},
|
|
1384
|
+
rate_limit: { messages_per_minute: def.rateLimit?.messagesPerMinute ?? 0 },
|
|
1385
|
+
history: encodeContainerHistory("message", def.history),
|
|
1386
|
+
...def.middleware !== void 0 ? { middleware: buildMiddlewareBlock(def.middleware) } : {},
|
|
1387
|
+
tag: encodeTags(def.tags)
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
var realtimeChannelKind = {
|
|
1391
|
+
name: "channel",
|
|
1392
|
+
payloadKey: "channel",
|
|
1393
|
+
encode: encodeRealtimeChannel,
|
|
1394
|
+
guidOf: (def) => realtimeChannelGuid(def)
|
|
1395
|
+
};
|
|
1396
|
+
registerKind(realtimeChannelKind);
|
|
1397
|
+
function channelPathParams(path) {
|
|
1398
|
+
return parsePathParams(`realtimeChannel "${path}"`, path);
|
|
1399
|
+
}
|
|
1400
|
+
function assertChannelPathParams(def) {
|
|
1401
|
+
const context = `realtimeChannel "${def.name}"`;
|
|
1402
|
+
assertStoredName(context, def.name, "route");
|
|
1403
|
+
assertChannelSegments(context, def.name);
|
|
1404
|
+
const params = parsePathParams(context, def.name);
|
|
1405
|
+
assertPathParamInputs(context, params, def.input);
|
|
1406
|
+
return params;
|
|
1407
|
+
}
|
|
1408
|
+
function assertChannelSegments(context, name) {
|
|
1409
|
+
const segments = name.split("/");
|
|
1410
|
+
if (segments.includes("")) {
|
|
1411
|
+
const fixed = segments.filter((seg) => seg !== "").join("/");
|
|
1412
|
+
throw new Error(
|
|
1413
|
+
`${context}: a channel path cannot have an empty segment (a leading, trailing or doubled "/") \u2014 the join matching rejects it rather than collapsing it, so no client could ever join this channel. ` + (fixed ? `Write "${fixed}".` : `Name the channel, e.g. "lobby".`)
|
|
1414
|
+
);
|
|
1415
|
+
}
|
|
1416
|
+
const partial = segments.find((seg) => /[{}]/.test(seg) && !/^\{[^/{}]+\}$/.test(seg));
|
|
1417
|
+
if (partial !== void 0) {
|
|
1418
|
+
throw new Error(
|
|
1419
|
+
`${context}: the segment "${partial}" embeds a {param} \u2014 in a channel path a {param} must be the WHOLE segment ("rooms/{room_id}"). Anything else is matched as literal text, so no joined path would match it. Make the param its own segment, e.g. "rooms/x/{room_id}".`
|
|
1420
|
+
);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
function realtimeChannel(def) {
|
|
1424
|
+
assertChannelPathParams(def);
|
|
1425
|
+
const context = `realtimeChannel "${def.name}"`;
|
|
1426
|
+
const getChannel = (params) => fillPathParams(context, "getChannel()", def.name, params);
|
|
1427
|
+
return brandDef({ ...def, getChannel }, "channel");
|
|
1428
|
+
}
|
|
1429
|
+
function realtimeChannelGuid(def) {
|
|
1430
|
+
const guid = def.guid || deriveGuid("channel", realtimeChannelSeedName(realtimeServerRefName(`realtimeChannel "${def.name}"`, def.server), def.name));
|
|
1431
|
+
noteHandleRef(guid);
|
|
1432
|
+
return guid;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// src/kinds/trigger-handle.ts
|
|
1436
|
+
function accessor(base) {
|
|
1437
|
+
const fn = (path) => inp(`${base}.${path}`);
|
|
1438
|
+
return Object.assign(fn, inp(base));
|
|
1439
|
+
}
|
|
1440
|
+
function buildTriggerHandle(objType, toolsetType) {
|
|
1441
|
+
const handle = {};
|
|
1442
|
+
for (const { name } of impliedInputs(objType, toolsetType)) {
|
|
1443
|
+
handle[name] = accessor(name);
|
|
1444
|
+
}
|
|
1445
|
+
return handle;
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
// src/kinds/trigger.ts
|
|
1449
|
+
function baseMeta() {
|
|
1450
|
+
return {
|
|
1451
|
+
database: {
|
|
1452
|
+
datasource: [],
|
|
1453
|
+
search: { expression: [] },
|
|
1454
|
+
action: { delete: false, insert: false, truncate: false, update: false }
|
|
1455
|
+
},
|
|
1456
|
+
toolset: { action: { connection: false } },
|
|
1457
|
+
workspace: { action: { branch_live: false, branch_merge: false, branch_new: false } },
|
|
1458
|
+
workspace_realtime_channel: { action: { message: false, join: false } },
|
|
1459
|
+
// The two realtime lifecycle groups. Every trigger type carries the WHOLE
|
|
1460
|
+
// skeleton with only its own group's flags set — verified against a live
|
|
1461
|
+
// engine capture, which emits all six groups for a table trigger, a workspace
|
|
1462
|
+
// trigger, and both realtime lifecycle triggers alike.
|
|
1463
|
+
realtime_server: { action: { connect: false, disconnect: false } },
|
|
1464
|
+
channel: { action: { join: false, leave: false, deliver: false } }
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
function assertSearchMatchesActions(name, expression, action) {
|
|
1468
|
+
if (action.truncate) {
|
|
1469
|
+
throw new Error(
|
|
1470
|
+
`tableTrigger "${name}": \`search\` is not supported with the \`truncate\` action \u2014 a truncate fires once for the whole table, with no row to test.`
|
|
1471
|
+
);
|
|
1472
|
+
}
|
|
1473
|
+
const operands = collectOperands(expression);
|
|
1474
|
+
for (const [enabled, forbidden] of [
|
|
1475
|
+
[action.insert, "OLD"],
|
|
1476
|
+
[action.delete, "NEW"]
|
|
1477
|
+
]) {
|
|
1478
|
+
if (!enabled) continue;
|
|
1479
|
+
const hit = operands.find((o) => o.startsWith(`${forbidden}.`));
|
|
1480
|
+
if (hit !== void 0) {
|
|
1481
|
+
const act = forbidden === "OLD" ? "insert" : "delete";
|
|
1482
|
+
throw new Error(
|
|
1483
|
+
`tableTrigger "${name}": \`search\` reads \`${hit}\`, which does not exist for the \`${act}\` action this trigger is enabled for. Use ${forbidden === "OLD" ? "`NEW.*`" : "`OLD.*`"}, or split the actions into separate triggers.`
|
|
1484
|
+
);
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
function collectOperands(node) {
|
|
1489
|
+
if (Array.isArray(node)) return node.flatMap(collectOperands);
|
|
1490
|
+
if (node === null || typeof node !== "object") return [];
|
|
1491
|
+
const out = [];
|
|
1492
|
+
for (const [key, value] of Object.entries(node)) {
|
|
1493
|
+
if (key === "operand" && typeof value === "string") out.push(value);
|
|
1494
|
+
else out.push(...collectOperands(value));
|
|
1495
|
+
}
|
|
1496
|
+
return out;
|
|
1497
|
+
}
|
|
1498
|
+
function encodeTrigger(def) {
|
|
1499
|
+
if (!def.name) throw new Error("trigger: `name` is required.");
|
|
1500
|
+
if (!isTriggerObjType(def.objType)) {
|
|
1501
|
+
throw new Error(
|
|
1502
|
+
`trigger "${def.name}": \`objType\` is ${describeEntry(def.objType)}, so this is not a trigger def \u2014 build one with tableTrigger, realtimeTrigger, realtimeServerTrigger, realtimeChannelTrigger, mcpServerTrigger, agentTrigger, workspaceTrigger or errorTrigger.`
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
const xdo = {
|
|
1506
|
+
name: def.name,
|
|
1507
|
+
active: def.active ?? true,
|
|
1508
|
+
description: def.description ?? "",
|
|
1509
|
+
obj_id: def.objId ?? 0,
|
|
1510
|
+
obj_type: def.objType,
|
|
1511
|
+
history: encodeHistory("trigger", def.history),
|
|
1512
|
+
output: [],
|
|
1513
|
+
meta: def.meta,
|
|
1514
|
+
tag: encodeTags(def.tags),
|
|
1515
|
+
// Inputs are implied by type (fixed by Xano, not user-editable) — always
|
|
1516
|
+
// inject the canonical per-type array, never a user-supplied map.
|
|
1517
|
+
input: impliedInputs(def.objType, def.toolsetType),
|
|
1518
|
+
run: encodeStack("trigger", def.name, def.stack)
|
|
1519
|
+
};
|
|
1520
|
+
if (def.hasResult) {
|
|
1521
|
+
xdo.result = encodeResponse(def.response);
|
|
1522
|
+
} else {
|
|
1523
|
+
xdo.result = [];
|
|
1524
|
+
}
|
|
1525
|
+
return xdo;
|
|
1526
|
+
}
|
|
1527
|
+
var RESPONSE_ARGS = ["response", "responseShape"];
|
|
1528
|
+
function triggerActions(factory, args, keys) {
|
|
1529
|
+
const actions = args.actions;
|
|
1530
|
+
if (typeof actions === "object" && actions !== null) {
|
|
1531
|
+
refuseUnknown(`${factory} "${String(args.name)}" \`actions\``, actions, keys);
|
|
1532
|
+
}
|
|
1533
|
+
return Object.fromEntries(keys.map((k) => [k, actions?.[k] ?? false]));
|
|
1534
|
+
}
|
|
1535
|
+
function triggerArgs(factory, args, own) {
|
|
1536
|
+
assertKnownKeys(`${factory} "${args.name}"`, args, [
|
|
1537
|
+
"name",
|
|
1538
|
+
"guid",
|
|
1539
|
+
"description",
|
|
1540
|
+
"active",
|
|
1541
|
+
"objId",
|
|
1542
|
+
"tags",
|
|
1543
|
+
"history",
|
|
1544
|
+
"diagnostics",
|
|
1545
|
+
"stack",
|
|
1546
|
+
...own
|
|
1547
|
+
]);
|
|
1548
|
+
}
|
|
1549
|
+
function tableTrigger(args) {
|
|
1550
|
+
triggerArgs("tableTrigger", args, ["table", "datasources", "actions", "search"]);
|
|
1551
|
+
const meta = baseMeta();
|
|
1552
|
+
assertDefShape("trigger", args);
|
|
1553
|
+
meta.database.datasource = (args.datasources ?? []).map((tag) => ({ tag }));
|
|
1554
|
+
meta.database.action = triggerActions("tableTrigger", args, ["delete", "insert", "truncate", "update"]);
|
|
1555
|
+
if (args.search !== void 0) {
|
|
1556
|
+
const encoded = encodeExpression(args.search);
|
|
1557
|
+
assertSearchMatchesActions(args.name, encoded.expression, meta.database.action);
|
|
1558
|
+
meta.database.search = encoded;
|
|
1559
|
+
}
|
|
1560
|
+
const objId = args.table !== void 0 ? resolveRef("dbo", args.table) : args.objId;
|
|
1561
|
+
const t = buildTriggerHandle("database");
|
|
1562
|
+
return brandDef({
|
|
1563
|
+
name: args.name,
|
|
1564
|
+
guid: args.guid,
|
|
1565
|
+
diagnostics: args.diagnostics,
|
|
1566
|
+
description: args.description,
|
|
1567
|
+
active: args.active,
|
|
1568
|
+
tags: args.tags,
|
|
1569
|
+
history: args.history,
|
|
1570
|
+
objId,
|
|
1571
|
+
objType: "database",
|
|
1572
|
+
hasResult: false,
|
|
1573
|
+
meta,
|
|
1574
|
+
stack: triggerStack(args.name, args.stack, t)
|
|
1575
|
+
}, "trigger");
|
|
1576
|
+
}
|
|
1577
|
+
function realtimeTrigger(args) {
|
|
1578
|
+
triggerArgs("realtimeTrigger", args, ["actions", ...RESPONSE_ARGS]);
|
|
1579
|
+
const meta = baseMeta();
|
|
1580
|
+
meta.workspace_realtime_channel.action = triggerActions("realtimeTrigger", args, ["message", "join"]);
|
|
1581
|
+
const t = buildTriggerHandle("workspace_realtime_channel");
|
|
1582
|
+
return brandDef({
|
|
1583
|
+
name: args.name,
|
|
1584
|
+
guid: args.guid,
|
|
1585
|
+
diagnostics: args.diagnostics,
|
|
1586
|
+
description: args.description,
|
|
1587
|
+
active: args.active,
|
|
1588
|
+
tags: args.tags,
|
|
1589
|
+
history: args.history,
|
|
1590
|
+
objId: args.objId,
|
|
1591
|
+
objType: "workspace_realtime_channel",
|
|
1592
|
+
hasResult: true,
|
|
1593
|
+
meta,
|
|
1594
|
+
// The `?? []` fallback matches `S`'s own `readonly []` default (which is what
|
|
1595
|
+
// `S` resolves to when the callback is omitted); the cast covers the branch
|
|
1596
|
+
// TypeScript cannot tie back to that default.
|
|
1597
|
+
stack: triggerStack(args.name, args.stack, t),
|
|
1598
|
+
// Xano default: echo the `payload` input back. It is a plain
|
|
1599
|
+
// `Value` with no trace, so an omitted callback derives `unknown`.
|
|
1600
|
+
response: args.response !== void 0 ? triggerResponse(args.response, t) : inp("payload")
|
|
1601
|
+
}, "trigger");
|
|
1602
|
+
}
|
|
1603
|
+
function realtimeServerTrigger(args) {
|
|
1604
|
+
triggerArgs("realtimeServerTrigger", args, ["realtimeServer", "actions", ...RESPONSE_ARGS]);
|
|
1605
|
+
const t = buildTriggerHandle("realtime_server");
|
|
1606
|
+
const serverMeta = baseMeta();
|
|
1607
|
+
serverMeta.realtime_server.action = triggerActions("realtimeServerTrigger", args, ["connect", "disconnect"]);
|
|
1608
|
+
return brandDef({
|
|
1609
|
+
name: args.name,
|
|
1610
|
+
guid: args.guid,
|
|
1611
|
+
diagnostics: args.diagnostics,
|
|
1612
|
+
description: args.description,
|
|
1613
|
+
active: args.active,
|
|
1614
|
+
tags: args.tags,
|
|
1615
|
+
history: args.history,
|
|
1616
|
+
objId: args.realtimeServer !== void 0 ? resolveRef("realtime_server", args.realtimeServer) : args.objId,
|
|
1617
|
+
objType: "realtime_server",
|
|
1618
|
+
hasResult: true,
|
|
1619
|
+
meta: serverMeta,
|
|
1620
|
+
// See the `realtimeTrigger` note: the fallback matches `S`'s own default.
|
|
1621
|
+
stack: triggerStack(args.name, args.stack, t),
|
|
1622
|
+
response: triggerResponse(args.response, t)
|
|
1623
|
+
}, "trigger");
|
|
1624
|
+
}
|
|
1625
|
+
function realtimeChannelTrigger(args) {
|
|
1626
|
+
triggerArgs("realtimeChannelTrigger", args, ["channel", "actions", ...RESPONSE_ARGS]);
|
|
1627
|
+
const channel = args.channel;
|
|
1628
|
+
if (channel !== void 0 && (typeof channel !== "object" || channel === null || !channel.server)) {
|
|
1629
|
+
throw new Error(
|
|
1630
|
+
`realtimeChannelTrigger ${JSON.stringify(args.name)}: \`channel\` must be a realtimeChannel() handle, which carries its server \u2014 got ${typeof channel === "string" ? `the bare path ${JSON.stringify(channel)}` : String(channel)}. A channel path is unique only within its server. Pass the handle: \`channel: <the realtimeChannel() result>\`.`
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
const t = buildTriggerHandle("channel");
|
|
1634
|
+
const channelMeta = baseMeta();
|
|
1635
|
+
channelMeta.channel.action = triggerActions("realtimeChannelTrigger", args, ["join", "leave", "deliver"]);
|
|
1636
|
+
return brandDef({
|
|
1637
|
+
name: args.name,
|
|
1638
|
+
guid: args.guid,
|
|
1639
|
+
diagnostics: args.diagnostics,
|
|
1640
|
+
description: args.description,
|
|
1641
|
+
active: args.active,
|
|
1642
|
+
tags: args.tags,
|
|
1643
|
+
history: args.history,
|
|
1644
|
+
objId: args.channel !== void 0 ? realtimeChannelGuid(args.channel) : args.objId,
|
|
1645
|
+
objType: "channel",
|
|
1646
|
+
hasResult: true,
|
|
1647
|
+
meta: channelMeta,
|
|
1648
|
+
// See the `realtimeTrigger` note: the fallback matches `S`'s own default.
|
|
1649
|
+
stack: triggerStack(args.name, args.stack, t),
|
|
1650
|
+
response: triggerResponse(args.response, t)
|
|
1651
|
+
}, "trigger");
|
|
1652
|
+
}
|
|
1653
|
+
function mcpServerTrigger(args) {
|
|
1654
|
+
triggerArgs("mcpServerTrigger", args, ["mcpServer", ...RESPONSE_ARGS]);
|
|
1655
|
+
return toolsetTrigger(args, args.mcpServer, "mcpServer");
|
|
1656
|
+
}
|
|
1657
|
+
function agentTrigger(args) {
|
|
1658
|
+
triggerArgs("agentTrigger", args, ["agent", ...RESPONSE_ARGS]);
|
|
1659
|
+
return toolsetTrigger(args, args.agent, "agent");
|
|
1660
|
+
}
|
|
1661
|
+
function workspaceTrigger(args) {
|
|
1662
|
+
triggerArgs("workspaceTrigger", args, ["actions"]);
|
|
1663
|
+
const meta = baseMeta();
|
|
1664
|
+
meta.workspace.action = triggerActions("workspaceTrigger", args, ["branch_live", "branch_merge", "branch_new"]);
|
|
1665
|
+
const t = buildTriggerHandle("workspace");
|
|
1666
|
+
return brandDef({
|
|
1667
|
+
name: args.name,
|
|
1668
|
+
guid: args.guid,
|
|
1669
|
+
diagnostics: args.diagnostics,
|
|
1670
|
+
description: args.description,
|
|
1671
|
+
active: args.active,
|
|
1672
|
+
tags: args.tags,
|
|
1673
|
+
history: args.history,
|
|
1674
|
+
objId: args.objId,
|
|
1675
|
+
objType: "workspace",
|
|
1676
|
+
hasResult: false,
|
|
1677
|
+
meta,
|
|
1678
|
+
stack: triggerStack(args.name, args.stack, t)
|
|
1679
|
+
}, "trigger");
|
|
1680
|
+
}
|
|
1681
|
+
function errorTrigger(args) {
|
|
1682
|
+
triggerArgs("errorTrigger", args, []);
|
|
1683
|
+
const t = buildTriggerHandle("error");
|
|
1684
|
+
return brandDef({
|
|
1685
|
+
name: args.name,
|
|
1686
|
+
guid: args.guid,
|
|
1687
|
+
diagnostics: args.diagnostics,
|
|
1688
|
+
description: args.description,
|
|
1689
|
+
active: args.active,
|
|
1690
|
+
tags: args.tags,
|
|
1691
|
+
history: args.history,
|
|
1692
|
+
objId: args.objId,
|
|
1693
|
+
objType: "error",
|
|
1694
|
+
hasResult: false,
|
|
1695
|
+
meta: baseMeta(),
|
|
1696
|
+
stack: triggerStack(args.name, args.stack, t)
|
|
1697
|
+
}, "trigger");
|
|
1698
|
+
}
|
|
1699
|
+
function toolsetTrigger(args, target, field2) {
|
|
1700
|
+
const meta = baseMeta();
|
|
1701
|
+
meta.toolset.action.connection = true;
|
|
1702
|
+
const toolsetType = field2 === "agent" ? "agent" : "mcp";
|
|
1703
|
+
const t = buildTriggerHandle("toolset", toolsetType);
|
|
1704
|
+
const passed = Object.keys(t).filter((name) => name !== "auth");
|
|
1705
|
+
const bound = target !== void 0 ? resolveRef("toolset", target) : void 0;
|
|
1706
|
+
const authoredStack = args.stack !== void 0 && args.stack !== null;
|
|
1707
|
+
if (bound !== void 0) noteToolsetTarget(bound, field2);
|
|
1708
|
+
return brandDef({
|
|
1709
|
+
name: args.name,
|
|
1710
|
+
guid: args.guid,
|
|
1711
|
+
diagnostics: args.diagnostics,
|
|
1712
|
+
description: args.description,
|
|
1713
|
+
active: args.active,
|
|
1714
|
+
tags: args.tags,
|
|
1715
|
+
history: args.history,
|
|
1716
|
+
objId: bound ?? args.objId,
|
|
1717
|
+
objType: "toolset",
|
|
1718
|
+
toolsetType,
|
|
1719
|
+
hasResult: true,
|
|
1720
|
+
meta,
|
|
1721
|
+
// Xano default: copy each input into a like-named stack var.
|
|
1722
|
+
// See the `realtimeTrigger` note on the cast; the default stack's `set_var`
|
|
1723
|
+
// bindings are untraceable anyway, so an omitted callback derives `unknown`.
|
|
1724
|
+
stack: authoredStack ? triggerStack(args.name, args.stack, t) : passed.map((name) => setVar(name, inp(name))),
|
|
1725
|
+
// Xano default: return each input. Over the default stack it reads the
|
|
1726
|
+
// vars that stack set (the stored default); under an author's stack, which
|
|
1727
|
+
// binds none of them, it reads the inputs themselves.
|
|
1728
|
+
response: args.response !== void 0 && args.response !== null ? triggerResponse(args.response, t) : Object.fromEntries(passed.map((name) => [name, authoredStack ? inp(name) : ref(name)]))
|
|
1729
|
+
}, "trigger");
|
|
1730
|
+
}
|
|
1731
|
+
function triggerStack(name, stack, t) {
|
|
1732
|
+
if (stack === void 0 || stack === null) return [];
|
|
1733
|
+
const steps = typeof stack === "function" && !isTaggedValue(stack) ? stack(t) : stack;
|
|
1734
|
+
if (!Array.isArray(steps)) {
|
|
1735
|
+
const what = typeof stack === "function" ? `the callback returned ${describeEntry(steps)}` : `got ${describeEntry(stack)}`;
|
|
1736
|
+
throw new Error(
|
|
1737
|
+
`Trigger ${JSON.stringify(String(name))}: stack must be a list of steps or a callback (t) => [ ... ] \u2014 ${what}.`
|
|
1738
|
+
);
|
|
1739
|
+
}
|
|
1740
|
+
return steps;
|
|
1741
|
+
}
|
|
1742
|
+
function triggerResponse(response, t) {
|
|
1743
|
+
if (response === void 0 || response === null) return void 0;
|
|
1744
|
+
return typeof response === "function" && !isTaggedValue(response) ? response(t) : response;
|
|
1745
|
+
}
|
|
1746
|
+
var triggerKind = {
|
|
1747
|
+
name: "trigger",
|
|
1748
|
+
payloadKey: "trigger",
|
|
1749
|
+
encode: encodeTrigger
|
|
1750
|
+
};
|
|
1751
|
+
registerKind(triggerKind);
|
|
1752
|
+
|
|
1753
|
+
// src/kinds/canonical.ts
|
|
1754
|
+
function resolveCanonicalToken(label, payloadKey, accessor2, def, override) {
|
|
1755
|
+
if (override) return override;
|
|
1756
|
+
if (typeof def.canonical === "string" && def.canonical !== "") return def.canonical;
|
|
1757
|
+
const locked = getLockedCanonical(lockKey(payloadKey, def.name));
|
|
1758
|
+
if (locked) return locked;
|
|
1759
|
+
throw new Error(
|
|
1760
|
+
`${label} "${def.name}": cannot resolve the \`canonical\` URL token. Set an explicit \`canonical\` in code, or run \`xanosdk export <entry>\` once (it mints a unique canonical and freezes it in xano.lock) and seed that lock before importing defs \u2014 the CLI does this automatically. As a last resort pass one directly (e.g. \`${accessor2}({ canonical: "..." })\`). (Minting here is unsafe \u2014 canonicals must be unique per instance across all workspaces, so they are only generated at locked export.)`
|
|
1761
|
+
);
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
// src/kinds/mcp-metadata.ts
|
|
1765
|
+
var ICON_KEYS = ["src", "mimeType", "sizes", "theme"];
|
|
1766
|
+
var ICON_MIME_TYPES = ["image/png", "image/jpeg", "image/webp"];
|
|
1767
|
+
var ICON_DATA_MAX_BYTES = 65536;
|
|
1768
|
+
var ICON_URL_MAX_LENGTH = 2048;
|
|
1769
|
+
function iconSrcProblem(src) {
|
|
1770
|
+
const lower = src.toLowerCase();
|
|
1771
|
+
if (src.startsWith(HOSTED_FILE_SCHEME)) {
|
|
1772
|
+
return /^xanosdk-file:\/\/[^/\s]+\/[^/\s]+$/.test(src) ? void 0 : "a xanosdk-file: src must be xanosdk-file://<canonical>/<name>";
|
|
1773
|
+
}
|
|
1774
|
+
if (/^\/vault\/[^/\s]+\/[^/\s]+\/[^/\s]+\/[^/\s]+$/.test(src)) {
|
|
1775
|
+
return src.length > ICON_URL_MAX_LENGTH ? `src is longer than ${ICON_URL_MAX_LENGTH} characters` : void 0;
|
|
1776
|
+
}
|
|
1777
|
+
if (lower.startsWith("https://")) {
|
|
1778
|
+
if (src.length > ICON_URL_MAX_LENGTH) return `src is longer than ${ICON_URL_MAX_LENGTH} characters`;
|
|
1779
|
+
let host = "";
|
|
1780
|
+
try {
|
|
1781
|
+
host = new URL(src).host;
|
|
1782
|
+
} catch {
|
|
1783
|
+
}
|
|
1784
|
+
if (host === "" || /\s/.test(src)) return "src is not a valid https URL";
|
|
1785
|
+
return void 0;
|
|
1786
|
+
}
|
|
1787
|
+
if (lower.startsWith("data:")) {
|
|
1788
|
+
const m = /^data:([a-z0-9.+/-]+);base64,([A-Za-z0-9+/]*={0,2})$/i.exec(src);
|
|
1789
|
+
if (!m) return "a data: src must be base64 image data (data:image/png;base64,\u2026)";
|
|
1790
|
+
const mime = m[1].toLowerCase();
|
|
1791
|
+
if (!ICON_MIME_TYPES.includes(mime)) {
|
|
1792
|
+
return `a data: src must be ${ICON_MIME_TYPES.join(", ")} \u2014 got "${mime}" (SVG is refused: it can carry script)`;
|
|
1793
|
+
}
|
|
1794
|
+
const payload = m[2];
|
|
1795
|
+
if (payload === "") return "a data: src must be base64 image data (data:image/png;base64,\u2026)";
|
|
1796
|
+
const padding = payload.endsWith("==") ? 2 : payload.endsWith("=") ? 1 : 0;
|
|
1797
|
+
if (payload.length / 4 * 3 - padding > ICON_DATA_MAX_BYTES) {
|
|
1798
|
+
return `a data: src is larger than ${ICON_DATA_MAX_BYTES} bytes`;
|
|
1799
|
+
}
|
|
1800
|
+
return void 0;
|
|
1801
|
+
}
|
|
1802
|
+
const scheme = /^([A-Za-z][A-Za-z0-9+.-]*):/.exec(src)?.[1] ?? src.slice(0, 20);
|
|
1803
|
+
return `src must be https: or a data: image \u2014 got "${scheme}"`;
|
|
1804
|
+
}
|
|
1805
|
+
function encodeIcons(owner, icons) {
|
|
1806
|
+
if (icons === void 0 || icons.length === 0) return void 0;
|
|
1807
|
+
if (!Array.isArray(icons)) throw new Error(`${owner} \`icons\`: expected a list of { src, mimeType?, sizes?, theme? }.`);
|
|
1808
|
+
return icons.map((icon, i) => {
|
|
1809
|
+
const at = `${owner} \`icons[${i}]\``;
|
|
1810
|
+
if (icon === null || typeof icon !== "object") throw new Error(`${at}: expected { src, mimeType?, sizes?, theme? }.`);
|
|
1811
|
+
refuseUnknown(at, icon, ICON_KEYS);
|
|
1812
|
+
const hosted = isHostedFile(icon.src) ? icon.src : void 0;
|
|
1813
|
+
if (hosted === void 0) {
|
|
1814
|
+
if (typeof icon.src !== "string" || icon.src.trim() === "") throw new Error(`${at}: an icon needs a \`src\`.`);
|
|
1815
|
+
const srcProblem = iconSrcProblem(icon.src);
|
|
1816
|
+
if (srcProblem) throw new Error(`${at}: ${srcProblem}.`);
|
|
1817
|
+
}
|
|
1818
|
+
if (icon.mimeType !== void 0 && !ICON_MIME_TYPES.includes(String(icon.mimeType).toLowerCase())) {
|
|
1819
|
+
throw new Error(`${at}: \`mimeType\` must be one of ${ICON_MIME_TYPES.join(", ")} \u2014 got "${String(icon.mimeType)}".`);
|
|
1820
|
+
}
|
|
1821
|
+
for (const size of icon.sizes ?? []) {
|
|
1822
|
+
if (typeof size !== "string" || !/^(\d{1,5}x\d{1,5}|any)$/.test(size)) {
|
|
1823
|
+
throw new Error(`${at}: each of \`sizes\` must be "WxH" (e.g. "48x48") or "any" \u2014 got ${JSON.stringify(size)}.`);
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
if (icon.theme !== void 0 && icon.theme !== "light" && icon.theme !== "dark") {
|
|
1827
|
+
throw new Error(`${at}: \`theme\` must be "light" or "dark" \u2014 got ${JSON.stringify(icon.theme)}.`);
|
|
1828
|
+
}
|
|
1829
|
+
const out = {
|
|
1830
|
+
src: "",
|
|
1831
|
+
mime_type: icon.mimeType ?? null,
|
|
1832
|
+
sizes: [...icon.sizes ?? []],
|
|
1833
|
+
theme: icon.theme ?? null
|
|
1834
|
+
};
|
|
1835
|
+
out.src = hosted === void 0 ? icon.src : pendingHostedSrc(out, hosted, {
|
|
1836
|
+
field: at,
|
|
1837
|
+
allowedMimes: ICON_MIME_TYPES,
|
|
1838
|
+
requirePublic: true,
|
|
1839
|
+
...icon.mimeType !== void 0 ? { declaredMime: String(icon.mimeType).toLowerCase() } : {}
|
|
1840
|
+
});
|
|
1841
|
+
return out;
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
function encodeTitle(owner, title) {
|
|
1845
|
+
if (title === void 0 || title === "") return void 0;
|
|
1846
|
+
if (typeof title !== "string") throw new Error(`${owner} \`title\`: expected a string.`);
|
|
1847
|
+
return title;
|
|
1848
|
+
}
|
|
1849
|
+
var TOOL_ANNOTATION_WIRE = {
|
|
1850
|
+
readOnlyHint: "read_only_hint",
|
|
1851
|
+
destructiveHint: "destructive_hint",
|
|
1852
|
+
idempotentHint: "idempotent_hint",
|
|
1853
|
+
openWorldHint: "open_world_hint"
|
|
1854
|
+
};
|
|
1855
|
+
function encodeToolAnnotations(owner, annotations) {
|
|
1856
|
+
if (annotations === void 0) return void 0;
|
|
1857
|
+
const at = `${owner} \`annotations\``;
|
|
1858
|
+
if (annotations === null || typeof annotations !== "object") throw new Error(`${at}: expected an object of boolean hints.`);
|
|
1859
|
+
refuseUnknown(at, annotations, Object.keys(TOOL_ANNOTATION_WIRE));
|
|
1860
|
+
const out = {
|
|
1861
|
+
read_only_hint: null,
|
|
1862
|
+
destructive_hint: null,
|
|
1863
|
+
idempotent_hint: null,
|
|
1864
|
+
open_world_hint: null
|
|
1865
|
+
};
|
|
1866
|
+
let any = false;
|
|
1867
|
+
for (const [key, wire] of Object.entries(TOOL_ANNOTATION_WIRE)) {
|
|
1868
|
+
const value = annotations[key];
|
|
1869
|
+
if (value === void 0) continue;
|
|
1870
|
+
if (typeof value !== "boolean") throw new Error(`${at}: \`${key}\` must be true or false \u2014 got ${JSON.stringify(value)}.`);
|
|
1871
|
+
out[wire] = value;
|
|
1872
|
+
any = true;
|
|
1873
|
+
}
|
|
1874
|
+
return any ? out : void 0;
|
|
1875
|
+
}
|
|
1876
|
+
var RESOURCE_ANNOTATION_KEYS = ["audience", "priority", "lastModified"];
|
|
1877
|
+
var ISO_8601 = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
1878
|
+
function encodeResourceAnnotations(owner, annotations) {
|
|
1879
|
+
if (annotations === void 0) return void 0;
|
|
1880
|
+
const at = `${owner} \`annotations\``;
|
|
1881
|
+
if (annotations === null || typeof annotations !== "object") throw new Error(`${at}: expected { audience?, priority?, lastModified? }.`);
|
|
1882
|
+
refuseUnknown(at, annotations, RESOURCE_ANNOTATION_KEYS);
|
|
1883
|
+
const audience = annotations.audience ?? [];
|
|
1884
|
+
for (const who of audience) {
|
|
1885
|
+
if (who !== "user" && who !== "assistant") {
|
|
1886
|
+
throw new Error(`${at}: \`audience\` entries must be "user" or "assistant" \u2014 got ${JSON.stringify(who)}.`);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
const { priority, lastModified } = annotations;
|
|
1890
|
+
if (priority !== void 0 && (typeof priority !== "number" || !Number.isFinite(priority) || priority < 0 || priority > 1)) {
|
|
1891
|
+
throw new Error(`${at}: \`priority\` must be a number from 0 to 1 \u2014 got ${JSON.stringify(priority)}.`);
|
|
1892
|
+
}
|
|
1893
|
+
if (lastModified !== void 0 && (typeof lastModified !== "string" || !ISO_8601.test(lastModified) || Number.isNaN(Date.parse(lastModified)))) {
|
|
1894
|
+
throw new Error(
|
|
1895
|
+
`${at}: \`lastModified\` must be an ISO 8601 date, e.g. "2025-01-12T15:00:58Z" \u2014 got ${JSON.stringify(lastModified)}.`
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
if (audience.length === 0 && priority === void 0 && lastModified === void 0) return void 0;
|
|
1899
|
+
return { audience: [...audience], priority: priority ?? null, last_modified: lastModified ?? null };
|
|
1900
|
+
}
|
|
1901
|
+
var RESOURCE_VARIABLE_TYPES = ["text", "int", "decimal", "bool", "enum", "email", "uuid"];
|
|
1902
|
+
function parseResourceUri(owner, uri) {
|
|
1903
|
+
const at = `${owner} \`uri\``;
|
|
1904
|
+
if (typeof uri !== "string" || uri === "") throw new Error(`${at}: a resource needs a uri (e.g. "docs://readme").`);
|
|
1905
|
+
if (uri.length > 2048) throw new Error(`${at}: is longer than 2048 characters.`);
|
|
1906
|
+
if ([...uri].some((ch) => /\s/.test(ch) || ch.charCodeAt(0) < 32 || ch.charCodeAt(0) === 127)) throw new Error(`${at}: "${uri}" must not contain whitespace.`);
|
|
1907
|
+
if (!/^[A-Za-z][A-Za-z0-9+.-]*:/.test(uri)) throw new Error(`${at}: "${uri}" must start with a scheme, e.g. docs://readme.`);
|
|
1908
|
+
const variables = [];
|
|
1909
|
+
let lastClose = -2;
|
|
1910
|
+
for (let i = 0; i < uri.length; i++) {
|
|
1911
|
+
const ch = uri[i];
|
|
1912
|
+
if (ch === "}") throw new Error(`${at}: "${uri}" has a "}" with no matching "{".`);
|
|
1913
|
+
if (ch !== "{") continue;
|
|
1914
|
+
const close = uri.indexOf("}", i + 1);
|
|
1915
|
+
if (close === -1) throw new Error(`${at}: "${uri}" has an unclosed "{".`);
|
|
1916
|
+
const expression = uri.slice(i + 1, close);
|
|
1917
|
+
if (expression.includes("{")) throw new Error(`${at}: "${uri}" has an unclosed "{".`);
|
|
1918
|
+
if (expression === "") throw new Error(`${at}: "${uri}" has an empty "{}".`);
|
|
1919
|
+
if ("+#./;?&=,!@|".includes(expression[0])) {
|
|
1920
|
+
throw new Error(`${at}: "{${expression}}" uses an operator; only level-1 {name} variables are supported.`);
|
|
1921
|
+
}
|
|
1922
|
+
if (expression.includes(",")) throw new Error(`${at}: "{${expression}}" lists several variables; use one {name} per variable.`);
|
|
1923
|
+
if (expression.includes("*") || expression.includes(":")) {
|
|
1924
|
+
throw new Error(`${at}: "{${expression}}" uses a modifier; only level-1 {name} variables are supported.`);
|
|
1925
|
+
}
|
|
1926
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(expression)) throw new Error(`${at}: variable "${expression}" must be letters, digits and _.`);
|
|
1927
|
+
if (variables.includes(expression)) throw new Error(`${at}: variable "${expression}" appears more than once.`);
|
|
1928
|
+
if (lastClose === i - 1) throw new Error(`${at}: "${uri}" has two adjacent variables, which cannot be told apart.`);
|
|
1929
|
+
variables.push(expression);
|
|
1930
|
+
lastClose = close;
|
|
1931
|
+
i = close;
|
|
1932
|
+
}
|
|
1933
|
+
return variables;
|
|
1934
|
+
}
|
|
1935
|
+
function assertResourceInput(owner, uri, input) {
|
|
1936
|
+
const variables = parseResourceUri(owner, uri);
|
|
1937
|
+
const fields = new Map(input.map((field2) => [field2.name, field2]));
|
|
1938
|
+
for (const variable of variables) {
|
|
1939
|
+
const field2 = fields.get(variable);
|
|
1940
|
+
if (field2 === void 0) {
|
|
1941
|
+
throw new Error(
|
|
1942
|
+
`${owner}: uri variable "${variable}" must be declared in \`input\` (e.g. \`input: { ${variable}: input.text() }\`).`
|
|
1943
|
+
);
|
|
1944
|
+
}
|
|
1945
|
+
if (!RESOURCE_VARIABLE_TYPES.includes(field2.type)) {
|
|
1946
|
+
throw new Error(
|
|
1947
|
+
`${owner}: uri variable "${variable}" must be one of ${RESOURCE_VARIABLE_TYPES.join(", ")} \u2014 got "${field2.type}".`
|
|
1948
|
+
);
|
|
1949
|
+
}
|
|
1950
|
+
if (field2.style?.type === "list") throw new Error(`${owner}: uri variable "${variable}" must be a single value, not a list.`);
|
|
1951
|
+
}
|
|
1952
|
+
for (const name of fields.keys()) {
|
|
1953
|
+
if (variables.includes(name)) continue;
|
|
1954
|
+
throw new Error(
|
|
1955
|
+
variables.length === 0 ? `${owner}: input "${name}" cannot be set \u2014 a static resource has no inputs. Use a uri template ("\u2026/{${name}}") to take one.` : `${owner}: input "${name}" is not a variable of the uri "${uri}". A resource's input is exactly its uri template's variables.`
|
|
1956
|
+
);
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
// src/kinds/toolset.ts
|
|
1961
|
+
var TOOL_REF_KEYS = ["tool", "id", "enabled", "auth", "type", "resourceUri", "toolMeta"];
|
|
1962
|
+
function encodeTool(def) {
|
|
1963
|
+
if (!def.name) throw new Error("tool: `name` is required.");
|
|
1964
|
+
const owner = `tool "${def.name}"`;
|
|
1965
|
+
assertStoredName(owner, def.name, "route");
|
|
1966
|
+
const title = encodeTitle(owner, def.title);
|
|
1967
|
+
const annotations = encodeToolAnnotations(owner, def.annotations);
|
|
1968
|
+
const icons = encodeIcons(owner, def.icons);
|
|
1969
|
+
const output = Object.entries(def.output ?? {}).map(([name, d]) => encodeInput(name, d));
|
|
1970
|
+
return {
|
|
1971
|
+
name: def.name,
|
|
1972
|
+
description: def.description ?? "",
|
|
1973
|
+
instructions: def.instructions ?? "",
|
|
1974
|
+
docs: def.docs ?? "",
|
|
1975
|
+
enabled: def.enabled ?? true,
|
|
1976
|
+
output: [],
|
|
1977
|
+
middleware: buildMiddlewareBlock(def.middleware),
|
|
1978
|
+
tag: encodeTags(def.tags),
|
|
1979
|
+
history: encodeHistory("tool", def.history),
|
|
1980
|
+
toolset: { id: def.toolsetId ?? 0 },
|
|
1981
|
+
input: Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d)),
|
|
1982
|
+
result: encodeResponse(def.response),
|
|
1983
|
+
run: encodeStack("tool", def.name, def.stack),
|
|
1984
|
+
test: [],
|
|
1985
|
+
// Omitted at their defaults, so a tool that sets none of them keeps the
|
|
1986
|
+
// exact bytes it had before they existed.
|
|
1987
|
+
...title !== void 0 ? { title } : {},
|
|
1988
|
+
...annotations !== void 0 ? { annotations } : {},
|
|
1989
|
+
...icons !== void 0 ? { icons } : {},
|
|
1990
|
+
...output.length > 0 ? { output_schema: output } : {}
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
var toolKind = {
|
|
1994
|
+
name: "tool",
|
|
1995
|
+
payloadKey: "tool",
|
|
1996
|
+
encode: encodeTool
|
|
1997
|
+
};
|
|
1998
|
+
registerKind(toolKind);
|
|
1999
|
+
function tool(def) {
|
|
2000
|
+
return brandDef(def, "tool");
|
|
2001
|
+
}
|
|
2002
|
+
function normalizeToolEntry(entry, index, owner) {
|
|
2003
|
+
if (typeof entry === "string") return { tool: entry };
|
|
2004
|
+
if (entry === null || typeof entry !== "object") {
|
|
2005
|
+
throw new Error(
|
|
2006
|
+
`${owner} \`tools[${index}]\`: expected a \`tool()\` handle, a tool name, or a { tool, enabled?, auth? } wrapper (got ${entry === null ? "null" : typeof entry}).`
|
|
2007
|
+
);
|
|
2008
|
+
}
|
|
2009
|
+
const ref2 = entry;
|
|
2010
|
+
if (ref2.tool !== void 0 || ref2.id !== void 0) {
|
|
2011
|
+
refuseUnknown(`${owner} \`tools[${index}]\``, ref2, TOOL_REF_KEYS);
|
|
2012
|
+
return ref2;
|
|
2013
|
+
}
|
|
2014
|
+
if (typeof ref2.name === "string" && ref2.name !== "") {
|
|
2015
|
+
return { tool: ref2 };
|
|
2016
|
+
}
|
|
2017
|
+
if (ref2.name === void 0) refuseUnknown(`${owner} \`tools[${index}]\``, ref2, TOOL_REF_KEYS);
|
|
2018
|
+
throw new Error(
|
|
2019
|
+
`${owner} \`tools[${index}]\`: names no tool. Pass the \`tool()\` handle (\`tools: [saveNote]\`), its name, or a wrapper (\`{ tool: saveNote, auth: users }\`). An entry with neither \`tool\` nor \`id\` encodes to \`id: 0\` \u2014 a reference to nothing, which deploys as a toolset whose tool is silently missing.`
|
|
2020
|
+
);
|
|
2021
|
+
}
|
|
2022
|
+
function encodeToolRefs(tools, owner = "toolset") {
|
|
2023
|
+
return (tools ?? []).map((entry, index) => {
|
|
2024
|
+
const t = normalizeToolEntry(entry, index, owner);
|
|
2025
|
+
if (t.tool !== void 0 && t.id !== void 0) {
|
|
2026
|
+
throw new Error(`${owner} \`tools[${index}]\`: set either \`tool\` (handle/name) or \`id\` (raw), not both.`);
|
|
2027
|
+
}
|
|
2028
|
+
const id = t.tool !== void 0 ? resolveRef("tool", t.tool) : t.id ?? 0;
|
|
2029
|
+
if (id === 0 || id === "" || id === "0") {
|
|
2030
|
+
emitDiagnostic({
|
|
2031
|
+
severity: "warning",
|
|
2032
|
+
code: "toolset.tool-ref-zero",
|
|
2033
|
+
message: `${owner} \`tools[${index}]\` is \`id: 0\`, which references no tool \u2014 engine ids start at 1. It deploys as a tool entry pointing at nothing, so the toolset simply never calls it, with no error anywhere. Pass the \`tool()\` handle (\`tools: [saveNote]\`) so the reference resolves to its guid.`
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
const label = typeof t.tool === "string" ? t.tool : t.tool?.name ?? String(t.id ?? "?");
|
|
2037
|
+
const type = t.type ?? "tool";
|
|
2038
|
+
if (type === "resource" && !t.resourceUri) {
|
|
2039
|
+
throw new Error(
|
|
2040
|
+
`${owner} \`tools[${index}]\` (${label}) is \`type: "resource"\` with no \`resourceUri\`. A resource is addressed BY its URI, so one without it is published and unreachable. Give it a URI, or drop \`type\` to publish the target as a callable tool.`
|
|
2041
|
+
);
|
|
2042
|
+
}
|
|
2043
|
+
const stale = type === "resource" ? t.toolMeta ? "toolMeta" : "" : t.resourceUri ? "resourceUri" : "";
|
|
2044
|
+
if (stale !== "") {
|
|
2045
|
+
throw new Error(
|
|
2046
|
+
`${owner} \`tools[${index}]\` (${label}) is \`type: "${type}"\` and sets \`${stale}\`, which belongs to the other type \u2014 the engine stores it against neither. Remove it, or change \`type\`.`
|
|
2047
|
+
);
|
|
2048
|
+
}
|
|
2049
|
+
return {
|
|
2050
|
+
id,
|
|
2051
|
+
enabled: t.enabled ?? true,
|
|
2052
|
+
auth: resolveAuthRef("toolset tool", label, t.auth),
|
|
2053
|
+
// `"tool"` is the engine's default and is omitted at it, so an ordinary
|
|
2054
|
+
// entry keeps the exact bytes a pulled one has.
|
|
2055
|
+
...type === "resource" ? { type } : {},
|
|
2056
|
+
...type === "resource" && t.resourceUri ? { resource_uri: t.resourceUri } : {},
|
|
2057
|
+
...type === "tool" && t.toolMeta ? { tool_meta: t.toolMeta } : {}
|
|
2058
|
+
};
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
function resolveToolsetCanonical(def, override) {
|
|
2062
|
+
return resolveCanonicalToken("toolset", "toolset", "getPath", def, override);
|
|
2063
|
+
}
|
|
2064
|
+
function encodeToolsetBase(def, label = "toolset") {
|
|
2065
|
+
assertCanonical(`${label} "${def.name}"`, def.canonical);
|
|
2066
|
+
return {
|
|
2067
|
+
name: def.name,
|
|
2068
|
+
description: def.description ?? "",
|
|
2069
|
+
instructions: def.instructions ?? "",
|
|
2070
|
+
docs: def.docs ?? "",
|
|
2071
|
+
enabled: def.enabled ?? true,
|
|
2072
|
+
canonical: def.canonical ?? "",
|
|
2073
|
+
spec: def.spec ?? "",
|
|
2074
|
+
middleware: emptyMiddleware(),
|
|
2075
|
+
history: encodeContainerHistory("tool", def.history),
|
|
2076
|
+
tag: encodeTags(def.tags),
|
|
2077
|
+
tool: encodeToolRefs(def.tools, `${label} "${def.name}"`)
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
function encodePrimitiveRefs(kind, entries, owner) {
|
|
2081
|
+
if (entries === void 0) return [];
|
|
2082
|
+
const field2 = `${kind}s`;
|
|
2083
|
+
if (!Array.isArray(entries)) throw new Error(`${owner} \`${field2}\`: expected a list of \`${kind}()\` handles.`);
|
|
2084
|
+
const keys = [kind, "id", "enabled", "auth"];
|
|
2085
|
+
const seen = /* @__PURE__ */ new Map();
|
|
2086
|
+
return entries.map((entry, index) => {
|
|
2087
|
+
const at = `${owner} \`${field2}[${index}]\``;
|
|
2088
|
+
let ref2;
|
|
2089
|
+
if (typeof entry === "string") {
|
|
2090
|
+
ref2 = { [kind]: entry };
|
|
2091
|
+
} else if (entry === null || typeof entry !== "object") {
|
|
2092
|
+
throw new Error(`${at}: expected a \`${kind}()\` handle, a name, or a { ${kind}, enabled?, auth? } wrapper.`);
|
|
2093
|
+
} else {
|
|
2094
|
+
const record = entry;
|
|
2095
|
+
if (record[kind] !== void 0 || record.id !== void 0) {
|
|
2096
|
+
refuseUnknown(at, record, keys);
|
|
2097
|
+
ref2 = entry;
|
|
2098
|
+
} else if (typeof record.name === "string" && record.name !== "") {
|
|
2099
|
+
ref2 = { [kind]: entry };
|
|
2100
|
+
} else {
|
|
2101
|
+
refuseUnknown(at, record, keys);
|
|
2102
|
+
throw new Error(`${at}: names no ${kind}. Pass the \`${kind}()\` handle, its name, or { ${kind}: handle, auth? }.`);
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
const target = ref2[kind];
|
|
2106
|
+
if (target !== void 0 && ref2.id !== void 0) throw new Error(`${at}: set either \`${kind}\` or \`id\`, not both.`);
|
|
2107
|
+
const id = target !== void 0 ? resolveRef(kind, target, at) : ref2.id ?? 0;
|
|
2108
|
+
if (id === 0) throw new Error(`${at}: \`id: 0\` references no ${kind} \u2014 engine ids start at 1. Pass the \`${kind}()\` handle.`);
|
|
2109
|
+
const first = seen.get(id);
|
|
2110
|
+
if (first !== void 0) throw new Error(`${at}: lists the same ${kind} as \`${field2}[${first}]\`. List each ${kind} once.`);
|
|
2111
|
+
seen.set(id, index);
|
|
2112
|
+
const label = typeof target === "string" ? target : target?.name ?? String(ref2.id);
|
|
2113
|
+
return { id, enabled: ref2.enabled ?? true, auth: resolveAuthRef(`mcpServer ${kind}`, label, ref2.auth) };
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
// src/kinds/prompt.ts
|
|
2118
|
+
function encodePrompt(def) {
|
|
2119
|
+
if (!def.name) throw new Error("prompt: `name` is required.");
|
|
2120
|
+
const owner = `prompt "${def.name}"`;
|
|
2121
|
+
assertStoredName(owner, def.name, "route");
|
|
2122
|
+
const title = encodeTitle(owner, def.title);
|
|
2123
|
+
const icons = encodeIcons(owner, def.icons);
|
|
2124
|
+
return {
|
|
2125
|
+
name: def.name,
|
|
2126
|
+
description: def.description ?? "",
|
|
2127
|
+
docs: def.docs ?? "",
|
|
2128
|
+
// Omitted at their defaults, like a tool's.
|
|
2129
|
+
...title !== void 0 ? { title } : {},
|
|
2130
|
+
...icons !== void 0 ? { icons } : {},
|
|
2131
|
+
input: Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d)),
|
|
2132
|
+
run: encodeStack("prompt", def.name, def.stack),
|
|
2133
|
+
result: encodeResponse(def.response),
|
|
2134
|
+
middleware: buildMiddlewareBlock(def.middleware),
|
|
2135
|
+
tag: encodeTags(def.tags),
|
|
2136
|
+
history: encodeHistory("prompt", def.history)
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
var promptKind = {
|
|
2140
|
+
name: "prompt",
|
|
2141
|
+
payloadKey: "prompt",
|
|
2142
|
+
encode: encodePrompt
|
|
2143
|
+
};
|
|
2144
|
+
registerKind(promptKind);
|
|
2145
|
+
function prompt(def) {
|
|
2146
|
+
return brandDef(def, "prompt");
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
// src/kinds/resource.ts
|
|
2150
|
+
var MIME_TYPE = /^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*(\s*;.*)?$/;
|
|
2151
|
+
function encodeResource(def) {
|
|
2152
|
+
if (!def.name) throw new Error("resource: `name` is required.");
|
|
2153
|
+
const owner = `resource "${def.name}"`;
|
|
2154
|
+
assertStoredName(owner, def.name, "route");
|
|
2155
|
+
if (def.mimeType !== void 0 && def.mimeType !== "" && !MIME_TYPE.test(def.mimeType)) {
|
|
2156
|
+
throw new Error(`${owner} \`mimeType\`: must be a MIME type such as text/markdown \u2014 got ${JSON.stringify(def.mimeType)}.`);
|
|
2157
|
+
}
|
|
2158
|
+
const input = Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d));
|
|
2159
|
+
assertResourceInput(owner, def.uri, input);
|
|
2160
|
+
const title = encodeTitle(owner, def.title);
|
|
2161
|
+
const icons = encodeIcons(owner, def.icons);
|
|
2162
|
+
const annotations = encodeResourceAnnotations(owner, def.annotations);
|
|
2163
|
+
return {
|
|
2164
|
+
name: def.name,
|
|
2165
|
+
uri: def.uri,
|
|
2166
|
+
description: def.description ?? "",
|
|
2167
|
+
docs: def.docs ?? "",
|
|
2168
|
+
mime_type: def.mimeType ?? "",
|
|
2169
|
+
// Omitted at their defaults, like a tool's.
|
|
2170
|
+
...title !== void 0 ? { title } : {},
|
|
2171
|
+
...icons !== void 0 ? { icons } : {},
|
|
2172
|
+
...annotations !== void 0 ? { annotations } : {},
|
|
2173
|
+
input,
|
|
2174
|
+
run: encodeStack("resource", def.name, def.stack),
|
|
2175
|
+
result: encodeResponse(def.response),
|
|
2176
|
+
middleware: buildMiddlewareBlock(def.middleware),
|
|
2177
|
+
tag: encodeTags(def.tags),
|
|
2178
|
+
history: encodeHistory("resource", def.history)
|
|
2179
|
+
};
|
|
2180
|
+
}
|
|
2181
|
+
var resourceKind = {
|
|
2182
|
+
name: "resource",
|
|
2183
|
+
payloadKey: "resource",
|
|
2184
|
+
encode: encodeResource
|
|
2185
|
+
};
|
|
2186
|
+
registerKind(resourceKind);
|
|
2187
|
+
function resource(def) {
|
|
2188
|
+
return brandDef(def, "resource");
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
// src/kinds/agent.ts
|
|
2192
|
+
function buildProviderConfig(llm) {
|
|
2193
|
+
let config;
|
|
2194
|
+
switch (llm.type) {
|
|
2195
|
+
case "anthropic":
|
|
2196
|
+
config = {
|
|
2197
|
+
apiKey: llm.apiKey ?? "",
|
|
2198
|
+
model: llm.model ?? "",
|
|
2199
|
+
temperature: llm.temperature ?? 1,
|
|
2200
|
+
sendReasoning: llm.sendReasoning ?? true,
|
|
2201
|
+
thinking: llm.thinkingTokens !== void 0 ? { type: "enabled", budgetTokens: llm.thinkingTokens } : { type: "disabled", budgetTokens: "" },
|
|
2202
|
+
baseURL: llm.baseURL ?? "",
|
|
2203
|
+
headers: llm.headers ?? ""
|
|
2204
|
+
};
|
|
2205
|
+
break;
|
|
2206
|
+
case "openai":
|
|
2207
|
+
config = {
|
|
2208
|
+
apiKey: llm.apiKey ?? "",
|
|
2209
|
+
model: llm.model ?? "",
|
|
2210
|
+
temperature: llm.temperature ?? 1,
|
|
2211
|
+
reasoningEffort: llm.reasoningEffort ?? "medium",
|
|
2212
|
+
baseURL: llm.baseURL ?? "",
|
|
2213
|
+
headers: llm.headers ?? "",
|
|
2214
|
+
organization: llm.organization ?? "",
|
|
2215
|
+
project: llm.project ?? "",
|
|
2216
|
+
compatibility: llm.compatibility ?? "strict"
|
|
2217
|
+
};
|
|
2218
|
+
break;
|
|
2219
|
+
case "google-genai":
|
|
2220
|
+
config = {
|
|
2221
|
+
apiKey: llm.apiKey ?? "",
|
|
2222
|
+
model: llm.model ?? "",
|
|
2223
|
+
temperature: llm.temperature ?? 1,
|
|
2224
|
+
useSearchGrounding: llm.searchGrounding ?? false,
|
|
2225
|
+
thinkingConfig: {
|
|
2226
|
+
includeThoughts: llm.includeThoughts ?? false,
|
|
2227
|
+
thinkingBudget: llm.thinkingBudget ?? 0
|
|
2228
|
+
},
|
|
2229
|
+
baseURL: llm.baseURL ?? "",
|
|
2230
|
+
headers: llm.headers ?? "",
|
|
2231
|
+
safetySettings: llm.safetySettings ?? "",
|
|
2232
|
+
dynamicRetrievalConfig: llm.dynamicRetrieval ?? ""
|
|
2233
|
+
};
|
|
2234
|
+
break;
|
|
2235
|
+
case "xano-free":
|
|
2236
|
+
config = {
|
|
2237
|
+
temperature: llm.temperature ?? 1,
|
|
2238
|
+
useSearchGrounding: llm.searchGrounding ?? false,
|
|
2239
|
+
thinkingConfig: {
|
|
2240
|
+
includeThoughts: llm.includeThoughts ?? false,
|
|
2241
|
+
thinkingBudget: llm.thinkingBudget ?? 0
|
|
2242
|
+
},
|
|
2243
|
+
baseURL: llm.baseURL ?? "",
|
|
2244
|
+
headers: llm.headers ?? "",
|
|
2245
|
+
safetySettings: llm.safetySettings ?? "",
|
|
2246
|
+
dynamicRetrievalConfig: llm.dynamicRetrieval ?? ""
|
|
2247
|
+
};
|
|
2248
|
+
break;
|
|
2249
|
+
}
|
|
2250
|
+
return llm.extraConfig ? { ...config, ...llm.extraConfig } : config;
|
|
2251
|
+
}
|
|
2252
|
+
var LLM_KEYS = {
|
|
2253
|
+
anthropic: ["sendReasoning", "thinkingTokens"],
|
|
2254
|
+
openai: ["reasoningEffort", "organization", "project", "compatibility"],
|
|
2255
|
+
"google-genai": ["searchGrounding", "thinkingBudget", "includeThoughts", "safetySettings", "dynamicRetrieval"],
|
|
2256
|
+
"xano-free": ["searchGrounding", "thinkingBudget", "includeThoughts", "safetySettings", "dynamicRetrieval"]
|
|
2257
|
+
};
|
|
2258
|
+
function buildAgentSettings(def, owner = "agent") {
|
|
2259
|
+
const llm = def.llm;
|
|
2260
|
+
const provider = Object.hasOwn(LLM_KEYS, llm.type) ? LLM_KEYS[llm.type] : void 0;
|
|
2261
|
+
if (!provider && llm.type !== "") {
|
|
2262
|
+
const types = Object.keys(LLM_KEYS);
|
|
2263
|
+
const near = typeof llm.type === "string" ? nearestKey(llm.type, types) : void 0;
|
|
2264
|
+
throw new Error(
|
|
2265
|
+
`${owner} llm: unknown provider type ${JSON.stringify(llm.type)}${near ? ` \u2014 did you mean "${near}"?` : "."} Expected one of: ${types.join(", ")}.`
|
|
2266
|
+
);
|
|
2267
|
+
}
|
|
2268
|
+
if (provider) {
|
|
2269
|
+
assertKnownKeys(`${owner} llm (${llm.type})`, llm, [
|
|
2270
|
+
"type",
|
|
2271
|
+
"systemPrompt",
|
|
2272
|
+
"maxSteps",
|
|
2273
|
+
"extraConfig",
|
|
2274
|
+
"prompt",
|
|
2275
|
+
"messages",
|
|
2276
|
+
...llm.type === "xano-free" ? [] : ["apiKey", "model"],
|
|
2277
|
+
"temperature",
|
|
2278
|
+
"baseURL",
|
|
2279
|
+
"headers",
|
|
2280
|
+
...provider
|
|
2281
|
+
]);
|
|
2282
|
+
}
|
|
2283
|
+
for (const key of ["temperature", "thinkingTokens", "thinkingBudget"]) {
|
|
2284
|
+
const v = llm[key];
|
|
2285
|
+
if (v === void 0 || v === "") continue;
|
|
2286
|
+
const n = typeof v === "number" ? v : typeof v === "string" ? Number(v) : NaN;
|
|
2287
|
+
if (!Number.isFinite(n)) {
|
|
2288
|
+
throw new Error(
|
|
2289
|
+
`${owner} llm (${llm.type}): \`${key}\` must be a number \u2014 got ${typeof v === "number" ? String(v) : JSON.stringify(v)}.`
|
|
2290
|
+
);
|
|
2291
|
+
}
|
|
2292
|
+
const max = llm.type === "anthropic" ? 1 : 2;
|
|
2293
|
+
if (key === "temperature" && (n < 0 || n > max)) {
|
|
2294
|
+
throw new Error(`${owner} llm (${llm.type}): \`temperature\` must be between 0 and ${max} for this provider \u2014 got ${n}.`);
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
if (def.output !== void 0) {
|
|
2298
|
+
if (typeof def.output === "object" && def.output !== null) refuseUnknown(`${owner} \`output\``, def.output, ["schema", "enabled"]);
|
|
2299
|
+
const schema = def.output.schema;
|
|
2300
|
+
if (schema === null || typeof schema !== "object" || Array.isArray(schema)) {
|
|
2301
|
+
throw new Error(
|
|
2302
|
+
`${owner} \`output\`: \`schema\` is required \u2014 a { field: input.*() } record, e.g. \`output: { schema: { summary: input.text() } }\`.`
|
|
2303
|
+
);
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
if (llm.prompt !== void 0 && llm.messages !== void 0) {
|
|
2307
|
+
throw new Error(
|
|
2308
|
+
`${owner} llm: \`prompt\` and \`messages\` are two spellings of ONE run prompt and cannot both be set \u2014 the engine stores a single \`prompt_type\`, so one of them would be dropped. Keep \`prompt\` for a plain string, or \`messages\` for a messages template.`
|
|
2309
|
+
);
|
|
2310
|
+
}
|
|
2311
|
+
const promptType = llm.messages !== void 0 ? "messages" : "prompt";
|
|
2312
|
+
return {
|
|
2313
|
+
type: llm.type,
|
|
2314
|
+
system_prompt: llm.systemPrompt ?? "",
|
|
2315
|
+
max_steps: llm.maxSteps ?? 5,
|
|
2316
|
+
prompt_type: promptType,
|
|
2317
|
+
prompt: promptType === "prompt" ? llm.prompt ?? "" : "",
|
|
2318
|
+
prompt_messages: promptType === "messages" ? llm.messages ?? "" : "",
|
|
2319
|
+
structuredOutputs: def.output ? def.output.enabled ?? true : false,
|
|
2320
|
+
structuredOutputsSchema: def.output ? Object.entries(def.output.schema).map(([name, d]) => encodeInput(name, d)) : [],
|
|
2321
|
+
configs: { [llm.type]: buildProviderConfig(llm) }
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
function encodeAgent(def) {
|
|
2325
|
+
if (!def.name) throw new Error("agent: `name` is required.");
|
|
2326
|
+
if (!def.llm) throw new Error(`agent "${def.name}": \`llm\` is required.`);
|
|
2327
|
+
return {
|
|
2328
|
+
...encodeToolsetBase(def, "agent"),
|
|
2329
|
+
type: "agent",
|
|
2330
|
+
agent_settings: buildAgentSettings(def, `agent "${def.name}"`)
|
|
2331
|
+
};
|
|
2332
|
+
}
|
|
2333
|
+
var agentKind = {
|
|
2334
|
+
name: "agent",
|
|
2335
|
+
payloadKey: "toolset",
|
|
2336
|
+
encode: encodeAgent
|
|
2337
|
+
};
|
|
2338
|
+
registerKind(agentKind);
|
|
2339
|
+
function agent(def) {
|
|
2340
|
+
const getCanonical = (opts) => resolveToolsetCanonical(def, opts?.canonical);
|
|
2341
|
+
return brandDef({ ...def, getCanonical }, "agent");
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
// src/kinds/mcp-server.ts
|
|
2345
|
+
function assertTenant(tenant) {
|
|
2346
|
+
if (!/^[A-Za-z0-9-]+$/.test(tenant)) {
|
|
2347
|
+
throw new Error(
|
|
2348
|
+
`mcp server: invalid \`tenant\` ${JSON.stringify(tenant)} \u2014 a tenant name is alphanumeric with dashes (e.g. "xxxx-xxxx-xxxx"). It rides as its own "/tenant/<name>" path pair, so "/" cannot appear in it.`
|
|
2349
|
+
);
|
|
2350
|
+
}
|
|
2351
|
+
return tenant;
|
|
2352
|
+
}
|
|
2353
|
+
function encodeMcpServer(def) {
|
|
2354
|
+
if (!def.name) throw new Error("mcp server: `name` is required.");
|
|
2355
|
+
const owner = `mcpServer "${def.name}"`;
|
|
2356
|
+
const prompts = encodePrimitiveRefs("prompt", def.prompts, owner);
|
|
2357
|
+
const resources = encodePrimitiveRefs("resource", def.resources, owner);
|
|
2358
|
+
const base = {
|
|
2359
|
+
...encodeToolsetBase(def, "mcpServer"),
|
|
2360
|
+
type: "mcp",
|
|
2361
|
+
// Written only when listed: a server with neither keeps the bytes it had
|
|
2362
|
+
// before prompts and resources existed.
|
|
2363
|
+
...prompts.length > 0 ? { prompt: prompts } : {},
|
|
2364
|
+
...resources.length > 0 ? { resource: resources } : {},
|
|
2365
|
+
// Written only when authored: a server without sign-in keeps its bytes.
|
|
2366
|
+
...def.oauth !== void 0 ? { oauth: encodeMcpOauth(owner, def.oauth) } : {}
|
|
2367
|
+
};
|
|
2368
|
+
return def.llm === void 0 ? base : { ...base, agent_settings: buildAgentSettings({ llm: def.llm, output: def.output }, `mcpServer "${def.name}"`) };
|
|
2369
|
+
}
|
|
2370
|
+
var mcpServerKind = {
|
|
2371
|
+
name: "mcp_server",
|
|
2372
|
+
payloadKey: "toolset",
|
|
2373
|
+
encode: encodeMcpServer
|
|
2374
|
+
};
|
|
2375
|
+
registerKind(mcpServerKind);
|
|
2376
|
+
function assertNotResolvedEndpointBase(base) {
|
|
2377
|
+
const shape = /(\/x2\/mcp\/(?:tenant\/[^/]+\/)?[^/]+\/)[^/]+(\/stream)$/i;
|
|
2378
|
+
if (!shape.test(base)) return;
|
|
2379
|
+
const redacted = base.replace(shape, "$1<token>$2");
|
|
2380
|
+
throw new Error(
|
|
2381
|
+
`mcp server: \`getUrl\` was given a base URL that already carries an MCP endpoint path (${redacted}). Pass the INSTANCE base URL, not the result of a previous getUrl() \u2014 resolving twice appends a second "/x2/mcp/<canonical>/<token>/stream".`
|
|
2382
|
+
);
|
|
2383
|
+
}
|
|
2384
|
+
function liftTenantFromBase(base, explicit) {
|
|
2385
|
+
const m = /^((?:https?:\/\/)?[^/]+)\/tenant\/([^/]+)(\/.*)?$/i.exec(base);
|
|
2386
|
+
if (!m) return { base, tenant: explicit };
|
|
2387
|
+
const origin = m[1];
|
|
2388
|
+
const fromBase = m[2];
|
|
2389
|
+
const rest = m[3] ?? "";
|
|
2390
|
+
if (explicit !== void 0 && explicit !== fromBase) {
|
|
2391
|
+
throw new Error(
|
|
2392
|
+
`mcp server: \`getUrl\` was given tenant ${JSON.stringify(explicit)} but the base URL names ${JSON.stringify(fromBase)} (".../tenant/${fromBase}"). Refusing to guess which one you meant \u2014 pass the matching tenant, or a base URL without the "/tenant/<name>" prefix.`
|
|
2393
|
+
);
|
|
2394
|
+
}
|
|
2395
|
+
return { base: `${origin}${rest}`, tenant: assertTenant(fromBase) };
|
|
2396
|
+
}
|
|
2397
|
+
function mcpServer(def) {
|
|
2398
|
+
const getPath = (opts) => {
|
|
2399
|
+
const tenant = opts?.tenant ? `tenant/${assertTenant(opts.tenant)}/` : "";
|
|
2400
|
+
return `/x2/mcp/${tenant}${resolveToolsetCanonical(def, opts?.canonical)}/${opts?.token || "mcp"}/stream`;
|
|
2401
|
+
};
|
|
2402
|
+
const getUrl = (baseUrl, opts) => {
|
|
2403
|
+
const base = (baseUrl ?? "").trim().replace(/\/+$/, "");
|
|
2404
|
+
if (!base) throw new Error('mcp server: `getUrl` needs a base URL (e.g. "https://x.dev.xano.io").');
|
|
2405
|
+
assertNotResolvedEndpointBase(base);
|
|
2406
|
+
const lifted = liftTenantFromBase(base, opts?.tenant);
|
|
2407
|
+
return `${lifted.base}${getPath({ ...opts, tenant: lifted.tenant })}`;
|
|
2408
|
+
};
|
|
2409
|
+
return brandDef({ ...def, getPath, getUrl }, "mcp_server");
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
// src/kinds/knowledge.ts
|
|
2413
|
+
var KNOWLEDGE_FILE = /* @__PURE__ */ Symbol.for("xanosdk.knowledge.file");
|
|
2414
|
+
var KNOWLEDGE_DIR = /* @__PURE__ */ Symbol.for("xanosdk.knowledge.dir");
|
|
2415
|
+
function isOsMetadataFile(path, binary) {
|
|
2416
|
+
const base = path.slice(path.lastIndexOf("/") + 1);
|
|
2417
|
+
return binary && /^(?:\.DS_Store|Thumbs\.db|desktop\.ini|\._.*)$/i.test(base);
|
|
2418
|
+
}
|
|
2419
|
+
function isOsMetadataRow(row) {
|
|
2420
|
+
const { path, content } = row ?? {};
|
|
2421
|
+
return typeof path === "string" && isOsMetadataFile(path, String(content ?? "").includes("\0"));
|
|
2422
|
+
}
|
|
2423
|
+
function knowledgeFile(path, base) {
|
|
2424
|
+
return { [KNOWLEDGE_FILE]: { path, base: typeof base === "string" ? base : base.href } };
|
|
2425
|
+
}
|
|
2426
|
+
function knowledgeDir(path, base) {
|
|
2427
|
+
return { [KNOWLEDGE_DIR]: { path, base: typeof base === "string" ? base : base.href } };
|
|
2428
|
+
}
|
|
2429
|
+
function isKnowledgeFileSource(v) {
|
|
2430
|
+
return typeof v === "object" && v !== null && KNOWLEDGE_FILE in v;
|
|
2431
|
+
}
|
|
2432
|
+
function isKnowledgeDirSource(v) {
|
|
2433
|
+
return typeof v === "object" && v !== null && KNOWLEDGE_DIR in v;
|
|
2434
|
+
}
|
|
2435
|
+
function encodeKnowledge(def) {
|
|
2436
|
+
if (!def.name) {
|
|
2437
|
+
throw new Error("knowledge kind: `name` is required.");
|
|
2438
|
+
}
|
|
2439
|
+
if (!isKnowledgeFileSource(def.body)) {
|
|
2440
|
+
throw new Error(
|
|
2441
|
+
`knowledge "${def.name}": \`body\` must be a knowledgeFile("./x.md", import.meta.url) marker. A knowledge body is authored as a markdown FILE, not a string.`
|
|
2442
|
+
);
|
|
2443
|
+
}
|
|
2444
|
+
if (def.refs !== void 0 && !isKnowledgeDirSource(def.refs)) {
|
|
2445
|
+
throw new Error(
|
|
2446
|
+
`knowledge "${def.name}": \`refs\` must be a knowledgeDir("./dir", import.meta.url) marker.`
|
|
2447
|
+
);
|
|
2448
|
+
}
|
|
2449
|
+
return {
|
|
2450
|
+
name: def.name,
|
|
2451
|
+
description: def.description ?? "",
|
|
2452
|
+
// Bodies are read in the compile path; see the module header.
|
|
2453
|
+
content: "",
|
|
2454
|
+
// Not authorable: a user-scoped item is private to one UI user and is
|
|
2455
|
+
// excluded from branch clone and merge, so it has no meaning in source.
|
|
2456
|
+
scope: "workspace",
|
|
2457
|
+
mode: def.mode ?? "auto",
|
|
2458
|
+
knowledge_type: def.type ?? "skill",
|
|
2459
|
+
enabled: def.enabled ?? true,
|
|
2460
|
+
// Instance-owned state, gated on a permission this SDK does not model.
|
|
2461
|
+
locked: false,
|
|
2462
|
+
// Derived by the platform from the stored reference files — never authored.
|
|
2463
|
+
references: [],
|
|
2464
|
+
// Deferred: linked refs never reach an agent's prompt, and the bulk
|
|
2465
|
+
// transport does not carry them.
|
|
2466
|
+
linked_refs: [],
|
|
2467
|
+
tag: encodeTags(def.tags)
|
|
2468
|
+
};
|
|
2469
|
+
}
|
|
2470
|
+
function knowledge(def) {
|
|
2471
|
+
return brandDef(def, "knowledge");
|
|
2472
|
+
}
|
|
2473
|
+
var knowledgeKind = {
|
|
2474
|
+
name: "knowledge",
|
|
2475
|
+
payloadKey: "knowledge",
|
|
2476
|
+
encode: encodeKnowledge
|
|
2477
|
+
};
|
|
2478
|
+
registerKind(knowledgeKind);
|
|
2479
|
+
|
|
2480
|
+
// src/kinds/realtime-server.ts
|
|
2481
|
+
function resolveRealtimeServerCanonical(def, override) {
|
|
2482
|
+
return resolveCanonicalToken("realtime server", "realtime_server", "getCanonical", def, override);
|
|
2483
|
+
}
|
|
2484
|
+
function encodeRealtimeServer(def) {
|
|
2485
|
+
if (!def.name) throw new Error("realtimeServer: `name` is required.");
|
|
2486
|
+
assertCanonical(`realtimeServer "${def.name}"`, def.canonical);
|
|
2487
|
+
return {
|
|
2488
|
+
name: def.name,
|
|
2489
|
+
description: def.description ?? "",
|
|
2490
|
+
canonical: def.canonical ?? "",
|
|
2491
|
+
enabled: def.enabled ?? false,
|
|
2492
|
+
history: encodeContainerHistory("message", def.history),
|
|
2493
|
+
...def.middleware !== void 0 ? { middleware: buildMiddlewareBlock(def.middleware) } : {},
|
|
2494
|
+
tag: encodeTags(def.tags)
|
|
2495
|
+
};
|
|
2496
|
+
}
|
|
2497
|
+
var realtimeServerKind = {
|
|
2498
|
+
name: "realtime_server",
|
|
2499
|
+
payloadKey: "realtime_server",
|
|
2500
|
+
encode: encodeRealtimeServer
|
|
2501
|
+
};
|
|
2502
|
+
registerKind(realtimeServerKind);
|
|
2503
|
+
function assertTenant2(tenant) {
|
|
2504
|
+
if (!/^[A-Za-z0-9-]+$/.test(tenant)) {
|
|
2505
|
+
throw new Error(
|
|
2506
|
+
`realtime server: invalid \`tenant\` ${JSON.stringify(tenant)} \u2014 a tenant name is alphanumeric with dashes (e.g. "xxxx-xxxx-xxxx"). It rides as a "<tenant>:<canonical>" prefix, so ":" and "/" cannot appear in it.`
|
|
2507
|
+
);
|
|
2508
|
+
}
|
|
2509
|
+
return tenant;
|
|
2510
|
+
}
|
|
2511
|
+
function assertNotResolvedSocketBase(fn, socketBase, given) {
|
|
2512
|
+
if (!/\/ws\/[^/]+$/i.test(socketBase)) return;
|
|
2513
|
+
throw new Error(
|
|
2514
|
+
`realtime server: \`${fn}\` was given a base URL that already carries a socket path (${given}). Pass the http(s) INSTANCE base URL, not the result of a previous getUrl()/socketUrl() \u2014 resolving twice appends a second "/ws/<canonical>" and drops the tenant.`
|
|
2515
|
+
);
|
|
2516
|
+
}
|
|
2517
|
+
function assertInstanceBase(fn, given) {
|
|
2518
|
+
const problem = /[?#]/.test(given) ? "a query or fragment" : /\/api:/i.test(given) ? "an API group's /api:<\u2026> path" : void 0;
|
|
2519
|
+
if (problem === void 0) return;
|
|
2520
|
+
throw new Error(
|
|
2521
|
+
`realtime server: \`${fn}\` was given a base URL with ${problem} (${given}). Pass the INSTANCE base URL \u2014 "https://<host>", or "https://<host>/tenant/<name>" \u2014 and the socket path is appended to it.`
|
|
2522
|
+
);
|
|
2523
|
+
}
|
|
2524
|
+
function liftTenantFromBase2(socketBase, explicit) {
|
|
2525
|
+
const m = /^(wss?:\/\/[^/]+)\/tenant\/([^/]+)(\/.*)?$/i.exec(socketBase);
|
|
2526
|
+
if (!m) return { base: socketBase, tenant: explicit };
|
|
2527
|
+
const origin = m[1];
|
|
2528
|
+
const fromBase = m[2];
|
|
2529
|
+
const rest = m[3] ?? "";
|
|
2530
|
+
if (explicit !== void 0 && explicit !== fromBase) {
|
|
2531
|
+
throw new Error(
|
|
2532
|
+
`realtime server: \`getUrl\` was given tenant ${JSON.stringify(explicit)} but the base URL names ${JSON.stringify(fromBase)} (".../tenant/${fromBase}"). Refusing to guess which one you meant \u2014 pass the matching tenant, or a base URL without the "/tenant/<name>" prefix.`
|
|
2533
|
+
);
|
|
2534
|
+
}
|
|
2535
|
+
return { base: `${origin}${rest}`, tenant: assertTenant2(fromBase) };
|
|
2536
|
+
}
|
|
2537
|
+
function realtimeServer(def) {
|
|
2538
|
+
const getCanonical = (opts) => resolveRealtimeServerCanonical(def, opts?.canonical);
|
|
2539
|
+
const getPath = (opts) => {
|
|
2540
|
+
const canonical = getCanonical(opts);
|
|
2541
|
+
const prefix = opts?.tenant ? `${assertTenant2(opts.tenant)}:` : "";
|
|
2542
|
+
return `/ws/${prefix}${canonical}`;
|
|
2543
|
+
};
|
|
2544
|
+
const getUrl = (baseUrl, opts) => {
|
|
2545
|
+
const base = baseUrl.trim().replace(/\/+$/, "");
|
|
2546
|
+
if (!base) throw new Error('realtimeServer: `getUrl` needs a base URL (e.g. "https://x.dev.xano.io").');
|
|
2547
|
+
const socketBase = /^wss?:\/\//i.test(base) ? base : /^https?:\/\//i.test(base) ? base.replace(/^http/i, "ws") : `wss://${base}`;
|
|
2548
|
+
assertNotResolvedSocketBase("getUrl", socketBase, base);
|
|
2549
|
+
assertInstanceBase("getUrl", base);
|
|
2550
|
+
const lifted = liftTenantFromBase2(socketBase, opts?.tenant);
|
|
2551
|
+
return `${lifted.base}${getPath({ ...opts, tenant: lifted.tenant })}`;
|
|
2552
|
+
};
|
|
2553
|
+
return brandDef({ ...def, getCanonical, getPath, getUrl }, "realtime_server");
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
// src/kinds/realtime-message.ts
|
|
2557
|
+
function resolveHost(def) {
|
|
2558
|
+
const context = `realtimeMessage "${def.name}"`;
|
|
2559
|
+
if (!def.channel) throw new Error(`${context}: \`channel\` is required.`);
|
|
2560
|
+
const handle = typeof def.channel === "string" ? void 0 : def.channel;
|
|
2561
|
+
if (!handle && def.server === void 0) {
|
|
2562
|
+
throw new Error(
|
|
2563
|
+
`${context}: \`server\` is required when \`channel\` is a bare path \u2014 a channel path is unique only within its realtime server, so "${def.channel}" alone is ambiguous. Pass the \`realtimeChannel()\` handle instead and the server comes with it.`
|
|
2564
|
+
);
|
|
2565
|
+
}
|
|
2566
|
+
const server = def.server ?? handle.server;
|
|
2567
|
+
const serverName = realtimeServerRefName(context, server);
|
|
2568
|
+
if (handle && def.server !== void 0) {
|
|
2569
|
+
const fromHandle = realtimeServerRefName(context, handle.server);
|
|
2570
|
+
if (fromHandle !== serverName) {
|
|
2571
|
+
throw new Error(
|
|
2572
|
+
`${context}: \`server\` is "${serverName}" but the channel handle belongs to "${fromHandle}". Remove \`server\` (the handle already carries it) or bind the message to a channel on "${serverName}".`
|
|
2573
|
+
);
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
return {
|
|
2577
|
+
channel: handle ?? { name: def.channel, server },
|
|
2578
|
+
server,
|
|
2579
|
+
serverName
|
|
2580
|
+
};
|
|
2581
|
+
}
|
|
2582
|
+
function realtimeMessageGuid(def) {
|
|
2583
|
+
if (def.guid) return def.guid;
|
|
2584
|
+
const { channel, serverName } = resolveHost(def);
|
|
2585
|
+
return deriveGuid("message", realtimeMessageSeedName(serverName, channel.name, def.name));
|
|
2586
|
+
}
|
|
2587
|
+
function encodeRealtimeMessage(def) {
|
|
2588
|
+
if (!def.name) throw new Error("realtimeMessage: `name` is required.");
|
|
2589
|
+
assertStoredName(`realtimeMessage "${def.name}"`, def.name, "plain");
|
|
2590
|
+
const host = resolveHost(def);
|
|
2591
|
+
const channelId = realtimeChannelGuid(host.channel);
|
|
2592
|
+
const serverId = resolveRealtimeServerRef(`realtimeMessage "${def.name}"`, host.server);
|
|
2593
|
+
return {
|
|
2594
|
+
name: def.name,
|
|
2595
|
+
description: def.description ?? "",
|
|
2596
|
+
active: def.active ?? true,
|
|
2597
|
+
channel: { id: channelId },
|
|
2598
|
+
server: { id: serverId },
|
|
2599
|
+
auth: resolveAuthRef("realtimeMessage", def.name, def.auth),
|
|
2600
|
+
deliver_to: def.deliverTo ?? "channel",
|
|
2601
|
+
input: Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d)),
|
|
2602
|
+
output: [],
|
|
2603
|
+
middleware: buildMiddlewareBlock(def.middleware),
|
|
2604
|
+
run: encodeStack("realtime message", def.name, def.stack),
|
|
2605
|
+
result: encodeResponse(def.response),
|
|
2606
|
+
history: encodeHistory("message", def.history),
|
|
2607
|
+
disabled: def.disabled ?? false,
|
|
2608
|
+
tag: encodeTags(def.tags)
|
|
2609
|
+
};
|
|
2610
|
+
}
|
|
2611
|
+
var realtimeMessageKind = {
|
|
2612
|
+
name: "message",
|
|
2613
|
+
payloadKey: "message",
|
|
2614
|
+
encode: encodeRealtimeMessage,
|
|
2615
|
+
guidOf: (def) => realtimeMessageGuid(def)
|
|
2616
|
+
};
|
|
2617
|
+
registerKind(realtimeMessageKind);
|
|
2618
|
+
function realtimeMessage(def) {
|
|
2619
|
+
return brandDef(def, "message");
|
|
2620
|
+
}
|
|
2621
|
+
|
|
2622
|
+
// src/kinds/task.ts
|
|
2623
|
+
var SCHEDULE_INSTANT = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:?\d{2})$/;
|
|
2624
|
+
function assertScheduleInstant(field2, value) {
|
|
2625
|
+
if (value === void 0) return;
|
|
2626
|
+
const wellShaped = SCHEDULE_INSTANT.test(value);
|
|
2627
|
+
const parsed = wellShaped ? Date.parse(value) : NaN;
|
|
2628
|
+
if (wellShaped && !Number.isNaN(parsed) && isCalendarDate(value)) return;
|
|
2629
|
+
if (wellShaped) {
|
|
2630
|
+
throw new Error(
|
|
2631
|
+
`task schedule: \`${field2}\` is ${JSON.stringify(value)}, which names a date or time that does not exist \u2014 the month must be 01\u201312, the day one that month has, the hour 00\u201323, and minutes/seconds 00\u201359.`
|
|
2632
|
+
);
|
|
2633
|
+
}
|
|
2634
|
+
throw new Error(
|
|
2635
|
+
`task schedule: \`${field2}\` is ${JSON.stringify(value)}, which is not a schedule instant. Write it as "2026-01-01T00:00:00Z" \u2014 a date, a "T" (or a space), a time, and a ZONE ("Z", "+02:00" or "+0000"). The zone is the part most often left off, and without it the value is not an instant at all. The engine stores this string verbatim and does not validate it: a value it cannot parse deploys successfully and the task then never fires, which is indistinguishable from a task whose time has not come yet.`
|
|
2636
|
+
);
|
|
2637
|
+
}
|
|
2638
|
+
function isCalendarDate(value) {
|
|
2639
|
+
const [y, m, d] = value.slice(0, 10).split("-").map(Number);
|
|
2640
|
+
const day = new Date(Date.UTC(y, m - 1, d));
|
|
2641
|
+
return day.getUTCFullYear() === y && day.getUTCMonth() === m - 1 && day.getUTCDate() === d;
|
|
2642
|
+
}
|
|
2643
|
+
function encodeSchedule(def) {
|
|
2644
|
+
assertScheduleInstant("startsOn", def.startsOn);
|
|
2645
|
+
assertScheduleInstant("endsOn", def.endsOn);
|
|
2646
|
+
const repeats = def.repeatEnabled ?? def.freq != null;
|
|
2647
|
+
const ends = def.endsEnabled ?? def.endsOn != null;
|
|
2648
|
+
const freq = def.freq ?? 86400;
|
|
2649
|
+
if ((repeats || def.freq != null) && !(typeof freq === "number" && Number.isInteger(freq) && freq > 0)) {
|
|
2650
|
+
throw new Error(
|
|
2651
|
+
`task schedule: \`freq\` is ${typeof freq === "number" ? String(freq) : JSON.stringify(freq)} \u2014 a repeat interval is a positive whole number of seconds (3600 hourly, 86400 daily). Omit \`freq\` for a one-off run.`
|
|
2652
|
+
);
|
|
2653
|
+
}
|
|
2654
|
+
if (ends && def.endsOn !== void 0 && Date.parse(def.endsOn) < Date.parse(def.startsOn)) {
|
|
2655
|
+
throw new Error(
|
|
2656
|
+
`task schedule: \`endsOn\` (${def.endsOn}) is before \`startsOn\` (${def.startsOn}), so the task never runs. Set \`endsOn\` after \`startsOn\`, or drop it to repeat indefinitely.`
|
|
2657
|
+
);
|
|
2658
|
+
}
|
|
2659
|
+
return {
|
|
2660
|
+
starts_on: def.startsOn,
|
|
2661
|
+
repeat: {
|
|
2662
|
+
enabled: repeats,
|
|
2663
|
+
ends: { enabled: ends, on: def.endsOn ?? def.startsOn },
|
|
2664
|
+
freq
|
|
2665
|
+
}
|
|
2666
|
+
};
|
|
2667
|
+
}
|
|
2668
|
+
function scheduleList(def) {
|
|
2669
|
+
const list = def.schedule;
|
|
2670
|
+
if (list === void 0 || list === null) return [];
|
|
2671
|
+
const bad = Array.isArray(list) ? list.findIndex((e) => typeof e !== "object" || e === null || Array.isArray(e)) : -1;
|
|
2672
|
+
if (!Array.isArray(list) || bad !== -1) {
|
|
2673
|
+
const at = Array.isArray(list) ? `schedule[${bad}]` : "schedule";
|
|
2674
|
+
const got = Array.isArray(list) ? list[bad] : list;
|
|
2675
|
+
throw new Error(
|
|
2676
|
+
`task "${def.name}": \`${at}\` must be ${Array.isArray(list) ? "a { startsOn, freq } entry" : "a list of { startsOn, freq } entries"} \u2014 got ${describeEntry(got)}.`
|
|
2677
|
+
);
|
|
2678
|
+
}
|
|
2679
|
+
return list;
|
|
2680
|
+
}
|
|
2681
|
+
function encodeTask(def) {
|
|
2682
|
+
if (!def.name) throw new Error("task: `name` is required.");
|
|
2683
|
+
return {
|
|
2684
|
+
name: def.name,
|
|
2685
|
+
description: def.description ?? "",
|
|
2686
|
+
docs: def.docs ?? "",
|
|
2687
|
+
datasource: def.datasource ?? "",
|
|
2688
|
+
active: def.active ?? true,
|
|
2689
|
+
middleware: buildMiddlewareBlock(def.middleware),
|
|
2690
|
+
tag: encodeTags(def.tags),
|
|
2691
|
+
history: encodeHistory("task", def.history),
|
|
2692
|
+
run: encodeStack("task", def.name, def.stack),
|
|
2693
|
+
schedule: encodeTaskSchedule(def)
|
|
2694
|
+
};
|
|
2695
|
+
}
|
|
2696
|
+
function encodeTaskSchedule(def) {
|
|
2697
|
+
return scheduleList(def).map((entry, i) => {
|
|
2698
|
+
try {
|
|
2699
|
+
return encodeSchedule(entry);
|
|
2700
|
+
} catch (err) {
|
|
2701
|
+
throw new Error(err.message.replace(/^task schedule:/, `task "${def.name}" \`schedule[${i}]\`:`), { cause: err });
|
|
2702
|
+
}
|
|
2703
|
+
});
|
|
2704
|
+
}
|
|
2705
|
+
var taskKind = {
|
|
2706
|
+
name: "task",
|
|
2707
|
+
payloadKey: "task",
|
|
2708
|
+
encode: encodeTask
|
|
2709
|
+
};
|
|
2710
|
+
registerKind(taskKind);
|
|
2711
|
+
function task(def) {
|
|
2712
|
+
const list = def.schedule;
|
|
2713
|
+
if (Array.isArray(list) && list.every((e) => typeof e === "object" && e !== null && !Array.isArray(e))) encodeTaskSchedule(def);
|
|
2714
|
+
return brandDef(def, "task");
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
// src/kinds/workflow-test.ts
|
|
2718
|
+
function encodeWorkflowTest(def) {
|
|
2719
|
+
if (!def.name) throw new Error("workflowTest: `name` is required.");
|
|
2720
|
+
const datasource = def.datasource ?? "";
|
|
2721
|
+
return {
|
|
2722
|
+
name: def.name,
|
|
2723
|
+
description: def.description ?? "",
|
|
2724
|
+
docs: def.docs ?? "",
|
|
2725
|
+
datasource,
|
|
2726
|
+
active: def.active ?? true,
|
|
2727
|
+
tag: encodeTags(def.tags),
|
|
2728
|
+
run: encodeStack("workflowTest", def.name, def.stack)
|
|
2729
|
+
};
|
|
2730
|
+
}
|
|
2731
|
+
var workflowTestKind = {
|
|
2732
|
+
name: "workflow_test",
|
|
2733
|
+
payloadKey: "workflow_test",
|
|
2734
|
+
encode: encodeWorkflowTest
|
|
2735
|
+
};
|
|
2736
|
+
registerKind(workflowTestKind);
|
|
2737
|
+
function workflowTest(def) {
|
|
2738
|
+
return brandDef(def, "workflow_test");
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2741
|
+
// src/kinds/middleware.ts
|
|
2742
|
+
function encodeMiddleware(def) {
|
|
2743
|
+
if (!def.name) throw new Error("middleware: `name` is required.");
|
|
2744
|
+
const xdo = {
|
|
2745
|
+
name: def.name,
|
|
2746
|
+
description: def.description ?? "",
|
|
2747
|
+
docs: def.docs ?? "",
|
|
2748
|
+
result_type: def.resultStrategy ?? "merge",
|
|
2749
|
+
exception: def.exceptionPolicy ?? "rethrow",
|
|
2750
|
+
history: encodeHistory("middleware", def.history),
|
|
2751
|
+
tag: encodeTags(def.tags),
|
|
2752
|
+
shared_workspace: { is_shared: false },
|
|
2753
|
+
input: Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d)),
|
|
2754
|
+
result: encodeResponse(def.response),
|
|
2755
|
+
run: encodeStack("middleware", def.name, def.stack),
|
|
2756
|
+
test: encodeTests(def.tests, "middleware", def.name)
|
|
2757
|
+
};
|
|
2758
|
+
resolveMockKeys(xdo.run, xdo.test, "middleware", def.name);
|
|
2759
|
+
return xdo;
|
|
2760
|
+
}
|
|
2761
|
+
var middlewareKind = {
|
|
2762
|
+
name: "middleware",
|
|
2763
|
+
payloadKey: "middleware",
|
|
2764
|
+
encode: encodeMiddleware
|
|
2765
|
+
};
|
|
2766
|
+
registerKind(middlewareKind);
|
|
2767
|
+
function middlewareImpl(def) {
|
|
2768
|
+
return brandDef(def, "middleware");
|
|
2769
|
+
}
|
|
2770
|
+
var middleware = Object.assign(middlewareImpl, { clear });
|
|
2771
|
+
|
|
2772
|
+
// src/kinds/addon.ts
|
|
2773
|
+
function buildContext(def) {
|
|
2774
|
+
const ctx = { ...def.context ?? {} };
|
|
2775
|
+
if (def.table !== void 0 && ctx.dbo === void 0) {
|
|
2776
|
+
ctx.dbo = def.table === null ? { as: def.tableAlias ?? "", id: "" } : {
|
|
2777
|
+
id: resolveRef("dbo", def.table),
|
|
2778
|
+
// Absent unless authored — writing it unconditionally would change the
|
|
2779
|
+
// bytes of every addon that omits it today.
|
|
2780
|
+
...def.tableAlias !== void 0 ? { as: def.tableAlias } : {}
|
|
2781
|
+
};
|
|
2782
|
+
}
|
|
2783
|
+
if (def.where !== void 0 && ctx.search === void 0) {
|
|
2784
|
+
const search = encodeSearch(def.where, void 0, `addon "${def.name}"`);
|
|
2785
|
+
if (search !== void 0) ctx.search = search;
|
|
2786
|
+
}
|
|
2787
|
+
const explicitReturn = ctx.return;
|
|
2788
|
+
if (def.cardinality !== void 0 && explicitReturn?.type !== void 0 && explicitReturn.type !== def.cardinality) {
|
|
2789
|
+
throw new Error(
|
|
2790
|
+
`addon: cardinality:"${def.cardinality}" conflicts with an explicit context.return.type "${explicitReturn.type}" \u2014 they shape the graft differently. Set one, not both.`
|
|
2791
|
+
);
|
|
2792
|
+
}
|
|
2793
|
+
const sort = encodeSort(def.sort, `addon "${def.name}"`);
|
|
2794
|
+
const cardinality = def.cardinality ?? "list";
|
|
2795
|
+
if ((cardinality === "count" || cardinality === "exists") && sort.length) {
|
|
2796
|
+
throw new Error(
|
|
2797
|
+
`addon: sort has no effect on cardinality:"${cardinality}" \u2014 it returns one number or boolean, not rows. Drop the sort.`
|
|
2798
|
+
);
|
|
2799
|
+
}
|
|
2800
|
+
if (ctx.return === void 0 && (cardinality === "list" || cardinality === "single") && sort.length) {
|
|
2801
|
+
ctx.return = { type: cardinality, [cardinality]: { sort } };
|
|
2802
|
+
} else if (def.cardinality !== void 0 && def.cardinality !== "list" && ctx.return === void 0) {
|
|
2803
|
+
if (def.cardinality === "aggregate") {
|
|
2804
|
+
const addonAlias = def.table === void 0 || def.table === null ? ctx.dbo?.as ?? "" : typeof def.table === "string" ? def.table : def.table.name;
|
|
2805
|
+
ctx.return = {
|
|
2806
|
+
type: "aggregate",
|
|
2807
|
+
aggregate: {
|
|
2808
|
+
sort: encodeSort(def.sort, `addon "${def.name}"`),
|
|
2809
|
+
eval: encodeEval(qualifyAggregateEvals(def.eval, addonAlias, "eval")) ?? [],
|
|
2810
|
+
group: encodeEval(qualifyAggregateEvals(def.group, addonAlias, "group")) ?? []
|
|
2811
|
+
}
|
|
2812
|
+
};
|
|
2813
|
+
} else {
|
|
2814
|
+
ctx.return = { type: def.cardinality };
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2817
|
+
return ctx;
|
|
2818
|
+
}
|
|
2819
|
+
function buildOutput(output) {
|
|
2820
|
+
if (!output) return { customize: false, items: [] };
|
|
2821
|
+
if (Array.isArray(output)) {
|
|
2822
|
+
return { customize: true, items: output.map((name) => ({ name, children: [] })) };
|
|
2823
|
+
}
|
|
2824
|
+
const block = output;
|
|
2825
|
+
return { customize: block.customize ?? false, items: block.items ?? [] };
|
|
2826
|
+
}
|
|
2827
|
+
function encodeAddon(def) {
|
|
2828
|
+
if (!def.name) throw new Error("addon: `name` is required.");
|
|
2829
|
+
return {
|
|
2830
|
+
name: def.name,
|
|
2831
|
+
description: def.description ?? "",
|
|
2832
|
+
context: buildContext(def),
|
|
2833
|
+
output: buildOutput(def.output),
|
|
2834
|
+
tag: encodeTags(def.tags),
|
|
2835
|
+
input: Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d))
|
|
2836
|
+
};
|
|
2837
|
+
}
|
|
2838
|
+
var addonKind = {
|
|
2839
|
+
name: "addon",
|
|
2840
|
+
payloadKey: "addon",
|
|
2841
|
+
encode: encodeAddon
|
|
2842
|
+
};
|
|
2843
|
+
registerKind(addonKind);
|
|
2844
|
+
function addon(def) {
|
|
2845
|
+
return brandDef(def, "addon");
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
// src/kinds/function.ts
|
|
2849
|
+
function encodeFunction(fn) {
|
|
2850
|
+
if (!fn.name) {
|
|
2851
|
+
throw new Error("function kind: `name` is required.");
|
|
2852
|
+
}
|
|
2853
|
+
warnUnboundReturn("function", fn.name, fn.stack, fn.response);
|
|
2854
|
+
const xdo = {
|
|
2855
|
+
name: fn.name,
|
|
2856
|
+
description: fn.description ?? "",
|
|
2857
|
+
docs: fn.docs ?? "",
|
|
2858
|
+
workspace: { id: fn.workspace ?? 0 },
|
|
2859
|
+
branch: { id: 0 },
|
|
2860
|
+
cache: defaultCache(fn.cache),
|
|
2861
|
+
history: encodeHistory("function", fn.history),
|
|
2862
|
+
middleware: buildMiddlewareBlock(fn.middleware),
|
|
2863
|
+
tag: encodeTags(fn.tags),
|
|
2864
|
+
input: Object.entries(fn.input ?? {}).map(
|
|
2865
|
+
([name, descriptor]) => encodeInput(name, descriptor)
|
|
2866
|
+
),
|
|
2867
|
+
result: encodeResponse(fn.response),
|
|
2868
|
+
run: encodeStack("function", fn.name, fn.stack),
|
|
2869
|
+
test: encodeTests(fn.tests, "function", fn.name),
|
|
2870
|
+
market_item: { id: 0, version: 0, guid: "" },
|
|
2871
|
+
shared_workspace: { is_shared: false }
|
|
2872
|
+
};
|
|
2873
|
+
resolveMockKeys(xdo.run, xdo.test, "function", fn.name);
|
|
2874
|
+
return xdo;
|
|
2875
|
+
}
|
|
2876
|
+
var functionKind = {
|
|
2877
|
+
name: "function",
|
|
2878
|
+
payloadKey: "function",
|
|
2879
|
+
encode: encodeFunction
|
|
2880
|
+
};
|
|
2881
|
+
registerKind(functionKind);
|
|
2882
|
+
|
|
2883
|
+
// src/kinds/all.ts
|
|
2884
|
+
var ALL_KINDS = [
|
|
2885
|
+
functionKind,
|
|
2886
|
+
triggerKind,
|
|
2887
|
+
toolKind,
|
|
2888
|
+
promptKind,
|
|
2889
|
+
resourceKind,
|
|
2890
|
+
mcpServerKind,
|
|
2891
|
+
agentKind,
|
|
2892
|
+
tableKind,
|
|
2893
|
+
queryKind,
|
|
2894
|
+
apiGroupKind,
|
|
2895
|
+
taskKind,
|
|
2896
|
+
workflowTestKind,
|
|
2897
|
+
middlewareKind,
|
|
2898
|
+
addonKind,
|
|
2899
|
+
microserviceKind,
|
|
2900
|
+
realtimeServerKind,
|
|
2901
|
+
realtimeChannelKind,
|
|
2902
|
+
realtimeMessageKind,
|
|
2903
|
+
knowledgeKind,
|
|
2904
|
+
workspaceKind
|
|
2905
|
+
];
|
|
2906
|
+
function registerAllKinds() {
|
|
2907
|
+
for (const kind of ALL_KINDS) registerKind(kind);
|
|
2908
|
+
}
|
|
2909
|
+
registerAllKinds();
|
|
2910
|
+
|
|
2911
|
+
// src/emit/emit.ts
|
|
2912
|
+
function emit(def, opts = {}) {
|
|
2913
|
+
registerAllKinds();
|
|
2914
|
+
registerAllStatements();
|
|
2915
|
+
const kind = standaloneDefKind(def);
|
|
2916
|
+
if (kind === void 0) {
|
|
2917
|
+
const name = def?.name;
|
|
2918
|
+
throw new Error(
|
|
2919
|
+
`emit: cannot tell what kind of def${typeof name === "string" ? ` "${name}"` : ""} this is \u2014 nothing marks it as a function, table, query, task, tool, agent, \u2026. Build it with its factory (\`defineFunction({...})\`, \`table({...})\`, \`task({...})\`, \u2026) rather than as an object literal or a spread copy.`
|
|
2920
|
+
);
|
|
2921
|
+
}
|
|
2922
|
+
const { entry, warnings } = new Xano().encodeEntry(kind, def, {
|
|
2923
|
+
...opts.hostedFiles !== void 0 ? { hostedFiles: opts.hostedFiles } : {},
|
|
2924
|
+
...opts.documentationTokens !== void 0 ? { documentationTokens: opts.documentationTokens } : {}
|
|
2925
|
+
});
|
|
2926
|
+
for (const warning of warnings) emitDiagnostic(warning);
|
|
2927
|
+
return JSON.stringify(entry, null, opts.indent ?? 2);
|
|
2928
|
+
}
|
|
2929
|
+
function serializeBundle(bundle, opts = {}) {
|
|
2930
|
+
return JSON.stringify(bundle, null, opts.indent ?? 2);
|
|
2931
|
+
}
|
|
2932
|
+
function emitBundle(xano, opts = {}) {
|
|
2933
|
+
return serializeBundle(xano.export({ strict: opts.strict }), opts);
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
export {
|
|
2937
|
+
setVar,
|
|
2938
|
+
updateVar,
|
|
2939
|
+
returnValue,
|
|
2940
|
+
die,
|
|
2941
|
+
debugLog,
|
|
2942
|
+
foreachBreak,
|
|
2943
|
+
foreachContinue,
|
|
2944
|
+
foreachRemove,
|
|
2945
|
+
forLoop,
|
|
2946
|
+
foreachLoop,
|
|
2947
|
+
whileLoop,
|
|
2948
|
+
group,
|
|
2949
|
+
switchCase,
|
|
2950
|
+
switchStatement,
|
|
2951
|
+
tryCatch,
|
|
2952
|
+
functionRun,
|
|
2953
|
+
functionCall,
|
|
2954
|
+
apiCall,
|
|
2955
|
+
taskCall,
|
|
2956
|
+
toolCall,
|
|
2957
|
+
triggerCall,
|
|
2958
|
+
middlewareCall,
|
|
2959
|
+
addonCall,
|
|
2960
|
+
actionCall,
|
|
2961
|
+
actionPackageCall,
|
|
2962
|
+
workflowTestCall,
|
|
2963
|
+
aiAgentRun,
|
|
2964
|
+
cloudJob,
|
|
2965
|
+
cloudJobAwait,
|
|
2966
|
+
cloudJobStatus,
|
|
2967
|
+
arrayMap,
|
|
2968
|
+
arrayUnion,
|
|
2969
|
+
comment,
|
|
2970
|
+
getRawInput,
|
|
2971
|
+
postProcess,
|
|
2972
|
+
realtimeEvent,
|
|
2973
|
+
createAuthToken,
|
|
2974
|
+
expectToThrow,
|
|
2975
|
+
ipLookup,
|
|
2976
|
+
mathAdd,
|
|
2977
|
+
mathSub,
|
|
2978
|
+
mathMul,
|
|
2979
|
+
mathDiv,
|
|
2980
|
+
bitwiseAnd,
|
|
2981
|
+
bitwiseOr,
|
|
2982
|
+
bitwiseXor,
|
|
2983
|
+
textAppend,
|
|
2984
|
+
textPrepend,
|
|
2985
|
+
objectKeys,
|
|
2986
|
+
objectValues,
|
|
2987
|
+
objectEntries,
|
|
2988
|
+
GENERATED_STATEMENT_NAMES,
|
|
2989
|
+
STORAGE_ACCESS,
|
|
2990
|
+
HEADER_DUPLICATES,
|
|
2991
|
+
s,
|
|
2992
|
+
encodeRealtimeChannel,
|
|
2993
|
+
realtimeChannelKind,
|
|
2994
|
+
channelPathParams,
|
|
2995
|
+
realtimeChannel,
|
|
2996
|
+
realtimeChannelGuid,
|
|
2997
|
+
encodeTrigger,
|
|
2998
|
+
tableTrigger,
|
|
2999
|
+
realtimeTrigger,
|
|
3000
|
+
realtimeServerTrigger,
|
|
3001
|
+
realtimeChannelTrigger,
|
|
3002
|
+
mcpServerTrigger,
|
|
3003
|
+
agentTrigger,
|
|
3004
|
+
workspaceTrigger,
|
|
3005
|
+
errorTrigger,
|
|
3006
|
+
triggerKind,
|
|
3007
|
+
TOOL_ANNOTATION_WIRE,
|
|
3008
|
+
encodeTool,
|
|
3009
|
+
toolKind,
|
|
3010
|
+
tool,
|
|
3011
|
+
encodeToolRefs,
|
|
3012
|
+
resolveToolsetCanonical,
|
|
3013
|
+
encodeToolsetBase,
|
|
3014
|
+
prompt,
|
|
3015
|
+
resource,
|
|
3016
|
+
encodeAgent,
|
|
3017
|
+
agentKind,
|
|
3018
|
+
agent,
|
|
3019
|
+
encodeMcpServer,
|
|
3020
|
+
mcpServerKind,
|
|
3021
|
+
mcpServer,
|
|
3022
|
+
KNOWLEDGE_FILE,
|
|
3023
|
+
KNOWLEDGE_DIR,
|
|
3024
|
+
isOsMetadataFile,
|
|
3025
|
+
isOsMetadataRow,
|
|
3026
|
+
knowledgeFile,
|
|
3027
|
+
knowledgeDir,
|
|
3028
|
+
isKnowledgeFileSource,
|
|
3029
|
+
isKnowledgeDirSource,
|
|
3030
|
+
encodeKnowledge,
|
|
3031
|
+
knowledge,
|
|
3032
|
+
knowledgeKind,
|
|
3033
|
+
resolveRealtimeServerCanonical,
|
|
3034
|
+
encodeRealtimeServer,
|
|
3035
|
+
realtimeServerKind,
|
|
3036
|
+
realtimeServer,
|
|
3037
|
+
realtimeMessageGuid,
|
|
3038
|
+
encodeRealtimeMessage,
|
|
3039
|
+
realtimeMessageKind,
|
|
3040
|
+
realtimeMessage,
|
|
3041
|
+
encodeSchedule,
|
|
3042
|
+
encodeTask,
|
|
3043
|
+
taskKind,
|
|
3044
|
+
task,
|
|
3045
|
+
encodeWorkflowTest,
|
|
3046
|
+
workflowTestKind,
|
|
3047
|
+
workflowTest,
|
|
3048
|
+
encodeMiddleware,
|
|
3049
|
+
middlewareKind,
|
|
3050
|
+
middleware,
|
|
3051
|
+
encodeAddon,
|
|
3052
|
+
addonKind,
|
|
3053
|
+
addon,
|
|
3054
|
+
encodeFunction,
|
|
3055
|
+
functionKind,
|
|
3056
|
+
registerAllKinds,
|
|
3057
|
+
emit,
|
|
3058
|
+
serializeBundle,
|
|
3059
|
+
emitBundle
|
|
3060
|
+
};
|
|
3061
|
+
//# sourceMappingURL=chunk-MXHSQOC4.js.map
|