@meistrari/tela-sdk-js 2.13.0 → 2.13.2

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` runs agents through the Tela gateway (`run` `POST /agent/:id/run`). Streaming, timeline, cancellation, and model updates are delegated to [`@meistrari/agent-sdk`](https://www.npmjs.com/package/@meistrari/agent-sdk). The SDK adds the Tela-specific bits: addressing agents by **`agentId`**, flattening a per-variable `inputs` map into the wire `inputSchema` array, uploading `TelaFile` inputs to the vault, and mapping your Tela credentials onto the agent-sdk auth strategy.
722
+
723
+ > **Transport:** `run` posts to the Tela gateway and is authenticated by your SDK credentials. The delegated streaming/timeline/cancel calls use an agent-sdk client against `/v4/sessions`; 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.
736
+ const started = await tela.agents.run({
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
+ `run` returns `{ success, sessionId }` — execution is async, so 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,74 @@ 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
-
758
- Or subscribe to lifecycle events and read state:
759
764
 
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** — `inputs` is a map keyed by variable name. Each value is a single entry or an array of entries; an entry can be a `TelaFile` (uploaded to the vault automatically), a ready `vault://` reference, or a text entry — each optionally carrying `metadata`. The SDK flattens this into the wire `inputSchema` array, tagging every entry with its variable name.
772
771
 
773
772
  ```typescript
774
- await agent.execute({
775
- prompt: 'Review this contract',
773
+ await tela.agents.run({
774
+ agentId,
775
+ message: 'Review this contract against the references',
776
776
  inputs: {
777
- document: tela.createFile(buffer, { name: 'contract.pdf', mimeType: 'application/pdf' }),
778
- focus: 'liability clauses',
777
+ // a TelaFile uploaded to the vault for you
778
+ contract: tela.createFile(buffer, { name: 'contract.pdf', mimeType: 'application/pdf' }),
779
+ // multiple entries for one variable; ready vault refs with metadata
780
+ references: [
781
+ { vaultRef: 'vault://...', filename: 'reference.txt', metadata: 'prior version' },
782
+ ],
783
+ // a text input
784
+ notes: { type: 'text', content: 'Focus on the indemnity clauses.' },
779
785
  },
780
- attachments: [{ vaultRef: 'vault://...', filename: 'reference.txt' }],
781
- }).result
786
+ environmentVariables: { LOCALE: 'en-US' },
787
+ })
782
788
  ```
783
789
 
784
- **Multi-turn** — continue the same session with another instruction:
790
+ **Multi-turn** — continue an existing session by passing its `sessionId` alongside the `agentId`:
785
791
 
786
792
  ```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
793
+ await tela.agents.run({ agentId, sessionId, message: 'Now implement step 1' })
790
794
  ```
791
795
 
792
- **Cancel / recover** an in-flight or failed run:
796
+ **Webhooks** register session lifecycle callbacks by passing `webhooks` to `run`. The gateway forwards the webhook config to the agent execution service unchanged. Passing `webhooks` on a continuation replaces the session's registration; omitting it keeps the existing registration.
793
797
 
794
798
  ```typescript
795
- await execution.cancel() // aborts the stream and cancels server-side
796
- await execution.recover() // resume a failed/terminal session
799
+ await tela.agents.run({
800
+ agentId,
801
+ message: 'Summarize the latest tickets',
802
+ webhooks: [{
803
+ url: 'https://example.com/hooks/agent-session',
804
+ events: ['session.completed', 'session.failed', 'session.cancelled'],
805
+ secret: 'whsec_a-long-random-string',
806
+ }],
807
+ })
797
808
  ```
798
809
 
799
- **Resume / inspect** a session by id useful for resumable workflows, dashboards, and background jobs:
810
+ Webhook URLs must be HTTPS and publicly reachable. Up to five webhooks can be registered per session. Use `verifyWebhookSignature` to verify signed deliveries.
811
+
812
+ **Model updates** — set an agent's model by id:
800
813
 
801
814
  ```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')
815
+ await tela.agents.updateAgentModel({ agentId, model: 'claude-opus-4-8', commitMessage: 'bump model' })
806
816
  ```
807
817
 
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).
818
+ The contract types (`SessionStreamEvent`, `SessionTimelineResponse`, `AgentRunWebhooks`, `SessionWebhookConfig`, …), `verifyWebhookSignature`, and `parseSessionStream` are re-exported from `@meistrari/tela-sdk-js` the agent-sdk is the single source of truth for the session/streaming/webhook contract.
819
+
820
+ **Migration note** — replace `tela.agents.executeAgent(...)` with `tela.agents.run(...)`. `agentId` is now required, `inputs` is keyed by variable name instead of a flat array, and `webhooks` moves unchanged onto `run`. The Tela gateway run path does not support agent-sdk `recover` requests; start or continue a session with `message` instead.
821
+
822
+ ```typescript
823
+ await tela.agents.run({
824
+ agentId,
825
+ message,
826
+ inputs: {
827
+ document: tela.createFile(file, { name: 'document.pdf' }),
828
+ },
829
+ webhooks,
830
+ })
831
+ ```
809
832
 
810
833
  ## Migration Guide from v1.x to v2
811
834