@meistrari/tela-sdk-js 1.0.2 → 2.0.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/README.md +213 -89
- package/dist/index.cjs +1062 -110
- package/dist/index.d.cts +601 -428
- package/dist/index.d.mts +601 -428
- package/dist/index.d.ts +601 -428
- package/dist/index.mjs +1036 -111
- package/package.json +17 -7
package/README.md
CHANGED
|
@@ -7,12 +7,14 @@ The Tela SDK for JavaScript provides a simple and powerful way to interact with
|
|
|
7
7
|
- [Installation](#installation)
|
|
8
8
|
- [Usage](#usage)
|
|
9
9
|
- [Examples](#examples)
|
|
10
|
-
- [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
10
|
+
- [Canvas API](#canvas-api)
|
|
11
|
+
- [Synchronous Execution](#synchronous-execution)
|
|
12
|
+
- [Asynchronous Execution with Polling](#asynchronous-execution-with-polling)
|
|
13
|
+
- [Streaming Execution](#streaming-execution)
|
|
14
|
+
- [Schema Validation](#schema-validation)
|
|
15
|
+
- [Multiple Files](#multiple-files)
|
|
16
|
+
- [Webhook Notifications](#webhook-notifications)
|
|
17
|
+
- [File Handling](#file-handling)
|
|
16
18
|
- [License](#license)
|
|
17
19
|
|
|
18
20
|
## Installation
|
|
@@ -30,130 +32,252 @@ pnpm add @meistrari/tela-sdk-js
|
|
|
30
32
|
First, you need to import the SDK and initialize it with your API key:
|
|
31
33
|
|
|
32
34
|
```typescript
|
|
33
|
-
import {
|
|
35
|
+
import { TelaSDK } from '@meistrari/tela-sdk-js'
|
|
34
36
|
|
|
35
|
-
const tela =
|
|
37
|
+
const tela = new TelaSDK({ apiKey: 'your-api-key' })
|
|
36
38
|
```
|
|
37
39
|
|
|
38
40
|
## Examples
|
|
39
41
|
|
|
40
|
-
###
|
|
42
|
+
### Canvas API
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
The Canvas API provides a type-safe way to execute prompts with schema validation and multiple execution modes.
|
|
45
|
+
|
|
46
|
+
#### Synchronous Execution
|
|
47
|
+
|
|
48
|
+
Execute a canvas and wait for the complete result:
|
|
43
49
|
|
|
44
50
|
```typescript
|
|
45
|
-
import {
|
|
46
|
-
import type { TelaFile } from '@meistrari/tela-sdk-js'
|
|
51
|
+
import { TelaSDK } from '@meistrari/tela-sdk-js'
|
|
47
52
|
|
|
48
|
-
const tela =
|
|
49
|
-
apiKey:
|
|
53
|
+
const tela = new TelaSDK({
|
|
54
|
+
apiKey: 'your-api-key'
|
|
50
55
|
})
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
57
|
+
// Get canvas with input/output schemas
|
|
58
|
+
const canvas = await tela.canvas.get({
|
|
59
|
+
id: 'canvas-id',
|
|
60
|
+
input: schema => schema.object({
|
|
61
|
+
query: schema.string()
|
|
62
|
+
}),
|
|
63
|
+
output: schema => schema.object({
|
|
64
|
+
result: schema.string()
|
|
65
|
+
}),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Execute synchronously - direct result access
|
|
69
|
+
const result = await canvas.execute({ query: 'What is the capital of France?' }).result
|
|
70
|
+
|
|
71
|
+
console.log(result) // { result: "Paris" }
|
|
72
|
+
|
|
73
|
+
// Alternative: get execution object for more control
|
|
74
|
+
const execution = await canvas.execute({ query: 'What is the capital of France?' })
|
|
75
|
+
const result2 = await execution.result
|
|
63
76
|
```
|
|
64
77
|
|
|
65
|
-
|
|
78
|
+
#### Asynchronous Execution with Polling
|
|
66
79
|
|
|
67
|
-
|
|
80
|
+
For long-running operations, use async mode with automatic polling:
|
|
68
81
|
|
|
69
82
|
```typescript
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
const canvas = await tela.canvas.get({
|
|
84
|
+
id: 'canvas-id',
|
|
85
|
+
input: schema => schema.object({
|
|
86
|
+
document: schema.file(),
|
|
87
|
+
query: schema.string()
|
|
88
|
+
}),
|
|
89
|
+
output: schema => schema.object({
|
|
90
|
+
summary: schema.string()
|
|
91
|
+
}),
|
|
73
92
|
})
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
93
|
+
|
|
94
|
+
// Execute asynchronously with polling - direct result access
|
|
95
|
+
const result = await canvas.execute(
|
|
96
|
+
{
|
|
97
|
+
document: TelaFile.create(documentBlob, { name: 'report.pdf' }),
|
|
98
|
+
query: 'Summarize this document'
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
async: true,
|
|
102
|
+
pollingInterval: 1000, // Poll every 1 second
|
|
103
|
+
pollingTimeout: 60000, // Timeout after 60 seconds
|
|
104
|
+
}
|
|
105
|
+
).result
|
|
106
|
+
|
|
107
|
+
console.log(result.summary)
|
|
82
108
|
```
|
|
83
109
|
|
|
84
|
-
|
|
110
|
+
#### Streaming Execution
|
|
85
111
|
|
|
86
|
-
|
|
112
|
+
Stream results as they're generated:
|
|
87
113
|
|
|
88
114
|
```typescript
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
115
|
+
const canvas = await tela.canvas.get({
|
|
116
|
+
id: 'canvas-id',
|
|
117
|
+
input: schema => schema.object({
|
|
118
|
+
prompt: schema.string()
|
|
119
|
+
}),
|
|
120
|
+
output: schema => schema.object({
|
|
121
|
+
response: schema.string()
|
|
122
|
+
}),
|
|
93
123
|
})
|
|
94
124
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
webhookUrl: 'https://webhook.site/4294967295',
|
|
102
|
-
stream: false,
|
|
103
|
-
})
|
|
104
|
-
console.log(JSON.stringify(webhook, null, 2))
|
|
125
|
+
// Execute with streaming - direct iteration
|
|
126
|
+
for await (const chunk of canvas.execute(
|
|
127
|
+
{ prompt: 'Write a story about a robot' },
|
|
128
|
+
{ stream: true }
|
|
129
|
+
).result) {
|
|
130
|
+
process.stdout.write(chunk.response || '')
|
|
105
131
|
}
|
|
106
|
-
run().catch(console.error)
|
|
107
132
|
```
|
|
108
133
|
|
|
109
|
-
|
|
134
|
+
#### Schema Validation
|
|
110
135
|
|
|
111
|
-
|
|
136
|
+
The Canvas API validates your inputs and outputs against the server schema:
|
|
112
137
|
|
|
113
138
|
```typescript
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
139
|
+
const canvas = await tela.canvas.get({
|
|
140
|
+
id: 'canvas-id',
|
|
141
|
+
input: schema => schema.object({
|
|
142
|
+
text: schema.string(),
|
|
143
|
+
file: schema.file(), // TelaFile validator
|
|
144
|
+
settings: schema.object({
|
|
145
|
+
temperature: schema.number(),
|
|
146
|
+
maxTokens: schema.number(),
|
|
147
|
+
}),
|
|
148
|
+
}),
|
|
149
|
+
output: schema => schema.object({
|
|
150
|
+
analysis: schema.string(),
|
|
151
|
+
confidence: schema.number(),
|
|
152
|
+
}),
|
|
153
|
+
skipSchemaValidation: false, // Enable schema validation warnings during canvas retrieval (default)
|
|
120
154
|
})
|
|
121
155
|
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
document: tela.createFile(fileStream),
|
|
130
|
-
},
|
|
131
|
-
stream: true,
|
|
132
|
-
})
|
|
133
|
-
for await (const chunk of completion) {
|
|
134
|
-
console.log(JSON.stringify(chunk))
|
|
156
|
+
// TypeScript will ensure you provide the correct types
|
|
157
|
+
const result = await canvas.execute({
|
|
158
|
+
text: 'Analyze this document',
|
|
159
|
+
file: TelaFile.create(blob, { name: 'data.pdf' }),
|
|
160
|
+
settings: {
|
|
161
|
+
temperature: 0.7,
|
|
162
|
+
maxTokens: 1000,
|
|
135
163
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
164
|
+
}).result
|
|
165
|
+
|
|
166
|
+
// Skip result validation to trust API response without Zod validation
|
|
167
|
+
const resultWithoutValidation = await canvas.execute(
|
|
168
|
+
{
|
|
169
|
+
text: 'Analyze this document',
|
|
170
|
+
file: TelaFile.create(blob, { name: 'data.pdf' }),
|
|
171
|
+
settings: {
|
|
172
|
+
temperature: 0.7,
|
|
173
|
+
maxTokens: 1000,
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
skipResultValidation: true // Skip Zod validation on results, just typecast
|
|
178
|
+
}
|
|
179
|
+
).result
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### Multiple Files
|
|
183
|
+
|
|
184
|
+
Process multiple files in a single canvas execution:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const canvas = await tela.canvas.get({
|
|
188
|
+
id: 'canvas-id',
|
|
189
|
+
input: schema => schema.object({
|
|
190
|
+
documents: schema.array(schema.file()),
|
|
191
|
+
instructions: schema.string()
|
|
192
|
+
}),
|
|
193
|
+
output: schema => schema.object({
|
|
194
|
+
comparison: schema.string()
|
|
195
|
+
}),
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
const result = await canvas.execute({
|
|
199
|
+
documents: [
|
|
200
|
+
TelaFile.create('https://example.com/doc1.pdf', { range: [0, 5] }),
|
|
201
|
+
TelaFile.create('https://example.com/doc2.pdf', { range: [0, 5] }),
|
|
202
|
+
TelaFile.create(localFileBlob, { name: 'doc3.pdf' })
|
|
203
|
+
],
|
|
204
|
+
instructions: 'Compare these documents and identify key differences'
|
|
205
|
+
}).result
|
|
206
|
+
|
|
207
|
+
console.log(result.comparison)
|
|
138
208
|
```
|
|
139
209
|
|
|
140
|
-
|
|
210
|
+
#### Webhook Notifications
|
|
141
211
|
|
|
142
|
-
|
|
212
|
+
Receive completion notifications via webhook for async executions:
|
|
143
213
|
|
|
144
|
-
|
|
214
|
+
```typescript
|
|
215
|
+
const canvas = await tela.canvas.get({
|
|
216
|
+
id: 'canvas-id',
|
|
217
|
+
input: schema => schema.object({
|
|
218
|
+
document: schema.file(),
|
|
219
|
+
query: schema.string()
|
|
220
|
+
}),
|
|
221
|
+
output: schema => schema.object({
|
|
222
|
+
analysis: schema.string()
|
|
223
|
+
}),
|
|
224
|
+
})
|
|
145
225
|
|
|
146
|
-
|
|
226
|
+
// Execute with webhook notification - you can still poll if needed
|
|
227
|
+
const result = await canvas.execute(
|
|
228
|
+
{
|
|
229
|
+
document: TelaFile.create('https://example.com/large-report.pdf'),
|
|
230
|
+
query: 'Analyze this report'
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
async: true,
|
|
234
|
+
webhookUrl: 'https://your-server.com/webhook',
|
|
235
|
+
pollingTimeout: 300000, // 5 minutes
|
|
236
|
+
}
|
|
237
|
+
).result
|
|
238
|
+
// OR wait for the webhook notification on your server instead of polling
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### File Handling
|
|
147
242
|
|
|
148
|
-
|
|
243
|
+
The `TelaFile` API provides flexible file handling with support for various input types:
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import { TelaFile } from '@meistrari/tela-sdk-js'
|
|
149
247
|
|
|
150
|
-
|
|
248
|
+
// From a Blob or File
|
|
249
|
+
const fileFromBlob = TelaFile.create(blob, { name: 'custom.pdf' })
|
|
151
250
|
|
|
152
|
-
|
|
251
|
+
// From a URL
|
|
252
|
+
const fileFromUrl = TelaFile.create('https://example.com/document.pdf')
|
|
153
253
|
|
|
154
|
-
|
|
155
|
-
|
|
254
|
+
// From bytes with explicit MIME type
|
|
255
|
+
const fileFromBytes = TelaFile.create(
|
|
256
|
+
new Uint8Array(['...']),
|
|
257
|
+
{
|
|
258
|
+
mimeType: 'application/pdf',
|
|
259
|
+
name: 'document.pdf'
|
|
260
|
+
}
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
// From a ReadableStream with explicit MIME type
|
|
264
|
+
const fileFromStream = TelaFile.create(
|
|
265
|
+
readableStream,
|
|
266
|
+
{
|
|
267
|
+
mimeType: 'image/jpeg',
|
|
268
|
+
name: 'photo.jpg'
|
|
269
|
+
}
|
|
270
|
+
)
|
|
156
271
|
|
|
157
|
-
|
|
272
|
+
// Vault reference (for files already uploaded)
|
|
273
|
+
const vaultFile = TelaFile.create('vault://file-id')
|
|
158
274
|
|
|
159
|
-
|
|
275
|
+
// With page range for PDFs
|
|
276
|
+
const fileWithRange = TelaFile.create(
|
|
277
|
+
'https://example.com/document.pdf',
|
|
278
|
+
{
|
|
279
|
+
range: [0, 5], // Pages 0-5
|
|
280
|
+
parserType: 'pdf'
|
|
281
|
+
}
|
|
282
|
+
)
|
|
283
|
+
```
|