@proveanything/smartlinks 2.1.40 → 2.1.41
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/README.md +754 -754
- package/dist/README.md +573 -573
- package/dist/adminCardsView.js +55 -55
- package/dist/api/collection.d.ts +8 -1
- package/dist/api/collection.js +10 -0
- package/dist/baseline.css +194 -194
- package/dist/docs/API_SUMMARY.md +863 -835
- package/dist/docs/admin-cards.md +189 -189
- package/dist/docs/agent-tools.md +156 -156
- package/dist/docs/ai-tools-and-skills.md +180 -180
- package/dist/docs/ai.md +1721 -1721
- package/dist/docs/analytics.md +39 -39
- package/dist/docs/app-data-storage.md +277 -277
- package/dist/docs/app-docs.md +73 -73
- package/dist/docs/app-manifest.md +852 -852
- package/dist/docs/app-records-pattern.md +388 -388
- package/dist/docs/appConfig.md +550 -550
- package/dist/docs/assistant-apps.md +172 -172
- package/dist/docs/assistant-context.md +119 -119
- package/dist/docs/bookings.md +442 -442
- package/dist/docs/comms.md +686 -686
- package/dist/docs/connectors.md +340 -340
- package/dist/docs/css-baseline.md +133 -133
- package/dist/docs/customer-guide.md +70 -70
- package/dist/docs/deploying-apps.md +340 -340
- package/dist/docs/entitlements.md +90 -90
- package/dist/docs/files.md +69 -69
- package/dist/docs/host-dependency-contract.md +210 -210
- package/dist/docs/integrations.md +322 -322
- package/dist/docs/interactions.md +545 -545
- package/dist/docs/item-context.md +181 -181
- package/dist/docs/knowledge.md +102 -102
- package/dist/docs/lots.md +111 -111
- package/dist/docs/loyalty.md +352 -352
- package/dist/docs/members.md +182 -182
- package/dist/docs/mobile-admin-container.md +693 -693
- package/dist/docs/operations.md +281 -281
- package/dist/docs/overview.md +482 -482
- package/dist/docs/proof-comms-triggers.md +142 -142
- package/dist/docs/proof-ownership-transfer.md +155 -155
- package/dist/docs/proof-product-data-scoping.md +462 -462
- package/dist/docs/proof-share-grants.md +305 -305
- package/dist/docs/realtime.md +138 -138
- package/dist/docs/records-admin-pattern.md +304 -304
- package/dist/docs/standard-query.md +187 -187
- package/dist/docs/tag-codes.md +97 -97
- package/dist/docs/theme-tokens.md +252 -252
- package/dist/docs/wallet-passes.md +107 -107
- package/dist/docs/websites.md +123 -123
- package/dist/openapi.yaml +80 -3
- package/dist/theme-boot.js +78 -78
- package/dist/theme.css +75 -75
- package/dist/types/appManifest.d.ts +21 -0
- package/dist/types/collection.d.ts +26 -0
- package/docs/API_SUMMARY.md +863 -835
- package/docs/admin-cards.md +189 -189
- package/docs/agent-tools.md +156 -156
- package/docs/ai-tools-and-skills.md +180 -180
- package/docs/ai.md +1721 -1721
- package/docs/analytics.md +39 -39
- package/docs/app-data-storage.md +277 -277
- package/docs/app-docs.md +73 -73
- package/docs/app-manifest.md +852 -852
- package/docs/app-records-pattern.md +388 -388
- package/docs/appConfig.md +550 -550
- package/docs/assistant-apps.md +172 -172
- package/docs/assistant-context.md +119 -119
- package/docs/bookings.md +442 -442
- package/docs/comms.md +686 -686
- package/docs/connectors.md +340 -340
- package/docs/css-baseline.md +133 -133
- package/docs/customer-guide.md +70 -70
- package/docs/deploying-apps.md +340 -340
- package/docs/entitlements.md +90 -90
- package/docs/files.md +69 -69
- package/docs/host-dependency-contract.md +210 -210
- package/docs/integrations.md +322 -322
- package/docs/interactions.md +545 -545
- package/docs/item-context.md +181 -181
- package/docs/knowledge.md +102 -102
- package/docs/lots.md +111 -111
- package/docs/loyalty.md +352 -352
- package/docs/members.md +182 -182
- package/docs/mobile-admin-container.md +693 -693
- package/docs/operations.md +281 -281
- package/docs/overview.md +482 -482
- package/docs/proof-comms-triggers.md +142 -142
- package/docs/proof-ownership-transfer.md +155 -155
- package/docs/proof-product-data-scoping.md +462 -462
- package/docs/proof-share-grants.md +305 -305
- package/docs/realtime.md +138 -138
- package/docs/standard-query.md +187 -187
- package/docs/tag-codes.md +97 -97
- package/docs/theme-lookbook.v1.json +120 -120
- package/docs/theme-tokens.md +252 -252
- package/docs/wallet-passes.md +107 -107
- package/docs/websites.md +123 -123
- package/openapi.yaml +80 -3
- package/package.json +87 -87
- package/scripts/headless-check.mjs +87 -87
- package/scripts/lib/bare-imports.mjs +57 -57
- package/scripts/lib/keyed-app-data.mjs +21 -21
- package/scripts/publish.mjs +272 -272
- package/scripts/register-release.mjs +91 -91
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
# Entitlements: "can this person do this?" without a mirror of their member base
|
|
2
|
-
|
|
3
|
-
A brand with twenty million members wants a game only Gold members can play. SmartLinks never copies
|
|
4
|
-
the member base to find out. A **gate** says what it needs — a predicate such as `tier>=gold` — and the
|
|
5
|
-
platform asks the collection's configured **sources**, in order, stopping at the first that answers.
|
|
6
|
-
The brand's system stays the record of truth; every answer says where it came from (`basis`) and how
|
|
7
|
-
old it is (`asOf`).
|
|
8
|
-
|
|
9
|
-
| Source | Data kept here | When it fits |
|
|
10
|
-
|---|---|---|
|
|
11
|
-
| **claims** | none | the brand's SSO or app issues a short-lived signed token carrying the tier; the caller presents it |
|
|
12
|
-
| **lookup** | a hashed key → a small answer, for minutes | the loyalty connector's `lookup` step answers for one person; cached in Valkey under an HMAC of the identity for the TTL the brand sets (default 15 min; "not a member" 5 min); one in-flight lookup per key; the connector's own rate limit applies |
|
|
13
|
-
| **contact** | what the contact already holds | `customFields.loyalty` / `loyaltyTier` written by the connector's member webhook (`ctx.sl.members.apply`) |
|
|
14
|
-
| **fallback** | — | when nothing answered: `deny` (default), `allow`, or `degrade` (allow, flagged `degraded: true`) |
|
|
15
|
-
|
|
16
|
-
Every decision is one structured log line — gate, predicate, allowed, basis, age, an identity **hash**
|
|
17
|
-
— and never an identifier. A caller sees `attributes` (tier, points, status, member) and never a member
|
|
18
|
-
id.
|
|
19
|
-
|
|
20
|
-
## Predicates
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
'tier>=gold' 'tier=silver' 'tier in gold,platinum' 'points>=500' 'member'
|
|
24
|
-
{ tier: { gte: 'gold' } } { tier: { in: ['gold', 'platinum'] } } { member: true }
|
|
25
|
-
{ attribute: { path: 'status', eq: 'active' } }
|
|
26
|
-
{ all: [p1, p2] } { any: [p1, p2] } { not: p }
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Tier comparisons use the collection's ordered `tiers` list (lowest first); a tier the list doesn't know
|
|
30
|
-
never satisfies an ordered comparison. A malformed predicate is a configuration error (`BAD_PREDICATE`),
|
|
31
|
-
never a silent denial.
|
|
32
|
-
|
|
33
|
-
## Where gates live
|
|
34
|
-
|
|
35
|
-
**An interaction type** — the public submit route checks it; the caller may present a claim:
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
await SL.interactions.updateInteraction(collectionId, appId, typeId, {
|
|
39
|
-
permissions: { allowPublicSubmit: true, requires: { entitlement: 'tier>=gold', fallback: 'deny' } },
|
|
40
|
-
})
|
|
41
|
-
// A refused submit: 403 { error: 'FORBIDDEN', reason: 'entitlement_denied' }
|
|
42
|
-
// With a claim: body.entitlementToken = '<jwt>' or header X-SmartLinks-Entitlement: <jwt>
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
**A server function** — for the signed-in caller by default:
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
const d = await ctx.sl.entitlements.check('tier>=gold') // needs sl:entitlements:read
|
|
49
|
-
// → { allowed: true, basis: 'lookup-cache', asOf: '2026-11-08T09:00:00.000Z', attributes: { tier: 'gold', points: 1500, member: true } }
|
|
50
|
-
if (!d.allowed) return new Response(JSON.stringify({ error: 'gold_only' }), { status: 403 })
|
|
51
|
-
// Someone else, or a presented claim:
|
|
52
|
-
await ctx.sl.entitlements.check({ points: { gte: 500 } }, { identity: { email }, token, fallback: 'degrade' })
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Configuring a collection
|
|
56
|
-
|
|
57
|
-
The `entitlements` setting group (`settings.set(collectionId, 'entitlements', {...})`):
|
|
58
|
-
|
|
59
|
-
```jsonc
|
|
60
|
-
{
|
|
61
|
-
"sources": ["claims", "lookup", "contact"], // tried in this order
|
|
62
|
-
"fallback": "deny",
|
|
63
|
-
"tiers": ["bronze", "silver", "gold", "platinum"], // lowest first
|
|
64
|
-
"claims": {
|
|
65
|
-
"secretRef": "sec_brand_sso", // HS256 shared secret in the secret store …
|
|
66
|
-
"publicKeyPem": "-----BEGIN PUBLIC KEY-----…", // … or an RS256 / ES256 public key
|
|
67
|
-
"issuer": "https://login.brand.example", "audience": "smartlinks",
|
|
68
|
-
"tierClaim": "tier", "memberIdClaim": "sub", "attributesClaim": "entitlements", "maxAgeSec": 900
|
|
69
|
-
},
|
|
70
|
-
"lookup": {
|
|
71
|
-
"connectorAppId": "acme-loyalty", "provider": "acme-loyalty",
|
|
72
|
-
"ttlSec": 900, "negativeTtlSec": 300,
|
|
73
|
-
"identity": "raw", // what the connector's lookup receives: 'raw' (email/phone) or 'hashed'
|
|
74
|
-
"want": ["tier", "points", "status"]
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
The connector side (`lookup`) is one step: one identity in, `{ found, memberId, tier, points, status,
|
|
80
|
-
asOf }` out; throw on an outage so the next source is tried — see
|
|
81
|
-
[connectors.md](connectors.md#loyalty-and-crm-connectors).
|
|
82
|
-
|
|
83
|
-
## What a brand can be told
|
|
84
|
-
|
|
85
|
-
- We never need a copy of your member base: claims and lookups hold nothing, or a minutes-old answer per
|
|
86
|
-
active person.
|
|
87
|
-
- Where you want a local copy, it holds no identifiers (the HMAC mirror — on request).
|
|
88
|
-
- Your system remains the record of truth: every answer carries `asOf` and `basis`; TTLs are yours to set.
|
|
89
|
-
- You see every call: the connector's calls are rate-limited, logged, and leave from a fixed egress IP.
|
|
90
|
-
- Nothing leaves without a policy: the envelope's identity policy per flow.
|
|
1
|
+
# Entitlements: "can this person do this?" without a mirror of their member base
|
|
2
|
+
|
|
3
|
+
A brand with twenty million members wants a game only Gold members can play. SmartLinks never copies
|
|
4
|
+
the member base to find out. A **gate** says what it needs — a predicate such as `tier>=gold` — and the
|
|
5
|
+
platform asks the collection's configured **sources**, in order, stopping at the first that answers.
|
|
6
|
+
The brand's system stays the record of truth; every answer says where it came from (`basis`) and how
|
|
7
|
+
old it is (`asOf`).
|
|
8
|
+
|
|
9
|
+
| Source | Data kept here | When it fits |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| **claims** | none | the brand's SSO or app issues a short-lived signed token carrying the tier; the caller presents it |
|
|
12
|
+
| **lookup** | a hashed key → a small answer, for minutes | the loyalty connector's `lookup` step answers for one person; cached in Valkey under an HMAC of the identity for the TTL the brand sets (default 15 min; "not a member" 5 min); one in-flight lookup per key; the connector's own rate limit applies |
|
|
13
|
+
| **contact** | what the contact already holds | `customFields.loyalty` / `loyaltyTier` written by the connector's member webhook (`ctx.sl.members.apply`) |
|
|
14
|
+
| **fallback** | — | when nothing answered: `deny` (default), `allow`, or `degrade` (allow, flagged `degraded: true`) |
|
|
15
|
+
|
|
16
|
+
Every decision is one structured log line — gate, predicate, allowed, basis, age, an identity **hash**
|
|
17
|
+
— and never an identifier. A caller sees `attributes` (tier, points, status, member) and never a member
|
|
18
|
+
id.
|
|
19
|
+
|
|
20
|
+
## Predicates
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
'tier>=gold' 'tier=silver' 'tier in gold,platinum' 'points>=500' 'member'
|
|
24
|
+
{ tier: { gte: 'gold' } } { tier: { in: ['gold', 'platinum'] } } { member: true }
|
|
25
|
+
{ attribute: { path: 'status', eq: 'active' } }
|
|
26
|
+
{ all: [p1, p2] } { any: [p1, p2] } { not: p }
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Tier comparisons use the collection's ordered `tiers` list (lowest first); a tier the list doesn't know
|
|
30
|
+
never satisfies an ordered comparison. A malformed predicate is a configuration error (`BAD_PREDICATE`),
|
|
31
|
+
never a silent denial.
|
|
32
|
+
|
|
33
|
+
## Where gates live
|
|
34
|
+
|
|
35
|
+
**An interaction type** — the public submit route checks it; the caller may present a claim:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
await SL.interactions.updateInteraction(collectionId, appId, typeId, {
|
|
39
|
+
permissions: { allowPublicSubmit: true, requires: { entitlement: 'tier>=gold', fallback: 'deny' } },
|
|
40
|
+
})
|
|
41
|
+
// A refused submit: 403 { error: 'FORBIDDEN', reason: 'entitlement_denied' }
|
|
42
|
+
// With a claim: body.entitlementToken = '<jwt>' or header X-SmartLinks-Entitlement: <jwt>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**A server function** — for the signed-in caller by default:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const d = await ctx.sl.entitlements.check('tier>=gold') // needs sl:entitlements:read
|
|
49
|
+
// → { allowed: true, basis: 'lookup-cache', asOf: '2026-11-08T09:00:00.000Z', attributes: { tier: 'gold', points: 1500, member: true } }
|
|
50
|
+
if (!d.allowed) return new Response(JSON.stringify({ error: 'gold_only' }), { status: 403 })
|
|
51
|
+
// Someone else, or a presented claim:
|
|
52
|
+
await ctx.sl.entitlements.check({ points: { gte: 500 } }, { identity: { email }, token, fallback: 'degrade' })
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Configuring a collection
|
|
56
|
+
|
|
57
|
+
The `entitlements` setting group (`settings.set(collectionId, 'entitlements', {...})`):
|
|
58
|
+
|
|
59
|
+
```jsonc
|
|
60
|
+
{
|
|
61
|
+
"sources": ["claims", "lookup", "contact"], // tried in this order
|
|
62
|
+
"fallback": "deny",
|
|
63
|
+
"tiers": ["bronze", "silver", "gold", "platinum"], // lowest first
|
|
64
|
+
"claims": {
|
|
65
|
+
"secretRef": "sec_brand_sso", // HS256 shared secret in the secret store …
|
|
66
|
+
"publicKeyPem": "-----BEGIN PUBLIC KEY-----…", // … or an RS256 / ES256 public key
|
|
67
|
+
"issuer": "https://login.brand.example", "audience": "smartlinks",
|
|
68
|
+
"tierClaim": "tier", "memberIdClaim": "sub", "attributesClaim": "entitlements", "maxAgeSec": 900
|
|
69
|
+
},
|
|
70
|
+
"lookup": {
|
|
71
|
+
"connectorAppId": "acme-loyalty", "provider": "acme-loyalty",
|
|
72
|
+
"ttlSec": 900, "negativeTtlSec": 300,
|
|
73
|
+
"identity": "raw", // what the connector's lookup receives: 'raw' (email/phone) or 'hashed'
|
|
74
|
+
"want": ["tier", "points", "status"]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The connector side (`lookup`) is one step: one identity in, `{ found, memberId, tier, points, status,
|
|
80
|
+
asOf }` out; throw on an outage so the next source is tried — see
|
|
81
|
+
[connectors.md](connectors.md#loyalty-and-crm-connectors).
|
|
82
|
+
|
|
83
|
+
## What a brand can be told
|
|
84
|
+
|
|
85
|
+
- We never need a copy of your member base: claims and lookups hold nothing, or a minutes-old answer per
|
|
86
|
+
active person.
|
|
87
|
+
- Where you want a local copy, it holds no identifiers (the HMAC mirror — on request).
|
|
88
|
+
- Your system remains the record of truth: every answer carries `asOf` and `basis`; TTLs are yours to set.
|
|
89
|
+
- You see every call: the connector's calls are rate-limited, logged, and leave from a fixed egress IP.
|
|
90
|
+
- Nothing leaves without a policy: the envelope's identity policy per flow.
|
package/dist/docs/files.md
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
# Files
|
|
2
|
-
|
|
3
|
-
Files are for the things an app or an AI tool needs to hold onto that nobody browses: a supplier's spec sheet fetched
|
|
4
|
-
to read product details from, a web page with a recipe, a deck to summarise, an image to read text from, a JSON result
|
|
5
|
-
to pass between steps.
|
|
6
|
-
|
|
7
|
-
A file is an asset, with three differences:
|
|
8
|
-
|
|
9
|
-
- **It can be temporary.** It's removed at `expiresAt` (`ttl` from `1h` to `30d`, default `1d`).
|
|
10
|
-
- **It's private** until kept. You read it through `files.read` or a signed link from `files.link`.
|
|
11
|
-
- **It stays out of asset lists.** Pickers, the media library, the Hub and the portal never show temporary or
|
|
12
|
-
extracted files. `files.keep` makes a file permanent and public (with an `assetUrl`), and it then shows like any
|
|
13
|
-
upload.
|
|
14
|
-
|
|
15
|
-
## Fetch once, extract once
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
import { files } from '@proveanything/smartlinks'
|
|
19
|
-
|
|
20
|
-
// The same address returns the same file while it's fresh; once stale, an unchanged page isn't downloaded again.
|
|
21
|
-
const { file } = await files.fetch(collectionId, { url: 'https://supplier.example/spec.pdf', ttl: '7d' })
|
|
22
|
-
|
|
23
|
-
// Each file is read each way once: asking again returns the same result (cached: true).
|
|
24
|
-
const { text } = await files.extract(collectionId, file.id, { variant: 'markdown' })
|
|
25
|
-
|
|
26
|
-
const { data } = await files.extract(collectionId, file.id, {
|
|
27
|
-
variant: 'json',
|
|
28
|
-
schema: { type: 'object', properties: { gtin: { type: 'string' }, weightKg: { type: 'number' } } },
|
|
29
|
-
})
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
| Variant | Gives | Works on |
|
|
33
|
-
|---|---|---|
|
|
34
|
-
| `text` | plain text | PDFs, HTML, text, JSON, and web pages / documents |
|
|
35
|
-
| `markdown` | Markdown | web pages, PDFs, decks, documents |
|
|
36
|
-
| `ocr` | text read from an image | images |
|
|
37
|
-
| `json` | typed fields (`schema` and/or `prompt`) | anything readable |
|
|
38
|
-
|
|
39
|
-
What's extracted is kept beside its source as a derived file (`origin: 'derived'`, `derivedFromId`, `variant`) and
|
|
40
|
-
lives as long as the source does.
|
|
41
|
-
|
|
42
|
-
## Your own files
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
const { file } = await files.put(collectionId, { name: 'notes.json', json: { step: 2 }, ttl: '1d' })
|
|
46
|
-
const { text } = await files.read(collectionId, file.id) // or 'base64'
|
|
47
|
-
const { url } = await files.link(collectionId, file.id, 15) // a signed link for 15 minutes
|
|
48
|
-
await files.keep(collectionId, file.id) // permanent, public, shows in pickers
|
|
49
|
-
await files.remove(collectionId, file.id)
|
|
50
|
-
const { files: mine } = await files.list(collectionId, { appId: 'my-app', origin: 'fetched' })
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## In a server function
|
|
54
|
-
|
|
55
|
-
The same calls are on `ctx.sl.files` (manifest scopes `sl:files:read` and `sl:files:write`), without the collection
|
|
56
|
-
id. AI tools get `file.fetch`, `file.extract` and `file.read`, which hand back file references rather than pasting
|
|
57
|
-
whole documents into the conversation.
|
|
58
|
-
|
|
59
|
-
```js
|
|
60
|
-
const page = await ctx.sl.files.fetch('https://cook.example/pancakes', { ttl: '7d' })
|
|
61
|
-
const { data } = await ctx.sl.files.extract(page.id, 'json', { schema })
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## Limits
|
|
65
|
-
|
|
66
|
-
- Fetching: public web addresses only (checked on every redirect), up to 50 MB.
|
|
67
|
-
- Reading contents: up to 25 MB.
|
|
68
|
-
- Temporary files per site: 5,000 files or 2 GB at once; past that the oldest temporary files go first. Kept files
|
|
69
|
-
aren't capped here.
|
|
1
|
+
# Files
|
|
2
|
+
|
|
3
|
+
Files are for the things an app or an AI tool needs to hold onto that nobody browses: a supplier's spec sheet fetched
|
|
4
|
+
to read product details from, a web page with a recipe, a deck to summarise, an image to read text from, a JSON result
|
|
5
|
+
to pass between steps.
|
|
6
|
+
|
|
7
|
+
A file is an asset, with three differences:
|
|
8
|
+
|
|
9
|
+
- **It can be temporary.** It's removed at `expiresAt` (`ttl` from `1h` to `30d`, default `1d`).
|
|
10
|
+
- **It's private** until kept. You read it through `files.read` or a signed link from `files.link`.
|
|
11
|
+
- **It stays out of asset lists.** Pickers, the media library, the Hub and the portal never show temporary or
|
|
12
|
+
extracted files. `files.keep` makes a file permanent and public (with an `assetUrl`), and it then shows like any
|
|
13
|
+
upload.
|
|
14
|
+
|
|
15
|
+
## Fetch once, extract once
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { files } from '@proveanything/smartlinks'
|
|
19
|
+
|
|
20
|
+
// The same address returns the same file while it's fresh; once stale, an unchanged page isn't downloaded again.
|
|
21
|
+
const { file } = await files.fetch(collectionId, { url: 'https://supplier.example/spec.pdf', ttl: '7d' })
|
|
22
|
+
|
|
23
|
+
// Each file is read each way once: asking again returns the same result (cached: true).
|
|
24
|
+
const { text } = await files.extract(collectionId, file.id, { variant: 'markdown' })
|
|
25
|
+
|
|
26
|
+
const { data } = await files.extract(collectionId, file.id, {
|
|
27
|
+
variant: 'json',
|
|
28
|
+
schema: { type: 'object', properties: { gtin: { type: 'string' }, weightKg: { type: 'number' } } },
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
| Variant | Gives | Works on |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `text` | plain text | PDFs, HTML, text, JSON, and web pages / documents |
|
|
35
|
+
| `markdown` | Markdown | web pages, PDFs, decks, documents |
|
|
36
|
+
| `ocr` | text read from an image | images |
|
|
37
|
+
| `json` | typed fields (`schema` and/or `prompt`) | anything readable |
|
|
38
|
+
|
|
39
|
+
What's extracted is kept beside its source as a derived file (`origin: 'derived'`, `derivedFromId`, `variant`) and
|
|
40
|
+
lives as long as the source does.
|
|
41
|
+
|
|
42
|
+
## Your own files
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
const { file } = await files.put(collectionId, { name: 'notes.json', json: { step: 2 }, ttl: '1d' })
|
|
46
|
+
const { text } = await files.read(collectionId, file.id) // or 'base64'
|
|
47
|
+
const { url } = await files.link(collectionId, file.id, 15) // a signed link for 15 minutes
|
|
48
|
+
await files.keep(collectionId, file.id) // permanent, public, shows in pickers
|
|
49
|
+
await files.remove(collectionId, file.id)
|
|
50
|
+
const { files: mine } = await files.list(collectionId, { appId: 'my-app', origin: 'fetched' })
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## In a server function
|
|
54
|
+
|
|
55
|
+
The same calls are on `ctx.sl.files` (manifest scopes `sl:files:read` and `sl:files:write`), without the collection
|
|
56
|
+
id. AI tools get `file.fetch`, `file.extract` and `file.read`, which hand back file references rather than pasting
|
|
57
|
+
whole documents into the conversation.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
const page = await ctx.sl.files.fetch('https://cook.example/pancakes', { ttl: '7d' })
|
|
61
|
+
const { data } = await ctx.sl.files.extract(page.id, 'json', { schema })
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Limits
|
|
65
|
+
|
|
66
|
+
- Fetching: public web addresses only (checked on every redirect), up to 50 MB.
|
|
67
|
+
- Reading contents: up to 25 MB.
|
|
68
|
+
- Temporary files per site: 5,000 files or 2 GB at once; past that the oldest temporary files go first. Kept files
|
|
69
|
+
aren't capped here.
|