@xano/developer-mcp 2.0.4 → 2.0.5-beta.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/dist/tools/xanoscript_docs.js +6 -2
- package/dist/xanoscript.d.ts +8 -0
- package/dist/xanoscript.js +43 -3
- package/dist/xanoscript_docs/README.md +1 -0
- package/dist/xanoscript_docs/docs_index.json +22 -3
- package/dist/xanoscript_docs/essentials.md +27 -0
- package/dist/xanoscript_docs/file-uploads.md +408 -0
- package/dist/xanoscript_docs/integrations/utilities.md +61 -21
- package/dist/xanoscript_docs/knowledge.md +146 -0
- package/dist/xanoscript_docs/types.md +12 -1
- package/dist/xanoscript_docs/version.json +2 -2
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ import { readFileSync } from "fs";
|
|
|
8
8
|
import { dirname, join } from "path";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import { z } from "zod";
|
|
11
|
-
import { readXanoscriptDocsV2, readXanoscriptDocsStructured, getXanoscriptDocsVersion, getTopicNames, getTopicDescriptions, } from "../xanoscript.js";
|
|
11
|
+
import { readXanoscriptDocsV2, readXanoscriptDocsStructured, getXanoscriptDocsVersion, getTopicNames, getAliasNames, getTopicDescriptions, } from "../xanoscript.js";
|
|
12
12
|
import { defineTool } from "./define_tool.js";
|
|
13
13
|
// =============================================================================
|
|
14
14
|
// Path Resolution
|
|
@@ -156,7 +156,11 @@ export function xanoscriptDocsTool(args) {
|
|
|
156
156
|
// =============================================================================
|
|
157
157
|
// MCP Tool Definition
|
|
158
158
|
// =============================================================================
|
|
159
|
-
|
|
159
|
+
// Accept canonical topic names AND their aliases (e.g. "upload", "storage" ->
|
|
160
|
+
// "file-uploads"). Aliases are resolved to canonical names inside the resolver.
|
|
161
|
+
const topicEnumValues = [
|
|
162
|
+
...new Set([...getTopicNames(), ...getAliasNames()]),
|
|
163
|
+
];
|
|
160
164
|
export const xanoscriptDocsToolSpec = defineTool({
|
|
161
165
|
name: "xano_xanoscript_docs",
|
|
162
166
|
description: "Get XanoScript programming language documentation for AI code generation. " +
|
package/dist/xanoscript.d.ts
CHANGED
|
@@ -19,6 +19,14 @@ export interface XanoscriptDocsArgs {
|
|
|
19
19
|
exclude_topics?: string[];
|
|
20
20
|
}
|
|
21
21
|
export declare const XANOSCRIPT_DOCS_V2: Record<string, DocConfig>;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a topic name or alias to a canonical topic name. Returns the input
|
|
24
|
+
* unchanged when it is already canonical or unknown, so callers can still
|
|
25
|
+
* surface the existing "Unknown topic" error for genuinely bad input.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveTopic(input?: string): string | undefined;
|
|
28
|
+
/** Get all alias names (keys of the alias -> canonical topic map). */
|
|
29
|
+
export declare function getAliasNames(): string[];
|
|
22
30
|
/**
|
|
23
31
|
* Clear all cached documentation content and version data.
|
|
24
32
|
* Useful for testing or when docs files change at runtime.
|
package/dist/xanoscript.js
CHANGED
|
@@ -24,6 +24,45 @@ function buildDocsConfig() {
|
|
|
24
24
|
return config;
|
|
25
25
|
}
|
|
26
26
|
export const XANOSCRIPT_DOCS_V2 = buildDocsConfig();
|
|
27
|
+
/**
|
|
28
|
+
* Map of alias -> canonical topic name, built from the `aliases` arrays in
|
|
29
|
+
* docs_index.json. Lets callers pass a natural synonym (e.g. "upload",
|
|
30
|
+
* "storage", "attachment") and have it resolve to the canonical topic
|
|
31
|
+
* ("file-uploads"). An alias that shadows a real topic name is skipped, and
|
|
32
|
+
* cross-topic collisions are resolved first-writer-wins.
|
|
33
|
+
*/
|
|
34
|
+
const ALIAS_TO_TOPIC = (() => {
|
|
35
|
+
const map = {};
|
|
36
|
+
for (const [key, topic] of Object.entries(docsIndex.topics)) {
|
|
37
|
+
const aliases = topic.aliases;
|
|
38
|
+
if (!aliases)
|
|
39
|
+
continue;
|
|
40
|
+
for (const alias of aliases) {
|
|
41
|
+
if (alias in XANOSCRIPT_DOCS_V2)
|
|
42
|
+
continue; // never shadow a canonical topic name
|
|
43
|
+
if (alias in map)
|
|
44
|
+
continue; // first-writer-wins on cross-topic collisions
|
|
45
|
+
map[alias] = key;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return map;
|
|
49
|
+
})();
|
|
50
|
+
/**
|
|
51
|
+
* Resolve a topic name or alias to a canonical topic name. Returns the input
|
|
52
|
+
* unchanged when it is already canonical or unknown, so callers can still
|
|
53
|
+
* surface the existing "Unknown topic" error for genuinely bad input.
|
|
54
|
+
*/
|
|
55
|
+
export function resolveTopic(input) {
|
|
56
|
+
if (!input)
|
|
57
|
+
return input;
|
|
58
|
+
if (input in XANOSCRIPT_DOCS_V2)
|
|
59
|
+
return input;
|
|
60
|
+
return ALIAS_TO_TOPIC[input] ?? input;
|
|
61
|
+
}
|
|
62
|
+
/** Get all alias names (keys of the alias -> canonical topic map). */
|
|
63
|
+
export function getAliasNames() {
|
|
64
|
+
return Object.keys(ALIAS_TO_TOPIC);
|
|
65
|
+
}
|
|
27
66
|
// =============================================================================
|
|
28
67
|
// Content Cache
|
|
29
68
|
// =============================================================================
|
|
@@ -206,15 +245,16 @@ export function readXanoscriptDocsV2(docsPath, args) {
|
|
|
206
245
|
const header = `# XanoScript Documentation for: ${args.file_path}\n\nMatched topics: ${topics.join(", ")}\nMode: ${mode}\nVersion: ${version}\n\n---\n\n`;
|
|
207
246
|
return header + docs.join("\n\n---\n\n");
|
|
208
247
|
}
|
|
209
|
-
// Topic-based: return specific doc
|
|
210
|
-
const
|
|
248
|
+
// Topic-based: return specific doc (resolve aliases to canonical names first)
|
|
249
|
+
const canonicalTopic = resolveTopic(args.topic);
|
|
250
|
+
const config = XANOSCRIPT_DOCS_V2[canonicalTopic];
|
|
211
251
|
if (!config) {
|
|
212
252
|
const availableTopics = Object.keys(XANOSCRIPT_DOCS_V2).join(", ");
|
|
213
253
|
throw new Error(`Unknown topic "${args.topic}".\n\nAvailable topics: ${availableTopics}`);
|
|
214
254
|
}
|
|
215
255
|
const content = cachedReadFile(join(docsPath, config.file));
|
|
216
256
|
const doc = mode === "quick_reference"
|
|
217
|
-
? extractQuickReference(content,
|
|
257
|
+
? extractQuickReference(content, canonicalTopic)
|
|
218
258
|
: content;
|
|
219
259
|
return `${doc}\n\n---\nDocumentation version: ${version}`;
|
|
220
260
|
}
|
|
@@ -234,6 +234,7 @@ Use `xano_xanoscript_docs({ tier: "survival" })` or `xano_xanoscript_docs({ tier
|
|
|
234
234
|
| Topic | Description | Key Sections |
|
|
235
235
|
| ---------- | --------------------------------------------------------------- | ------------ |
|
|
236
236
|
| `apis` | HTTP endpoint definitions with authentication and CRUD patterns | Decision Tree, CRUD Examples |
|
|
237
|
+
| `file-uploads` | Uploading files to native Xano storage | `file?` input, create_attachment, signed URLs |
|
|
237
238
|
| `tasks` | Scheduled and cron jobs | Cron Syntax, Input Handling |
|
|
238
239
|
| `triggers` | Event-driven handlers (table, realtime, workspace, agent, MCP) | Predefined Inputs, Event Types |
|
|
239
240
|
| `realtime` | Real-time channels and events for push updates | Channels, Events |
|
|
@@ -125,6 +125,12 @@
|
|
|
125
125
|
"priority": 15,
|
|
126
126
|
"aliases": ["mcp", "model-context-protocol"]
|
|
127
127
|
},
|
|
128
|
+
"knowledge": {
|
|
129
|
+
"file": "knowledge.md",
|
|
130
|
+
"description": "Agent Knowledge: Skills, Docs, and AGENTS.md Context that steer the Xano AI agent (disclosure modes, scopes, authoring)",
|
|
131
|
+
"applyTo": [],
|
|
132
|
+
"aliases": ["skills", "skill", "docs", "agent-knowledge", "agents-md", "context"]
|
|
133
|
+
},
|
|
128
134
|
"unit-testing": {
|
|
129
135
|
"file": "unit-testing.md",
|
|
130
136
|
"description": "Unit tests, mocks, and assertions within functions, APIs, and middleware",
|
|
@@ -145,9 +151,9 @@
|
|
|
145
151
|
},
|
|
146
152
|
"integrations/cloud-storage": {
|
|
147
153
|
"file": "integrations/cloud-storage.md",
|
|
148
|
-
"description": "AWS S3, Azure Blob, and GCP Storage operations",
|
|
154
|
+
"description": "AWS S3, Azure Blob, and GCP Storage operations (external buckets, not native Xano storage)",
|
|
149
155
|
"applyTo": [],
|
|
150
|
-
"aliases": ["s3", "azure", "gcp", "
|
|
156
|
+
"aliases": ["s3", "azure", "gcp", "external-storage", "bucket"]
|
|
151
157
|
},
|
|
152
158
|
"integrations/search": {
|
|
153
159
|
"file": "integrations/search.md",
|
|
@@ -173,6 +179,13 @@
|
|
|
173
179
|
"applyTo": [],
|
|
174
180
|
"aliases": ["email", "zip", "lambda", "archive"]
|
|
175
181
|
},
|
|
182
|
+
"file-uploads": {
|
|
183
|
+
"file": "file-uploads.md",
|
|
184
|
+
"description": "Uploading files to native Xano storage: file? input, create_attachment, sign_private_url",
|
|
185
|
+
"applyTo": ["api/**/*.xs", "function/**/*.xs"],
|
|
186
|
+
"priority": 9,
|
|
187
|
+
"aliases": ["file-upload", "upload", "uploads", "attachment", "attachments", "file", "files", "private-storage", "storage", "multipart"]
|
|
188
|
+
},
|
|
176
189
|
"frontend": {
|
|
177
190
|
"file": "frontend.md",
|
|
178
191
|
"description": "Static frontend development and deployment",
|
|
@@ -358,6 +371,12 @@
|
|
|
358
371
|
"util.get_env": { "file": "integrations/utilities.md" },
|
|
359
372
|
"util.get_all_input": { "file": "integrations/utilities.md" },
|
|
360
373
|
"util.get_input": { "file": "integrations/utilities.md" },
|
|
374
|
+
"storage.create_attachment": { "file": "file-uploads.md" },
|
|
375
|
+
"storage.create_image": { "file": "file-uploads.md" },
|
|
376
|
+
"storage.sign_private_url": { "file": "file-uploads.md" },
|
|
377
|
+
"storage.create_file_resource": { "file": "integrations/utilities.md" },
|
|
378
|
+
"storage.read_file_resource": { "file": "integrations/utilities.md" },
|
|
379
|
+
"storage.delete_file": { "file": "integrations/utilities.md" },
|
|
361
380
|
"cloud.aws.s3.upload_file": { "file": "integrations/cloud-storage.md" },
|
|
362
381
|
"cloud.aws.s3.read_file": { "file": "integrations/cloud-storage.md" },
|
|
363
382
|
"cloud.aws.s3.sign_url": { "file": "integrations/cloud-storage.md" },
|
|
@@ -387,7 +406,7 @@
|
|
|
387
406
|
"rate_limiting": ["security.md", "integrations/redis.md"],
|
|
388
407
|
"error_handling": ["syntax.md", "essentials.md"],
|
|
389
408
|
"pagination": ["database.md", "apis.md"],
|
|
390
|
-
"file_upload": ["integrations/cloud-storage.md", "streaming.md"],
|
|
409
|
+
"file_upload": ["file-uploads.md", "integrations/cloud-storage.md", "streaming.md"],
|
|
391
410
|
"caching": ["performance.md", "integrations/redis.md"],
|
|
392
411
|
"search": ["integrations/search.md"],
|
|
393
412
|
"email": ["integrations/utilities.md"],
|
|
@@ -640,6 +640,32 @@ Each `.xs` file must contain exactly **one** construct. Placing two constructs i
|
|
|
640
640
|
// function/helper_b.xs -> contains only "helper_b"
|
|
641
641
|
```
|
|
642
642
|
|
|
643
|
+
### 14. Using `image?` for file uploads (the `.path` footgun)
|
|
644
|
+
|
|
645
|
+
Upload inputs **must** be typed `file?`. `image?`/`attachment?`/`video?`/`audio?` pass the raw upload object (which has `tmp_name` but no `.path`), so `storage.*` fails at runtime with `Missing param: path`. The validator does **not** catch this — it is syntactically valid.
|
|
646
|
+
|
|
647
|
+
```xs
|
|
648
|
+
// Wrong - image? input; storage op fails with "Missing param: path"
|
|
649
|
+
// input { image? photo }
|
|
650
|
+
// storage.create_image { value = $input.photo } as $f
|
|
651
|
+
|
|
652
|
+
// Also wrong - hand-setting .path from a hallucinated .tmp_name property
|
|
653
|
+
// |set:"path":$input.photo.tmp_name
|
|
654
|
+
|
|
655
|
+
// Correct - file? input populates .path; create_attachment accepts any type
|
|
656
|
+
// (value, access, and filename are all required on storage.create_attachment)
|
|
657
|
+
stack {
|
|
658
|
+
storage.create_attachment {
|
|
659
|
+
value = $input.photo
|
|
660
|
+
access = "private"
|
|
661
|
+
filename = $input.photo.name
|
|
662
|
+
} as $f
|
|
663
|
+
}
|
|
664
|
+
// input { file? photo }
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
See `xano_xanoscript_docs({ topic: "file-uploads" })` for the full pattern.
|
|
668
|
+
|
|
643
669
|
---
|
|
644
670
|
|
|
645
671
|
## Related Topics
|
|
@@ -653,5 +679,6 @@ Explore more with `xano_xanoscript_docs({ topic: "<topic>" })`:
|
|
|
653
679
|
| `database` | All db.* operations: query, get, add, edit, delete |
|
|
654
680
|
| `functions` | Reusable function stacks, async patterns, loops |
|
|
655
681
|
| `apis` | HTTP endpoints, authentication, CRUD patterns |
|
|
682
|
+
| `file-uploads` | Uploading files to Xano storage (`file?`, create_attachment, signed URLs) |
|
|
656
683
|
| `security` | Security best practices and authentication |
|
|
657
684
|
| `integrations` | External API patterns (OpenAI, Stripe, etc.) |
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "api/**/*.xs, function/**/*.xs"
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# File Uploads (Native Xano Storage)
|
|
6
|
+
|
|
7
|
+
> **TL;DR:** To accept an uploaded file, declare the input as `file?` — **never** `image?`. Only `file` pre-processes the upload and populates `.path`; `image`/`attachment`/`video`/`audio` pass the raw upload object and every `storage.*` op then fails with `Missing param: path` (HTTP 400). Store with `storage.create_attachment` (accepts any file type), save the result to an `attachment?`/`image?` column, then return a viewable link: `storage.sign_private_url` for **private** files, or the instance URL + `.path` for **public** files.
|
|
8
|
+
|
|
9
|
+
This topic covers uploading files **to Xano's own private/public storage** (the vault). For pushing files to external buckets (AWS S3, Azure Blob, GCP Storage), see `integrations/cloud-storage` instead.
|
|
10
|
+
|
|
11
|
+
> **Comment syntax note:** XanoScript comments use `//` only (never `#`), and `//` is valid **only on its own line at the `input {}` / `stack {}` / top level — never inside an operation's `{ ... }` argument block and never as a trailing same-line comment**. Putting a comment inside `storage.create_attachment { ... }` or after `file? photo` is a parse error. Every example below follows this rule.
|
|
12
|
+
|
|
13
|
+
## Quick Reference
|
|
14
|
+
|
|
15
|
+
| Concern | Correct | Wrong |
|
|
16
|
+
|---------|---------|-------|
|
|
17
|
+
| Input type for an upload | `file? my_file` / `file[]? my_files` | `image?`, `attachment?`, `video?`, `audio?` |
|
|
18
|
+
| Storage op for any file type (PDF, HEIC, …) | `storage.create_attachment` | `storage.create_image` (image extensions only) |
|
|
19
|
+
| Storage op for images only (JPEG/PNG/GIF/WEBP) | `storage.create_image` | — |
|
|
20
|
+
| Reading the stored path | `$stored_file.path` | `$input.my_file.tmp_name`, `.path` (not real input properties) |
|
|
21
|
+
| Viewing a **private** file | `storage.sign_private_url` (pathname + ttl, one arg per line) | reading `.path` directly (returns HTTP 403) |
|
|
22
|
+
| Viewing a **public** file | instance base URL `~ $stored_file.path` (no signing) | `storage.sign_private_url` (works but is unnecessary) |
|
|
23
|
+
| Multiple-file form field | append as `field[]` (e.g. `photos[]`) | append repeatedly as `photos` (only the last file is kept) |
|
|
24
|
+
| Required `storage.*` args | always pass `value`, `access`, **and** `filename` | omitting `access` or `filename` (validation error) |
|
|
25
|
+
| Frontend `Content-Type` | let the browser set it | manually setting `multipart/form-data` |
|
|
26
|
+
|
|
27
|
+
## The Core Rule: `file?`, not `image?`
|
|
28
|
+
|
|
29
|
+
When the input is declared `image?` (or `video?`/`audio?`/`attachment?`), Xano hands your stack the raw upload object, which does **not** have a populated `.path`. Xano detects the missing `.path` at the **input-parsing layer**, before your stack even runs, so every upload fails:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
Status 400 Bad Request
|
|
33
|
+
{ "code": "ERROR_CODE_INPUT_ERROR", "message": "Missing param: path",
|
|
34
|
+
"payload": { "param": "my_file.path" } }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Because this fires before the stack runs, no in-stack workaround (e.g. copying `tmp_name` into `.path`) can rescue it — see Common Mistakes. When the input is declared `file?`, Xano pre-processes the multipart upload and sets `.path` **before the stack runs**. This is the single fix for `Missing param: path`.
|
|
38
|
+
|
|
39
|
+
> The input type names (`image`, `video`, `audio`, `attachment`, `file`) look like semantic choices but are technical: **only `file` populates `.path` on a multipart upload.** Use `file?` universally for uploads regardless of what kind of file you expect.
|
|
40
|
+
|
|
41
|
+
### Input type forms
|
|
42
|
+
|
|
43
|
+
```xs
|
|
44
|
+
// single file, optional
|
|
45
|
+
file? my_file
|
|
46
|
+
// single file, required
|
|
47
|
+
file my_file
|
|
48
|
+
// multiple files, optional array
|
|
49
|
+
file[]? my_files
|
|
50
|
+
// multiple files, required array
|
|
51
|
+
file[] my_files
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Storage Operations
|
|
55
|
+
|
|
56
|
+
All `storage.create_*` operations require three arguments — `value`, `access`, and `filename` — written one per line (block arguments are newline-separated; commas are only used inside object literals like `data = { ... }`).
|
|
57
|
+
|
|
58
|
+
### `storage.create_attachment` — any file type (recommended default)
|
|
59
|
+
|
|
60
|
+
```xs
|
|
61
|
+
storage.create_attachment {
|
|
62
|
+
value = $input.my_file
|
|
63
|
+
access = "private"
|
|
64
|
+
filename = $input.my_file.name
|
|
65
|
+
} as $stored_file
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Accepts images, PDFs, HEIC, and any other file type. Use this for documents, receipts, mixed uploads — anything where the file type is not guaranteed to be an image. Set `access` to `"private"` (default for sensitive data) or `"public"`.
|
|
69
|
+
|
|
70
|
+
### `storage.create_image` — images only
|
|
71
|
+
|
|
72
|
+
```xs
|
|
73
|
+
storage.create_image {
|
|
74
|
+
value = $input.my_file
|
|
75
|
+
access = "private"
|
|
76
|
+
filename = $input.my_file.name
|
|
77
|
+
} as $stored_file
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Validates the extension internally and **only accepts JPEG, PNG, GIF, WEBP**. A PDF or HEIC upload returns `Invalid file extension.` (HTTP 500, `code: ERROR_FATAL`). Only use when you are certain the upload will always be one of those image formats; otherwise prefer `storage.create_attachment`.
|
|
81
|
+
|
|
82
|
+
### The stored-file object
|
|
83
|
+
|
|
84
|
+
Both ops return an object with this shape (verified against a live workspace):
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
{
|
|
88
|
+
"access": "private", // or "public" — the access you passed
|
|
89
|
+
"path": "/vault/Xq9lrwqH/.../doc.pdf",
|
|
90
|
+
"name": "doc.pdf",
|
|
91
|
+
"type": "image" | "pdf" | "video" | "audio" | ...,
|
|
92
|
+
"size": 303, // bytes
|
|
93
|
+
"mime": "application/pdf", // full MIME type
|
|
94
|
+
"meta": { "validated": false } // images add "width" and "height"
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`.path` is the permanent Xano vault path. Use it everywhere — in the DB record, in `sign_private_url`, and in responses. Save the **whole object** into an `attachment?`/`image?` column (not just the path) so the metadata is preserved.
|
|
99
|
+
|
|
100
|
+
### Viewing a private file — `storage.sign_private_url`
|
|
101
|
+
|
|
102
|
+
A `private` file is **not** directly reachable: requesting its `.path` without a signature returns HTTP 403. Generate a time-limited signed URL to display or download it:
|
|
103
|
+
|
|
104
|
+
```xs
|
|
105
|
+
storage.sign_private_url {
|
|
106
|
+
pathname = $stored_file.path
|
|
107
|
+
ttl = 3600
|
|
108
|
+
} as $signed_url
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`pathname` is the stored `.path` (use `$record.file.path` after reading the record back from the database). `ttl` is the lifetime in seconds, so `3600` = 1 hour; the URL stops working once it expires.
|
|
112
|
+
|
|
113
|
+
### Viewing a public file — no signing needed
|
|
114
|
+
|
|
115
|
+
A file stored with `access = "public"` is served **directly** at your instance's base URL followed by the stored `.path` (no signing, valid until the file is deleted). The stored object has **no** `url` field, so build the URL from `.path`:
|
|
116
|
+
|
|
117
|
+
```xs
|
|
118
|
+
storage.create_attachment {
|
|
119
|
+
value = $input.my_file
|
|
120
|
+
access = "public"
|
|
121
|
+
filename = $input.my_file.name
|
|
122
|
+
} as $stored_file
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Then return the path and let the client prepend its base URL, or build the absolute URL server-side (set `PUBLIC_BASE_URL` to your instance origin, e.g. `https://your-instance.xano.io`, in workspace env vars):
|
|
126
|
+
|
|
127
|
+
```xs
|
|
128
|
+
response = {
|
|
129
|
+
path : $stored_file.path
|
|
130
|
+
public_url: ($env.PUBLIC_BASE_URL ~ $stored_file.path)
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Use `public` only for non-sensitive assets (anyone with the URL can access it). Use `private` + `sign_private_url` for anything access-controlled.
|
|
135
|
+
|
|
136
|
+
### Serving a generated file (not an upload)
|
|
137
|
+
|
|
138
|
+
To serve a file you build in the stack (CSV/JSON/zip export, etc.), create it with `storage.create_file_resource`, then **store** it with `storage.create_attachment` to get a vault `.path`. The `create_file_resource` result is an internal file-resource token — it has **no** servable URL/path of its own.
|
|
139
|
+
|
|
140
|
+
```xs
|
|
141
|
+
storage.create_file_resource {
|
|
142
|
+
filename = "export.csv"
|
|
143
|
+
filedata = $csv_content
|
|
144
|
+
} as $resource
|
|
145
|
+
storage.create_attachment {
|
|
146
|
+
value = $resource
|
|
147
|
+
access = "public"
|
|
148
|
+
filename = "export.csv"
|
|
149
|
+
} as $stored_file
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Then serve `$stored_file` like any uploaded file: instance URL + `.path` for `public`, or `storage.sign_private_url` for `private`. See `integrations/utilities` for `create_file_resource` and zip/CSV details.
|
|
153
|
+
|
|
154
|
+
## Complete Single-Upload Pattern
|
|
155
|
+
|
|
156
|
+
This is the full, end-to-end flow validated against a live Xano workspace (`file?` input → `storage.create_attachment` → `db.add` → `storage.sign_private_url`):
|
|
157
|
+
|
|
158
|
+
```xs
|
|
159
|
+
query upload verb=POST {
|
|
160
|
+
api_group = "FileUploadDemo"
|
|
161
|
+
input {
|
|
162
|
+
text? name? filters=trim
|
|
163
|
+
// MUST be `file?` — only `file` populates `.path` on a multipart upload.
|
|
164
|
+
file? document
|
|
165
|
+
}
|
|
166
|
+
stack {
|
|
167
|
+
precondition ($input.document != null) {
|
|
168
|
+
error_type = "inputerror"
|
|
169
|
+
error = "Provide a file in the `document` field."
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// create_attachment accepts any file type (PDF, HEIC, etc.).
|
|
173
|
+
storage.create_attachment {
|
|
174
|
+
value = $input.document
|
|
175
|
+
access = "private"
|
|
176
|
+
filename = $input.document.name
|
|
177
|
+
} as $stored_file
|
|
178
|
+
|
|
179
|
+
db.add upload_demo_file {
|
|
180
|
+
data = {
|
|
181
|
+
created_at: "now"
|
|
182
|
+
name : $input.name
|
|
183
|
+
file : $stored_file
|
|
184
|
+
}
|
|
185
|
+
} as $rec
|
|
186
|
+
|
|
187
|
+
storage.sign_private_url {
|
|
188
|
+
pathname = $rec.file.path
|
|
189
|
+
ttl = 3600
|
|
190
|
+
} as $signed_url
|
|
191
|
+
}
|
|
192
|
+
response = {
|
|
193
|
+
id : $rec.id
|
|
194
|
+
name : $rec.name
|
|
195
|
+
path : $rec.file.path
|
|
196
|
+
size : $rec.file.size
|
|
197
|
+
signed_url: $signed_url
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Complete Multiple-Upload Pattern
|
|
203
|
+
|
|
204
|
+
Declare the input `file[]?` and loop with `foreach`/`each as`. **The multipart field name must be sent with a `[]` suffix** (e.g. `photos[]`) for Xano to collect repeated parts into the array — see the frontend note below.
|
|
205
|
+
|
|
206
|
+
```xs
|
|
207
|
+
query upload_many verb=POST {
|
|
208
|
+
api_group = "FileUploadDemo"
|
|
209
|
+
input {
|
|
210
|
+
text item_id
|
|
211
|
+
file[]? photos?
|
|
212
|
+
}
|
|
213
|
+
stack {
|
|
214
|
+
var $created { value = [] }
|
|
215
|
+
conditional {
|
|
216
|
+
if ($input.photos != null && ($input.photos|count) > 0) {
|
|
217
|
+
foreach ($input.photos) {
|
|
218
|
+
each as $file {
|
|
219
|
+
storage.create_attachment {
|
|
220
|
+
value = $file
|
|
221
|
+
access = "private"
|
|
222
|
+
filename = $file.name
|
|
223
|
+
} as $stored_file
|
|
224
|
+
db.add item_photo {
|
|
225
|
+
data = {
|
|
226
|
+
item_id: $input.item_id
|
|
227
|
+
file : $stored_file
|
|
228
|
+
}
|
|
229
|
+
} as $new_photo
|
|
230
|
+
var.update $created {
|
|
231
|
+
value = $created|push:{ id: $new_photo.id, path: $new_photo.file.path }
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
response = {
|
|
239
|
+
count : $created|count
|
|
240
|
+
created: $created
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Table Schema for Stored Files
|
|
246
|
+
|
|
247
|
+
Store the file metadata object in an `attachment?` (or `image?`) column. Despite the names, both column types store the identical JSON structure (`access`, `path`, `name`, `type`, `size`, `mime`, `meta`), and both accept the result of `storage.create_attachment` **and** `storage.create_image` — there is no type mismatch at the data layer (verified live: an `image?` column accepts a `create_attachment` result and vice-versa).
|
|
248
|
+
|
|
249
|
+
```xs
|
|
250
|
+
table upload_demo_file {
|
|
251
|
+
auth = false
|
|
252
|
+
schema {
|
|
253
|
+
int id
|
|
254
|
+
timestamp created_at?=now
|
|
255
|
+
text? name? filters=trim
|
|
256
|
+
// File metadata from storage.create_attachment / storage.create_image.
|
|
257
|
+
attachment? file?
|
|
258
|
+
}
|
|
259
|
+
index = [
|
|
260
|
+
{type: "primary", field: [{name: "id"}]}
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Use `attachment?` for general files and `image?` for image-only columns if you want the schema to be semantically accurate. Functionally, both work for either storage op.
|
|
266
|
+
|
|
267
|
+
## Deleting & Replacing Files
|
|
268
|
+
|
|
269
|
+
Delete a stored file from the vault by its `.path` (verified live — the signed URL returns 404 afterwards):
|
|
270
|
+
|
|
271
|
+
```xs
|
|
272
|
+
storage.delete_file { pathname = $stored_file.path }
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
To **replace** a file on a record: store the new upload, `db.edit`/`db.patch` the column with the new stored object, then `storage.delete_file` the old `.path`. Clearing the column (e.g. `db.patch` setting `file` to `null`) removes the reference but does not delete the vault file — call `delete_file` for that. (`storage.delete_file` lives in the `integrations/utilities` topic alongside `create_file_resource` and `read_file_resource`.)
|
|
276
|
+
|
|
277
|
+
## Frontend Pattern (JavaScript)
|
|
278
|
+
|
|
279
|
+
Always send files via `FormData`. **Never** set `Content-Type` manually — the browser sets `multipart/form-data` with the required boundary automatically.
|
|
280
|
+
|
|
281
|
+
```javascript
|
|
282
|
+
// Single file
|
|
283
|
+
async function uploadFile(file, name) {
|
|
284
|
+
const formData = new FormData();
|
|
285
|
+
formData.append('document', file); // field name must match the XanoScript input name
|
|
286
|
+
formData.append('name', name); // text fields go in the same FormData
|
|
287
|
+
const response = await fetch(`${BASE_URL}/upload`, {
|
|
288
|
+
method: 'POST',
|
|
289
|
+
headers: { Authorization: `Bearer ${token}` }, // NO Content-Type header
|
|
290
|
+
body: formData
|
|
291
|
+
});
|
|
292
|
+
if (!response.ok) throw new Error((await response.json()).message);
|
|
293
|
+
return response.json();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Multiple files — append with a `[]` suffix so a `file[]?` input receives ALL files.
|
|
297
|
+
// Appending repeatedly as 'photos' (no brackets) makes Xano keep only the LAST file.
|
|
298
|
+
async function uploadFiles(files, itemId) {
|
|
299
|
+
const formData = new FormData();
|
|
300
|
+
files.forEach(file => formData.append('photos[]', file)); // note the [] suffix
|
|
301
|
+
formData.append('item_id', itemId);
|
|
302
|
+
const response = await fetch(`${BASE_URL}/upload_many`, {
|
|
303
|
+
method: 'POST',
|
|
304
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
305
|
+
body: formData
|
|
306
|
+
});
|
|
307
|
+
return response.json();
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
```html
|
|
312
|
+
<!-- Any file (documents, images, PDFs) -->
|
|
313
|
+
<input type="file" id="document" accept="image/*,application/pdf">
|
|
314
|
+
<!-- Multiple -->
|
|
315
|
+
<input type="file" id="photos" accept="image/*" multiple>
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## JSON Endpoints vs Multipart Endpoints
|
|
319
|
+
|
|
320
|
+
- An endpoint with **no** file inputs receives a JSON body (`Content-Type: application/json`).
|
|
321
|
+
- An endpoint with **any** file input must be sent as `FormData` (multipart). If you need both a file and text fields in one request, put everything in `FormData` — text fields become form fields, files become file parts. Do not mix a JSON body with a file part.
|
|
322
|
+
- An endpoint's mode is determined by whether it currently has any file inputs. **Adding a file input to an existing JSON-only endpoint and pushing it via the CLI works** — the endpoint switches to multipart automatically on the next request (verified live; you do **not** need to create a separate endpoint).
|
|
323
|
+
|
|
324
|
+
## Common Mistakes
|
|
325
|
+
|
|
326
|
+
❌ **`image?` input — `Missing param: path` at runtime (validator does NOT catch this):**
|
|
327
|
+
```xs
|
|
328
|
+
input { image? photo }
|
|
329
|
+
stack {
|
|
330
|
+
storage.create_image {
|
|
331
|
+
value = $input.photo
|
|
332
|
+
access = "private"
|
|
333
|
+
filename = $input.photo.name
|
|
334
|
+
} as $f
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
The snippet above is fully valid syntax — `xano_validate_xanoscript` passes it — but it fails at runtime because `image?` never populates `$input.photo.path`.
|
|
338
|
+
|
|
339
|
+
✅ **`file?` input populates `.path`:**
|
|
340
|
+
```xs
|
|
341
|
+
input { file? photo }
|
|
342
|
+
stack {
|
|
343
|
+
storage.create_attachment {
|
|
344
|
+
value = $input.photo
|
|
345
|
+
access = "private"
|
|
346
|
+
filename = $input.photo.name
|
|
347
|
+
} as $f
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
❌ **Touching `.tmp_name` / hand-setting `.path` (hallucinated input properties — AI anti-pattern).** This does **not** help: with an `image?` input the `Missing param: path` error fires at the input layer before the stack runs, so the `|set` never executes (verified live).
|
|
352
|
+
```xs
|
|
353
|
+
input { image? photo }
|
|
354
|
+
stack {
|
|
355
|
+
var $patched {
|
|
356
|
+
value = $input.photo|set:"path":$input.photo.tmp_name
|
|
357
|
+
}
|
|
358
|
+
storage.create_attachment {
|
|
359
|
+
value = $patched
|
|
360
|
+
access = "private"
|
|
361
|
+
filename = $patched.name
|
|
362
|
+
} as $f
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
✅ **Just use `file?`** — Xano sets `.path` for you before the stack runs.
|
|
367
|
+
|
|
368
|
+
❌ **`storage.create_image` for a PDF — `Invalid file extension.` (HTTP 500):**
|
|
369
|
+
```xs
|
|
370
|
+
storage.create_image {
|
|
371
|
+
value = $input.document
|
|
372
|
+
access = "private"
|
|
373
|
+
filename = $input.document.name
|
|
374
|
+
} as $f
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
✅ **`storage.create_attachment` accepts any type:**
|
|
378
|
+
```xs
|
|
379
|
+
storage.create_attachment {
|
|
380
|
+
value = $input.document
|
|
381
|
+
access = "private"
|
|
382
|
+
filename = $input.document.name
|
|
383
|
+
} as $f
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
❌ **Omitting `access` or `filename`** — `storage.create_attachment { value = $input.photo } as $f` fails validation with `Missing required argument 'access'`. Always pass all three.
|
|
387
|
+
|
|
388
|
+
❌ **Comma-separated or commented op args** — `storage.create_attachment { value = ..., filename = ... }` and a comment inside the `{ }` are both parse errors. One argument per line, comments on their own line outside the block.
|
|
389
|
+
|
|
390
|
+
## Error Reference
|
|
391
|
+
|
|
392
|
+
| Error | Status | Cause | Fix |
|
|
393
|
+
|-------|--------|-------|-----|
|
|
394
|
+
| `Missing param: path` (`ERROR_CODE_INPUT_ERROR`, `payload.param` ends in `.path`) | 400 | Input declared `image?`/`video?`/`audio?`/`attachment?` — Xano doesn't set `.path` on the raw upload object | Change input type to `file?` |
|
|
395
|
+
| `Invalid file extension.` (`ERROR_FATAL`) | 500 | `storage.create_image` with a non-image (PDF, HEIC, …) | Use `storage.create_attachment` |
|
|
396
|
+
| `Missing required argument 'access'` (validation, at push time) | — | A `storage.create_*` call omitted `access` (or `filename`) | Pass `value`, `access`, and `filename` |
|
|
397
|
+
| HTTP 403 when fetching a file's `.path` | 403 | The file is `private`; raw paths aren't public | Generate `storage.sign_private_url`, or store the file as `public` |
|
|
398
|
+
| Multiple upload stored only one file | — | Multipart field appended without the `[]` suffix | Append files as `field[]` (e.g. `photos[]`) |
|
|
399
|
+
|
|
400
|
+
## Related Topics
|
|
401
|
+
|
|
402
|
+
| Topic | Use For |
|
|
403
|
+
|-------|---------|
|
|
404
|
+
| `integrations/utilities` | Other `storage.*` ops: `create_file_resource`, `read_file_resource`, `delete_file` |
|
|
405
|
+
| `integrations/cloud-storage` | Uploading to external buckets (AWS S3, Azure, GCP) instead of Xano's vault |
|
|
406
|
+
| `types` | Input block syntax and the full file-type list |
|
|
407
|
+
| `database` | `db.add` and storing the file metadata record |
|
|
408
|
+
| `streaming` | Streaming large files in requests/responses |
|
|
@@ -23,42 +23,70 @@ applyTo: "function/**/*.xs, api/**/*.xs, task/*.xs"
|
|
|
23
23
|
|
|
24
24
|
### File Operations
|
|
25
25
|
|
|
26
|
+
> **⚠️ XanoScript comments use `//`, never `#`.** A `#` inside a `.xs` file is a parse error. Also: comments are not allowed inside an operation's `{ ... }` argument block — keep them on their own line above the op.
|
|
27
|
+
|
|
26
28
|
```xs
|
|
27
|
-
|
|
29
|
+
// create_file_resource turns in-stack data (CSV/JSON/zip output) into a FILE
|
|
30
|
+
// RESOURCE — the same value type a `file?` input produces. It is NOT a stored
|
|
31
|
+
// vault file and has no servable URL/path of its own; to persist or serve it,
|
|
32
|
+
// pass it to storage.create_attachment (see "Storing a generated file" below).
|
|
28
33
|
storage.create_file_resource {
|
|
29
34
|
filename = "report.csv"
|
|
30
35
|
filedata = $csv_content
|
|
31
|
-
} as $
|
|
36
|
+
} as $resource
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
// read_file_resource returns the contents of a file resource (e.g. to parse it).
|
|
34
39
|
storage.read_file_resource {
|
|
35
|
-
value = $input.
|
|
40
|
+
value = $input.upload
|
|
36
41
|
} as $content
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
storage.delete_file { pathname =
|
|
43
|
+
// Delete a stored vault file by its `.path` (the value saved on the DB record).
|
|
44
|
+
storage.delete_file { pathname = $stored_file.path }
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Storing a generated file (so it has a URL)
|
|
48
|
+
|
|
49
|
+
A `create_file_resource` value cannot be served directly. Store it via `storage.create_attachment` (or `create_image`), then serve it like any uploaded file — `sign_private_url` for private, or instance URL + `.path` for public:
|
|
50
|
+
|
|
51
|
+
```xs
|
|
52
|
+
storage.create_file_resource {
|
|
53
|
+
filename = "export.csv"
|
|
54
|
+
filedata = $csv_content
|
|
55
|
+
} as $resource
|
|
56
|
+
storage.create_attachment {
|
|
57
|
+
value = $resource
|
|
58
|
+
access = "public"
|
|
59
|
+
filename = "export.csv"
|
|
60
|
+
} as $stored_file
|
|
40
61
|
```
|
|
41
62
|
|
|
63
|
+
Then return `($env.PUBLIC_BASE_URL ~ $stored_file.path)` for public, or `storage.sign_private_url` for private. See `xano_xanoscript_docs({ topic: "file-uploads" })`.
|
|
64
|
+
|
|
42
65
|
### Image/Attachment Handling
|
|
43
66
|
|
|
67
|
+
> **⚠️ Upload inputs must be typed `file?`, not `image?`/`attachment?`.** Only `file` populates `.path` on a multipart upload; the others pass the raw object and `storage.*` fails with `Missing param: path`. Use `storage.create_attachment` (any file type) over `storage.create_image` (image extensions only). Full pattern: `xano_xanoscript_docs({ topic: "file-uploads" })`.
|
|
68
|
+
|
|
44
69
|
```xs
|
|
45
|
-
|
|
70
|
+
// The upload input is declared `file?` so Xano populates `.path` first.
|
|
71
|
+
// input { file? upload }
|
|
72
|
+
|
|
73
|
+
// Create image metadata (images only: JPEG/PNG/GIF/WEBP)
|
|
46
74
|
storage.create_image {
|
|
47
|
-
value = $input.
|
|
75
|
+
value = $input.upload
|
|
48
76
|
access = "public"
|
|
49
|
-
filename =
|
|
77
|
+
filename = $input.upload.name
|
|
50
78
|
} as $image_meta
|
|
51
79
|
|
|
52
|
-
|
|
80
|
+
// Create attachment metadata (any file type — recommended default)
|
|
53
81
|
storage.create_attachment {
|
|
54
|
-
value = $input.
|
|
82
|
+
value = $input.upload
|
|
55
83
|
access = "private"
|
|
56
|
-
filename =
|
|
84
|
+
filename = $input.upload.name
|
|
57
85
|
} as $attachment_meta
|
|
58
86
|
|
|
59
|
-
|
|
87
|
+
// Sign private URL (use the stored .path, never a hand-built path)
|
|
60
88
|
storage.sign_private_url {
|
|
61
|
-
pathname =
|
|
89
|
+
pathname = $attachment_meta.path
|
|
62
90
|
ttl = 300
|
|
63
91
|
} as $signed_url
|
|
64
92
|
```
|
|
@@ -70,12 +98,12 @@ storage.sign_private_url {
|
|
|
70
98
|
### Password Hashing
|
|
71
99
|
|
|
72
100
|
```xs
|
|
73
|
-
|
|
101
|
+
// Password is auto-hashed on insert
|
|
74
102
|
db.add "user" {
|
|
75
103
|
data = { email: $input.email, password: $input.password }
|
|
76
104
|
}
|
|
77
105
|
|
|
78
|
-
|
|
106
|
+
// Verify password
|
|
79
107
|
security.check_password {
|
|
80
108
|
text_password = $input.password
|
|
81
109
|
hash_password = $user.password
|
|
@@ -85,7 +113,7 @@ security.check_password {
|
|
|
85
113
|
### Encryption
|
|
86
114
|
|
|
87
115
|
```xs
|
|
88
|
-
|
|
116
|
+
// Encrypt
|
|
89
117
|
security.encrypt {
|
|
90
118
|
data = $sensitive_data
|
|
91
119
|
algorithm = "aes-256-cbc"
|
|
@@ -93,7 +121,7 @@ security.encrypt {
|
|
|
93
121
|
iv = $env.ENCRYPTION_IV
|
|
94
122
|
} as $encrypted
|
|
95
123
|
|
|
96
|
-
|
|
124
|
+
// Decrypt
|
|
97
125
|
security.decrypt {
|
|
98
126
|
data = $encrypted
|
|
99
127
|
algorithm = "aes-256-cbc"
|
|
@@ -105,7 +133,7 @@ security.decrypt {
|
|
|
105
133
|
### JWT (JWS/JWE)
|
|
106
134
|
|
|
107
135
|
```xs
|
|
108
|
-
|
|
136
|
+
// Sign JWT
|
|
109
137
|
security.jws_encode {
|
|
110
138
|
claims = { user_id: $user.id, role: $user.role }
|
|
111
139
|
key = $env.JWT_SECRET
|
|
@@ -113,7 +141,7 @@ security.jws_encode {
|
|
|
113
141
|
ttl = 3600
|
|
114
142
|
} as $token
|
|
115
143
|
|
|
116
|
-
|
|
144
|
+
// Verify JWT
|
|
117
145
|
security.jws_decode {
|
|
118
146
|
token = $input.token
|
|
119
147
|
key = $env.JWT_SECRET
|
|
@@ -264,9 +292,21 @@ query "export_data" {
|
|
|
264
292
|
storage.create_file_resource {
|
|
265
293
|
filename = "export.zip"
|
|
266
294
|
filedata = $archive
|
|
295
|
+
} as $resource
|
|
296
|
+
|
|
297
|
+
// create_file_resource is not directly servable — store it to get a vault path.
|
|
298
|
+
storage.create_attachment {
|
|
299
|
+
value = $resource
|
|
300
|
+
access = "private"
|
|
301
|
+
filename = "export.zip"
|
|
267
302
|
} as $download
|
|
303
|
+
|
|
304
|
+
storage.sign_private_url {
|
|
305
|
+
pathname = $download.path
|
|
306
|
+
ttl = 600
|
|
307
|
+
} as $download_url
|
|
268
308
|
}
|
|
269
|
-
response = { download_url: $
|
|
309
|
+
response = { download_url: $download_url }
|
|
270
310
|
}
|
|
271
311
|
```
|
|
272
312
|
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: []
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Skills & Docs (Agent Knowledge)
|
|
6
|
+
|
|
7
|
+
Teach the Xano AI agent how to work in your workspace — standing rules, reference docs, and repeatable procedures it follows when building your backend.
|
|
8
|
+
|
|
9
|
+
> **TL;DR:** Agent Knowledge has three kinds of files. **Context** (`AGENTS.md`) is always loaded — standing rules for every run. A **Doc** is a single markdown file the agent reads for reference when a task calls for it. A **Skill** is a folder (`SKILL.md` + optional reference files) the agent follows step by step. Control *when* each loads with a disclosure mode, and *who* sees it with a scope.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Quick Reference
|
|
14
|
+
|
|
15
|
+
| Type | Lives at | Best for | Loading |
|
|
16
|
+
|------|----------|----------|---------|
|
|
17
|
+
| **Context** | `AGENTS.md` | Standing rules & conventions the agent must always know | Always, in full |
|
|
18
|
+
| **Doc** | `docs/<name>.md` | Facts, specs, guidelines the agent reads on demand | On demand |
|
|
19
|
+
| **Skill** | `skills/<name>/SKILL.md` | Repeatable, multi-step procedures | On demand or manual |
|
|
20
|
+
| **Reference** | a file inside a skill | Supporting detail a skill step needs | Pulled in by its skill |
|
|
21
|
+
|
|
22
|
+
**Disclosure** (when it loads): `Always included` · `On demand` · `Manual`
|
|
23
|
+
**Scope** (who sees it): `Workspace` (everyone) · `Private` (only you)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## The three knowledge types
|
|
28
|
+
|
|
29
|
+
### Context — your `AGENTS.md`
|
|
30
|
+
|
|
31
|
+
A single `AGENTS.md` file that is **injected into every agent session, in full**. It's the right home for the conventions, rules, and patterns you want the agent to repeat on every run: the backend's purpose, the data model's shape, naming conventions, the auth model, standard error shapes.
|
|
32
|
+
|
|
33
|
+
Because every line is loaded on every run, every line has a permanent context cost — so keep it lean. Capture the *shape* and the *non-obvious*; let the agent drill into specifics with its own tools when it needs them.
|
|
34
|
+
|
|
35
|
+
```markdown
|
|
36
|
+
# Acme Orders API
|
|
37
|
+
|
|
38
|
+
> Backend for the Acme storefront — handles auth, catalog, and checkout.
|
|
39
|
+
|
|
40
|
+
## Data model
|
|
41
|
+
| Table | Purpose | Key fields / relationships |
|
|
42
|
+
| ------ | --------------- | ---------------------------- |
|
|
43
|
+
| users | Auth + profile | id, email; has many `orders` |
|
|
44
|
+
| orders | Customer orders | id, user_id → users, status |
|
|
45
|
+
|
|
46
|
+
Orders are soft-deleted (`deleted_at`), never hard-deleted.
|
|
47
|
+
|
|
48
|
+
## Conventions
|
|
49
|
+
- Auth: JWT in `Authorization: Bearer`. Protect every non-public endpoint.
|
|
50
|
+
- Errors: return `{ error: { code, message } }`, never a bare string.
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
> **Tip:** Use the **`init`** skill to scaffold `AGENTS.md` — it inspects your workspace (read-only) and works with you to capture purpose, data model, APIs, logic, and conventions, asking one question at a time rather than guessing.
|
|
54
|
+
|
|
55
|
+
### Doc — reference material
|
|
56
|
+
|
|
57
|
+
A single markdown file at `docs/<name>.md` that the agent reads **when a task calls for it**. Best for facts, specs, and guidelines — a style guide, an external API's quirks, a domain glossary. The agent sees the title and description up front and pulls in the full file only when relevant, so docs don't spend context on every run.
|
|
58
|
+
|
|
59
|
+
### Skill — a repeatable procedure
|
|
60
|
+
|
|
61
|
+
A folder at `skills/<name>/` containing a `SKILL.md` (and optional reference files) that the agent **follows step by step**. Best for multi-step workflows that recur — "scaffold a CRUD API for a table", "apply rate limiting to an endpoint", "add audit logging to a mutation".
|
|
62
|
+
|
|
63
|
+
```markdown
|
|
64
|
+
---
|
|
65
|
+
name: rate-limit-endpoint
|
|
66
|
+
description: Apply rate limiting to an endpoint. Use when a user asks to
|
|
67
|
+
throttle, protect, or rate-limit an endpoint, or guard it from abuse.
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
# Rate Limit an Endpoint
|
|
71
|
+
|
|
72
|
+
Add a Rate Limit function to the start of an endpoint's stack so repeated
|
|
73
|
+
calls from the same caller are rejected before they do work.
|
|
74
|
+
|
|
75
|
+
## Steps
|
|
76
|
+
1. Confirm which endpoint and the limit (requests per window) with the user.
|
|
77
|
+
2. Add a `precondition` that checks the caller's recent request count.
|
|
78
|
+
3. Return a 429 with a clear message when the limit is exceeded.
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
> **Tip:** Use the **`create-skill`** skill to author one — it captures *what* the agent should do, *when* it should trigger, and *what good looks like*, then writes a well-formed `SKILL.md`.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Disclosure — controlling when knowledge loads
|
|
86
|
+
|
|
87
|
+
Each doc and skill has a disclosure mode that decides how it enters the agent's context:
|
|
88
|
+
|
|
89
|
+
| Mode | What loads | Use when |
|
|
90
|
+
|------|-----------|----------|
|
|
91
|
+
| **Always included** | The full file, every run | Rules the agent must never miss. Use sparingly — it spends context on every run. |
|
|
92
|
+
| **On demand** | Only the title + description up front; the agent pulls the full file when it judges it relevant | The default. Reference material and most skills. |
|
|
93
|
+
| **Manual** | Nothing automatically; loads only when you name it in the prompt | Niche or expensive procedures you want to invoke deliberately. |
|
|
94
|
+
|
|
95
|
+
`AGENTS.md` is always *Always included* — that's the whole point of Context. Reserve *Always included* on docs and skills for the rare thing the agent genuinely must read every time.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Scope — controlling who sees it
|
|
100
|
+
|
|
101
|
+
| Scope | Who | Use for |
|
|
102
|
+
|-------|-----|---------|
|
|
103
|
+
| **Workspace** | Everyone in the workspace | Shared conventions, team procedures, project docs |
|
|
104
|
+
| **Private** | Only you | Personal helpers and drafts you're still refining |
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Writing knowledge the agent actually follows
|
|
109
|
+
|
|
110
|
+
The same principles run through good Context, Docs, and Skills:
|
|
111
|
+
|
|
112
|
+
- **Write a description that earns its place.** For docs and skills, the description is the *only* text always loaded — it's what the agent uses to decide whether to pull in the rest. Be explicit and specific: name the exact situations and phrases that should trigger it. A vague description means the file never gets used (or gets used at the wrong time).
|
|
113
|
+
- **Explain *why*, not just *what*.** Rigid commands ("ALWAYS do X") are brittle — the agent can't adapt when a situation differs slightly. Give the reasoning instead, so it applies the rule correctly in cases you didn't foresee. Weak: "Validate input before saving." Better: "Validate input before saving — bad records are far harder to find and fix once they're in your live tables."
|
|
114
|
+
- **Keep it lean.** Every line costs context the agent could spend reasoning. Cut preamble, ceremony, and anything the agent already knows.
|
|
115
|
+
- **Put rules in `AGENTS.md`, procedures in skills.** Workspace-wide conventions (naming, auth, error shapes) belong in `AGENTS.md`, which is always loaded. A skill is for a repeatable *workflow* — it should *assume* those conventions and use them, not restate them.
|
|
116
|
+
- **Generalize past the example.** A skill is usually born from one concrete request. Write the general pattern, not the one case, so it helps with the whole class of tasks.
|
|
117
|
+
- **Add a guardrail before anything hard to reverse.** Have a skill confirm with the user before a destructive change (deleting a table, dropping an endpoint).
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Common Mistakes
|
|
122
|
+
|
|
123
|
+
❌ **Putting a one-off task in a skill.** Skills are for workflows that recur. A single task is faster to just ask for.
|
|
124
|
+
✅ Create a skill only when the same multi-step workflow comes up again and again.
|
|
125
|
+
|
|
126
|
+
❌ **Restating `AGENTS.md` conventions inside a skill.** Duplicated instructions drift out of sync and bloat the body.
|
|
127
|
+
✅ Assume `AGENTS.md` is loaded; reference its conventions and use them.
|
|
128
|
+
|
|
129
|
+
❌ **Stuffing reference material into `AGENTS.md` to "make sure the agent has it".** It then pays that cost on every run.
|
|
130
|
+
✅ Put reference material in a **Doc** (on demand). Reserve `AGENTS.md` for rules that apply every time.
|
|
131
|
+
|
|
132
|
+
❌ **A vague skill description** ("helps with endpoints").
|
|
133
|
+
✅ A pushy, specific one that names the trigger: "Apply rate limiting to an endpoint. Use when a user asks to throttle or protect an endpoint from abuse."
|
|
134
|
+
|
|
135
|
+
❌ **Marking many skills "Always included".**
|
|
136
|
+
✅ Default to **On demand**; reserve *Always included* for the rare thing the agent must read every time.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Related Topics
|
|
141
|
+
|
|
142
|
+
| Topic | Description |
|
|
143
|
+
|-------|-------------|
|
|
144
|
+
| `agents` | XanoScript `agent` construct — LLM providers and tools |
|
|
145
|
+
| `tools` | Functions an agent can execute |
|
|
146
|
+
| `workspace` | Workspace-level settings and preferences |
|
|
@@ -204,14 +204,25 @@ object[] items {
|
|
|
204
204
|
```
|
|
205
205
|
|
|
206
206
|
### File Types
|
|
207
|
+
|
|
208
|
+
> **⚠️ For uploaded files, always use `file`.** Only `file` pre-processes a multipart upload and populates `.path`; `image`/`attachment`/`video`/`audio` pass the raw upload object, so any `storage.*` op fails with `Missing param: path`. The names look like semantic choices but are technical. See `xano_xanoscript_docs({ topic: "file-uploads" })`.
|
|
209
|
+
|
|
207
210
|
```xs
|
|
211
|
+
// ✅ use `file` for ALL uploads — only `file` populates .path
|
|
212
|
+
file generic_file
|
|
213
|
+
// optional upload
|
|
214
|
+
file? document
|
|
215
|
+
// multiple uploads
|
|
216
|
+
file[]? attachments
|
|
217
|
+
|
|
218
|
+
// image/attachment/video/audio exist but DO NOT populate .path on upload —
|
|
219
|
+
// they are mainly useful as table column types for stored file metadata.
|
|
208
220
|
image photo {
|
|
209
221
|
description = "Profile photo"
|
|
210
222
|
}
|
|
211
223
|
attachment document
|
|
212
224
|
video recording
|
|
213
225
|
audio clip
|
|
214
|
-
file generic_file
|
|
215
226
|
```
|
|
216
227
|
|
|
217
228
|
### Geographic Types
|
package/package.json
CHANGED