@proveanything/smartlinks 2.1.38 → 2.1.40
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 +1 -0
- package/dist/adminViews.d.ts +1 -1
- package/dist/adminViews.js +3 -1
- package/dist/ai-tools.d.ts +2 -1
- package/dist/ai-tools.js +3 -0
- package/dist/api/ai.d.ts +2 -21
- package/dist/api/ai.js +0 -35
- package/dist/api/asset.js +2 -0
- package/dist/api/files.d.ts +69 -0
- package/dist/api/files.js +81 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/api/knowledge.d.ts +64 -0
- package/dist/api/knowledge.js +97 -0
- package/dist/docs/API_SUMMARY.md +301 -125
- package/dist/docs/admin-views.md +257 -255
- package/dist/docs/ai.md +239 -352
- package/dist/docs/assets.md +4 -0
- package/dist/docs/files.md +69 -0
- package/dist/docs/knowledge.md +102 -0
- package/dist/docs/overview.md +482 -481
- package/dist/docs/server-functions.md +1219 -1197
- package/dist/openapi.yaml +406 -303
- package/dist/types/ai.d.ts +9 -91
- package/dist/types/asset.d.ts +17 -0
- package/dist/types/files.d.ts +78 -0
- package/dist/types/files.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/knowledge.d.ts +120 -0
- package/dist/types/knowledge.js +2 -0
- package/docs/API_SUMMARY.md +301 -125
- package/docs/admin-views.md +257 -255
- package/docs/ai.md +239 -352
- package/docs/assets.md +4 -0
- package/docs/files.md +69 -0
- package/docs/knowledge.md +102 -0
- package/docs/overview.md +482 -481
- package/docs/server-functions.md +1219 -1197
- package/openapi.yaml +406 -303
- package/package.json +1 -1
package/docs/assets.md
CHANGED
|
@@ -129,6 +129,10 @@ GET /asset
|
|
|
129
129
|
| `order` | string | `desc` (default), `asc` |
|
|
130
130
|
| `limit` | number | Max results (default 50, max 200) |
|
|
131
131
|
| `offset` | number | Pagination offset |
|
|
132
|
+
| `include` | string | `temporary`, `derived` (comma-separated): also list files that are normally left out |
|
|
133
|
+
|
|
134
|
+
Lists show only what people put there. Temporary files and files extracted from other files (see
|
|
135
|
+
[files.md](files.md)) are left out unless you ask with `include`, so pickers never fill up with them.
|
|
132
136
|
|
|
133
137
|
**Response:**
|
|
134
138
|
|
package/docs/files.md
ADDED
|
@@ -0,0 +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.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Knowledge search
|
|
3
|
+
description: Make a collection's content searchable by meaning and keywords, for people and for AI agents.
|
|
4
|
+
category: AI
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Knowledge search
|
|
8
|
+
|
|
9
|
+
Knowledge search makes a business's own content searchable by meaning and by keywords: product manuals,
|
|
10
|
+
help articles, FAQs, docs, or anything your app holds. People search it from a website, Portal or Hub, and
|
|
11
|
+
AI agents search it with the `knowledge.search` tool. Because it matches meaning and exact words together,
|
|
12
|
+
"how do I clean it" finds a "Descaling" section, and a model number or error code still finds itself.
|
|
13
|
+
|
|
14
|
+
## How it fits together
|
|
15
|
+
|
|
16
|
+
- **Sets.** A collection has knowledge sets, such as "Product manuals" or "Help articles". Each set is
|
|
17
|
+
`public` (anyone), `customer` (signed-in people) or `staff` (the business and its assistants).
|
|
18
|
+
- **Sources.** A set points at sources instead of holding copies:
|
|
19
|
+
- `markdown_feed`: a Markdown bundle at an address (documents separated by `---`, each with a
|
|
20
|
+
`Source: <url>` line).
|
|
21
|
+
- `url`: one web page or document.
|
|
22
|
+
- `documents`: documents your app pushes with `knowledge.upsertDocuments`.
|
|
23
|
+
- **Passages.** The platform splits each document into passages along its headings. Each passage keeps its
|
|
24
|
+
heading path ("Settings › Email footer") and a link to its section. Feeds and pages are re-read on a
|
|
25
|
+
schedule (every 24 hours by default), and only changed text is processed again.
|
|
26
|
+
|
|
27
|
+
## Set it up (admin)
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { knowledge } from '@proveanything/smartlinks'
|
|
31
|
+
|
|
32
|
+
await knowledge.saveSet('coll_123', { key: 'manuals', name: 'Product manuals', visibility: 'public' })
|
|
33
|
+
|
|
34
|
+
// Documents your app pushes. The same ref replaces its earlier version.
|
|
35
|
+
const src = await knowledge.addSource('coll_123', 'manuals', { kind: 'documents' })
|
|
36
|
+
await knowledge.upsertDocuments('coll_123', src.id, [
|
|
37
|
+
{
|
|
38
|
+
ref: 'kettle-k200',
|
|
39
|
+
title: 'K200 kettle manual',
|
|
40
|
+
body: '## Descaling\n\nDescale every month with citric acid…',
|
|
41
|
+
url: 'https://brand.example/manuals/k200',
|
|
42
|
+
meta: { productId: 'prod_k200' },
|
|
43
|
+
},
|
|
44
|
+
])
|
|
45
|
+
|
|
46
|
+
// Or a page / a Markdown feed, re-read every 24 hours
|
|
47
|
+
await knowledge.addSource('coll_123', 'manuals', {
|
|
48
|
+
kind: 'url',
|
|
49
|
+
config: { url: 'https://brand.example/support/k200' },
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
A source's `status` shows whether it's `ready`, still `indexing`, or `failed` (with `error` saying why). A
|
|
54
|
+
failed re-read keeps the previous passages searchable. `knowledge.reindex` reads a source again now.
|
|
55
|
+
|
|
56
|
+
## Search
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// From a website, Portal or Hub: public sets, plus customer sets for a signed-in person
|
|
60
|
+
const { results } = await knowledge.publicSearch('coll_123', {
|
|
61
|
+
query: 'how do I descale',
|
|
62
|
+
filters: { productId: 'prod_k200' }, // exact matches on a document's meta
|
|
63
|
+
k: 5,
|
|
64
|
+
})
|
|
65
|
+
for (const r of results) console.log(r.title, r.heading, r.url, r.snippet)
|
|
66
|
+
|
|
67
|
+
// Staff: every set
|
|
68
|
+
await knowledge.search('coll_123', { query: 'refund policy for damaged items' })
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Each result has `title` (the document), `heading` (its section), `url` (a link to the section), `snippet`
|
|
72
|
+
(for a results list) and `text` (the whole passage, for an AI to read). `mode` says how the search ran:
|
|
73
|
+
`hybrid` (meaning and keywords) or `keywords`.
|
|
74
|
+
|
|
75
|
+
## For AI agents
|
|
76
|
+
|
|
77
|
+
Give an agent the `knowledge.search` tool, and it searches before it answers and can cite the links:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const run = await ai.agent.run('coll_123', {
|
|
81
|
+
input: 'A customer asks how to descale the K200. Draft a reply with the steps.',
|
|
82
|
+
toolbelt: { builtins: ['knowledge.search'] },
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
On the public surface (`ai.public.agentRun`), built-in tools are off, so public assistants don't get this
|
|
87
|
+
tool yet. A cited-answer call for public use is planned.
|
|
88
|
+
|
|
89
|
+
## Who sees what
|
|
90
|
+
|
|
91
|
+
| Caller | Sets searched |
|
|
92
|
+
|---|---|
|
|
93
|
+
| Anyone (`publicSearch`, no sign-in) | `public` |
|
|
94
|
+
| A signed-in person (`publicSearch`) | `public`, `customer` |
|
|
95
|
+
| Staff (`search`, agents in Studio) | `public`, `customer`, `staff` |
|
|
96
|
+
|
|
97
|
+
Naming a set the caller may not read in `sets` returns nothing from it.
|
|
98
|
+
|
|
99
|
+
## Costs
|
|
100
|
+
|
|
101
|
+
Making passages searchable by meaning, and searching by meaning, use AI. That use is counted against the
|
|
102
|
+
collection's AI credits like any other AI call. Unchanged text is never processed twice.
|