@meistrari/tela-sdk-js 2.13.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
@@ -718,27 +718,35 @@ This is particularly useful when reading task input files: `tela.tasks.getInputF
718
718
 
719
719
  ### Agents API
720
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**.
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
+ > ```
722
728
 
723
729
  ```typescript
724
730
  const tela = new TelaSDK({ apiKey: 'your-api-key' })
725
731
 
726
- // Discover agents, then get a handle by id (mirrors `tela.canvas.get`)
732
+ // Discover agents (Tela gateway)
727
733
  const agents = await tela.agents.list()
728
- const agent = await tela.agents.get(agents[0].id)
729
734
 
730
- // Run the published agent and await the final result
731
- const result = await agent.execute({
732
- prompt: 'Summarize the latest tickets',
733
- }).result
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)
734
742
 
735
- console.log(result.content)
743
+ const { sessionId } = started
736
744
  ```
737
745
 
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:
746
+ `executeAgent` returns the agent-sdk `ExecuteAgentResponse` (`{ success: true, sessionId } | { success: false, error }`). Stream the session's events by id:
739
747
 
740
748
  ```typescript
741
- for await (const event of agent.execute({ prompt: 'Investigate the failing build' }).stream) {
749
+ for await (const event of await tela.agents.streamSession(sessionId)) {
742
750
  switch (event.kind) {
743
751
  case 'status':
744
752
  console.log('status:', event.status)
@@ -753,59 +761,66 @@ for await (const event of agent.execute({ prompt: 'Investigate the failing build
753
761
  throw new Error(event.error)
754
762
  }
755
763
  }
756
- ```
757
764
 
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)
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)
769
768
  ```
770
769
 
771
- **Inputs & attachments** — provide values for the agent's declared inputs (keyed by name) plus ad-hoc file attachments:
770
+ **Inputs** — pass file inputs as `TelaFile`s (uploaded to the vault automatically) or ready `vault://` references:
772
771
 
773
772
  ```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
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
+ })
782
781
  ```
783
782
 
784
- **Multi-turn** — continue the same session with another instruction:
783
+ **Multi-turn / recover** — continue or recover an existing session by `sessionId` (omit `agentId`):
785
784
 
786
785
  ```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
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
790
788
  ```
791
789
 
792
- **Cancel / recover** an in-flight or failed run:
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.
793
791
 
794
792
  ```typescript
795
- await execution.cancel() // aborts the stream and cancels server-side
796
- await execution.recover() // resume a failed/terminal session
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
797
815
  ```
798
816
 
799
- **Resume / inspect** a session by id useful for resumable workflows, dashboards, and background jobs:
817
+ **Model updates** — set an agent's model by id:
800
818
 
801
819
  ```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')
820
+ await tela.agents.updateAgentModel({ agentId, model: 'claude-opus-4-8', commitMessage: 'bump model' })
806
821
  ```
807
822
 
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).
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.
809
824
 
810
825
  ## Migration Guide from v1.x to v2
811
826