@xanots/sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +384 -0
- package/dist/agent-file-refresh-7XCACU34.js +95 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +184 -0
- package/dist/capture-HUV5BNTC.js +32 -0
- package/dist/chunk-26CNBZE2.js +963 -0
- package/dist/chunk-33ND6LKO.js +78 -0
- package/dist/chunk-3DUAGYGP.js +1550 -0
- package/dist/chunk-3IGNIP6R.js +89 -0
- package/dist/chunk-47WDWMBJ.js +14 -0
- package/dist/chunk-4BXJGVZ3.js +318 -0
- package/dist/chunk-4HT3BNZ7.js +675 -0
- package/dist/chunk-4YMD2OOZ.js +23 -0
- package/dist/chunk-5WGEURVI.js +156 -0
- package/dist/chunk-5YTBTF25.js +29 -0
- package/dist/chunk-6DHBYBTO.js +166 -0
- package/dist/chunk-76QBEIGO.js +66 -0
- package/dist/chunk-7DKX2SPN.js +100 -0
- package/dist/chunk-7REDODS2.js +468 -0
- package/dist/chunk-C56BC2FY.js +254 -0
- package/dist/chunk-DGSF2Q5H.js +60 -0
- package/dist/chunk-EMCAWMHC.js +3982 -0
- package/dist/chunk-EZG76F7R.js +159 -0
- package/dist/chunk-FJ6ZS5KB.js +3607 -0
- package/dist/chunk-GNPVYOPB.js +17 -0
- package/dist/chunk-HJPTWBLH.js +38 -0
- package/dist/chunk-IZW6MK3U.js +248 -0
- package/dist/chunk-LH6Z6KFV.js +247 -0
- package/dist/chunk-MZUI3JNX.js +93 -0
- package/dist/chunk-NDZFBZHC.js +167 -0
- package/dist/chunk-NOO35BQ2.js +37 -0
- package/dist/chunk-NUQCEOKA.js +13 -0
- package/dist/chunk-QTNO2WD6.js +56 -0
- package/dist/chunk-RVB7ITKN.js +49 -0
- package/dist/chunk-TRU5OHQ5.js +6904 -0
- package/dist/chunk-VKFQJEMW.js +814 -0
- package/dist/chunk-VTIL47DT.js +125 -0
- package/dist/chunk-WHOJWOSV.js +112 -0
- package/dist/chunk-WKP4D5MO.js +1692 -0
- package/dist/chunk-X4DVXBFY.js +38 -0
- package/dist/chunk-XQ22GLYS.js +118 -0
- package/dist/chunk-YDZYMZBE.js +670 -0
- package/dist/chunk-YGPIY3WT.js +1146 -0
- package/dist/chunk-YYRDLFSJ.js +602 -0
- package/dist/chunk-ZUTSMMAG.js +46 -0
- package/dist/cli.d.ts +331 -0
- package/dist/cli.js +33 -0
- package/dist/codegen-command-OOKK6AZK.js +40 -0
- package/dist/codegen.d.ts +114 -0
- package/dist/codegen.js +71 -0
- package/dist/completion-TIPPZN7H.js +298 -0
- package/dist/config-NL33PN4D.js +84 -0
- package/dist/deploy-command-4EQ7XX5G.js +451 -0
- package/dist/env-target-IFJ5QDHC.js +16 -0
- package/dist/ephemeral-command-3X3I4ULC.js +242 -0
- package/dist/index.d.ts +4477 -0
- package/dist/index.js +300 -0
- package/dist/init-command-R6H7ZXW5.js +27 -0
- package/dist/internal.d.ts +74 -0
- package/dist/internal.js +2065 -0
- package/dist/io-AMIKRLPC.js +11 -0
- package/dist/live-diff-Y3AKETHE.js +196 -0
- package/dist/lock-3CVKALKT.js +37 -0
- package/dist/lock-commands-XTR2YKLY.js +232 -0
- package/dist/login-command-ACJF6KWQ.js +167 -0
- package/dist/logout-command-MX3MJS5U.js +68 -0
- package/dist/loop-OM3P2Z6O.js +93 -0
- package/dist/marketplace-command-RATXTKXN.js +379 -0
- package/dist/meta-client-OW5WKWW7.js +170 -0
- package/dist/node.d.ts +59 -0
- package/dist/node.js +442 -0
- package/dist/profile-command-SWJ3SPKR.js +77 -0
- package/dist/release-command-VV5UVZKL.js +427 -0
- package/dist/response-CVAE2kMj.d.ts +1915 -0
- package/dist/routes-manifest-SP3ZXLMR.js +244 -0
- package/dist/runtime-V4C3AC3A.js +13 -0
- package/dist/sandbox-details-command-HJE5SPVG.js +18 -0
- package/dist/sandbox-export-command-QCJY4GMV.js +24 -0
- package/dist/static-host-D6KS7X45.js +138 -0
- package/dist/store-BQ97nKIF.d.ts +7760 -0
- package/dist/test-command-TSPBQHBM.js +383 -0
- package/dist/validate-command-4ERHJSCO.js +122 -0
- package/dist/verify-rollout-FAVQ6EJY.js +40 -0
- package/dist/workspace-K72NP7SX.js +49 -0
- package/dist/workspace-command-OF23DPNI.js +156 -0
- package/dist/workspace-export-AJMGN3CQ.js +10 -0
- package/llms/fields.md +104 -0
- package/llms/filters.md +183 -0
- package/llms/kinds-agent-mcp.md +11 -0
- package/llms/kinds-core.md +68 -0
- package/llms/kinds-realtime.md +76 -0
- package/llms/lambda.md +111 -0
- package/llms/legacy.md +43 -0
- package/llms/object-kinds.md +31 -0
- package/llms/statements-calls.md +23 -0
- package/llms/statements-catalog.md +309 -0
- package/llms/statements-data.md +58 -0
- package/llms/statements-runtime.md +48 -0
- package/llms/tests.md +58 -0
- package/llms/triggers.md +22 -0
- package/llms/values.md +29 -0
- package/llms-full.txt +1672 -0
- package/llms.txt +483 -0
- package/manifest.json +9592 -0
- package/package.json +110 -0
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
import {
|
|
2
|
+
encodeEval,
|
|
3
|
+
encodeSearch,
|
|
4
|
+
encodeSort,
|
|
5
|
+
qualifyAggregateEvals,
|
|
6
|
+
realtimeChannelGuid,
|
|
7
|
+
realtimeServerRefName,
|
|
8
|
+
resolveRealtimeServerRef
|
|
9
|
+
} from "./chunk-FJ6ZS5KB.js";
|
|
10
|
+
import {
|
|
11
|
+
assertCanonical,
|
|
12
|
+
assertOneOf,
|
|
13
|
+
assertStoredName,
|
|
14
|
+
buildMiddlewareBlock,
|
|
15
|
+
clear,
|
|
16
|
+
emitDiagnostic,
|
|
17
|
+
emptyMiddleware,
|
|
18
|
+
encodeContainerHistory,
|
|
19
|
+
encodeHistory,
|
|
20
|
+
encodeInput,
|
|
21
|
+
encodeResponse,
|
|
22
|
+
encodeTags,
|
|
23
|
+
encodeTests,
|
|
24
|
+
registerKind,
|
|
25
|
+
resolveAuthRef,
|
|
26
|
+
resolveMockKeys,
|
|
27
|
+
warnLiveDatasource
|
|
28
|
+
} from "./chunk-EMCAWMHC.js";
|
|
29
|
+
import {
|
|
30
|
+
encodeStatement
|
|
31
|
+
} from "./chunk-LH6Z6KFV.js";
|
|
32
|
+
import {
|
|
33
|
+
deriveGuid,
|
|
34
|
+
getLockedCanonical,
|
|
35
|
+
lockKey,
|
|
36
|
+
realtimeMessageSeedName,
|
|
37
|
+
resolveRef
|
|
38
|
+
} from "./chunk-4HT3BNZ7.js";
|
|
39
|
+
|
|
40
|
+
// src/kinds/canonical.ts
|
|
41
|
+
function resolveCanonicalToken(label, payloadKey, accessor, def, override) {
|
|
42
|
+
if (override) return override;
|
|
43
|
+
if (typeof def.canonical === "string" && def.canonical !== "") return def.canonical;
|
|
44
|
+
const locked = getLockedCanonical(lockKey(payloadKey, def.name));
|
|
45
|
+
if (locked) return locked;
|
|
46
|
+
throw new Error(
|
|
47
|
+
`${label} "${def.name}": cannot resolve the \`canonical\` URL token. Set an explicit \`canonical\` in code, or run \`xanots export <entry> --lock\` 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. \`${accessor}({ canonical: "..." })\`). (Minting here is unsafe \u2014 canonicals must be unique per instance across all workspaces, so they are only generated at locked export.)`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/kinds/toolset.ts
|
|
52
|
+
function encodeTool(def) {
|
|
53
|
+
if (!def.name) throw new Error("tool: `name` is required.");
|
|
54
|
+
assertStoredName(`tool "${def.name}"`, def.name, "route");
|
|
55
|
+
return {
|
|
56
|
+
name: def.name,
|
|
57
|
+
description: def.description ?? "",
|
|
58
|
+
instructions: def.instructions ?? "",
|
|
59
|
+
docs: def.docs ?? "",
|
|
60
|
+
enabled: def.enabled ?? true,
|
|
61
|
+
output: [],
|
|
62
|
+
middleware: buildMiddlewareBlock(def.middleware),
|
|
63
|
+
tag: encodeTags(def.tags),
|
|
64
|
+
history: encodeHistory("tool", def.history),
|
|
65
|
+
toolset: { id: def.toolsetId ?? 0 },
|
|
66
|
+
input: Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d)),
|
|
67
|
+
result: encodeResponse(def.response),
|
|
68
|
+
run: (def.stack ?? []).map(encodeStatement),
|
|
69
|
+
test: []
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
var toolKind = {
|
|
73
|
+
name: "tool",
|
|
74
|
+
payloadKey: "tool",
|
|
75
|
+
encode: encodeTool
|
|
76
|
+
};
|
|
77
|
+
registerKind(toolKind);
|
|
78
|
+
function tool(def) {
|
|
79
|
+
return def;
|
|
80
|
+
}
|
|
81
|
+
function normalizeToolEntry(entry, index) {
|
|
82
|
+
if (typeof entry === "string") return { tool: entry };
|
|
83
|
+
if (entry === null || typeof entry !== "object") {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`toolset tool ref [${index}]: expected a \`tool()\` handle, a tool name, or a { tool, enabled?, auth? } wrapper (got ${entry === null ? "null" : typeof entry}).`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const ref = entry;
|
|
89
|
+
if (ref.tool !== void 0 || ref.id !== void 0) return ref;
|
|
90
|
+
if (typeof ref.name === "string" && ref.name !== "") {
|
|
91
|
+
return { tool: ref };
|
|
92
|
+
}
|
|
93
|
+
throw new Error(
|
|
94
|
+
`toolset tool ref [${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.`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
function encodeToolRefs(tools) {
|
|
98
|
+
return (tools ?? []).map((entry, index) => {
|
|
99
|
+
const t = normalizeToolEntry(entry, index);
|
|
100
|
+
if (t.tool !== void 0 && t.id !== void 0) {
|
|
101
|
+
throw new Error("toolset tool ref: set either `tool` (handle/name) or `id` (raw), not both.");
|
|
102
|
+
}
|
|
103
|
+
const id = t.tool !== void 0 ? resolveRef("tool", t.tool) : t.id ?? 0;
|
|
104
|
+
if (id === 0 || id === "" || id === "0") {
|
|
105
|
+
emitDiagnostic({
|
|
106
|
+
severity: "warning",
|
|
107
|
+
code: "toolset.tool-ref-zero",
|
|
108
|
+
message: `toolset tool ref [${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.`
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const label = typeof t.tool === "string" ? t.tool : t.tool?.name ?? String(t.id ?? "?");
|
|
112
|
+
return { id, enabled: t.enabled ?? true, auth: resolveAuthRef("toolset tool", label, t.auth) };
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function resolveToolsetCanonical(def, override) {
|
|
116
|
+
return resolveCanonicalToken("toolset", "toolset", "getPath", def, override);
|
|
117
|
+
}
|
|
118
|
+
function encodeToolsetBase(def, label = "toolset") {
|
|
119
|
+
assertCanonical(`${label} "${def.name}"`, def.canonical);
|
|
120
|
+
return {
|
|
121
|
+
name: def.name,
|
|
122
|
+
description: def.description ?? "",
|
|
123
|
+
instructions: def.instructions ?? "",
|
|
124
|
+
docs: def.docs ?? "",
|
|
125
|
+
enabled: def.enabled ?? true,
|
|
126
|
+
canonical: def.canonical ?? "",
|
|
127
|
+
spec: def.spec ?? "",
|
|
128
|
+
middleware: emptyMiddleware(),
|
|
129
|
+
history: encodeContainerHistory("tool", def.history),
|
|
130
|
+
tag: encodeTags(def.tags),
|
|
131
|
+
tool: encodeToolRefs(def.tools)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/kinds/agent.ts
|
|
136
|
+
function buildProviderConfig(llm) {
|
|
137
|
+
let config;
|
|
138
|
+
switch (llm.type) {
|
|
139
|
+
case "anthropic":
|
|
140
|
+
config = {
|
|
141
|
+
apiKey: llm.apiKey ?? "",
|
|
142
|
+
model: llm.model ?? "",
|
|
143
|
+
temperature: llm.temperature ?? 1,
|
|
144
|
+
sendReasoning: llm.sendReasoning ?? true,
|
|
145
|
+
thinking: llm.thinkingTokens !== void 0 ? { type: "enabled", budgetTokens: llm.thinkingTokens } : { type: "disabled", budgetTokens: "" },
|
|
146
|
+
baseURL: llm.baseURL ?? "",
|
|
147
|
+
headers: llm.headers ?? ""
|
|
148
|
+
};
|
|
149
|
+
break;
|
|
150
|
+
case "openai":
|
|
151
|
+
config = {
|
|
152
|
+
apiKey: llm.apiKey ?? "",
|
|
153
|
+
model: llm.model ?? "",
|
|
154
|
+
temperature: llm.temperature ?? 1,
|
|
155
|
+
reasoningEffort: llm.reasoningEffort ?? "medium",
|
|
156
|
+
baseURL: llm.baseURL ?? "",
|
|
157
|
+
headers: llm.headers ?? "",
|
|
158
|
+
organization: llm.organization ?? "",
|
|
159
|
+
project: llm.project ?? "",
|
|
160
|
+
compatibility: llm.compatibility ?? "strict"
|
|
161
|
+
};
|
|
162
|
+
break;
|
|
163
|
+
case "google-genai":
|
|
164
|
+
config = {
|
|
165
|
+
apiKey: llm.apiKey ?? "",
|
|
166
|
+
model: llm.model ?? "",
|
|
167
|
+
temperature: llm.temperature ?? 1,
|
|
168
|
+
useSearchGrounding: llm.searchGrounding ?? false,
|
|
169
|
+
thinkingConfig: {
|
|
170
|
+
includeThoughts: llm.includeThoughts ?? false,
|
|
171
|
+
thinkingBudget: llm.thinkingBudget ?? 0
|
|
172
|
+
},
|
|
173
|
+
baseURL: llm.baseURL ?? "",
|
|
174
|
+
headers: llm.headers ?? "",
|
|
175
|
+
safetySettings: llm.safetySettings ?? "",
|
|
176
|
+
dynamicRetrievalConfig: llm.dynamicRetrieval ?? ""
|
|
177
|
+
};
|
|
178
|
+
break;
|
|
179
|
+
case "xano-free":
|
|
180
|
+
config = {
|
|
181
|
+
temperature: llm.temperature ?? 1,
|
|
182
|
+
useSearchGrounding: llm.searchGrounding ?? false,
|
|
183
|
+
thinkingConfig: {
|
|
184
|
+
includeThoughts: llm.includeThoughts ?? false,
|
|
185
|
+
thinkingBudget: llm.thinkingBudget ?? 0
|
|
186
|
+
},
|
|
187
|
+
baseURL: llm.baseURL ?? "",
|
|
188
|
+
headers: llm.headers ?? "",
|
|
189
|
+
safetySettings: llm.safetySettings ?? "",
|
|
190
|
+
dynamicRetrievalConfig: llm.dynamicRetrieval ?? ""
|
|
191
|
+
};
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
return llm.extraConfig ? { ...config, ...llm.extraConfig } : config;
|
|
195
|
+
}
|
|
196
|
+
function buildAgentSettings(def) {
|
|
197
|
+
const llm = def.llm;
|
|
198
|
+
if (llm.prompt !== void 0 && llm.messages !== void 0) {
|
|
199
|
+
throw new Error(
|
|
200
|
+
"agent 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."
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
const promptType = llm.messages !== void 0 ? "messages" : "prompt";
|
|
204
|
+
return {
|
|
205
|
+
type: llm.type,
|
|
206
|
+
system_prompt: llm.systemPrompt ?? "",
|
|
207
|
+
max_steps: llm.maxSteps ?? 5,
|
|
208
|
+
prompt_type: promptType,
|
|
209
|
+
prompt: promptType === "prompt" ? llm.prompt ?? "" : "",
|
|
210
|
+
prompt_messages: promptType === "messages" ? llm.messages ?? "" : "",
|
|
211
|
+
structuredOutputs: def.output ? def.output.enabled ?? true : false,
|
|
212
|
+
structuredOutputsSchema: def.output ? Object.entries(def.output.schema).map(([name, d]) => encodeInput(name, d)) : [],
|
|
213
|
+
configs: { [llm.type]: buildProviderConfig(llm) }
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function encodeAgent(def) {
|
|
217
|
+
if (!def.name) throw new Error("agent: `name` is required.");
|
|
218
|
+
if (!def.llm) throw new Error("agent: `llm` is required.");
|
|
219
|
+
return {
|
|
220
|
+
...encodeToolsetBase(def, "agent"),
|
|
221
|
+
type: "agent",
|
|
222
|
+
agent_settings: buildAgentSettings(def)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
var agentKind = {
|
|
226
|
+
name: "agent",
|
|
227
|
+
payloadKey: "toolset",
|
|
228
|
+
encode: encodeAgent
|
|
229
|
+
};
|
|
230
|
+
registerKind(agentKind);
|
|
231
|
+
function agent(def) {
|
|
232
|
+
const getCanonical = (opts) => resolveToolsetCanonical(def, opts?.canonical);
|
|
233
|
+
return { ...def, getCanonical };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/kinds/mcp-server.ts
|
|
237
|
+
function encodeMcpServer(def) {
|
|
238
|
+
if (!def.name) throw new Error("mcp server: `name` is required.");
|
|
239
|
+
const base = { ...encodeToolsetBase(def, "mcpServer"), type: "mcp" };
|
|
240
|
+
return def.llm === void 0 ? base : { ...base, agent_settings: buildAgentSettings({ llm: def.llm, output: def.output }) };
|
|
241
|
+
}
|
|
242
|
+
var mcpServerKind = {
|
|
243
|
+
name: "mcp_server",
|
|
244
|
+
payloadKey: "toolset",
|
|
245
|
+
encode: encodeMcpServer
|
|
246
|
+
};
|
|
247
|
+
registerKind(mcpServerKind);
|
|
248
|
+
function assertNotResolvedEndpointBase(base) {
|
|
249
|
+
const shape = /(\/x2\/mcp\/[^/]+\/)[^/]+(\/stream)$/i;
|
|
250
|
+
if (!shape.test(base)) return;
|
|
251
|
+
const redacted = base.replace(shape, "$1<token>$2");
|
|
252
|
+
throw new Error(
|
|
253
|
+
`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".`
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
function mcpServer(def) {
|
|
257
|
+
const getPath = (opts) => `/x2/mcp/${resolveToolsetCanonical(def, opts?.canonical)}/${opts?.token || "mcp"}/stream`;
|
|
258
|
+
const getUrl = (baseUrl, opts) => {
|
|
259
|
+
const base = (baseUrl ?? "").trim().replace(/\/+$/, "");
|
|
260
|
+
if (!base) throw new Error('mcp server: `getUrl` needs a base URL (e.g. "https://x.dev.xano.io").');
|
|
261
|
+
assertNotResolvedEndpointBase(base);
|
|
262
|
+
return `${base}${getPath(opts)}`;
|
|
263
|
+
};
|
|
264
|
+
return { ...def, getPath, getUrl };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// src/kinds/api-group.ts
|
|
268
|
+
var CORS_MODES = ["default", "custom", "disabled"];
|
|
269
|
+
function encodeCors(context, cors) {
|
|
270
|
+
assertOneOf(
|
|
271
|
+
context,
|
|
272
|
+
"cors.mode",
|
|
273
|
+
cors?.mode,
|
|
274
|
+
CORS_MODES,
|
|
275
|
+
'The engine does not reject an unrecognized mode and does not blank the field \u2014 it DROPS THE ENTIRE API GROUP on import. The deploy reports success, the group is missing, and every query in it 404s "Unable to locate request."'
|
|
276
|
+
);
|
|
277
|
+
return {
|
|
278
|
+
mode: cors?.mode ?? "default",
|
|
279
|
+
allowOrigins: cors?.allowOrigins ?? [],
|
|
280
|
+
allowHeaders: cors?.allowHeaders ?? [],
|
|
281
|
+
allowCredentials: cors?.allowCredentials ?? false,
|
|
282
|
+
maxAge: cors?.maxAge ?? 0,
|
|
283
|
+
allowMethods: {
|
|
284
|
+
delete: cors?.allowMethods?.delete ?? false,
|
|
285
|
+
get: cors?.allowMethods?.get ?? false,
|
|
286
|
+
head: cors?.allowMethods?.head ?? false,
|
|
287
|
+
patch: cors?.allowMethods?.patch ?? false,
|
|
288
|
+
post: cors?.allowMethods?.post ?? false,
|
|
289
|
+
put: cors?.allowMethods?.put ?? false
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function encodeApiGroup(def) {
|
|
294
|
+
if (!def.name) throw new Error("apiGroup: `name` is required.");
|
|
295
|
+
assertCanonical(`apiGroup "${def.name}"`, def.canonical);
|
|
296
|
+
return {
|
|
297
|
+
name: def.name,
|
|
298
|
+
description: def.description ?? "",
|
|
299
|
+
canonical: def.canonical ?? "",
|
|
300
|
+
swagger: def.swagger ?? false,
|
|
301
|
+
api_group_enabled: def.apiGroupEnabled ?? true,
|
|
302
|
+
docs: def.docs ?? "",
|
|
303
|
+
documentation: def.documentation ?? { require_token: false, token: "" },
|
|
304
|
+
middleware: buildMiddlewareBlock(def.middleware),
|
|
305
|
+
history: encodeContainerHistory("query", def.history),
|
|
306
|
+
tag: encodeTags(def.tags),
|
|
307
|
+
cors: encodeCors(`apiGroup "${def.name}"`, def.cors)
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
var apiGroupKind = {
|
|
311
|
+
name: "api_group",
|
|
312
|
+
payloadKey: "app",
|
|
313
|
+
encode: encodeApiGroup
|
|
314
|
+
};
|
|
315
|
+
registerKind(apiGroupKind);
|
|
316
|
+
function apiGroup(def) {
|
|
317
|
+
return def;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/kinds/realtime-server.ts
|
|
321
|
+
function resolveRealtimeServerCanonical(def, override) {
|
|
322
|
+
return resolveCanonicalToken("realtime server", "realtime_server", "getCanonical", def, override);
|
|
323
|
+
}
|
|
324
|
+
function encodeRealtimeServer(def) {
|
|
325
|
+
if (!def.name) throw new Error("realtimeServer: `name` is required.");
|
|
326
|
+
assertCanonical(`realtimeServer "${def.name}"`, def.canonical);
|
|
327
|
+
return {
|
|
328
|
+
name: def.name,
|
|
329
|
+
description: def.description ?? "",
|
|
330
|
+
canonical: def.canonical ?? "",
|
|
331
|
+
enabled: def.enabled ?? false,
|
|
332
|
+
history: encodeContainerHistory("message", def.history),
|
|
333
|
+
tag: encodeTags(def.tags)
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
var realtimeServerKind = {
|
|
337
|
+
name: "realtime_server",
|
|
338
|
+
payloadKey: "realtime_server",
|
|
339
|
+
encode: encodeRealtimeServer
|
|
340
|
+
};
|
|
341
|
+
registerKind(realtimeServerKind);
|
|
342
|
+
function assertTenant(tenant) {
|
|
343
|
+
if (!/^[A-Za-z0-9-]+$/.test(tenant)) {
|
|
344
|
+
throw new Error(
|
|
345
|
+
`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.`
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
return tenant;
|
|
349
|
+
}
|
|
350
|
+
function assertNotResolvedSocketBase(fn, socketBase, given) {
|
|
351
|
+
if (!/\/ws\/[^/]+$/i.test(socketBase)) return;
|
|
352
|
+
throw new Error(
|
|
353
|
+
`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.`
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
function liftTenantFromBase(socketBase, explicit) {
|
|
357
|
+
const m = /^(wss?:\/\/[^/]+)\/tenant\/([^/]+)(\/.*)?$/i.exec(socketBase);
|
|
358
|
+
if (!m) return { base: socketBase, tenant: explicit };
|
|
359
|
+
const origin = m[1];
|
|
360
|
+
const fromBase = m[2];
|
|
361
|
+
const rest = m[3] ?? "";
|
|
362
|
+
if (explicit !== void 0 && explicit !== fromBase) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
`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.`
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
return { base: `${origin}${rest}`, tenant: assertTenant(fromBase) };
|
|
368
|
+
}
|
|
369
|
+
function realtimeServer(def) {
|
|
370
|
+
const getCanonical = (opts) => resolveRealtimeServerCanonical(def, opts?.canonical);
|
|
371
|
+
const getPath = (opts) => {
|
|
372
|
+
const canonical = getCanonical(opts);
|
|
373
|
+
const prefix = opts?.tenant ? `${assertTenant(opts.tenant)}:` : "";
|
|
374
|
+
return `/ws/${prefix}${canonical}`;
|
|
375
|
+
};
|
|
376
|
+
const getUrl = (baseUrl, opts) => {
|
|
377
|
+
const base = baseUrl.trim().replace(/\/+$/, "");
|
|
378
|
+
if (!base) throw new Error('realtimeServer: `getUrl` needs a base URL (e.g. "https://x.dev.xano.io").');
|
|
379
|
+
const socketBase = /^wss?:\/\//i.test(base) ? base : /^https?:\/\//i.test(base) ? base.replace(/^http/i, "ws") : `wss://${base}`;
|
|
380
|
+
assertNotResolvedSocketBase("getUrl", socketBase, base);
|
|
381
|
+
const lifted = liftTenantFromBase(socketBase, opts?.tenant);
|
|
382
|
+
return `${lifted.base}${getPath({ ...opts, tenant: lifted.tenant })}`;
|
|
383
|
+
};
|
|
384
|
+
return { ...def, getCanonical, getPath, getUrl };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// src/kinds/realtime-message.ts
|
|
388
|
+
function resolveHost(def) {
|
|
389
|
+
const context = `realtimeMessage "${def.name}"`;
|
|
390
|
+
if (!def.channel) throw new Error(`${context}: \`channel\` is required.`);
|
|
391
|
+
const handle = typeof def.channel === "string" ? void 0 : def.channel;
|
|
392
|
+
if (!handle && def.server === void 0) {
|
|
393
|
+
throw new Error(
|
|
394
|
+
`${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.`
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
const server = def.server ?? handle.server;
|
|
398
|
+
const serverName = realtimeServerRefName(context, server);
|
|
399
|
+
if (handle && def.server !== void 0) {
|
|
400
|
+
const fromHandle = realtimeServerRefName(context, handle.server);
|
|
401
|
+
if (fromHandle !== serverName) {
|
|
402
|
+
throw new Error(
|
|
403
|
+
`${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}".`
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
channel: handle ?? { name: def.channel, server },
|
|
409
|
+
server,
|
|
410
|
+
serverName
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
function realtimeMessageGuid(def) {
|
|
414
|
+
if (def.guid) return def.guid;
|
|
415
|
+
const { channel, serverName } = resolveHost(def);
|
|
416
|
+
return deriveGuid("message", realtimeMessageSeedName(serverName, channel.name, def.name));
|
|
417
|
+
}
|
|
418
|
+
function encodeRealtimeMessage(def) {
|
|
419
|
+
if (!def.name) throw new Error("realtimeMessage: `name` is required.");
|
|
420
|
+
assertStoredName(`realtimeMessage "${def.name}"`, def.name, "plain");
|
|
421
|
+
const host = resolveHost(def);
|
|
422
|
+
const channelId = realtimeChannelGuid(host.channel);
|
|
423
|
+
const serverId = resolveRealtimeServerRef(`realtimeMessage "${def.name}"`, host.server);
|
|
424
|
+
return {
|
|
425
|
+
name: def.name,
|
|
426
|
+
description: def.description ?? "",
|
|
427
|
+
active: def.active ?? true,
|
|
428
|
+
channel: { id: channelId },
|
|
429
|
+
server: { id: serverId },
|
|
430
|
+
auth: resolveAuthRef("realtimeMessage", def.name, def.auth),
|
|
431
|
+
deliver_to: def.deliverTo ?? "channel",
|
|
432
|
+
input: Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d)),
|
|
433
|
+
output: [],
|
|
434
|
+
middleware: buildMiddlewareBlock(def.middleware),
|
|
435
|
+
run: (def.stack ?? []).map(encodeStatement),
|
|
436
|
+
result: encodeResponse(def.response),
|
|
437
|
+
history: encodeHistory("message", def.history),
|
|
438
|
+
disabled: def.disabled ?? false,
|
|
439
|
+
tag: encodeTags(def.tags)
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
var realtimeMessageKind = {
|
|
443
|
+
name: "message",
|
|
444
|
+
payloadKey: "message",
|
|
445
|
+
encode: encodeRealtimeMessage,
|
|
446
|
+
guidOf: (def) => realtimeMessageGuid(def)
|
|
447
|
+
};
|
|
448
|
+
registerKind(realtimeMessageKind);
|
|
449
|
+
function realtimeMessage(def) {
|
|
450
|
+
return def;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// src/kinds/task.ts
|
|
454
|
+
var SCHEDULE_INSTANT = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:?\d{2})$/;
|
|
455
|
+
function assertScheduleInstant(field, value) {
|
|
456
|
+
if (value === void 0) return;
|
|
457
|
+
const wellShaped = SCHEDULE_INSTANT.test(value);
|
|
458
|
+
const parsed = wellShaped ? Date.parse(value) : NaN;
|
|
459
|
+
if (wellShaped && !Number.isNaN(parsed)) return;
|
|
460
|
+
throw new Error(
|
|
461
|
+
`task schedule: \`${field}\` 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.`
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
function encodeSchedule(def) {
|
|
465
|
+
assertScheduleInstant("startsOn", def.startsOn);
|
|
466
|
+
assertScheduleInstant("endsOn", def.endsOn);
|
|
467
|
+
return {
|
|
468
|
+
starts_on: def.startsOn,
|
|
469
|
+
repeat: {
|
|
470
|
+
enabled: def.repeatEnabled ?? def.freq != null,
|
|
471
|
+
ends: { enabled: def.endsEnabled ?? def.endsOn != null, on: def.endsOn ?? def.startsOn },
|
|
472
|
+
freq: def.freq ?? 86400
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function encodeTask(def) {
|
|
477
|
+
if (!def.name) throw new Error("task: `name` is required.");
|
|
478
|
+
return {
|
|
479
|
+
name: def.name,
|
|
480
|
+
description: def.description ?? "",
|
|
481
|
+
docs: def.docs ?? "",
|
|
482
|
+
datasource: def.datasource ?? "",
|
|
483
|
+
active: def.active ?? false,
|
|
484
|
+
middleware: buildMiddlewareBlock(def.middleware),
|
|
485
|
+
tag: encodeTags(def.tags),
|
|
486
|
+
history: encodeHistory("task", def.history),
|
|
487
|
+
run: (def.stack ?? []).map(encodeStatement),
|
|
488
|
+
schedule: (def.schedule ?? []).map(encodeSchedule)
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
var taskKind = {
|
|
492
|
+
name: "task",
|
|
493
|
+
payloadKey: "task",
|
|
494
|
+
encode: encodeTask
|
|
495
|
+
};
|
|
496
|
+
registerKind(taskKind);
|
|
497
|
+
function task(def) {
|
|
498
|
+
return def;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// src/kinds/workflow-test.ts
|
|
502
|
+
function encodeWorkflowTest(def) {
|
|
503
|
+
if (!def.name) throw new Error("workflow test: `name` is required.");
|
|
504
|
+
const datasource = def.datasource ?? "";
|
|
505
|
+
warnLiveDatasource({
|
|
506
|
+
code: "workflow-test.live-datasource",
|
|
507
|
+
subject: `workflow test "${def.name}"`,
|
|
508
|
+
datasource
|
|
509
|
+
});
|
|
510
|
+
return {
|
|
511
|
+
name: def.name,
|
|
512
|
+
description: def.description ?? "",
|
|
513
|
+
docs: def.docs ?? "",
|
|
514
|
+
datasource,
|
|
515
|
+
active: def.active ?? true,
|
|
516
|
+
tag: encodeTags(def.tags),
|
|
517
|
+
run: (def.stack ?? []).map(encodeStatement)
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
var workflowTestKind = {
|
|
521
|
+
name: "workflow_test",
|
|
522
|
+
payloadKey: "workflow_test",
|
|
523
|
+
encode: encodeWorkflowTest
|
|
524
|
+
};
|
|
525
|
+
registerKind(workflowTestKind);
|
|
526
|
+
function workflowTest(def) {
|
|
527
|
+
return def;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// src/kinds/middleware.ts
|
|
531
|
+
function encodeMiddleware(def) {
|
|
532
|
+
if (!def.name) throw new Error("middleware: `name` is required.");
|
|
533
|
+
const xdo = {
|
|
534
|
+
name: def.name,
|
|
535
|
+
description: def.description ?? "",
|
|
536
|
+
docs: def.docs ?? "",
|
|
537
|
+
result_type: def.resultStrategy ?? "merge",
|
|
538
|
+
exception: def.exceptionPolicy ?? "rethrow",
|
|
539
|
+
history: encodeHistory("middleware", def.history),
|
|
540
|
+
tag: encodeTags(def.tags),
|
|
541
|
+
shared_workspace: { is_shared: false },
|
|
542
|
+
input: Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d)),
|
|
543
|
+
result: encodeResponse(def.response),
|
|
544
|
+
run: (def.stack ?? []).map(encodeStatement),
|
|
545
|
+
test: encodeTests(def.tests, "middleware", def.name)
|
|
546
|
+
};
|
|
547
|
+
resolveMockKeys(xdo.run, xdo.test, "middleware", def.name);
|
|
548
|
+
return xdo;
|
|
549
|
+
}
|
|
550
|
+
var middlewareKind = {
|
|
551
|
+
name: "middleware",
|
|
552
|
+
payloadKey: "middleware",
|
|
553
|
+
encode: encodeMiddleware
|
|
554
|
+
};
|
|
555
|
+
registerKind(middlewareKind);
|
|
556
|
+
function middlewareImpl(def) {
|
|
557
|
+
return def;
|
|
558
|
+
}
|
|
559
|
+
var middleware = Object.assign(middlewareImpl, { clear });
|
|
560
|
+
|
|
561
|
+
// src/kinds/addon.ts
|
|
562
|
+
function buildContext(def) {
|
|
563
|
+
const ctx = { ...def.context ?? {} };
|
|
564
|
+
if (def.table !== void 0 && ctx.dbo === void 0) {
|
|
565
|
+
ctx.dbo = def.table === null ? { as: def.tableAlias ?? "", id: "" } : {
|
|
566
|
+
id: resolveRef("dbo", def.table),
|
|
567
|
+
// Absent unless authored — writing it unconditionally would change the
|
|
568
|
+
// bytes of every addon that omits it today.
|
|
569
|
+
...def.tableAlias !== void 0 ? { as: def.tableAlias } : {}
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
if (def.where !== void 0 && ctx.search === void 0) {
|
|
573
|
+
const search = encodeSearch(def.where);
|
|
574
|
+
if (search !== void 0) ctx.search = search;
|
|
575
|
+
}
|
|
576
|
+
if (def.sort !== void 0 && ctx.sort === void 0) {
|
|
577
|
+
const sort = encodeSort(def.sort);
|
|
578
|
+
if (sort.length) ctx.sort = sort;
|
|
579
|
+
}
|
|
580
|
+
const explicitReturn = ctx.return;
|
|
581
|
+
if (def.cardinality !== void 0 && explicitReturn?.type !== void 0 && explicitReturn.type !== def.cardinality) {
|
|
582
|
+
throw new Error(
|
|
583
|
+
`addon: cardinality:"${def.cardinality}" conflicts with an explicit context.return.type "${explicitReturn.type}" \u2014 they shape the graft differently. Set one, not both.`
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
if (def.cardinality !== void 0 && def.cardinality !== "list" && ctx.return === void 0) {
|
|
587
|
+
if (def.cardinality === "aggregate") {
|
|
588
|
+
const addonAlias = def.table === void 0 || def.table === null ? ctx.dbo?.as ?? "" : typeof def.table === "string" ? def.table : def.table.name;
|
|
589
|
+
ctx.return = {
|
|
590
|
+
type: "aggregate",
|
|
591
|
+
aggregate: {
|
|
592
|
+
sort: encodeSort(def.sort),
|
|
593
|
+
eval: encodeEval(qualifyAggregateEvals(def.eval, addonAlias, "eval")) ?? [],
|
|
594
|
+
group: encodeEval(qualifyAggregateEvals(def.group, addonAlias, "group")) ?? []
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
} else {
|
|
598
|
+
ctx.return = { type: def.cardinality };
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return ctx;
|
|
602
|
+
}
|
|
603
|
+
function buildOutput(output) {
|
|
604
|
+
if (!output) return { customize: false, items: [] };
|
|
605
|
+
if (Array.isArray(output)) {
|
|
606
|
+
return { customize: true, items: output.map((name) => ({ name })) };
|
|
607
|
+
}
|
|
608
|
+
const block = output;
|
|
609
|
+
return { customize: block.customize ?? false, items: block.items ?? [] };
|
|
610
|
+
}
|
|
611
|
+
function encodeAddon(def) {
|
|
612
|
+
if (!def.name) throw new Error("addon: `name` is required.");
|
|
613
|
+
return {
|
|
614
|
+
name: def.name,
|
|
615
|
+
description: def.description ?? "",
|
|
616
|
+
context: buildContext(def),
|
|
617
|
+
output: buildOutput(def.output),
|
|
618
|
+
tag: encodeTags(def.tags),
|
|
619
|
+
input: Object.entries(def.input ?? {}).map(([name, d]) => encodeInput(name, d))
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
var addonKind = {
|
|
623
|
+
name: "addon",
|
|
624
|
+
payloadKey: "addon",
|
|
625
|
+
encode: encodeAddon
|
|
626
|
+
};
|
|
627
|
+
registerKind(addonKind);
|
|
628
|
+
function addon(def) {
|
|
629
|
+
return def;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
export {
|
|
633
|
+
encodeTool,
|
|
634
|
+
toolKind,
|
|
635
|
+
tool,
|
|
636
|
+
encodeToolRefs,
|
|
637
|
+
resolveToolsetCanonical,
|
|
638
|
+
encodeToolsetBase,
|
|
639
|
+
encodeAgent,
|
|
640
|
+
agentKind,
|
|
641
|
+
agent,
|
|
642
|
+
encodeMcpServer,
|
|
643
|
+
mcpServerKind,
|
|
644
|
+
mcpServer,
|
|
645
|
+
encodeApiGroup,
|
|
646
|
+
apiGroupKind,
|
|
647
|
+
apiGroup,
|
|
648
|
+
resolveRealtimeServerCanonical,
|
|
649
|
+
encodeRealtimeServer,
|
|
650
|
+
realtimeServerKind,
|
|
651
|
+
realtimeServer,
|
|
652
|
+
realtimeMessageGuid,
|
|
653
|
+
encodeRealtimeMessage,
|
|
654
|
+
realtimeMessageKind,
|
|
655
|
+
realtimeMessage,
|
|
656
|
+
encodeSchedule,
|
|
657
|
+
encodeTask,
|
|
658
|
+
taskKind,
|
|
659
|
+
task,
|
|
660
|
+
encodeWorkflowTest,
|
|
661
|
+
workflowTestKind,
|
|
662
|
+
workflowTest,
|
|
663
|
+
encodeMiddleware,
|
|
664
|
+
middlewareKind,
|
|
665
|
+
middleware,
|
|
666
|
+
encodeAddon,
|
|
667
|
+
addonKind,
|
|
668
|
+
addon
|
|
669
|
+
};
|
|
670
|
+
//# sourceMappingURL=chunk-YDZYMZBE.js.map
|