sarvam-agents-client 0.5.2 → 0.5.3
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 +52 -29
- package/dist/apis/AgentsApi.d.ts +96 -11
- package/dist/apis/AgentsApi.js +229 -9
- package/dist/apis/ConversationsApi.d.ts +5 -2
- package/dist/apis/ConversationsApi.js +7 -2
- package/dist/client.d.ts +3 -2
- package/dist/client.js +2 -1
- package/dist/compose/deploy.d.ts +14 -3
- package/dist/compose/deploy.js +60 -7
- package/dist/compose/errors.d.ts +4 -0
- package/dist/compose/errors.js +6 -1
- package/dist/compose/settingsTransport.d.ts +18 -13
- package/dist/compose/settingsTransport.js +78 -130
- package/dist/compose/transport.d.ts +12 -2
- package/dist/compose/webhook.d.ts +10 -13
- package/dist/compose/webhook.js +48 -45
- package/dist/compose/webhookSecrets.d.ts +79 -49
- package/dist/compose/webhookSecrets.js +244 -195
- package/dist/esm/apis/AgentsApi.d.ts +96 -11
- package/dist/esm/apis/AgentsApi.js +230 -10
- package/dist/esm/apis/ConversationsApi.d.ts +5 -2
- package/dist/esm/apis/ConversationsApi.js +7 -2
- package/dist/esm/client.d.ts +3 -2
- package/dist/esm/client.js +2 -1
- package/dist/esm/compose/deploy.d.ts +14 -3
- package/dist/esm/compose/deploy.js +60 -7
- package/dist/esm/compose/errors.d.ts +4 -0
- package/dist/esm/compose/errors.js +4 -0
- package/dist/esm/compose/settingsTransport.d.ts +18 -13
- package/dist/esm/compose/settingsTransport.js +80 -132
- package/dist/esm/compose/transport.d.ts +12 -2
- package/dist/esm/compose/webhook.d.ts +10 -13
- package/dist/esm/compose/webhook.js +45 -42
- package/dist/esm/compose/webhookSecrets.d.ts +79 -49
- package/dist/esm/compose/webhookSecrets.js +241 -193
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/models/AgentConversationDetail.d.ts +12 -0
- package/dist/esm/models/AgentConversationDetail.js +4 -0
- package/dist/esm/models/AgentConversationView.d.ts +12 -0
- package/dist/esm/models/AgentConversationView.js +4 -0
- package/dist/esm/models/AgentResource.d.ts +7 -0
- package/dist/esm/models/AgentResource.js +3 -0
- package/dist/esm/models/AgentVersionSavedResource.d.ts +65 -0
- package/dist/esm/models/AgentVersionSavedResource.js +60 -0
- package/dist/esm/models/AgentWebhookList.d.ts +33 -0
- package/dist/esm/models/AgentWebhookList.js +44 -0
- package/dist/esm/models/AgentWebhookView.d.ts +76 -0
- package/dist/esm/models/AgentWebhookView.js +70 -0
- package/dist/esm/models/ConversationDetail.d.ts +6 -0
- package/dist/esm/models/ConversationDetail.js +2 -0
- package/dist/esm/models/ConversationView.d.ts +6 -0
- package/dist/esm/models/ConversationView.js +2 -0
- package/dist/esm/models/ErrorDetailItem.d.ts +3 -0
- package/dist/esm/models/FileNodeView.d.ts +7 -0
- package/dist/esm/models/FileNodeView.js +3 -0
- package/dist/esm/models/QueueMessageInput.d.ts +6 -0
- package/dist/esm/models/QueueMessageInput.js +2 -0
- package/dist/esm/models/RotatedWebhookSecretView.d.ts +58 -0
- package/dist/esm/models/RotatedWebhookSecretView.js +61 -0
- package/dist/esm/models/SaveWarningView.d.ts +44 -0
- package/dist/esm/models/SaveWarningView.js +51 -0
- package/dist/esm/models/ShareSkippedResource.d.ts +41 -0
- package/dist/esm/models/ShareSkippedResource.js +47 -0
- package/dist/esm/models/WebhookSecretPutBody.d.ts +32 -0
- package/dist/esm/models/WebhookSecretPutBody.js +43 -0
- package/dist/esm/models/WebhookSecretStateView.d.ts +52 -0
- package/dist/esm/models/WebhookSecretStateView.js +56 -0
- package/dist/esm/models/WebhookSecretValueView.d.ts +32 -0
- package/dist/esm/models/WebhookSecretValueView.js +44 -0
- package/dist/esm/models/WebhookWarning.d.ts +44 -0
- package/dist/esm/models/WebhookWarning.js +51 -0
- package/dist/esm/models/index.d.ts +10 -0
- package/dist/esm/models/index.js +10 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/dist/models/AgentConversationDetail.d.ts +12 -0
- package/dist/models/AgentConversationDetail.js +4 -0
- package/dist/models/AgentConversationView.d.ts +12 -0
- package/dist/models/AgentConversationView.js +4 -0
- package/dist/models/AgentResource.d.ts +7 -0
- package/dist/models/AgentResource.js +3 -0
- package/dist/models/AgentVersionSavedResource.d.ts +65 -0
- package/dist/models/AgentVersionSavedResource.js +67 -0
- package/dist/models/AgentWebhookList.d.ts +33 -0
- package/dist/models/AgentWebhookList.js +51 -0
- package/dist/models/AgentWebhookView.d.ts +76 -0
- package/dist/models/AgentWebhookView.js +78 -0
- package/dist/models/ConversationDetail.d.ts +6 -0
- package/dist/models/ConversationDetail.js +2 -0
- package/dist/models/ConversationView.d.ts +6 -0
- package/dist/models/ConversationView.js +2 -0
- package/dist/models/ErrorDetailItem.d.ts +3 -0
- package/dist/models/FileNodeView.d.ts +7 -0
- package/dist/models/FileNodeView.js +3 -0
- package/dist/models/QueueMessageInput.d.ts +6 -0
- package/dist/models/QueueMessageInput.js +2 -0
- package/dist/models/RotatedWebhookSecretView.d.ts +58 -0
- package/dist/models/RotatedWebhookSecretView.js +69 -0
- package/dist/models/SaveWarningView.d.ts +44 -0
- package/dist/models/SaveWarningView.js +58 -0
- package/dist/models/ShareSkippedResource.d.ts +41 -0
- package/dist/models/ShareSkippedResource.js +54 -0
- package/dist/models/WebhookSecretPutBody.d.ts +32 -0
- package/dist/models/WebhookSecretPutBody.js +50 -0
- package/dist/models/WebhookSecretStateView.d.ts +52 -0
- package/dist/models/WebhookSecretStateView.js +64 -0
- package/dist/models/WebhookSecretValueView.d.ts +32 -0
- package/dist/models/WebhookSecretValueView.js +51 -0
- package/dist/models/WebhookWarning.d.ts +44 -0
- package/dist/models/WebhookWarning.js +58 -0
- package/dist/models/index.d.ts +10 -0
- package/dist/models/index.js +10 -0
- package/package.json +1 -1
- package/src/apis/AgentsApi.ts +366 -11
- package/src/apis/ConversationsApi.ts +9 -2
- package/src/client.ts +3 -2
- package/src/compose/deploy.ts +71 -10
- package/src/compose/errors.ts +4 -0
- package/src/compose/settingsTransport.ts +78 -131
- package/src/compose/transport.ts +10 -2
- package/src/compose/webhook.ts +49 -45
- package/src/compose/webhookSecrets.ts +227 -179
- package/src/index.ts +2 -1
- package/src/models/AgentConversationDetail.ts +16 -0
- package/src/models/AgentConversationView.ts +16 -0
- package/src/models/AgentResource.ts +15 -0
- package/src/models/AgentVersionSavedResource.ts +119 -0
- package/src/models/AgentWebhookList.ts +74 -0
- package/src/models/AgentWebhookView.ts +129 -0
- package/src/models/ConversationDetail.ts +8 -0
- package/src/models/ConversationView.ts +8 -0
- package/src/models/ErrorDetailItem.ts +3 -0
- package/src/models/FileNodeView.ts +16 -0
- package/src/models/QueueMessageInput.ts +8 -0
- package/src/models/RotatedWebhookSecretView.ts +103 -0
- package/src/models/SaveWarningView.ts +84 -0
- package/src/models/ShareSkippedResource.ts +78 -0
- package/src/models/WebhookSecretPutBody.ts +66 -0
- package/src/models/WebhookSecretStateView.ts +94 -0
- package/src/models/WebhookSecretValueView.ts +66 -0
- package/src/models/WebhookWarning.ts +84 -0
- package/src/models/index.ts +10 -0
|
@@ -18,7 +18,7 @@ import { ConversationDetailFromJSON, ConversationViewFromJSON, CreateConversatio
|
|
|
18
18
|
*/
|
|
19
19
|
export class ConversationsApi extends runtime.BaseAPI {
|
|
20
20
|
/**
|
|
21
|
-
* ``origin=managed_agents`` creates the conversation as session type ``api`` (a managed-agent API session, hidden from the default inbox). It requires ``agentId``: a managed-agent session is always about one agent, and the session log lists it by that id. The agent must be visible to the caller (else 404, existence hidden like every other agent read) and a deployed managed agent (else 409 ``AGENT_NOT_DEPLOYED``). Without ``origin``
|
|
21
|
+
* ``origin=managed_agents`` creates the conversation as session type ``api`` (a managed-agent API session, hidden from the default inbox). It requires ``agentId``: a managed-agent session is always about one agent, and the session log lists it by that id. The agent must be visible to the caller (else 404, existence hidden like every other agent read) and a deployed managed agent (else 409 ``AGENT_NOT_DEPLOYED``). Without ``origin``, an ``agentId`` or ``metadata.agent_id`` (how Indus binds a chat) must still name an agent the caller can see (else 404): the binding puts the chat in that agent\'s session log and interaction count. A conversation created with ``X-Panja-Surface: playground`` (an agent\'s Playground) is saved as session type ``playground``: hidden from the default inbox and listed apart from real chats in the agent\'s session log. Never gated, so drafts work (``services.session_types``).
|
|
22
22
|
* Create Conversation Route
|
|
23
23
|
*/
|
|
24
24
|
async createConversationRaw(requestParameters, initOverrides) {
|
|
@@ -51,7 +51,7 @@ export class ConversationsApi extends runtime.BaseAPI {
|
|
|
51
51
|
return new runtime.JSONApiResponse(response, (jsonValue) => ConversationViewFromJSON(jsonValue));
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
* ``origin=managed_agents`` creates the conversation as session type ``api`` (a managed-agent API session, hidden from the default inbox). It requires ``agentId``: a managed-agent session is always about one agent, and the session log lists it by that id. The agent must be visible to the caller (else 404, existence hidden like every other agent read) and a deployed managed agent (else 409 ``AGENT_NOT_DEPLOYED``). Without ``origin``
|
|
54
|
+
* ``origin=managed_agents`` creates the conversation as session type ``api`` (a managed-agent API session, hidden from the default inbox). It requires ``agentId``: a managed-agent session is always about one agent, and the session log lists it by that id. The agent must be visible to the caller (else 404, existence hidden like every other agent read) and a deployed managed agent (else 409 ``AGENT_NOT_DEPLOYED``). Without ``origin``, an ``agentId`` or ``metadata.agent_id`` (how Indus binds a chat) must still name an agent the caller can see (else 404): the binding puts the chat in that agent\'s session log and interaction count. A conversation created with ``X-Panja-Surface: playground`` (an agent\'s Playground) is saved as session type ``playground``: hidden from the default inbox and listed apart from real chats in the agent\'s session log. Never gated, so drafts work (``services.session_types``).
|
|
55
55
|
* Create Conversation Route
|
|
56
56
|
*/
|
|
57
57
|
async createConversation(requestParameters, initOverrides) {
|
|
@@ -184,6 +184,9 @@ export class ConversationsApi extends runtime.BaseAPI {
|
|
|
184
184
|
if (requestParameters['sessionType'] != null) {
|
|
185
185
|
queryParameters['sessionType'] = requestParameters['sessionType'];
|
|
186
186
|
}
|
|
187
|
+
if (requestParameters['agentId'] != null) {
|
|
188
|
+
queryParameters['agentId'] = requestParameters['agentId'];
|
|
189
|
+
}
|
|
187
190
|
const headerParameters = {};
|
|
188
191
|
if (this.configuration && this.configuration.accessToken) {
|
|
189
192
|
const token = this.configuration.accessToken;
|
|
@@ -313,6 +316,7 @@ export class ConversationsApi extends runtime.BaseAPI {
|
|
|
313
316
|
return await response.value();
|
|
314
317
|
}
|
|
315
318
|
/**
|
|
319
|
+
* Rename or replace ``metadata``. A ``metadata.agent_id`` that differs from the stored one must name an agent the caller can see (else 404); an unchanged one is not re-checked, so a chat whose agent was since unshared can still be renamed.
|
|
316
320
|
* Update Conversation Route
|
|
317
321
|
*/
|
|
318
322
|
async updateConversationRaw(requestParameters, initOverrides) {
|
|
@@ -342,6 +346,7 @@ export class ConversationsApi extends runtime.BaseAPI {
|
|
|
342
346
|
return new runtime.JSONApiResponse(response, (jsonValue) => ConversationViewFromJSON(jsonValue));
|
|
343
347
|
}
|
|
344
348
|
/**
|
|
349
|
+
* Rename or replace ``metadata``. A ``metadata.agent_id`` that differs from the stored one must name an agent the caller can see (else 404); an unchanged one is not re-checked, so a chat whose agent was since unshared can still be renamed.
|
|
345
350
|
* Update Conversation Route
|
|
346
351
|
*/
|
|
347
352
|
async updateConversation(requestParameters, initOverrides) {
|
package/dist/esm/client.d.ts
CHANGED
|
@@ -6,13 +6,14 @@ import { WebhookSecrets } from "./compose/webhookSecrets.js";
|
|
|
6
6
|
*
|
|
7
7
|
* ```ts
|
|
8
8
|
* const client = new Client(config);
|
|
9
|
-
* const
|
|
9
|
+
* const hooks = await client.webhooks.list(agentId); // each webhook and its secretStatus
|
|
10
|
+
* const secret = await client.webhooks.getSecret(agentId, "https://hooks.acme.com/panja");
|
|
10
11
|
* const github = await client.triggers.setSecret(agentId, "github_issues"); // a provider trigger's signing secret
|
|
11
12
|
* ```
|
|
12
13
|
*/
|
|
13
14
|
export declare class Client {
|
|
14
15
|
readonly config: Configuration;
|
|
15
|
-
/**
|
|
16
|
+
/** List an agent's webhooks; create, view, rotate, set and delete each one's signing secret. */
|
|
16
17
|
readonly webhooks: WebhookSecrets;
|
|
17
18
|
/** An agent's inbound triggers: set, rotate, check and delete a trigger's signing secret (or rotate a bearer
|
|
18
19
|
* trigger's token), and page through its events. */
|
package/dist/esm/client.js
CHANGED
|
@@ -5,7 +5,8 @@ import { WebhookSecrets } from "./compose/webhookSecrets.js";
|
|
|
5
5
|
*
|
|
6
6
|
* ```ts
|
|
7
7
|
* const client = new Client(config);
|
|
8
|
-
* const
|
|
8
|
+
* const hooks = await client.webhooks.list(agentId); // each webhook and its secretStatus
|
|
9
|
+
* const secret = await client.webhooks.getSecret(agentId, "https://hooks.acme.com/panja");
|
|
9
10
|
* const github = await client.triggers.setSecret(agentId, "github_issues"); // a provider trigger's signing secret
|
|
10
11
|
* ```
|
|
11
12
|
*/
|
|
@@ -10,13 +10,19 @@ export interface Deployment {
|
|
|
10
10
|
/** The live version, or while the agent is paused, the paused version (what `resumeAgent` brings back); undefined
|
|
11
11
|
* from a server without versions, or when no version was ever live. */
|
|
12
12
|
version?: number;
|
|
13
|
-
/** URLs of the webhooks that
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
/** URLs of the agent's webhooks that have no signing secret after this deploy: one it added whose secret it could
|
|
14
|
+
* not create (it warned why), or one deployed before whose secret is missing (deleted, perhaps on purpose; deploy
|
|
15
|
+
* never recreates it). Nothing is delivered to them: `client.webhooks.createSecret(agentId, url)` gives one. Left
|
|
16
|
+
* out when there are none. */
|
|
16
17
|
webhooksMissingSecret?: string[];
|
|
17
18
|
/** The token (and fire URL) of each bearer trigger this deploy created. The server shows a token only once: keep
|
|
18
19
|
* it now. Left out when nothing was minted; `client.triggers.list(agentId)` lists every trigger's URL. */
|
|
19
20
|
triggerTokens?: MintedTriggerToken[];
|
|
21
|
+
/** The signing secret this deploy created for each webhook it added (every webhook on a first deploy), by URL. Give each to its receiver
|
|
22
|
+
* now (`client.webhooks.getSecret` shows it again). A webhook that already had a secret keeps it and is not listed.
|
|
23
|
+
* The property is non-enumerable, so logging or serialising the deployment leaves it out. Left out when deploy
|
|
24
|
+
* created none. */
|
|
25
|
+
readonly webhookSecrets?: Readonly<Record<string, string>>;
|
|
20
26
|
}
|
|
21
27
|
/** Set (or clear, with null) the client used when deploy/remove/run get no client. */
|
|
22
28
|
export declare function setDefaultClient(config: Configuration | null): void;
|
|
@@ -30,6 +36,11 @@ export declare function resolveTransport(client?: Configuration, transport?: Tra
|
|
|
30
36
|
* saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
|
|
31
37
|
* overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
|
|
32
38
|
* version (the paused one while paused).
|
|
39
|
+
*
|
|
40
|
+
* The deploy then creates the signing secret of each webhook it added (a URL not in the agent.json last deployed;
|
|
41
|
+
* every webhook on a first deploy) and returns it once in `webhookSecrets` (by URL). An existing secret is never
|
|
42
|
+
* rotated or overwritten, and a missing one on a webhook deployed before is never recreated: it is listed in
|
|
43
|
+
* `webhooksMissingSecret`.
|
|
33
44
|
*/
|
|
34
45
|
export declare function deploy(agent: Agent<OutputType | undefined>, opts?: {
|
|
35
46
|
client?: Configuration;
|
|
@@ -41,7 +41,7 @@ function changedFields(remote, agent) {
|
|
|
41
41
|
keys.push("instructions");
|
|
42
42
|
return keys;
|
|
43
43
|
}
|
|
44
|
-
async function update(transport, remote, agent, strict) {
|
|
44
|
+
async function update(transport, remote, agent, strict, added) {
|
|
45
45
|
const stored = storedHash(remote);
|
|
46
46
|
if (stored !== undefined && settingsFingerprint(remote.instructions, remote.settings) !== stored) {
|
|
47
47
|
const changed = changedFields(remote, agent);
|
|
@@ -50,8 +50,9 @@ async function update(transport, remote, agent, strict) {
|
|
|
50
50
|
console.warn(`agent "${agent.name}" (${remote.agentId}) was edited outside the SDK; overwriting fields: ${changed.join(", ")}`);
|
|
51
51
|
}
|
|
52
52
|
else if (stored === agent.specHash()) {
|
|
53
|
-
return settle(transport, remote, agent);
|
|
53
|
+
return settle(transport, remote, agent, added);
|
|
54
54
|
}
|
|
55
|
+
added.urls = await addedUrls(transport, remote, agent);
|
|
55
56
|
const updated = await transport.updateAgent(remote.agentId, agent);
|
|
56
57
|
return deployment(remote.agentId, "updated", liveVersion(updated), missingSecrets(updated), updated === null || updated === void 0 ? void 0 : updated.triggerTokens);
|
|
57
58
|
}
|
|
@@ -63,6 +64,40 @@ function deployment(agentId, action, version, webhooksMissingSecret = [], tokens
|
|
|
63
64
|
out.triggerTokens = tokens;
|
|
64
65
|
return out;
|
|
65
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* The URLs of `agent`'s webhooks that this deploy adds: not in the agent.json last deployed (read before the write,
|
|
69
|
+
* with the transport's optional `deployedWebhookUrls`). Nothing deployed yet: every webhook. A read that fails
|
|
70
|
+
* (`null`), or a transport that cannot tell: none, so a secret is never created for a webhook deployed before.
|
|
71
|
+
*/
|
|
72
|
+
async function addedUrls(transport, remote, agent) {
|
|
73
|
+
var _a;
|
|
74
|
+
const urls = ((_a = agent.webhooks) !== null && _a !== void 0 ? _a : []).map((h) => h.url);
|
|
75
|
+
if (urls.length === 0 || transport.deployedWebhookUrls === undefined)
|
|
76
|
+
return new Set();
|
|
77
|
+
const previous = await transport.deployedWebhookUrls(remote.agentId, remote.liveVersion, remote.versionState);
|
|
78
|
+
if (previous === null)
|
|
79
|
+
return new Set();
|
|
80
|
+
return new Set(urls.filter((u) => !previous.has(u)));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create the signing secret of each webhook this deploy added (a URL not in the agent.json last deployed; on a first
|
|
84
|
+
* deploy, every webhook) when it has none. A webhook deployed before is never given a secret here, even when it has
|
|
85
|
+
* none (its owner may have deleted it on purpose): it is listed in `webhooksMissingSecret`, like a webhook whose create
|
|
86
|
+
* failed. Never rotates or overwrites a secret, and a failure never fails the deploy.
|
|
87
|
+
*/
|
|
88
|
+
async function withWebhookSecrets(transport, agent, out, added) {
|
|
89
|
+
var _a;
|
|
90
|
+
if (!agent.webhooks || agent.webhooks.length === 0 || transport.createWebhookSecrets === undefined)
|
|
91
|
+
return out;
|
|
92
|
+
const { created, missing } = await transport.createWebhookSecrets(out.agentId, agent, added);
|
|
93
|
+
const allMissing = [...new Set([...((_a = out.webhooksMissingSecret) !== null && _a !== void 0 ? _a : []), ...missing])];
|
|
94
|
+
if (allMissing.length > 0)
|
|
95
|
+
out.webhooksMissingSecret = allMissing;
|
|
96
|
+
if (Object.keys(created).length > 0) {
|
|
97
|
+
Object.defineProperty(out, "webhookSecrets", { value: Object.freeze({ ...created }), enumerable: false });
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
66
101
|
function missingSecrets(remote) {
|
|
67
102
|
const missing = remote === null || remote === void 0 ? void 0 : remote.webhooksMissingSecret;
|
|
68
103
|
return Array.isArray(missing) ? [...missing] : [];
|
|
@@ -92,16 +127,18 @@ function liveVersion(remote) {
|
|
|
92
127
|
* goes live again with the next deploy of a changed definition. Only an agent with no live version that was never
|
|
93
128
|
* paused (created, but its first deploy did not finish) is published here.
|
|
94
129
|
*/
|
|
95
|
-
async function settle(transport, remote, agent) {
|
|
130
|
+
async function settle(transport, remote, agent, added) {
|
|
96
131
|
const state = remote.versionState;
|
|
97
132
|
if (state === undefined || state === "live" || state === "paused" || !transport.publish) {
|
|
98
133
|
if (state === "live")
|
|
99
134
|
await checkTriggers(transport, remote, agent);
|
|
100
135
|
return deployment(remote.agentId, "unchanged", remote.liveVersion);
|
|
101
136
|
}
|
|
137
|
+
added.urls = await addedUrls(transport, remote, agent);
|
|
102
138
|
return published(remote.agentId, await transport.publish(remote.agentId, VERSION_NOTE));
|
|
103
139
|
}
|
|
104
|
-
async function deployWith(agent, transport, strict, adopt) {
|
|
140
|
+
async function deployWith(agent, transport, strict, added, adopt) {
|
|
141
|
+
var _a;
|
|
105
142
|
const found = await transport.findAgents(agent.name);
|
|
106
143
|
if (adopt !== undefined) {
|
|
107
144
|
const target = await transport.readAgent(adopt);
|
|
@@ -114,16 +151,18 @@ async function deployWith(agent, transport, strict, adopt) {
|
|
|
114
151
|
if (others.length) {
|
|
115
152
|
throw new UserError(`cannot adopt ${adopt}: agent "${agent.name}" is already deployed as ${others.join(", ")}`);
|
|
116
153
|
}
|
|
154
|
+
added.urls = await addedUrls(transport, target, agent);
|
|
117
155
|
const adopted = await transport.updateAgent(adopt, agent);
|
|
118
156
|
return deployment(adopt, "updated", liveVersion(adopted), missingSecrets(adopted), adopted === null || adopted === void 0 ? void 0 : adopted.triggerTokens);
|
|
119
157
|
}
|
|
120
158
|
if (found.length > 1)
|
|
121
159
|
throw new DuplicateAgentsError(found.map((r) => r.agentId));
|
|
122
160
|
if (found.length === 0) {
|
|
161
|
+
added.urls = new Set(((_a = agent.webhooks) !== null && _a !== void 0 ? _a : []).map((h) => h.url)); // a new agent: every webhook is new
|
|
123
162
|
const created = await transport.createAgent(agent);
|
|
124
163
|
return deployment(created.agentId, "created", liveVersion(created), missingSecrets(created), created.triggerTokens);
|
|
125
164
|
}
|
|
126
|
-
return update(transport, found[0], agent, strict);
|
|
165
|
+
return update(transport, found[0], agent, strict, added);
|
|
127
166
|
}
|
|
128
167
|
/**
|
|
129
168
|
* The id of the deployed agent named `agent.name`, for a run with `deploy: false`: reads only, writes nothing. The run
|
|
@@ -152,11 +191,21 @@ async function findDeployed(agent, transport) {
|
|
|
152
191
|
* saves any edits the owner left in the draft, so check the draft first. `strict: true` throws `DriftError` instead of
|
|
153
192
|
* overwriting fields edited outside the SDK. `adopt: agentId` takes over an agent made elsewhere. `version` is the live
|
|
154
193
|
* version (the paused one while paused).
|
|
194
|
+
*
|
|
195
|
+
* The deploy then creates the signing secret of each webhook it added (a URL not in the agent.json last deployed;
|
|
196
|
+
* every webhook on a first deploy) and returns it once in `webhookSecrets` (by URL). An existing secret is never
|
|
197
|
+
* rotated or overwritten, and a missing one on a webhook deployed before is never recreated: it is listed in
|
|
198
|
+
* `webhooksMissingSecret`.
|
|
155
199
|
*/
|
|
156
200
|
export async function deploy(agent, opts = {}) {
|
|
157
201
|
const transport = resolveTransport(opts.client, opts.transport);
|
|
158
202
|
forget(agent.name); // this deploy may replace what cached runs of the name point at
|
|
159
|
-
return serialized(agent.name, () => {
|
|
203
|
+
return serialized(agent.name, async () => {
|
|
204
|
+
var _a;
|
|
205
|
+
const added = { urls: new Set() };
|
|
206
|
+
const out = await deployWith(agent, transport, (_a = opts.strict) !== null && _a !== void 0 ? _a : false, added, opts.adopt);
|
|
207
|
+
return withWebhookSecrets(transport, agent, out, added.urls);
|
|
208
|
+
});
|
|
160
209
|
}
|
|
161
210
|
/**
|
|
162
211
|
* Delete the agent named `name` and all its versions; resolves true if one was deleted. It cannot be undone.
|
|
@@ -227,7 +276,11 @@ export function agentIdFor(agent, transport, owner, deploy = true) {
|
|
|
227
276
|
if (prev && prev.hash === hash)
|
|
228
277
|
return prev.id;
|
|
229
278
|
const id = deploy
|
|
230
|
-
? serialized(agent.name,
|
|
279
|
+
? serialized(agent.name, async () => {
|
|
280
|
+
// As deploy(): the webhooks a run's deploy adds get their secrets (client.webhooks.getSecret shows them).
|
|
281
|
+
const added = { urls: new Set() };
|
|
282
|
+
return withWebhookSecrets(transport, agent, await deployWith(agent, transport, false, added), added.urls);
|
|
283
|
+
}).then((d) => d.agentId)
|
|
231
284
|
: serialized(agent.name, () => findDeployed(agent, transport));
|
|
232
285
|
const entry = { hash, id };
|
|
233
286
|
owners.set(owner, entry);
|
|
@@ -16,6 +16,10 @@ export declare class UserError extends AgentsError {
|
|
|
16
16
|
message?: string;
|
|
17
17
|
}>);
|
|
18
18
|
}
|
|
19
|
+
/** `client.webhooks.createSecret`: the webhook already has a signing secret. Rotate it (`rotateSecret`), view it
|
|
20
|
+
* (`getSecret`), or delete it first. */
|
|
21
|
+
export declare class SecretExistsError extends UserError {
|
|
22
|
+
}
|
|
19
23
|
/** Where a `ModelBehaviorError` came from: the server's check, or the `outputType`'s own `parse`. */
|
|
20
24
|
export type ModelBehaviorErrorSource = "server" | "local_parse";
|
|
21
25
|
/**
|
|
@@ -13,6 +13,10 @@ export class UserError extends AgentsError {
|
|
|
13
13
|
this.issues = issues;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
/** `client.webhooks.createSecret`: the webhook already has a signing secret. Rotate it (`rotateSecret`), view it
|
|
17
|
+
* (`getSecret`), or delete it first. */
|
|
18
|
+
export class SecretExistsError extends UserError {
|
|
19
|
+
}
|
|
16
20
|
/**
|
|
17
21
|
* The agent's answer didn't match its `outputType`. `source` says where: `"server"` (no answer matched the schema
|
|
18
22
|
* after the server's retry; `rawText` is the model's last attempt) or `"local_parse"` (the server accepted the answer
|
|
@@ -19,24 +19,29 @@ export declare class SettingsTransport implements Transport {
|
|
|
19
19
|
private readonly agents;
|
|
20
20
|
private readonly conversations;
|
|
21
21
|
private readonly responses;
|
|
22
|
-
private readonly customApis;
|
|
23
22
|
private readonly triggers;
|
|
24
|
-
private readonly secrets;
|
|
25
23
|
constructor(config: Configuration);
|
|
26
24
|
findAgents(sdkName: string): Promise<RemoteAgent[]>;
|
|
27
25
|
readAgent(agentId: string): Promise<RemoteAgent>;
|
|
28
26
|
createAgent(agent: Agent<OutputType | undefined>): Promise<RemoteAgent>;
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The webhook URLs of the agent.json last deployed, read before a deploy writes: the live (or paused) version's,
|
|
29
|
+
* `GET /v2/agents/{agentId}/versions/{version}` (its `agent.json` file). Without versions on the server, the
|
|
30
|
+
* agent's settings (`GET /v1/agents/{agentId}/settings`), which are what is deployed there. An empty set when
|
|
31
|
+
* nothing was ever deployed; null, with a warning, when it cannot be read.
|
|
32
|
+
*/
|
|
33
|
+
deployedWebhookUrls(agentId: string, liveVersion?: number, versionState?: string): Promise<Set<string> | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Create the signing secret of each webhook in `added` (the URLs this deploy added) whose `secretStatus` is
|
|
36
|
+
* `missing` (`POST .../webhooks/{webhookKey}/secret`); resolves to the new secrets by URL and the URLs of `agent`'s
|
|
37
|
+
* webhooks still without one. A webhook deployed before whose secret is missing is reported, never given one. An
|
|
38
|
+
* existing secret is never rotated or overwritten. Nothing here fails the deploy: a failure is logged (never with a
|
|
39
|
+
* secret) and the webhook reported missing.
|
|
40
|
+
*/
|
|
41
|
+
createWebhookSecrets(agentId: string, agent: Agent<OutputType | undefined>, added?: ReadonlySet<string>): Promise<{
|
|
42
|
+
created: Record<string, string>;
|
|
43
|
+
missing: string[];
|
|
44
|
+
}>;
|
|
40
45
|
updateAgent(agentId: string, agent: Agent<OutputType | undefined>): Promise<RemoteAgent>;
|
|
41
46
|
/** Make what was just written what end users get. A server without versions (no `versionState`) gets the bodiless
|
|
42
47
|
* deploy 0.3 sent; otherwise the draft is saved as a version and that version deployed. */
|