@agentstep/agent-sdk 0.5.37 → 0.5.39

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.
@@ -97,17 +97,29 @@ function handleCreateInteraction(request) {
97
97
  ).run(interactionId2, sessionId2, seq, result2.status, environmentId ?? null, (/* @__PURE__ */ new Date()).toISOString());
98
98
  return jsonOk(buildResponse(interactionId2, result2, environmentId));
99
99
  }
100
- const agentName = data.agent || `auto-${(data.model || "gemini-2.5-flash").replace(/[^a-z0-9-]/g, "-")}`;
100
+ const modelId = data.model || "gemini-2.5-flash";
101
+ const agentName = data.agent || `auto-${modelId.replace(/[^a-z0-9-]/g, "-")}`;
101
102
  const listReq = new Request(request.url.replace(/\/google\/v1beta\/interactions.*/, `/v1/agents?limit=1000`), {
102
103
  headers: request.headers
103
104
  });
104
105
  const listRes = await handleListAgents(listReq);
105
106
  const listBody = await listRes.json();
106
- const existing = listBody.data?.find((a) => a.name === agentName);
107
+ const { listVaults } = await import("./db/vaults.js");
108
+ const { tenantFilter: getTenantFilter } = await import("./auth/scope.js");
109
+ const allVaults = listVaults({ tenantFilter: getTenantFilter(auth) }).filter((v) => !v.archived_at);
110
+ let existing;
111
+ if (data.agent) {
112
+ existing = listBody.data?.find((a) => a.name === agentName);
113
+ } else {
114
+ const modelMatches = listBody.data?.filter((a) => a.model?.id === modelId) ?? [];
115
+ const withVaults = modelMatches.filter(
116
+ (a) => allVaults.some((v) => v.agent_id === a.id || !v.agent_id)
117
+ );
118
+ existing = modelMatches.find((a) => allVaults.some((v) => v.agent_id === a.id)) ?? withVaults[0] ?? modelMatches[0];
119
+ }
107
120
  if (existing) {
108
121
  agentId = existing.id;
109
122
  } else {
110
- const modelId = data.model || "gemini-2.5-flash";
111
123
  const createReq = new Request(request.url.replace(/\/google\/v1beta\/interactions.*/, `/v1/agents`), {
112
124
  method: "POST",
113
125
  headers: request.headers,
@@ -144,13 +156,7 @@ function handleCreateInteraction(request) {
144
156
  }
145
157
  }
146
158
  if (!environmentId) throw badRequest("no environment available");
147
- const { listVaults } = await import("./db/vaults.js");
148
- const { tenantFilter: getTenantFilter } = await import("./auth/scope.js");
149
- const tenantVaults = listVaults({
150
- tenantFilter: getTenantFilter(auth)
151
- });
152
- const agentVaults = tenantVaults.filter((v) => v.agent_id === agentId || !v.agent_id);
153
- const vaultIds = agentVaults.filter((v) => !v.archived_at).map((v) => v.id);
159
+ const vaultIds = allVaults.filter((v) => v.agent_id === agentId || !v.agent_id).map((v) => v.id);
154
160
  const sessReq = new Request(request.url.replace(/\/google\/v1beta\/interactions.*/, `/v1/sessions`), {
155
161
  method: "POST",
156
162
  headers: request.headers,
@@ -254,7 +254,7 @@ function handleCreateSession(request) {
254
254
  const vaultRow = getDb().prepare(`SELECT agent_id, tenant_id FROM vaults WHERE id = ?`).get(vid);
255
255
  if (!vaultRow) throw badRequest(`vault not found: ${vid}`);
256
256
  assertResourceTenant(auth, vaultRow.tenant_id, `vault not found: ${vid}`);
257
- if (vaultRow.agent_id !== agent.id) {
257
+ if (vaultRow.agent_id && vaultRow.agent_id !== agent.id) {
258
258
  throw badRequest(
259
259
  `vault ${vid} belongs to a different agent \u2014 vaults are scoped per-agent`
260
260
  );
@@ -4,7 +4,7 @@ import {
4
4
  handleCreateInteraction,
5
5
  handleDeleteInteraction,
6
6
  handleGetInteraction
7
- } from "../../chunk-VRWXVIIG.js";
7
+ } from "../../chunk-KSKJ7IYH.js";
8
8
  import {
9
9
  handleCreateGoogleAgent,
10
10
  handleDeleteGoogleAgent,
@@ -3,7 +3,7 @@ import {
3
3
  handleCreateInteraction,
4
4
  handleDeleteInteraction,
5
5
  handleGetInteraction
6
- } from "../../chunk-VRWXVIIG.js";
6
+ } from "../../chunk-KSKJ7IYH.js";
7
7
  import "../../chunk-RMCBO7K7.js";
8
8
  import "../../chunk-D2XITRN6.js";
9
9
  import "../../chunk-CWB2DQN5.js";
@@ -4,7 +4,7 @@ import {
4
4
  handleCreateInteraction,
5
5
  handleDeleteInteraction,
6
6
  handleGetInteraction
7
- } from "../chunk-VRWXVIIG.js";
7
+ } from "../chunk-KSKJ7IYH.js";
8
8
  import {
9
9
  handleCreateGoogleAgent,
10
10
  handleDeleteGoogleAgent,
@@ -103,7 +103,7 @@ import {
103
103
  handleGetSession,
104
104
  handleListSessions,
105
105
  handleUpdateSession
106
- } from "../chunk-R6NWAM37.js";
106
+ } from "../chunk-VSDPZ77X.js";
107
107
  import "../chunk-VCU64NHY.js";
108
108
  import {
109
109
  handleGetSetting,
@@ -5,7 +5,7 @@ import {
5
5
  handleGetSession,
6
6
  handleListSessions,
7
7
  handleUpdateSession
8
- } from "../chunk-R6NWAM37.js";
8
+ } from "../chunk-VSDPZ77X.js";
9
9
  import "../chunk-VCU64NHY.js";
10
10
  import "../chunk-ZBWKJ42J.js";
11
11
  import "../chunk-23UKWXJH.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "license": "Apache-2.0",
3
3
  "name": "@agentstep/agent-sdk",
4
- "version": "0.5.37",
4
+ "version": "0.5.39",
5
5
  "description": "Core engine for AgentStep Gateway \u2014 backends, sandbox providers, session orchestration, and vault encryption.",
6
6
  "keywords": [
7
7
  "anthropic",