@meistrari/tela-sdk-js 2.12.0 → 2.13.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 +92 -0
- package/dist/index.cjs +677 -130
- package/dist/index.d.cts +511 -1
- package/dist/index.d.mts +511 -1
- package/dist/index.d.ts +511 -1
- package/dist/index.mjs +674 -131
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ The Tela SDK for JavaScript provides a simple and powerful way to interact with
|
|
|
19
19
|
- [File Handling](#file-handling)
|
|
20
20
|
- [Tasks API](#tasks-api)
|
|
21
21
|
- [Vault API](#vault-api)
|
|
22
|
+
- [Agents API](#agents-api)
|
|
22
23
|
- [Migration Guide from v1.x to v2](#migration-guide-from-v1x-to-v2)
|
|
23
24
|
- [Breaking Changes](#breaking-changes)
|
|
24
25
|
- [Migration Checklist](#migration-checklist)
|
|
@@ -715,6 +716,97 @@ const stream = await tela.vault.stream('vault://abc-123')
|
|
|
715
716
|
|
|
716
717
|
This is particularly useful when reading task input files: `tela.tasks.getInputFiles(id)` returns the file references, and `tela.vault.download(file.url)` downloads them in one call.
|
|
717
718
|
|
|
719
|
+
### Agents API
|
|
720
|
+
|
|
721
|
+
The Agents API runs **agents** — an agent is a configured project (with its own instructions and skills) that executes a prompt asynchronously, streaming its steps until it produces a result. Agents run through the standard Tela API, so no extra configuration is needed: authentication and the vault are shared. Agents are identified by their **agentId**.
|
|
722
|
+
|
|
723
|
+
```typescript
|
|
724
|
+
const tela = new TelaSDK({ apiKey: 'your-api-key' })
|
|
725
|
+
|
|
726
|
+
// Discover agents, then get a handle by id (mirrors `tela.canvas.get`)
|
|
727
|
+
const agents = await tela.agents.list()
|
|
728
|
+
const agent = await tela.agents.get(agents[0].id)
|
|
729
|
+
|
|
730
|
+
// Run the published agent and await the final result
|
|
731
|
+
const result = await agent.execute({
|
|
732
|
+
prompt: 'Summarize the latest tickets',
|
|
733
|
+
}).result
|
|
734
|
+
|
|
735
|
+
console.log(result.content)
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
`execute()` runs the **published** version by default (pass `{ draft: true }` to run the current draft). It returns a promise-like handle — consume **either** `.result` **or** `.stream` (they share one underlying stream). Stream the session's events as they happen:
|
|
739
|
+
|
|
740
|
+
```typescript
|
|
741
|
+
for await (const event of agent.execute({ prompt: 'Investigate the failing build' }).stream) {
|
|
742
|
+
switch (event.kind) {
|
|
743
|
+
case 'status':
|
|
744
|
+
console.log('status:', event.status)
|
|
745
|
+
break
|
|
746
|
+
case 'steps':
|
|
747
|
+
console.log('steps:', event.steps)
|
|
748
|
+
break
|
|
749
|
+
case 'result':
|
|
750
|
+
console.log('result:', event.result)
|
|
751
|
+
break
|
|
752
|
+
case 'error':
|
|
753
|
+
throw new Error(event.error)
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
Or subscribe to lifecycle events and read state:
|
|
759
|
+
|
|
760
|
+
```typescript
|
|
761
|
+
const execution = await agent.execute({ prompt: 'Refactor the auth module' })
|
|
762
|
+
execution.on('status', status => console.log(status))
|
|
763
|
+
execution.on('step', steps => console.log(steps))
|
|
764
|
+
execution.on('result', result => console.log(result))
|
|
765
|
+
execution.on('error', err => console.error(err))
|
|
766
|
+
|
|
767
|
+
await execution.result
|
|
768
|
+
console.log(execution.sessionId, execution.status)
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
**Inputs & attachments** — provide values for the agent's declared inputs (keyed by name) plus ad-hoc file attachments:
|
|
772
|
+
|
|
773
|
+
```typescript
|
|
774
|
+
await agent.execute({
|
|
775
|
+
prompt: 'Review this contract',
|
|
776
|
+
inputs: {
|
|
777
|
+
document: tela.createFile(buffer, { name: 'contract.pdf', mimeType: 'application/pdf' }),
|
|
778
|
+
focus: 'liability clauses',
|
|
779
|
+
},
|
|
780
|
+
attachments: [{ vaultRef: 'vault://...', filename: 'reference.txt' }],
|
|
781
|
+
}).result
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
**Multi-turn** — continue the same session with another instruction:
|
|
785
|
+
|
|
786
|
+
```typescript
|
|
787
|
+
const execution = await agent.execute({ prompt: 'Draft a migration plan' })
|
|
788
|
+
await execution.result
|
|
789
|
+
await execution.continue({ prompt: 'Now implement step 1' }).result
|
|
790
|
+
```
|
|
791
|
+
|
|
792
|
+
**Cancel / recover** an in-flight or failed run:
|
|
793
|
+
|
|
794
|
+
```typescript
|
|
795
|
+
await execution.cancel() // aborts the stream and cancels server-side
|
|
796
|
+
await execution.recover() // resume a failed/terminal session
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
**Resume / inspect** a session by id — useful for resumable workflows, dashboards, and background jobs:
|
|
800
|
+
|
|
801
|
+
```typescript
|
|
802
|
+
const execution = await tela.agents.getSession('session-uuid') // resumable: .stream / .result / .cancel / .recover
|
|
803
|
+
const timeline = await tela.agents.getTimeline('session-uuid') // duration + token/cost metrics
|
|
804
|
+
await tela.agents.cancel('session-uuid')
|
|
805
|
+
await tela.agents.endSession('session-uuid')
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
`TelaFile` inputs and attachments are uploaded to the vault automatically. `execute()` defaults the prompt to `"Execute"` for input-driven agents, and `.result` resolves on `completed` **or** `waiting_messages` (check `.status` and `.continue()` from a paused turn).
|
|
809
|
+
|
|
718
810
|
## Migration Guide from v1.x to v2
|
|
719
811
|
|
|
720
812
|
Version 2.0 of the Tela SDK introduces significant improvements to type safety, schema validation, and API design. This guide will help you migrate your code from v1.x to v2.
|