@simpleplatform/sdk 2.1.0 → 2.2.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/ai.d.ts +52 -2
- package/dist/ai.js +24 -3
- package/package.json +1 -1
package/dist/ai.d.ts
CHANGED
|
@@ -65,6 +65,52 @@ export interface JSONSchemaArray extends JSONSchemaBase {
|
|
|
65
65
|
* This provides developers with precise autocompletion and type-checking.
|
|
66
66
|
*/
|
|
67
67
|
export type JSONSchema = JSONSchemaArray | JSONSchemaBoolean | JSONSchemaNumber | JSONSchemaObject | JSONSchemaString;
|
|
68
|
+
/**
|
|
69
|
+
* A stored file handed to an AI operation, together with what should be done
|
|
70
|
+
* with it.
|
|
71
|
+
*
|
|
72
|
+
* A PDF travels to the model as a PDF, because the model reads one: its tables,
|
|
73
|
+
* its layout and its figures survive the trip, and none of them survive being
|
|
74
|
+
* turned into text. Asking for text is therefore opt-in.
|
|
75
|
+
*
|
|
76
|
+
* The page range and `deliver_as` are two questions, asked in that order. The
|
|
77
|
+
* range says WHICH DOCUMENT the call is about: those pages are taken out of
|
|
78
|
+
* the PDF first, and everything after that is about them and nothing else.
|
|
79
|
+
* `deliver_as` then says how that document should reach the model.
|
|
80
|
+
*
|
|
81
|
+
* Refused, before the file is read or anything is spent:
|
|
82
|
+
* - `first_page` or `last_page` on anything that is not a PDF;
|
|
83
|
+
* - one of the pair without the other, a `first_page` below 1, a `last_page`
|
|
84
|
+
* before `first_page`, or either one not a whole number;
|
|
85
|
+
* - a range that runs past the end of the document;
|
|
86
|
+
* - `deliver_as: 'text'` on an image, which is not read as text;
|
|
87
|
+
* - `deliver_as: 'document'` on a Word, Excel, PowerPoint, CSV, RTF or text
|
|
88
|
+
* file,
|
|
89
|
+
* which only ever travels as text.
|
|
90
|
+
*
|
|
91
|
+
* A page the platform cannot read as text sends the pages asked for as a PDF
|
|
92
|
+
* instead, so an answer is never built on text with a hole in it.
|
|
93
|
+
*
|
|
94
|
+
* Pages asked for as text arrive numbered from 1, because by then they are a
|
|
95
|
+
* document of their own. A line above them says which pages of which document
|
|
96
|
+
* they were, rather than the numbers being rewritten inside the text: a page
|
|
97
|
+
* number printed in a header or a cross-reference cannot be told apart from a
|
|
98
|
+
* page label, so editing them would corrupt the document's own words.
|
|
99
|
+
*/
|
|
100
|
+
export type AIDocumentInput = DocumentHandle & {
|
|
101
|
+
/** The first page to use, counted from 1. Named with `last_page`. PDF only. */
|
|
102
|
+
first_page?: number;
|
|
103
|
+
/** The last page to use, included. Named with `first_page`. PDF only. */
|
|
104
|
+
last_page?: number;
|
|
105
|
+
/**
|
|
106
|
+
* How the document reaches the model: `'document'`, the default, sends the
|
|
107
|
+
* document itself; `'text'` sends the text the platform reads out of it.
|
|
108
|
+
*
|
|
109
|
+
* Both answers are sayable, so the default can be written down rather than
|
|
110
|
+
* left to the absence of a key.
|
|
111
|
+
*/
|
|
112
|
+
deliver_as?: 'document' | 'text';
|
|
113
|
+
};
|
|
68
114
|
/**
|
|
69
115
|
* A set of common configuration options shared across all AI operations.
|
|
70
116
|
* This adheres to the DRY principle, ensuring a consistent API surface.
|
|
@@ -200,22 +246,26 @@ export interface AIExecutionResult {
|
|
|
200
246
|
* Extracts structured data from a given input using the Simple AI engine.
|
|
201
247
|
*
|
|
202
248
|
* @param input The source data for the extraction (string, document handle, or object).
|
|
249
|
+
* A document handle may carry `deliver_as`, `first_page` and `last_page`; see
|
|
250
|
+
* `AIDocumentInput`.
|
|
203
251
|
* @param options The configuration for the extraction operation.
|
|
204
252
|
* @param context The execution context provided by the host.
|
|
205
253
|
* @returns A promise that resolves to an `AIExecutionResult` object.
|
|
206
254
|
* @throws Will throw an error if the operation fails or inputs are invalid.
|
|
207
255
|
*/
|
|
208
|
-
export declare function extract(input: DocumentHandle | object | string, options: AIExtractOptions, context: Context): Promise<AIExecutionResult>;
|
|
256
|
+
export declare function extract(input: AIDocumentInput | DocumentHandle | object | string, options: AIExtractOptions, context: Context): Promise<AIExecutionResult>;
|
|
209
257
|
/**
|
|
210
258
|
* Generates a summary for a given input using the Simple AI engine.
|
|
211
259
|
*
|
|
212
260
|
* @param input The source data for the summarization (string, document handle, or object).
|
|
261
|
+
* A document handle may carry `deliver_as`, `first_page` and `last_page`; see
|
|
262
|
+
* `AIDocumentInput`.
|
|
213
263
|
* @param options The configuration for the summarization operation.
|
|
214
264
|
* @param context The execution context provided by the host.
|
|
215
265
|
* @returns A promise that resolves to an `AIExecutionResult` object containing the summary.
|
|
216
266
|
* @throws Will throw an error if the operation fails or inputs are invalid.
|
|
217
267
|
*/
|
|
218
|
-
export declare function summarize(input: DocumentHandle | object | string, options: AISummarizeOptions, context: Context): Promise<AIExecutionResult>;
|
|
268
|
+
export declare function summarize(input: AIDocumentInput | DocumentHandle | object | string, options: AISummarizeOptions, context: Context): Promise<AIExecutionResult>;
|
|
219
269
|
/**
|
|
220
270
|
* Transcribes audio or video from a document handle using the Simple AI engine.
|
|
221
271
|
*
|
package/dist/ai.js
CHANGED
|
@@ -5,8 +5,9 @@ import { execute as hostExecute } from './host';
|
|
|
5
5
|
/**
|
|
6
6
|
* Recursively processes an object to detect and upload pending files.
|
|
7
7
|
* When a pending DocumentHandle is detected (has `pending: true` and `file_hash`),
|
|
8
|
-
* it calls the ephemeral upload host function and
|
|
9
|
-
*
|
|
8
|
+
* it calls the ephemeral upload host function and hands the operation the
|
|
9
|
+
* stored handle the upload answered with, carrying over the keys the caller
|
|
10
|
+
* put on the handle.
|
|
10
11
|
*
|
|
11
12
|
* @internal
|
|
12
13
|
*/
|
|
@@ -19,7 +20,23 @@ async function _uploadPendingFiles(obj, context) {
|
|
|
19
20
|
if (!response.ok) {
|
|
20
21
|
throw new Error(response.error?.message || 'Failed to upload pending file');
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
// The upload answers with the stored file's own reference: where it is,
|
|
24
|
+
// what it hashes to, its name, its type and its size. Every one of those
|
|
25
|
+
// keys describes the file, so every one of them is taken from the upload
|
|
26
|
+
// and none is carried over — a value from before the upload would name a
|
|
27
|
+
// file that is no longer the one being read.
|
|
28
|
+
//
|
|
29
|
+
// Everything else on the handle is the caller's: how the file is to be
|
|
30
|
+
// sent, which of its pages, and any key added to a file reference later.
|
|
31
|
+
// Those describe the request, not the file, and the upload knows nothing
|
|
32
|
+
// about them, so they are carried over. A caller reads a pending file and
|
|
33
|
+
// a stored one the same way.
|
|
34
|
+
//
|
|
35
|
+
// `pending` is the one key that is neither: it said the bytes had not been
|
|
36
|
+
// stored yet. They have been now, so it is dropped. A handle that still
|
|
37
|
+
// called itself pending would be uploaded a second time on the next pass.
|
|
38
|
+
const { pending: _pending, ...caller } = obj;
|
|
39
|
+
return { ...caller, ...response.data };
|
|
23
40
|
}
|
|
24
41
|
if (Array.isArray(obj)) {
|
|
25
42
|
return Promise.all(obj.map(item => _uploadPendingFiles(item, context)));
|
|
@@ -82,6 +99,8 @@ async function _executeAIOperation(operation, input, options, context) {
|
|
|
82
99
|
* Extracts structured data from a given input using the Simple AI engine.
|
|
83
100
|
*
|
|
84
101
|
* @param input The source data for the extraction (string, document handle, or object).
|
|
102
|
+
* A document handle may carry `deliver_as`, `first_page` and `last_page`; see
|
|
103
|
+
* `AIDocumentInput`.
|
|
85
104
|
* @param options The configuration for the extraction operation.
|
|
86
105
|
* @param context The execution context provided by the host.
|
|
87
106
|
* @returns A promise that resolves to an `AIExecutionResult` object.
|
|
@@ -105,6 +124,8 @@ export async function extract(input, options, context) {
|
|
|
105
124
|
* Generates a summary for a given input using the Simple AI engine.
|
|
106
125
|
*
|
|
107
126
|
* @param input The source data for the summarization (string, document handle, or object).
|
|
127
|
+
* A document handle may carry `deliver_as`, `first_page` and `last_page`; see
|
|
128
|
+
* `AIDocumentInput`.
|
|
108
129
|
* @param options The configuration for the summarization operation.
|
|
109
130
|
* @param context The execution context provided by the host.
|
|
110
131
|
* @returns A promise that resolves to an `AIExecutionResult` object containing the summary.
|