@meistrari/tela-sdk-js 2.12.0 → 2.13.1

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 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,112 @@ 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
+ `tela.agents` is a thin **pass-through wrapper** around [`@meistrari/agent-sdk`](https://www.npmjs.com/package/@meistrari/agent-sdk). Execution, streaming, timeline, cancellation, and model updates are delegated straight to the agent-sdk client; the SDK adds only the Tela-specific bits: addressing agents by **`agentId`** (resolved to the underlying `organizationName`/`repository`), uploading `TelaFile` inputs to the vault, and mapping your Tela credentials onto the agent-sdk auth strategy. Method names and shapes mirror the agent-sdk contract.
722
+
723
+ > **Transport:** the wrapper builds an agent-sdk client that calls the `/v4/agents` and `/v4/sessions` endpoints. It defaults to your `baseURL`; set `agentBaseURL` when the v4 agent service lives at a different host:
724
+ >
725
+ > ```typescript
726
+ > const tela = new TelaSDK({ apiKey: 'your-api-key', agentBaseURL: 'https://agents.example.com' })
727
+ > ```
728
+
729
+ ```typescript
730
+ const tela = new TelaSDK({ apiKey: 'your-api-key' })
731
+
732
+ // Discover agents (Tela gateway)
733
+ const agents = await tela.agents.list()
734
+
735
+ // Start a session by agentId — resolved to org/repo under the hood.
736
+ const started = await tela.agents.executeAgent({
737
+ agentId: agents[0].id,
738
+ message: 'Summarize the latest tickets',
739
+ })
740
+ if (!started.success)
741
+ throw new Error(started.error)
742
+
743
+ const { sessionId } = started
744
+ ```
745
+
746
+ `executeAgent` returns the agent-sdk `ExecuteAgentResponse` (`{ success: true, sessionId } | { success: false, error }`). Stream the session's events by id:
747
+
748
+ ```typescript
749
+ for await (const event of await tela.agents.streamSession(sessionId)) {
750
+ switch (event.kind) {
751
+ case 'status':
752
+ console.log('status:', event.status)
753
+ break
754
+ case 'steps':
755
+ console.log('steps:', event.steps)
756
+ break
757
+ case 'result':
758
+ console.log('result:', event.result)
759
+ break
760
+ case 'error':
761
+ throw new Error(event.error)
762
+ }
763
+ }
764
+
765
+ // Timeline metrics (duration, token/cost) and cancellation, by session id:
766
+ const timeline = await tela.agents.fetchTimeline(sessionId)
767
+ await tela.agents.cancelSession(sessionId)
768
+ ```
769
+
770
+ **Inputs** — pass file inputs as `TelaFile`s (uploaded to the vault automatically) or ready `vault://` references:
771
+
772
+ ```typescript
773
+ await tela.agents.executeAgent({
774
+ agentId,
775
+ message: 'Review this contract',
776
+ inputs: [
777
+ tela.createFile(buffer, { name: 'contract.pdf', mimeType: 'application/pdf' }),
778
+ { vaultRef: 'vault://...', filename: 'reference.txt' },
779
+ ],
780
+ })
781
+ ```
782
+
783
+ **Multi-turn / recover** — continue or recover an existing session by `sessionId` (omit `agentId`):
784
+
785
+ ```typescript
786
+ await tela.agents.executeAgent({ sessionId, message: 'Now implement step 1' }) // continue
787
+ await tela.agents.executeAgent({ sessionId, recover: true }) // recover a failed/terminal session
788
+ ```
789
+
790
+ **Webhooks** — register up to 5 HTTPS endpoints to receive session lifecycle callbacks instead of (or alongside) streaming. Passing `webhooks` on a continuation **replaces** the set.
791
+
792
+ ```typescript
793
+ import { verifyWebhookSignature } from '@meistrari/tela-sdk-js'
794
+ import type { SessionWebhookEventPayload } from '@meistrari/tela-sdk-js'
795
+
796
+ await tela.agents.executeAgent({
797
+ agentId,
798
+ message: 'Audit the README for typos',
799
+ webhooks: [{
800
+ url: 'https://example.com/hooks/agent',
801
+ events: ['session.completed', 'session.failed'], // defaults to all session.* events
802
+ secret: 'whsec_…', // optional HMAC-SHA256 signing secret
803
+ }],
804
+ })
805
+
806
+ // On your endpoint, verify the signature before trusting the payload:
807
+ const valid = await verifyWebhookSignature(
808
+ rawBody,
809
+ req.headers.get('x-tela-agent-webhook-signature'),
810
+ process.env.WEBHOOK_SECRET!,
811
+ )
812
+ if (!valid)
813
+ return res.status(401).end()
814
+ const event = JSON.parse(rawBody) as SessionWebhookEventPayload
815
+ ```
816
+
817
+ **Model updates** — set an agent's model by id:
818
+
819
+ ```typescript
820
+ await tela.agents.updateAgentModel({ agentId, model: 'claude-opus-4-8', commitMessage: 'bump model' })
821
+ ```
822
+
823
+ The contract types (`SessionStreamEvent`, `SessionTimelineResponse`, `SessionWebhookConfig`, …), `verifyWebhookSignature`, and `parseSessionStream` are re-exported from `@meistrari/tela-sdk-js` — the agent-sdk is the single source of truth.
824
+
718
825
  ## Migration Guide from v1.x to v2
719
826
 
720
827
  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.