@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/README.md
CHANGED
|
@@ -24,6 +24,7 @@ If you're new to the SDK, this is the easiest path:
|
|
|
24
24
|
- [docs/analytics.md](docs/analytics.md) — fire-and-forget web analytics, tag scan telemetry, and dashboard queries
|
|
25
25
|
- [docs/proof-share-grants.md](docs/proof-share-grants.md) — delegated, scoped, revocable share links for a proof (album sharing, guest comments, proof-of-ownership)
|
|
26
26
|
- [docs/assets.md](docs/assets.md) — asset uploads, including resumable uploads for large files (video)
|
|
27
|
+
- [docs/files.md](docs/files.md) — temporary files, fetching web pages and documents once, and extracting text, Markdown, OCR or fields from them
|
|
27
28
|
- [docs/app-objects.md](docs/app-objects.md) — cases, threads (comments), and records
|
|
28
29
|
- [docs/translations.md](docs/translations.md) — runtime translation lookup, browser-side caching, and translation admin flows
|
|
29
30
|
- [docs/widgets.md](docs/widgets.md) — embeddable React components
|
package/dist/adminViews.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ export interface DestinationInfo {
|
|
|
110
110
|
/** The platform's screens any admin screen can open by name. */
|
|
111
111
|
export declare const DESTINATIONS: DestinationInfo[];
|
|
112
112
|
/** A destination name. Any string is accepted, so a newer host's names work on an older SDK. */
|
|
113
|
-
export type Destination = 'contacts' | 'contact' | 'contact.messages' | 'contact.conversations' | 'conversation' | 'segment' | 'loyalty.scheme' | 'message.compose' | 'message.log' | 'campaign.new' | 'campaign' | 'templates' | 'template' | 'product' | 'proof' | 'interaction.type' | 'batch' | 'variant' | 'lot' | 'tags' | 'print' | 'form' | 'assets' | 'asset' | 'asset.history' | 'places' | 'settings.billing' | 'settings.integrations' | 'settings.guide' | 'settings.translationRules' | 'settings' | 'settings.address' | 'settings.domain' | 'settings.languages' | 'settings.translations' | 'settings.email' | 'settings.team' | 'settings.userGroups' | 'settings.setupLists' | 'settings.portal' | 'settings.hub' | 'settings.signIn' | 'media' | 'app' | (string & {});
|
|
113
|
+
export type Destination = 'contacts' | 'contact' | 'contact.messages' | 'contact.conversations' | 'conversation' | 'segment' | 'loyalty.scheme' | 'message.compose' | 'message.log' | 'campaign.new' | 'campaign' | 'templates' | 'template' | 'product' | 'proof' | 'interaction.type' | 'batch' | 'variant' | 'lot' | 'tags' | 'print' | 'form' | 'assets' | 'asset' | 'asset.history' | 'places' | 'settings.billing' | 'settings.addons' | 'settings.modules' | 'settings.integrations' | 'settings.guide' | 'settings.translationRules' | 'settings' | 'settings.address' | 'settings.domain' | 'settings.languages' | 'settings.translations' | 'settings.email' | 'settings.team' | 'settings.userGroups' | 'settings.setupLists' | 'settings.portal' | 'settings.hub' | 'settings.signIn' | 'media' | 'app' | (string & {});
|
|
114
114
|
/** What a message is about (the same shape as `comms.sendTransactional`'s `about`). Ids only. */
|
|
115
115
|
export interface DestinationAbout {
|
|
116
116
|
appId?: string;
|
package/dist/adminViews.js
CHANGED
|
@@ -299,7 +299,9 @@ export const DESTINATIONS = [
|
|
|
299
299
|
{ name: 'settings.email', required: [], description: 'Email settings: the sending address and its look.' },
|
|
300
300
|
{ name: 'settings.team', required: [], description: 'The people who run the business in Studio.' },
|
|
301
301
|
{ name: 'settings.userGroups', required: [], description: 'User groups.' },
|
|
302
|
-
{ name: 'settings.billing', required: [], description: 'Billing: the plan, invoices and AI credits (top up when the allowance is used up).' },
|
|
302
|
+
{ name: 'settings.billing', required: [], optional: ['intent'], description: 'Billing: the plan, invoices and AI credits (top up when the allowance is used up). intent=upgrade opens on the plans to move up to.' },
|
|
303
|
+
{ name: 'settings.addons', required: [], description: 'Add-ons: features the account can switch on (on enterprise, each feature can be switched).' },
|
|
304
|
+
{ name: 'settings.modules', required: [], description: 'Modules: install, reorder and remove the apps the account uses.' },
|
|
303
305
|
{ name: 'settings.integrations', required: [], description: 'Integrations: connections to other systems.' },
|
|
304
306
|
{ name: 'settings.guide', required: [], description: 'The customer guide: the assistant visitors talk to.' },
|
|
305
307
|
{ name: 'settings.translationRules', required: [], description: 'Translation rules: the brief, notes per language and terms to keep.' },
|
package/dist/ai-tools.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface BuiltinAiToolDescriptor {
|
|
|
7
7
|
/** Capability tags the tool requires. */
|
|
8
8
|
capabilities: AiToolCapability[];
|
|
9
9
|
/** Grouping for tool-picker UIs. */
|
|
10
|
-
group: 'web' | 'vision' | 'image' | 'media' | 'net' | 'text';
|
|
10
|
+
group: 'web' | 'vision' | 'image' | 'media' | 'net' | 'text' | 'knowledge';
|
|
11
11
|
}
|
|
12
12
|
/** Stable name constants — reference tools without stringly-typed literals. */
|
|
13
13
|
export declare const AI_TOOL_NAMES: {
|
|
@@ -37,6 +37,7 @@ export declare const AI_TOOL_NAMES: {
|
|
|
37
37
|
readonly PDF_PRINT_READY: "pdf.printReady";
|
|
38
38
|
readonly HTTP_REQUEST: "http.request";
|
|
39
39
|
readonly TRANSLATE: "translate";
|
|
40
|
+
readonly KNOWLEDGE_SEARCH: "knowledge.search";
|
|
40
41
|
};
|
|
41
42
|
/** The curated core toolset shipped with the SDK. */
|
|
42
43
|
export declare const BUILTIN_AI_TOOLS: BuiltinAiToolDescriptor[];
|
package/dist/ai-tools.js
CHANGED
|
@@ -34,9 +34,12 @@ export const AI_TOOL_NAMES = {
|
|
|
34
34
|
PDF_PRINT_READY: 'pdf.printReady',
|
|
35
35
|
HTTP_REQUEST: 'http.request',
|
|
36
36
|
TRANSLATE: 'translate',
|
|
37
|
+
KNOWLEDGE_SEARCH: 'knowledge.search',
|
|
37
38
|
};
|
|
38
39
|
/** The curated core toolset shipped with the SDK. */
|
|
39
40
|
export const BUILTIN_AI_TOOLS = [
|
|
41
|
+
{ name: 'knowledge.search', group: 'knowledge', capabilities: ['knowledge:read'],
|
|
42
|
+
description: "Search the business's own knowledge (help articles, manuals, docs) by meaning and keywords; returns passages with links." },
|
|
40
43
|
{ name: 'web.search', group: 'web', capabilities: ['web:read'],
|
|
41
44
|
description: 'Search the live web; returns candidate results (url/title/description) to then read.' },
|
|
42
45
|
{ name: 'web.fetchPage', group: 'web', capabilities: ['web:read'],
|
package/dist/api/ai.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { guide as guideApi, content as contentApi, startLive } from "./aiGuide.js";
|
|
2
|
-
import type { ContentPart, FunctionCall, ToolCall, ChatMessage, ToolDefinition, ResponseTool, ResponseInputItem, ResponsesRequest, ResponsesResult, ResponsesStreamEvent, ChatCompletionRequest, ChatCompletionChoice, ChatCompletionResponse, ChatCompletionChunk, AIModel, AIModelListParams, AIModelListResponse, AgentRunRequest, AgentRunResult, AgentToolsQuery, AgentToolsResponse, ToolRunResult, AiToolName, AiToolArgsMap, PublicAgentRunRequest, ClientTool, RunWithClientToolsOptions, SkillsListResponse, CatalogResponse,
|
|
3
|
-
export type { ContentPart, FunctionCall, ToolCall, ChatMessage, ToolDefinition, ResponseTool, ResponseInputItem, ResponsesRequest, ResponsesResult, ResponsesStreamEvent, ChatCompletionRequest, ChatCompletionChoice, ChatCompletionResponse, ChatCompletionChunk, AIModel, AIModelListParams, AIModelListResponse,
|
|
2
|
+
import type { ContentPart, FunctionCall, ToolCall, ChatMessage, ToolDefinition, ResponseTool, ResponseInputItem, ResponsesRequest, ResponsesResult, ResponsesStreamEvent, ChatCompletionRequest, ChatCompletionChoice, ChatCompletionResponse, ChatCompletionChunk, AIModel, AIModelListParams, AIModelListResponse, AgentRunRequest, AgentRunResult, AgentToolsQuery, AgentToolsResponse, ToolRunResult, AiToolName, AiToolArgsMap, PublicAgentRunRequest, ClientTool, RunWithClientToolsOptions, SkillsListResponse, CatalogResponse, Session, RateLimitStatus, SessionStatistics, AiSession, AiSessionCreate, AiUsageReport, VoiceSessionRequest, VoiceSessionResponse, EphemeralTokenRequest, EphemeralTokenResponse, TranscriptionResponse, TTSRequest, GeneratePodcastRequest, PodcastScript, GeneratePodcastResponse, PodcastStatus, AIGenerateContentRequest, AIGenerateContentCandidate, AIGenerateContentResponse, AIGenerateImageRequest, AIGenerateImageResponse, AIGeneratedImage, AISearchPhotosRequest, AISearchPhotosPhoto, AISearchPhotosResponse, AIUploadedFile, AICacheRef } from "../types/ai.js";
|
|
3
|
+
export type { ContentPart, FunctionCall, ToolCall, ChatMessage, ToolDefinition, ResponseTool, ResponseInputItem, ResponsesRequest, ResponsesResult, ResponsesStreamEvent, ChatCompletionRequest, ChatCompletionChoice, ChatCompletionResponse, ChatCompletionChunk, AIModel, AIModelListParams, AIModelListResponse, Session, RateLimitStatus, SessionStatistics, AiSession, AiSessionCreate, AiUsageReport, VoiceSessionRequest, VoiceSessionResponse, EphemeralTokenRequest, EphemeralTokenResponse, TranscriptionResponse, TTSRequest, GeneratePodcastRequest, PodcastScript, GeneratePodcastResponse, PodcastStatus, AIGenerateContentRequest, AIGenerateContentCandidate, AIGenerateContentResponse, AIGenerateImageRequest, AIGenerateImageResponse, AIGeneratedImage, AISearchPhotosRequest, AISearchPhotosPhoto, AISearchPhotosResponse, AIUploadedFile, AICacheRef, };
|
|
4
4
|
declare namespace aiInternal {
|
|
5
5
|
namespace chat {
|
|
6
6
|
namespace responses {
|
|
@@ -70,16 +70,6 @@ declare namespace aiInternal {
|
|
|
70
70
|
*/
|
|
71
71
|
function get(collectionId: string, modelId: string): Promise<AIModel>;
|
|
72
72
|
}
|
|
73
|
-
namespace rag {
|
|
74
|
-
/**
|
|
75
|
-
* Index a document for RAG
|
|
76
|
-
*/
|
|
77
|
-
function indexDocument(collectionId: string, request: IndexDocumentRequest): Promise<IndexDocumentResponse>;
|
|
78
|
-
/**
|
|
79
|
-
* Configure AI assistant behavior
|
|
80
|
-
*/
|
|
81
|
-
function configureAssistant(collectionId: string, request: ConfigureAssistantRequest): Promise<ConfigureAssistantResponse>;
|
|
82
|
-
}
|
|
83
73
|
namespace sessions {
|
|
84
74
|
/**
|
|
85
75
|
* Get session statistics
|
|
@@ -146,10 +136,6 @@ declare namespace aiInternal {
|
|
|
146
136
|
function generate(collectionId: string, request: TTSRequest): Promise<Blob>;
|
|
147
137
|
}
|
|
148
138
|
namespace publicClient {
|
|
149
|
-
/**
|
|
150
|
-
* Chat with product assistant (RAG)
|
|
151
|
-
*/
|
|
152
|
-
function chat(collectionId: string, request: PublicChatRequest): Promise<PublicChatResponse>;
|
|
153
139
|
/**
|
|
154
140
|
* Public agent loop — run the orchestration-neutral tool loop on the consumer surface. Exposes an
|
|
155
141
|
* app's PUBLIC server functions (`agent.tool:true`, `visibility:'public'`) to a consumer assistant;
|
|
@@ -268,10 +254,6 @@ export declare const ai: {
|
|
|
268
254
|
list: typeof aiInternal.models.list;
|
|
269
255
|
get: typeof aiInternal.models.get;
|
|
270
256
|
};
|
|
271
|
-
rag: {
|
|
272
|
-
indexDocument: typeof aiInternal.rag.indexDocument;
|
|
273
|
-
configureAssistant: typeof aiInternal.rag.configureAssistant;
|
|
274
|
-
};
|
|
275
257
|
sessions: {
|
|
276
258
|
stats: typeof aiInternal.sessions.stats;
|
|
277
259
|
};
|
|
@@ -286,7 +268,6 @@ export declare const ai: {
|
|
|
286
268
|
generate: typeof aiInternal.tts.generate;
|
|
287
269
|
};
|
|
288
270
|
public: {
|
|
289
|
-
chat: typeof aiInternal.publicClient.chat;
|
|
290
271
|
agentRun: typeof aiInternal.publicClient.agentRun;
|
|
291
272
|
getSession: typeof aiInternal.publicClient.getSession;
|
|
292
273
|
clearSession: typeof aiInternal.publicClient.clearSession;
|
package/dist/api/ai.js
CHANGED
|
@@ -151,28 +151,6 @@ var aiInternal;
|
|
|
151
151
|
models.get = get;
|
|
152
152
|
})(models = aiInternal.models || (aiInternal.models = {}));
|
|
153
153
|
// ============================================================================
|
|
154
|
-
// RAG API
|
|
155
|
-
// ============================================================================
|
|
156
|
-
let rag;
|
|
157
|
-
(function (rag) {
|
|
158
|
-
/**
|
|
159
|
-
* Index a document for RAG
|
|
160
|
-
*/
|
|
161
|
-
async function indexDocument(collectionId, request) {
|
|
162
|
-
const path = `/admin/collection/${encodeURIComponent(collectionId)}/ai/indexDocument`;
|
|
163
|
-
return post(path, request);
|
|
164
|
-
}
|
|
165
|
-
rag.indexDocument = indexDocument;
|
|
166
|
-
/**
|
|
167
|
-
* Configure AI assistant behavior
|
|
168
|
-
*/
|
|
169
|
-
async function configureAssistant(collectionId, request) {
|
|
170
|
-
const path = `/admin/collection/${encodeURIComponent(collectionId)}/ai/configureAssistant`;
|
|
171
|
-
return post(path, request);
|
|
172
|
-
}
|
|
173
|
-
rag.configureAssistant = configureAssistant;
|
|
174
|
-
})(rag = aiInternal.rag || (aiInternal.rag = {}));
|
|
175
|
-
// ============================================================================
|
|
176
154
|
// Sessions API
|
|
177
155
|
// ============================================================================
|
|
178
156
|
let sessions;
|
|
@@ -294,14 +272,6 @@ var aiInternal;
|
|
|
294
272
|
// ============================================================================
|
|
295
273
|
let publicClient;
|
|
296
274
|
(function (publicClient) {
|
|
297
|
-
/**
|
|
298
|
-
* Chat with product assistant (RAG)
|
|
299
|
-
*/
|
|
300
|
-
async function chat(collectionId, request) {
|
|
301
|
-
const path = `/public/collection/${encodeURIComponent(collectionId)}/ai/chat`;
|
|
302
|
-
return post(path, request);
|
|
303
|
-
}
|
|
304
|
-
publicClient.chat = chat;
|
|
305
275
|
/**
|
|
306
276
|
* Public agent loop — run the orchestration-neutral tool loop on the consumer surface. Exposes an
|
|
307
277
|
* app's PUBLIC server functions (`agent.tool:true`, `visibility:'public'`) to a consumer assistant;
|
|
@@ -548,10 +518,6 @@ export const ai = {
|
|
|
548
518
|
list: aiInternal.models.list,
|
|
549
519
|
get: aiInternal.models.get,
|
|
550
520
|
},
|
|
551
|
-
rag: {
|
|
552
|
-
indexDocument: aiInternal.rag.indexDocument,
|
|
553
|
-
configureAssistant: aiInternal.rag.configureAssistant,
|
|
554
|
-
},
|
|
555
521
|
sessions: {
|
|
556
522
|
stats: aiInternal.sessions.stats,
|
|
557
523
|
},
|
|
@@ -566,7 +532,6 @@ export const ai = {
|
|
|
566
532
|
generate: aiInternal.tts.generate,
|
|
567
533
|
},
|
|
568
534
|
public: {
|
|
569
|
-
chat: aiInternal.publicClient.chat,
|
|
570
535
|
agentRun: aiInternal.publicClient.agentRun,
|
|
571
536
|
getSession: aiInternal.publicClient.getSession,
|
|
572
537
|
clearSession: aiInternal.publicClient.clearSession,
|
package/dist/api/asset.js
CHANGED
|
@@ -334,6 +334,8 @@ export var asset;
|
|
|
334
334
|
params.set('limit', String(options.limit));
|
|
335
335
|
if (typeof options.offset === 'number')
|
|
336
336
|
params.set('offset', String(options.offset));
|
|
337
|
+
if (options.include && options.include.length)
|
|
338
|
+
params.set('include', options.include.join(','));
|
|
337
339
|
const qs = params.toString();
|
|
338
340
|
const path = `/admin/collection/${encodeURIComponent(options.collectionId)}/asset${qs ? `?${qs}` : ''}`;
|
|
339
341
|
return request(path);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { FileRecord, PutFileRequest, FetchFileRequest, FetchedFile, ListFilesQuery, ExtractFileRequest, ExtractFileResponse, ReadFileResponse, FileLinkResponse } from "../types/files.js";
|
|
2
|
+
/**
|
|
3
|
+
* Files: temporary or kept files, web pages and documents fetched by address, and what's extracted from them
|
|
4
|
+
* (text, Markdown, OCR, typed fields). Files are assets, but private until kept and left out of asset lists, so
|
|
5
|
+
* pickers and the media library never fill up with them.
|
|
6
|
+
*
|
|
7
|
+
* - Fetch once, read many times: the same address returns the same file while it's fresh, and an unchanged page
|
|
8
|
+
* isn't downloaded again.
|
|
9
|
+
* - Extract once: each file is read each way only once; the result is kept beside it.
|
|
10
|
+
* - `keep` makes a file permanent and public (an `assetUrl`), and it then shows in asset lists like any upload.
|
|
11
|
+
*
|
|
12
|
+
* In a server function the same calls are `ctx.sl.files.*` (needs `sl:files:read` / `sl:files:write`).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const page = await files.fetch('coll_123', { url: 'https://supplier.example/spec.pdf', ttl: '7d' })
|
|
17
|
+
* const { text } = await files.extract('coll_123', page.file.id, { variant: 'markdown' })
|
|
18
|
+
* const { data } = await files.extract('coll_123', page.file.id, {
|
|
19
|
+
* variant: 'json',
|
|
20
|
+
* schema: { type: 'object', properties: { gtin: { type: 'string' }, weightKg: { type: 'number' } } },
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare namespace files {
|
|
25
|
+
/** Files on this site that aren't ordinary uploads: temporary, fetched, derived or generated (admin). */
|
|
26
|
+
function list(collectionId: string, query?: ListFilesQuery): Promise<{
|
|
27
|
+
ok: true;
|
|
28
|
+
files: FileRecord[];
|
|
29
|
+
}>;
|
|
30
|
+
/** A new file from text, base64 or JSON. Temporary (default 1 day) and private. */
|
|
31
|
+
function put(collectionId: string, body: PutFileRequest): Promise<{
|
|
32
|
+
ok: true;
|
|
33
|
+
file: FileRecord;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* A web address's contents as a file, cached by address.
|
|
37
|
+
* @throws `BAD_URL`, `PRIVATE_ADDRESS`, `FETCH_FAILED`, `TOO_LARGE` (over 50 MB)
|
|
38
|
+
*/
|
|
39
|
+
function fetch(collectionId: string, body: FetchFileRequest): Promise<{
|
|
40
|
+
ok: true;
|
|
41
|
+
file: FetchedFile;
|
|
42
|
+
}>;
|
|
43
|
+
/** One file. @throws `NOT_FOUND`, `EXPIRED` */
|
|
44
|
+
function get(collectionId: string, fileId: string): Promise<{
|
|
45
|
+
ok: true;
|
|
46
|
+
file: FileRecord;
|
|
47
|
+
}>;
|
|
48
|
+
/** A file's contents, as text (default) or base64 (up to 25 MB). */
|
|
49
|
+
function read(collectionId: string, fileId: string, as?: "text" | "base64"): Promise<ReadFileResponse>;
|
|
50
|
+
/** A signed link to a private file (default 15 minutes), or a kept file's permanent address. */
|
|
51
|
+
function link(collectionId: string, fileId: string, minutes?: number): Promise<FileLinkResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* What's in a file: `text`, `markdown`, `ocr` (images) or `json` (typed fields: give a `schema` and/or a
|
|
54
|
+
* `prompt`). Each file is read each way once; asking again returns the same result (`cached: true`).
|
|
55
|
+
* @throws `BAD_VARIANT`, `SCHEMA_REQUIRED`, `USE_OCR` (text from an image), `NOT_AN_IMAGE`, `NOTHING_FOUND`
|
|
56
|
+
*/
|
|
57
|
+
function extract(collectionId: string, fileId: string, body: ExtractFileRequest): Promise<ExtractFileResponse>;
|
|
58
|
+
/** Keep a file: permanent and public, with an `assetUrl`. It then shows in asset lists like any upload. */
|
|
59
|
+
function keep(collectionId: string, fileId: string): Promise<{
|
|
60
|
+
ok: true;
|
|
61
|
+
file: FileRecord;
|
|
62
|
+
}>;
|
|
63
|
+
/** Remove a file (a kept file is deleted like any asset, and can be restored). */
|
|
64
|
+
function remove(collectionId: string, fileId: string): Promise<{
|
|
65
|
+
ok: true;
|
|
66
|
+
removed: boolean;
|
|
67
|
+
softDeleted?: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { request, post, del } from "../http.js";
|
|
2
|
+
/**
|
|
3
|
+
* Files: temporary or kept files, web pages and documents fetched by address, and what's extracted from them
|
|
4
|
+
* (text, Markdown, OCR, typed fields). Files are assets, but private until kept and left out of asset lists, so
|
|
5
|
+
* pickers and the media library never fill up with them.
|
|
6
|
+
*
|
|
7
|
+
* - Fetch once, read many times: the same address returns the same file while it's fresh, and an unchanged page
|
|
8
|
+
* isn't downloaded again.
|
|
9
|
+
* - Extract once: each file is read each way only once; the result is kept beside it.
|
|
10
|
+
* - `keep` makes a file permanent and public (an `assetUrl`), and it then shows in asset lists like any upload.
|
|
11
|
+
*
|
|
12
|
+
* In a server function the same calls are `ctx.sl.files.*` (needs `sl:files:read` / `sl:files:write`).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const page = await files.fetch('coll_123', { url: 'https://supplier.example/spec.pdf', ttl: '7d' })
|
|
17
|
+
* const { text } = await files.extract('coll_123', page.file.id, { variant: 'markdown' })
|
|
18
|
+
* const { data } = await files.extract('coll_123', page.file.id, {
|
|
19
|
+
* variant: 'json',
|
|
20
|
+
* schema: { type: 'object', properties: { gtin: { type: 'string' }, weightKg: { type: 'number' } } },
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export var files;
|
|
25
|
+
(function (files) {
|
|
26
|
+
const adm = (collectionId) => `/admin/collection/${encodeURIComponent(collectionId)}/files`;
|
|
27
|
+
const one = (collectionId, fileId) => `${adm(collectionId)}/${encodeURIComponent(fileId)}`;
|
|
28
|
+
/** Files on this site that aren't ordinary uploads: temporary, fetched, derived or generated (admin). */
|
|
29
|
+
async function list(collectionId, query = {}) {
|
|
30
|
+
const qs = new URLSearchParams(Object.entries(query).filter(([, v]) => v != null).map(([k, v]) => [k, String(v)])).toString();
|
|
31
|
+
return request(`${adm(collectionId)}${qs ? `?${qs}` : ""}`);
|
|
32
|
+
}
|
|
33
|
+
files.list = list;
|
|
34
|
+
/** A new file from text, base64 or JSON. Temporary (default 1 day) and private. */
|
|
35
|
+
async function put(collectionId, body) {
|
|
36
|
+
return post(adm(collectionId), body);
|
|
37
|
+
}
|
|
38
|
+
files.put = put;
|
|
39
|
+
/**
|
|
40
|
+
* A web address's contents as a file, cached by address.
|
|
41
|
+
* @throws `BAD_URL`, `PRIVATE_ADDRESS`, `FETCH_FAILED`, `TOO_LARGE` (over 50 MB)
|
|
42
|
+
*/
|
|
43
|
+
async function fetch(collectionId, body) {
|
|
44
|
+
return post(`${adm(collectionId)}/fetch`, body);
|
|
45
|
+
}
|
|
46
|
+
files.fetch = fetch;
|
|
47
|
+
/** One file. @throws `NOT_FOUND`, `EXPIRED` */
|
|
48
|
+
async function get(collectionId, fileId) {
|
|
49
|
+
return request(one(collectionId, fileId));
|
|
50
|
+
}
|
|
51
|
+
files.get = get;
|
|
52
|
+
/** A file's contents, as text (default) or base64 (up to 25 MB). */
|
|
53
|
+
async function read(collectionId, fileId, as = "text") {
|
|
54
|
+
return request(`${one(collectionId, fileId)}/read?as=${as}`);
|
|
55
|
+
}
|
|
56
|
+
files.read = read;
|
|
57
|
+
/** A signed link to a private file (default 15 minutes), or a kept file's permanent address. */
|
|
58
|
+
async function link(collectionId, fileId, minutes) {
|
|
59
|
+
return request(`${one(collectionId, fileId)}/link${minutes ? `?minutes=${minutes}` : ""}`);
|
|
60
|
+
}
|
|
61
|
+
files.link = link;
|
|
62
|
+
/**
|
|
63
|
+
* What's in a file: `text`, `markdown`, `ocr` (images) or `json` (typed fields: give a `schema` and/or a
|
|
64
|
+
* `prompt`). Each file is read each way once; asking again returns the same result (`cached: true`).
|
|
65
|
+
* @throws `BAD_VARIANT`, `SCHEMA_REQUIRED`, `USE_OCR` (text from an image), `NOT_AN_IMAGE`, `NOTHING_FOUND`
|
|
66
|
+
*/
|
|
67
|
+
async function extract(collectionId, fileId, body) {
|
|
68
|
+
return post(`${one(collectionId, fileId)}/extract`, body);
|
|
69
|
+
}
|
|
70
|
+
files.extract = extract;
|
|
71
|
+
/** Keep a file: permanent and public, with an `assetUrl`. It then shows in asset lists like any upload. */
|
|
72
|
+
async function keep(collectionId, fileId) {
|
|
73
|
+
return post(`${one(collectionId, fileId)}/keep`, {});
|
|
74
|
+
}
|
|
75
|
+
files.keep = keep;
|
|
76
|
+
/** Remove a file (a kept file is deleted like any asset, and can be restored). */
|
|
77
|
+
async function remove(collectionId, fileId) {
|
|
78
|
+
return del(one(collectionId, fileId));
|
|
79
|
+
}
|
|
80
|
+
files.remove = remove;
|
|
81
|
+
})(files || (files = {}));
|
package/dist/api/index.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export { segments } from "./segments.js";
|
|
|
28
28
|
export { userGroups } from "./userGroups.js";
|
|
29
29
|
export { conditions } from "./conditions.js";
|
|
30
30
|
export { wallet } from "./wallet.js";
|
|
31
|
+
export { files } from "./files.js";
|
|
32
|
+
export { knowledge } from "./knowledge.js";
|
|
31
33
|
export { operations } from "./operations.js";
|
|
32
34
|
export { journeys } from "./journeys.js";
|
|
33
35
|
export { journeysAnalytics } from "./journeysAnalytics.js";
|
package/dist/api/index.js
CHANGED
|
@@ -30,6 +30,8 @@ export { segments } from "./segments.js";
|
|
|
30
30
|
export { userGroups } from "./userGroups.js";
|
|
31
31
|
export { conditions } from "./conditions.js";
|
|
32
32
|
export { wallet } from "./wallet.js";
|
|
33
|
+
export { files } from "./files.js";
|
|
34
|
+
export { knowledge } from "./knowledge.js";
|
|
33
35
|
export { operations } from "./operations.js";
|
|
34
36
|
export { journeys } from "./journeys.js";
|
|
35
37
|
export { journeysAnalytics } from "./journeysAnalytics.js";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { KnowledgeSet, SaveKnowledgeSetRequest, UpdateKnowledgeSetRequest, KnowledgeSource, AddKnowledgeSourceRequest, UpdateKnowledgeSourceRequest, KnowledgeDocument, KnowledgeSearchRequest, KnowledgeSearchResponse } from "../types/knowledge.js";
|
|
2
|
+
/**
|
|
3
|
+
* Knowledge search: make a collection's content searchable by meaning and keywords, for people and for AI.
|
|
4
|
+
*
|
|
5
|
+
* A collection has **sets** ("Product manuals", "Help articles"), each `public`, `customer` (signed-in
|
|
6
|
+
* people) or `staff`. A set points at **sources**: a Markdown feed, a web page, or documents your app pushes.
|
|
7
|
+
* The platform splits them into passages along their headings, keeps them in step as the sources change, and
|
|
8
|
+
* searches with meaning and keywords together, so exact terms (model numbers, error codes) are found too.
|
|
9
|
+
*
|
|
10
|
+
* - Admin calls (`listSets`, `saveSet`, `addSource`, `upsertDocuments`, `search`) need a collection admin.
|
|
11
|
+
* - `publicSearch` works from a website, Portal or Hub: anyone sees public sets, a signed-in person customer
|
|
12
|
+
* sets too. Staff sets are never searchable there.
|
|
13
|
+
* - AI agents get the `knowledge.search` tool.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* await knowledge.saveSet('coll_123', { key: 'manuals', name: 'Product manuals', visibility: 'public' })
|
|
18
|
+
* const src = await knowledge.addSource('coll_123', 'manuals', { kind: 'documents' })
|
|
19
|
+
* await knowledge.upsertDocuments('coll_123', src.id, [
|
|
20
|
+
* { ref: 'kettle', title: 'Kettle manual', body: '## Descaling\n\nDescale monthly…', meta: { productId: 'p1' } },
|
|
21
|
+
* ])
|
|
22
|
+
* const { results } = await knowledge.publicSearch('coll_123', { query: 'how do I descale', filters: { productId: 'p1' } })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare namespace knowledge {
|
|
26
|
+
/** Every set, with its source and passage counts (admin). */
|
|
27
|
+
function listSets(collectionId: string): Promise<KnowledgeSet[]>;
|
|
28
|
+
/** Create a set, or update the one with this key (admin). */
|
|
29
|
+
function saveSet(collectionId: string, body: SaveKnowledgeSetRequest): Promise<KnowledgeSet>;
|
|
30
|
+
/** One set, by id or key (admin). */
|
|
31
|
+
function getSet(collectionId: string, set: string): Promise<KnowledgeSet>;
|
|
32
|
+
function updateSet(collectionId: string, set: string, body: UpdateKnowledgeSetRequest): Promise<KnowledgeSet>;
|
|
33
|
+
/** Delete a set with its sources and passages (admin). */
|
|
34
|
+
function deleteSet(collectionId: string, set: string): Promise<{
|
|
35
|
+
deleted: boolean;
|
|
36
|
+
}>;
|
|
37
|
+
/** A set's sources, with their status (admin). */
|
|
38
|
+
function listSources(collectionId: string, set: string): Promise<KnowledgeSource[]>;
|
|
39
|
+
/** Add a source; feeds and pages are read in the background (admin). */
|
|
40
|
+
function addSource(collectionId: string, set: string, body: AddKnowledgeSourceRequest): Promise<KnowledgeSource>;
|
|
41
|
+
function updateSource(collectionId: string, sourceId: string, body: UpdateKnowledgeSourceRequest): Promise<KnowledgeSource>;
|
|
42
|
+
function deleteSource(collectionId: string, sourceId: string): Promise<{
|
|
43
|
+
deleted: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
/** Read a source again now (`force` re-splits even if it hasn't changed) (admin). */
|
|
46
|
+
function reindex(collectionId: string, sourceId: string, opts?: {
|
|
47
|
+
force?: boolean;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
queued: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
/** Push documents into a `documents` source; the same `ref` replaces its earlier version. Up to 500 at a time (admin). */
|
|
52
|
+
function upsertDocuments(collectionId: string, sourceId: string, documents: KnowledgeDocument[]): Promise<{
|
|
53
|
+
documents: number;
|
|
54
|
+
passages: number;
|
|
55
|
+
}>;
|
|
56
|
+
/** Remove pushed documents by `ref` (admin). */
|
|
57
|
+
function removeDocuments(collectionId: string, sourceId: string, refs: string[]): Promise<{
|
|
58
|
+
removed: number;
|
|
59
|
+
}>;
|
|
60
|
+
/** Search every set, staff ones included (admin). */
|
|
61
|
+
function search(collectionId: string, body: KnowledgeSearchRequest): Promise<KnowledgeSearchResponse>;
|
|
62
|
+
/** Search from a website, Portal or Hub: public sets, plus customer sets for a signed-in person. */
|
|
63
|
+
function publicSearch(collectionId: string, body: KnowledgeSearchRequest): Promise<KnowledgeSearchResponse>;
|
|
64
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { request, post, patch, del } from "../http.js";
|
|
2
|
+
/**
|
|
3
|
+
* Knowledge search: make a collection's content searchable by meaning and keywords, for people and for AI.
|
|
4
|
+
*
|
|
5
|
+
* A collection has **sets** ("Product manuals", "Help articles"), each `public`, `customer` (signed-in
|
|
6
|
+
* people) or `staff`. A set points at **sources**: a Markdown feed, a web page, or documents your app pushes.
|
|
7
|
+
* The platform splits them into passages along their headings, keeps them in step as the sources change, and
|
|
8
|
+
* searches with meaning and keywords together, so exact terms (model numbers, error codes) are found too.
|
|
9
|
+
*
|
|
10
|
+
* - Admin calls (`listSets`, `saveSet`, `addSource`, `upsertDocuments`, `search`) need a collection admin.
|
|
11
|
+
* - `publicSearch` works from a website, Portal or Hub: anyone sees public sets, a signed-in person customer
|
|
12
|
+
* sets too. Staff sets are never searchable there.
|
|
13
|
+
* - AI agents get the `knowledge.search` tool.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* await knowledge.saveSet('coll_123', { key: 'manuals', name: 'Product manuals', visibility: 'public' })
|
|
18
|
+
* const src = await knowledge.addSource('coll_123', 'manuals', { kind: 'documents' })
|
|
19
|
+
* await knowledge.upsertDocuments('coll_123', src.id, [
|
|
20
|
+
* { ref: 'kettle', title: 'Kettle manual', body: '## Descaling\n\nDescale monthly…', meta: { productId: 'p1' } },
|
|
21
|
+
* ])
|
|
22
|
+
* const { results } = await knowledge.publicSearch('coll_123', { query: 'how do I descale', filters: { productId: 'p1' } })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export var knowledge;
|
|
26
|
+
(function (knowledge) {
|
|
27
|
+
const adm = (collectionId) => `/admin/collection/${encodeURIComponent(collectionId)}/knowledge`;
|
|
28
|
+
const pub = (collectionId) => `/public/collection/${encodeURIComponent(collectionId)}/knowledge`;
|
|
29
|
+
const enc = encodeURIComponent;
|
|
30
|
+
/** Every set, with its source and passage counts (admin). */
|
|
31
|
+
async function listSets(collectionId) {
|
|
32
|
+
return request(`${adm(collectionId)}/sets`);
|
|
33
|
+
}
|
|
34
|
+
knowledge.listSets = listSets;
|
|
35
|
+
/** Create a set, or update the one with this key (admin). */
|
|
36
|
+
async function saveSet(collectionId, body) {
|
|
37
|
+
return post(`${adm(collectionId)}/sets`, body);
|
|
38
|
+
}
|
|
39
|
+
knowledge.saveSet = saveSet;
|
|
40
|
+
/** One set, by id or key (admin). */
|
|
41
|
+
async function getSet(collectionId, set) {
|
|
42
|
+
return request(`${adm(collectionId)}/sets/${enc(set)}`);
|
|
43
|
+
}
|
|
44
|
+
knowledge.getSet = getSet;
|
|
45
|
+
async function updateSet(collectionId, set, body) {
|
|
46
|
+
return patch(`${adm(collectionId)}/sets/${enc(set)}`, body);
|
|
47
|
+
}
|
|
48
|
+
knowledge.updateSet = updateSet;
|
|
49
|
+
/** Delete a set with its sources and passages (admin). */
|
|
50
|
+
async function deleteSet(collectionId, set) {
|
|
51
|
+
return del(`${adm(collectionId)}/sets/${enc(set)}`);
|
|
52
|
+
}
|
|
53
|
+
knowledge.deleteSet = deleteSet;
|
|
54
|
+
/** A set's sources, with their status (admin). */
|
|
55
|
+
async function listSources(collectionId, set) {
|
|
56
|
+
return request(`${adm(collectionId)}/sets/${enc(set)}/sources`);
|
|
57
|
+
}
|
|
58
|
+
knowledge.listSources = listSources;
|
|
59
|
+
/** Add a source; feeds and pages are read in the background (admin). */
|
|
60
|
+
async function addSource(collectionId, set, body) {
|
|
61
|
+
return post(`${adm(collectionId)}/sets/${enc(set)}/sources`, body);
|
|
62
|
+
}
|
|
63
|
+
knowledge.addSource = addSource;
|
|
64
|
+
async function updateSource(collectionId, sourceId, body) {
|
|
65
|
+
return patch(`${adm(collectionId)}/sources/${enc(sourceId)}`, body);
|
|
66
|
+
}
|
|
67
|
+
knowledge.updateSource = updateSource;
|
|
68
|
+
async function deleteSource(collectionId, sourceId) {
|
|
69
|
+
return del(`${adm(collectionId)}/sources/${enc(sourceId)}`);
|
|
70
|
+
}
|
|
71
|
+
knowledge.deleteSource = deleteSource;
|
|
72
|
+
/** Read a source again now (`force` re-splits even if it hasn't changed) (admin). */
|
|
73
|
+
async function reindex(collectionId, sourceId, opts = {}) {
|
|
74
|
+
return post(`${adm(collectionId)}/sources/${enc(sourceId)}/reindex`, opts);
|
|
75
|
+
}
|
|
76
|
+
knowledge.reindex = reindex;
|
|
77
|
+
/** Push documents into a `documents` source; the same `ref` replaces its earlier version. Up to 500 at a time (admin). */
|
|
78
|
+
async function upsertDocuments(collectionId, sourceId, documents) {
|
|
79
|
+
return post(`${adm(collectionId)}/sources/${enc(sourceId)}/documents`, { documents });
|
|
80
|
+
}
|
|
81
|
+
knowledge.upsertDocuments = upsertDocuments;
|
|
82
|
+
/** Remove pushed documents by `ref` (admin). */
|
|
83
|
+
async function removeDocuments(collectionId, sourceId, refs) {
|
|
84
|
+
return post(`${adm(collectionId)}/sources/${enc(sourceId)}/documents/remove`, { refs });
|
|
85
|
+
}
|
|
86
|
+
knowledge.removeDocuments = removeDocuments;
|
|
87
|
+
/** Search every set, staff ones included (admin). */
|
|
88
|
+
async function search(collectionId, body) {
|
|
89
|
+
return post(`${adm(collectionId)}/search`, body);
|
|
90
|
+
}
|
|
91
|
+
knowledge.search = search;
|
|
92
|
+
/** Search from a website, Portal or Hub: public sets, plus customer sets for a signed-in person. */
|
|
93
|
+
async function publicSearch(collectionId, body) {
|
|
94
|
+
return post(`${pub(collectionId)}/search`, body);
|
|
95
|
+
}
|
|
96
|
+
knowledge.publicSearch = publicSearch;
|
|
97
|
+
})(knowledge || (knowledge = {}));
|