@jini-ai/integrations 0.7.1 → 0.7.3-next.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.
Files changed (121) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/README.md +1 -0
  3. package/dist/api-connections/access-token.js +4 -4
  4. package/dist/api-connections/account-actions.d.ts +10 -4
  5. package/dist/api-connections/account-actions.js +13 -13
  6. package/dist/api-connections/attempt-state.d.ts +11 -5
  7. package/dist/api-connections/attempt-state.js +4 -4
  8. package/dist/api-connections/authorization.d.ts +7 -3
  9. package/dist/api-connections/authorization.js +18 -18
  10. package/dist/api-connections/finish-authorization.d.ts +8 -4
  11. package/dist/api-connections/finish-authorization.js +9 -9
  12. package/dist/api-connections/host.d.ts +30 -32
  13. package/dist/api-connections/host.js +232 -205
  14. package/dist/api-connections/hosted-mcp/contracts.d.ts +1 -1
  15. package/dist/api-connections/hosted-mcp/oauth-row-writes.d.ts +50 -0
  16. package/dist/api-connections/hosted-mcp/oauth-row-writes.js +38 -0
  17. package/dist/api-connections/hosted-mcp/shared-sign-in.d.ts +40 -40
  18. package/dist/api-connections/hosted-mcp/shared-sign-in.js +98 -22
  19. package/dist/api-connections/hosted-mcp/sign-in-configuration.d.ts +29 -0
  20. package/dist/api-connections/hosted-mcp/sign-in-configuration.js +127 -0
  21. package/dist/api-connections/hosted-mcp/sign-in-discovery.d.ts +72 -0
  22. package/dist/api-connections/hosted-mcp/sign-in-discovery.js +131 -0
  23. package/dist/api-connections/hosted-mcp/sign-in-flow.d.ts +42 -0
  24. package/dist/api-connections/hosted-mcp/sign-in-flow.js +50 -0
  25. package/dist/api-connections/hosted-mcp/sign-in-provider.d.ts +103 -0
  26. package/dist/api-connections/hosted-mcp/sign-in-provider.js +142 -0
  27. package/dist/api-connections/hosted-mcp/sign-in-status.d.ts +19 -0
  28. package/dist/api-connections/hosted-mcp/sign-in-status.js +143 -0
  29. package/dist/api-connections/hosted-mcp/sign-in.d.ts +2 -9
  30. package/dist/api-connections/hosted-mcp/sign-in.js +219 -770
  31. package/dist/api-connections/index.js +1 -1
  32. package/dist/api-connections/install-credential.d.ts +4 -2
  33. package/dist/api-connections/install-credential.js +7 -7
  34. package/dist/api-connections/records.d.ts +17 -5
  35. package/dist/api-connections/records.js +5 -5
  36. package/dist/api-connections/request-checks.d.ts +29 -9
  37. package/dist/api-connections/request-checks.js +13 -13
  38. package/dist/api-connections/service.d.ts +1 -1
  39. package/dist/api-connections/service.js +6 -6
  40. package/dist/api-connections/status.d.ts +3 -1
  41. package/dist/api-connections/status.js +3 -3
  42. package/dist/api-connections/token-store/errors.d.ts +3 -1
  43. package/dist/api-connections/token-store/errors.js +1 -1
  44. package/dist/api-connections/token-store/vault-token-store.js +186 -173
  45. package/dist/args.d.ts +4 -1
  46. package/dist/args.js +1 -1
  47. package/dist/credentialed-http/credentialed-request.d.ts +5 -5
  48. package/dist/credentialed-http/credentialed-request.js +8 -8
  49. package/dist/credentialed-http/response-redaction.d.ts +18 -4
  50. package/dist/credentialed-http/response-redaction.js +7 -7
  51. package/dist/credentialed-http/sets/vault-repo.js +5 -1
  52. package/dist/credentialed-http/tools/credential-copy-tool.js +20 -15
  53. package/dist/credentialed-http/tools/tool-registrations.js +272 -249
  54. package/dist/media-providers/catalog.d.ts +1 -0
  55. package/dist/media-providers/catalog.js +1 -0
  56. package/dist/media-providers/dispatch/async-operation-store.d.ts +6 -4
  57. package/dist/media-providers/dispatch/async-operation-store.js +100 -88
  58. package/dist/media-providers/dispatch/context.js +1 -1
  59. package/dist/media-providers/dispatch/engine.d.ts +5 -1
  60. package/dist/media-providers/dispatch/engine.js +2 -2
  61. package/dist/media-providers/dispatch/index.d.ts +1 -1
  62. package/dist/media-providers/dispatch/index.js +1 -1
  63. package/dist/media-providers/dispatch/node.d.ts +1 -1
  64. package/dist/media-providers/dispatch/node.js +1 -1
  65. package/dist/media-providers/dispatch/openai-compatible.d.ts +50 -11
  66. package/dist/media-providers/dispatch/openai-compatible.js +21 -17
  67. package/dist/media-providers/dispatch/operation-runtime.js +18 -18
  68. package/dist/media-providers/dispatch/outbound.d.ts +2 -2
  69. package/dist/media-providers/dispatch/outbound.js +1 -1
  70. package/dist/media-providers/dispatch/polling-adapter.d.ts +1 -1
  71. package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts +20 -6
  72. package/dist/media-providers/dispatch/providers/aihubmix-shared.js +8 -8
  73. package/dist/media-providers/dispatch/providers/aihubmix.js +12 -12
  74. package/dist/media-providers/dispatch/providers/custom-image.js +4 -4
  75. package/dist/media-providers/dispatch/providers/fishaudio.js +2 -9
  76. package/dist/media-providers/dispatch/providers/grok.js +5 -19
  77. package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +22 -20
  78. package/dist/media-providers/dispatch/providers/imagerouter.js +7 -21
  79. package/dist/media-providers/dispatch/providers/minimax.js +2 -9
  80. package/dist/media-providers/dispatch/providers/nanobanana.js +2 -2
  81. package/dist/media-providers/dispatch/providers/openai.js +6 -6
  82. package/dist/media-providers/dispatch/providers/openrouter.js +4 -4
  83. package/dist/media-providers/dispatch/providers/senseaudio.js +5 -19
  84. package/dist/media-providers/dispatch/providers/volcengine.js +5 -12
  85. package/dist/media-providers/dispatch/response-parsers.js +3 -3
  86. package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +1 -1
  87. package/dist/media-providers/dispatch/sqlite-async-operation-store.js +31 -5
  88. package/dist/media-providers/dispatch/ssrf-guard.js +5 -12
  89. package/dist/media-providers/dispatch/stub.js +2 -2
  90. package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
  91. package/dist/media-providers/image-model-ids.d.ts +36 -0
  92. package/dist/media-providers/image-model-ids.js +24 -0
  93. package/dist/media-providers/sqlite-driver.adapter.d.ts +1 -1
  94. package/dist/media-providers/sqlite-task-store.d.ts +2 -2
  95. package/dist/media-providers/sqlite-task-store.js +31 -4
  96. package/dist/media-providers/task-lifecycle.d.ts +17 -4
  97. package/dist/media-providers/task-lifecycle.js +4 -4
  98. package/dist/media-providers/task-store.js +28 -24
  99. package/dist/media-providers/ui-defaults.d.ts +7 -0
  100. package/dist/media-providers/ui-defaults.js +11 -17
  101. package/dist/saved-requests/types.d.ts +1 -1
  102. package/dist/webhooks/delivery.js +31 -27
  103. package/dist/webhooks/ports.d.ts +4 -1
  104. package/dist/webhooks/subscriptions.d.ts +7 -2
  105. package/dist/webhooks/subscriptions.js +30 -37
  106. package/dist/webhooks/tools/agent-tools.d.ts +82 -0
  107. package/dist/webhooks/tools/agent-tools.js +120 -0
  108. package/dist/webhooks/tools/index.d.ts +7 -0
  109. package/dist/webhooks/tools/index.js +5 -0
  110. package/dist/webhooks/tools/tool-handlers.d.ts +22 -0
  111. package/dist/webhooks/tools/tool-handlers.js +154 -0
  112. package/dist/webhooks/tools/tool-handlers.types.d.ts +64 -0
  113. package/dist/webhooks/tools/tool-handlers.types.js +2 -0
  114. package/dist/webhooks/tools/tool-registrations.d.ts +35 -0
  115. package/dist/webhooks/tools/tool-registrations.js +95 -0
  116. package/dist/webhooks/tools/tool-views.d.ts +62 -0
  117. package/dist/webhooks/tools/tool-views.js +50 -0
  118. package/dist/webhooks/types.d.ts +2 -0
  119. package/dist/webhooks/worker.d.ts +7 -4
  120. package/dist/webhooks/worker.js +22 -20
  121. package/package.json +16 -18
@@ -188,6 +188,36 @@ async function recordDeliveryOutcome(row, outcome, deps) {
188
188
  }, { claimedAttempts: row.attempts, ...(isExhausted ? { deadAtIso: failedAtIso } : {}) });
189
189
  return isExhausted ? "dead" : "failed";
190
190
  }
191
+ /** Sign the envelope for the subscription, POST it, and map the response to an attempt outcome. */
192
+ async function postSignedDelivery({ row, subscription, envelope, deps }) {
193
+ const rawBody = JSON.stringify(envelope);
194
+ const timestampSeconds = Math.floor(Date.parse(nowIso({ clock: deps.clock })) / 1000);
195
+ const signatureHeader = await deps.signer.signForSubscription({
196
+ subscription,
197
+ rawBody,
198
+ timestampSeconds,
199
+ });
200
+ const response = await deps.httpClient.send({ request: {
201
+ method: "POST",
202
+ url: subscription.targetUrl,
203
+ headers: {
204
+ "content-type": "application/json",
205
+ [deps.headers.signature]: signatureHeader,
206
+ [deps.headers.deliveryId]: row.id,
207
+ [deps.headers.eventId]: row.eventId,
208
+ },
209
+ ...deps.request,
210
+ body: rawBody,
211
+ } });
212
+ if (response.status >= 200 && response.status < 300) {
213
+ return { ok: true, responseStatus: response.status };
214
+ }
215
+ return {
216
+ ok: false,
217
+ error: `non-2xx response: ${response.status}`,
218
+ responseStatus: response.status,
219
+ };
220
+ }
191
221
  // Missing/inactive subscriptions, missing envelopes, hook failures, transport failures and
192
222
  // non-2xx responses all use one failed-attempt outcome so retry/dead-letter policy cannot drift.
193
223
  async function attemptOneDelivery(row, deps) {
@@ -212,33 +242,7 @@ async function attemptOneDelivery(row, deps) {
212
242
  }
213
243
  // Older queued events and hooks also pass this boundary before signing/sending.
214
244
  const envelope = publicWebhookEnvelope({ envelope: await runBeforeDispatchHooks(deps.hooks, { subscription, envelope: storedEnvelope }) });
215
- const rawBody = JSON.stringify(envelope);
216
- const timestampSeconds = Math.floor(Date.parse(nowIso({ clock: deps.clock })) / 1000);
217
- const signatureHeader = await deps.signer.signForSubscription({
218
- subscription,
219
- rawBody,
220
- timestampSeconds,
221
- });
222
- const response = await deps.httpClient.send({ request: {
223
- method: "POST",
224
- url: subscription.targetUrl,
225
- headers: {
226
- "content-type": "application/json",
227
- [deps.headers.signature]: signatureHeader,
228
- [deps.headers.deliveryId]: row.id,
229
- [deps.headers.eventId]: row.eventId,
230
- },
231
- ...deps.request,
232
- body: rawBody,
233
- } });
234
- if (response.status >= 200 && response.status < 300) {
235
- return { ok: true, responseStatus: response.status };
236
- }
237
- return {
238
- ok: false,
239
- error: `non-2xx response: ${response.status}`,
240
- responseStatus: response.status,
241
- };
245
+ return await postSignedDelivery({ row, subscription, envelope, deps });
242
246
  }
243
247
  catch (err) {
244
248
  const message = err instanceof Error ? err.message : "unknown webhook delivery error";
@@ -31,7 +31,10 @@ export interface SecretSealerPort {
31
31
  }
32
32
  export interface WebhookSubscriptionRepoPort {
33
33
  insert(record: WebhookSubscriptionRecord): Promise<void>;
34
- save(record: WebhookSubscriptionRecord): Promise<void>;
34
+ /** Upsert without a basis; with one, compare-and-set or throw RecordVersionConflictError. */
35
+ save(record: WebhookSubscriptionRecord, optional?: {
36
+ expectedVersion?: number;
37
+ }): Promise<void>;
35
38
  findById(required: {
36
39
  workspaceId: UUID;
37
40
  id: IntegrationId;
@@ -45,7 +45,9 @@ export interface UpdateSubscriptionRequired {
45
45
  input: UpdateSubscriptionInput;
46
46
  }
47
47
  /** Validate a replacement before saving; missing or soft-deleted workspace-scoped rows throw. */
48
- export declare function updateSubscription(required: UpdateSubscriptionRequired, _optional?: WebhookSubscriptionOptional): Promise<{
48
+ export declare function updateSubscription(required: UpdateSubscriptionRequired, optional?: WebhookSubscriptionOptional & {
49
+ expectedVersion?: number;
50
+ }): Promise<{
49
51
  subscription: WebhookSubscriptionRecord;
50
52
  }>;
51
53
  export interface PauseSubscriptionInput {
@@ -58,6 +60,7 @@ export interface PauseSubscriptionRequired {
58
60
  }
59
61
  export interface PauseSubscriptionOptional {
60
62
  paused?: boolean;
63
+ expectedVersion?: number;
61
64
  }
62
65
  /** Pause or resume a subscription; disabled subscriptions cannot resume. */
63
66
  export declare function pauseSubscription(required: PauseSubscriptionRequired, optional?: PauseSubscriptionOptional): Promise<{
@@ -72,7 +75,9 @@ export interface DeleteSubscriptionRequired {
72
75
  input: DeleteSubscriptionInput;
73
76
  }
74
77
  /** Soft-disable a subscription while retaining its audit history. */
75
- export declare function deleteSubscription(required: DeleteSubscriptionRequired, _optional?: WebhookSubscriptionOptional): Promise<{
78
+ export declare function deleteSubscription(required: DeleteSubscriptionRequired, optional?: WebhookSubscriptionOptional & {
79
+ expectedVersion?: number;
80
+ }): Promise<{
76
81
  subscription: WebhookSubscriptionRecord;
77
82
  }>;
78
83
  //# sourceMappingURL=subscriptions.d.ts.map
@@ -4,20 +4,28 @@ export class WebhookSubscriptionNotFoundError extends IntegrationError {
4
4
  }
5
5
  export class WebhookSubscriptionValidationError extends IntegrationError {
6
6
  }
7
- /** Validate then insert an active subscription; no write occurs on validation failure. */
8
- export async function createSubscription(required, optional = {}) {
9
- const { deps, input } = required;
7
+ /** Validate the replacement fields in the same order used for creation and updates. */
8
+ async function validateSubscriptionFields({ deps, input }, _optional = {}) {
10
9
  const label = input.label.trim();
11
10
  if (!label)
12
11
  throw new WebhookSubscriptionValidationError({ message: "label is required" });
13
- const targetUrl = await validateTargetUrl({
14
- targetUrl: input.targetUrl,
15
- isAllowedTarget: deps.isAllowedTarget,
16
- });
12
+ const targetUrl = await validateTargetUrl({ targetUrl: input.targetUrl, isAllowedTarget: deps.isAllowedTarget });
17
13
  const topics = normalizeTopics(input.topics);
18
- if (topics.length === 0) {
14
+ if (topics.length === 0)
19
15
  throw new WebhookSubscriptionValidationError({ message: "at least one topic is required" });
20
- }
16
+ return { label, targetUrl, topics };
17
+ }
18
+ /** Load a workspace-scoped subscription or report the existing not-found error. */
19
+ async function requireSubscription({ deps, workspaceId, id }, _optional = {}) {
20
+ const existing = await deps.repo.findById({ workspaceId, id });
21
+ if (!existing)
22
+ throw new WebhookSubscriptionNotFoundError({ message: `webhook subscription '${id}' was not found` });
23
+ return existing;
24
+ }
25
+ /** Validate then insert an active subscription; no write occurs on validation failure. */
26
+ export async function createSubscription(required, optional = {}) {
27
+ const { deps, input } = required;
28
+ const { label, targetUrl, topics } = await validateSubscriptionFields({ deps, input });
21
29
  const now = nowIso({ clock: deps.clock });
22
30
  const subscription = {
23
31
  id: deps.idGenerator.newId(),
@@ -34,51 +42,37 @@ export async function createSubscription(required, optional = {}) {
34
42
  createdByPluginId: optional.createdByPluginId ?? null,
35
43
  createdAt: now,
36
44
  updatedAt: now,
45
+ version: 1,
37
46
  disabledAt: null,
38
47
  };
39
48
  await deps.repo.insert(subscription);
40
49
  return { subscription };
41
50
  }
42
51
  /** Validate a replacement before saving; missing or soft-deleted workspace-scoped rows throw. */
43
- export async function updateSubscription(required, _optional = {}) {
52
+ export async function updateSubscription(required, optional = {}) {
44
53
  const { deps, input } = required;
45
- const existing = await deps.repo.findById({ workspaceId: input.workspaceId, id: input.id });
46
- if (!existing) {
47
- throw new WebhookSubscriptionNotFoundError({ message: `webhook subscription '${input.id}' was not found` });
48
- }
54
+ const existing = await requireSubscription({ deps, workspaceId: input.workspaceId, id: input.id });
49
55
  // Soft deletion is terminal: an update must preserve the disabled row's audit history.
50
56
  if (existing.status === "disabled") {
51
57
  throw new WebhookSubscriptionValidationError({ message: `webhook subscription '${input.id}' is disabled (deleted) and cannot be updated` });
52
58
  }
53
- const label = input.label.trim();
54
- if (!label)
55
- throw new WebhookSubscriptionValidationError({ message: "label is required" });
56
- const targetUrl = await validateTargetUrl({
57
- targetUrl: input.targetUrl,
58
- isAllowedTarget: deps.isAllowedTarget,
59
- });
60
- const topics = normalizeTopics(input.topics);
61
- if (topics.length === 0) {
62
- throw new WebhookSubscriptionValidationError({ message: "at least one topic is required" });
63
- }
59
+ const { label, targetUrl, topics } = await validateSubscriptionFields({ deps, input });
64
60
  const subscription = {
65
61
  ...existing,
66
62
  label,
67
63
  targetUrl,
68
64
  topics,
69
65
  updatedAt: nowIso({ clock: deps.clock }),
66
+ version: existing.version + 1,
70
67
  };
71
- await deps.repo.save(subscription);
68
+ await deps.repo.save(subscription, optional.expectedVersion === undefined ? {} : { expectedVersion: optional.expectedVersion });
72
69
  return { subscription };
73
70
  }
74
71
  /** Pause or resume a subscription; disabled subscriptions cannot resume. */
75
72
  export async function pauseSubscription(required, optional = {}) {
76
73
  const { deps, input } = required;
77
74
  const { paused = true } = optional;
78
- const existing = await deps.repo.findById({ workspaceId: input.workspaceId, id: input.id });
79
- if (!existing) {
80
- throw new WebhookSubscriptionNotFoundError({ message: `webhook subscription '${input.id}' was not found` });
81
- }
75
+ const existing = await requireSubscription({ deps, workspaceId: input.workspaceId, id: input.id });
82
76
  if (existing.status === "disabled") {
83
77
  // Soft deletion is terminal: preserving audit history must not offer a resume-to-life path.
84
78
  throw new WebhookSubscriptionValidationError({ message: `webhook subscription '${input.id}' is disabled and cannot be paused or resumed` });
@@ -87,26 +81,25 @@ export async function pauseSubscription(required, optional = {}) {
87
81
  ...existing,
88
82
  status: paused ? "paused" : "active",
89
83
  updatedAt: nowIso({ clock: deps.clock }),
84
+ version: existing.version + 1,
90
85
  };
91
- await deps.repo.save(subscription);
86
+ await deps.repo.save(subscription, { expectedVersion: optional.expectedVersion ?? existing.version });
92
87
  return { subscription };
93
88
  }
94
89
  /** Soft-disable a subscription while retaining its audit history. */
95
- export async function deleteSubscription(required, _optional = {}) {
90
+ export async function deleteSubscription(required, optional = {}) {
96
91
  // Retain the row and disabledAt for audit durability; the repository intentionally has no delete.
97
92
  const { deps, input } = required;
98
- const existing = await deps.repo.findById({ workspaceId: input.workspaceId, id: input.id });
99
- if (!existing) {
100
- throw new WebhookSubscriptionNotFoundError({ message: `webhook subscription '${input.id}' was not found` });
101
- }
93
+ const existing = await requireSubscription({ deps, workspaceId: input.workspaceId, id: input.id });
102
94
  const now = nowIso({ clock: deps.clock });
103
95
  const subscription = {
104
96
  ...existing,
105
97
  status: "disabled",
106
98
  disabledAt: now,
107
99
  updatedAt: now,
100
+ version: existing.version + 1,
108
101
  };
109
- await deps.repo.save(subscription);
102
+ await deps.repo.save(subscription, { expectedVersion: optional.expectedVersion ?? existing.version });
110
103
  return { subscription };
111
104
  }
112
105
  async function validateTargetUrl(params) {
@@ -0,0 +1,82 @@
1
+ import type { AgentToolDefinition as SharedAgentToolDefinition } from "@jini-ai/core";
2
+ /**
3
+ * @file The Integrations (webhooks) domain's agent-tool catalog, instantiating the
4
+ * naming/callability convention (the same shape every other domain catalog uses).
5
+ *
6
+ * Purpose:
7
+ * A static, in-process catalog describing every agent-callable tool this domain exposes. Every
8
+ * entry maps 1:1 onto a real admin HTTP route already exposed to a human operator
9
+ * (the host's admin HTTP routes) — this catalog never names an operation
10
+ * the admin UI does not already perform.
11
+ *
12
+ * the host's admin HTTP routes expose exactly 5 routes: list, create, pause
13
+ * (both directions), delete (soft), and deliveries (a per-subscription delivery log read). All 5 are
14
+ * wired here — plain webhook-subscription CRUD/read over already-durable rows, no credential
15
+ * material anywhere in the response shape (`WebhookSubscriptionRecord` — `types.ts` — has no secret
16
+ * field at all, so there is nothing to redact).
17
+ *
18
+ * Deliberately absent from this catalog entirely (not merely unwired — there is no operation to
19
+ * even name a tool against, the same framing `identity/agent-tools.ts` uses for role revocation):
20
+ *
21
+ * Owner 2026-10-09 authorizes the update tool; the historical exclusion below is superseded
22
+ * for subscription edits only. Signing-secret exclusions remain binding.
23
+ * - Subscription UPDATE. `subscriptions.ts` exports `updateSubscription` (rewrites label/
24
+ * targetUrl/topics), but NO admin route calls it — the host's integrations routes have no
25
+ * update/PATCH/PUT handler at all. Wiring a tool for it would hand an agent a capability
26
+ * the human admin UI itself does not expose today, which is exactly what every catalog in this
27
+ * codebase says it never does. If an update route ships later, its tool belongs in the same
28
+ * pass that ships it, mirrored 1:1 like every other entry here.
29
+ * - Signing-secret rotation/generation/reveal. `signing.ts`/`signing.keyring.ts`/`keyring.env.ts`/
30
+ * `keyring.memory.ts` derive a subscription's HMAC signing secret via
31
+ * `KeyringPort.deriveSigningSecret` (HKDF over the install site key) at delivery time — the
32
+ * secret is NEVER stored, and no admin route reveals, regenerates, or rotates it (there is no
33
+ * rotation admin route at all yet; `WebhookSubscriptionRecord.previousSecretVersion` exists in
34
+ * the type but nothing currently writes a rotation). Even if such a route existed, site-key /
35
+ * signing-secret material is credential-adjacent in exactly the same class as Identity's
36
+ * excluded `resetUserPassword`: reachable-by-prompt-injection agent access to a lever that
37
+ * controls what a third party trusts as an authentic webhook from this workspace is a
38
+ * capability the admin UI reserves for a human, not this catalog's default. Defaults to
39
+ * EXCLUDED regardless of whether a future admin route surfaces it.
40
+ *
41
+ * How it relates to the project:
42
+ * The server-side tool filter consumes this catalog to decide which tool names an agent
43
+ * session may even see; `authorize()` enforces the actual permission checks at call
44
+ * time — this module only declares the catalog shape, it performs no I/O and no enforcement itself.
45
+ *
46
+ * Architectural role:
47
+ * `integrations` domain logic. No dependencies — `WebhookTopic` is a plain `string` (the topic
48
+ * catalog is the domain-event name namespace, not a fixed enum this file could import without
49
+ * depending on every event-emitting domain), so `topics` is published as a free-form string array,
50
+ * validated (non-empty after trim, de-duplicated, at least one required) by `subscriptions.ts`
51
+ * itself, same as the admin UI's own free-text topic entry.
52
+ */
53
+ /**
54
+ * This domain's copy of the shared union (see the core kit's own `AgentToolSideEffect` for
55
+ * why `deletes-durable-state` is a distinct member and not a flavor of `mutates-durable-state`, and
56
+ * why each domain must widen its own narrower copy to opt in rather than inheriting it for free).
57
+ * Widened to add `deletes-durable-state` for `webhooks_delete_subscription`: once a subscription
58
+ * is disabled there is no un-disable/reactivate path anywhere in this domain, so — same standard as
59
+ * `content_post_delete` (the post catalog) — there is no agent-reachable undo, even
60
+ * though the row itself is never physically deleted.
61
+ */
62
+ export type AgentToolSideEffect = "none" | "mutates-durable-state" | "deletes-durable-state" | "mints-token";
63
+ /**
64
+ * JSON Schema for this tool's `input`, published via `ToolDescriptor.inputSchema`
65
+ * (the core kit's `buildDomainRegistrations`, which refuses to wire any
66
+ * tool lacking one). Every entry in this catalog is wired, so this is required, not optional —
67
+ * mirrors the user-management catalog's identical reasoning.
68
+ */
69
+ export type AgentToolDefinition = SharedAgentToolDefinition & {
70
+ sideEffects: AgentToolSideEffect;
71
+ inputSchema: Readonly<Record<string, unknown>>;
72
+ };
73
+ /**
74
+ * The Integrations domain's fixed agent-tool catalog. See this file's header for the two whole
75
+ * classes of operation deliberately absent (subscription update; signing-secret rotation/
76
+ * generation/reveal).
77
+ *
78
+ * @complexity O(1) — a fixed, statically-defined list.
79
+ * @overallScore 100
80
+ */
81
+ export declare function getWebhooksAgentToolCatalog(): AgentToolDefinition[];
82
+ //# sourceMappingURL=agent-tools.d.ts.map
@@ -0,0 +1,120 @@
1
+ const MANAGE_INTEGRATIONS_PERMISSION = "admin.integrations.manage";
2
+ const SUBSCRIPTION_ID_PROPERTY = {
3
+ type: "string",
4
+ minLength: 1,
5
+ description: "A webhook subscription's id, as returned by webhooks_create_subscription or {{read:webhook_subscription}}.",
6
+ };
7
+ const SUBSCRIPTION_ID_SCHEMA = {
8
+ type: "object",
9
+ additionalProperties: false,
10
+ required: ["subscriptionId"],
11
+ properties: { subscriptionId: SUBSCRIPTION_ID_PROPERTY },
12
+ };
13
+ const LABEL_PROPERTY = { type: "string", minLength: 1, description: "Human-readable label shown in the admin UI." };
14
+ const TARGET_URL_PROPERTY = {
15
+ type: "string",
16
+ minLength: 1,
17
+ description: "The absolute https:// URL deliveries are POSTed to. Must be https and must resolve against this workspace's egress allowlist, or the write is refused.",
18
+ };
19
+ const TOPICS_PROPERTY = {
20
+ type: "array",
21
+ minItems: 1,
22
+ items: { type: "string", minLength: 1 },
23
+ description: "Event topics this subscription matches (e.g. 'post.published'). At least one is required; blanks are dropped and duplicates de-duplicated. A trailing '.*' matches every action for an entity.",
24
+ };
25
+ const CREATE_SUBSCRIPTION_SCHEMA = {
26
+ type: "object",
27
+ additionalProperties: false,
28
+ required: ["label", "targetUrl", "topics"],
29
+ properties: {
30
+ label: LABEL_PROPERTY,
31
+ targetUrl: TARGET_URL_PROPERTY,
32
+ topics: TOPICS_PROPERTY,
33
+ },
34
+ };
35
+ const PAUSE_SUBSCRIPTION_SCHEMA = {
36
+ type: "object",
37
+ additionalProperties: false,
38
+ required: ["subscriptionId"],
39
+ properties: {
40
+ subscriptionId: SUBSCRIPTION_ID_PROPERTY,
41
+ paused: { type: "boolean", description: "true (default) pauses delivery; false resumes an already-paused subscription back to active. Cannot resume a deleted (disabled) subscription." },
42
+ },
43
+ };
44
+ const GET_DELIVERIES_SCHEMA = {
45
+ type: "object",
46
+ additionalProperties: false,
47
+ required: ["subscriptionId"],
48
+ properties: {
49
+ subscriptionId: SUBSCRIPTION_ID_PROPERTY,
50
+ limit: { type: "integer", minimum: 1, description: "Max rows to return, newest first. Defaults to 50; capped at 200 regardless of what is requested." },
51
+ },
52
+ };
53
+ const UPDATE_SUBSCRIPTION_TOOL = {
54
+ name: "webhooks_update_subscription",
55
+ description: "Replaces a webhook subscription's label, HTTPS targetUrl and topics by subscriptionId. Supply all three fields; use {{read:webhook_subscription}} to read current values first. Returns {subscription}, with signing version metadata but no secret. Status and signing generation stay unchanged. Missing ids, empty labels/topics, malformed targets, denied permission and disallowed egress are refused. Requires admin.integrations.manage. Pass expectedVersion from {{read:webhook_subscription}}; if someone changed it since, nothing is saved and you must re-read.",
56
+ sideEffects: "mutates-durable-state", authorization: { permission: MANAGE_INTEGRATIONS_PERMISSION },
57
+ inputSchema: { type: "object", additionalProperties: false, required: ["subscriptionId", "label", "targetUrl", "topics", "expectedVersion"], properties: {
58
+ expectedVersion: { type: "integer", minimum: 0, description: "The record's version from {{read:webhook_subscription}}. Required." },
59
+ subscriptionId: { type: "string", minLength: 1 }, label: { type: "string", minLength: 1 }, targetUrl: { type: "string", minLength: 1 }, topics: { type: "array", minItems: 1, items: { type: "string" } },
60
+ } },
61
+ };
62
+ const LIST_SUBSCRIPTIONS_TOOL = {
63
+ name: "webhooks_list_subscriptions",
64
+ description: "Lists the workspace's webhook subscriptions, each annotated with its most recent delivery attempt (if any). Read-only.",
65
+ sideEffects: "none",
66
+ authorization: { permission: MANAGE_INTEGRATIONS_PERMISSION },
67
+ inputSchema: {
68
+ type: "object",
69
+ additionalProperties: false,
70
+ required: [],
71
+ properties: {},
72
+ },
73
+ };
74
+ const GET_DELIVERIES_TOOL = {
75
+ name: "webhooks_get_deliveries",
76
+ description: "Fetches the delivery log (status, attempts, last response, timestamps) for one webhook subscription, newest first.",
77
+ sideEffects: "none",
78
+ authorization: { permission: MANAGE_INTEGRATIONS_PERMISSION },
79
+ inputSchema: GET_DELIVERIES_SCHEMA,
80
+ };
81
+ const CREATE_SUBSCRIPTION_TOOL = {
82
+ name: "webhooks_create_subscription",
83
+ description: "Creates a new webhook subscription. Starts active at signing-secret generation 1 — the signing secret itself is never generated or exposed by this tool (it is derived at delivery time from the install site key, never stored).",
84
+ sideEffects: "mutates-durable-state",
85
+ authorization: { permission: MANAGE_INTEGRATIONS_PERMISSION },
86
+ inputSchema: CREATE_SUBSCRIPTION_SCHEMA,
87
+ };
88
+ const PAUSE_SUBSCRIPTION_TOOL = {
89
+ name: "webhooks_pause_subscription",
90
+ description: "Pauses or resumes a webhook subscription's deliveries. One tool, both directions (paused defaults to true). Refused if the subscription is already deleted (disabled).",
91
+ sideEffects: "mutates-durable-state",
92
+ authorization: { permission: MANAGE_INTEGRATIONS_PERMISSION },
93
+ inputSchema: PAUSE_SUBSCRIPTION_SCHEMA,
94
+ };
95
+ const DELETE_SUBSCRIPTION_TOOL = {
96
+ name: "webhooks_delete_subscription",
97
+ description: "Soft-deletes a webhook subscription (never row-deleted, for audit durability). Safe to call again on an already-deleted subscription — it does not error, though disabledAt/updatedAt are stamped again.",
98
+ // Classified `deletes-durable-state`, not `mutates-durable-state`, despite being a soft
99
+ // delete at the storage layer: the same "no agent-reachable undo" standard that justifies
100
+ // `content_post_delete`'s classification (the post tool wiring) applies
101
+ // here too. Once disabled there is no un-disable/reactivate path anywhere in this domain —
102
+ // `pauseSubscription` explicitly refuses once `status === "disabled"` — so from an agent's
103
+ // (or this tool's caller's) perspective the effect is as final as a hard delete, even though
104
+ // the row survives for audit. See the matching comment on `webhooksDerivedRisk` in `tool-registrations.ts`.
105
+ sideEffects: "deletes-durable-state",
106
+ authorization: { permission: MANAGE_INTEGRATIONS_PERMISSION },
107
+ inputSchema: SUBSCRIPTION_ID_SCHEMA,
108
+ };
109
+ /**
110
+ * The Integrations domain's fixed agent-tool catalog. See this file's header for the two whole
111
+ * classes of operation deliberately absent (subscription update; signing-secret rotation/
112
+ * generation/reveal).
113
+ *
114
+ * @complexity O(1) — a fixed, statically-defined list.
115
+ * @overallScore 100
116
+ */
117
+ export function getWebhooksAgentToolCatalog() {
118
+ return [UPDATE_SUBSCRIPTION_TOOL, LIST_SUBSCRIPTIONS_TOOL, GET_DELIVERIES_TOOL, CREATE_SUBSCRIPTION_TOOL, PAUSE_SUBSCRIPTION_TOOL, DELETE_SUBSCRIPTION_TOOL];
119
+ }
120
+ //# sourceMappingURL=agent-tools.js.map
@@ -0,0 +1,7 @@
1
+ /** Webhook agent tools over required repository, origin and confirmation ports. */
2
+ export { getWebhooksAgentToolCatalog } from "./agent-tools.js";
3
+ export type { AgentToolDefinition, AgentToolSideEffect } from "./agent-tools.js";
4
+ export { buildWebhooksToolRegistrations, webhooksDerivedRisk } from "./tool-registrations.js";
5
+ export { toWebhookDeliveryView } from "./tool-views.js";
6
+ export type * from "./tool-handlers.types.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ /** Webhook agent tools over required repository, origin and confirmation ports. */
2
+ export { getWebhooksAgentToolCatalog } from "./agent-tools.js";
3
+ export { buildWebhooksToolRegistrations, webhooksDerivedRisk } from "./tool-registrations.js";
4
+ export { toWebhookDeliveryView } from "./tool-views.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,22 @@
1
+ import { type HostReadVocabulary, type ToolHandler } from "@jini-ai/core";
2
+ import type { WebhooksPackageToolDeps, WebhooksToolSurfaces } from "./tool-handlers.types.js";
3
+ /** What every tool handler factory is given: the route deps and the confirmation surface store. */
4
+ interface WebhookHandlerArgs {
5
+ deps: WebhooksPackageToolDeps;
6
+ surfaces: WebhooksToolSurfaces;
7
+ hostReads?: HostReadVocabulary | undefined;
8
+ }
9
+ export declare const webhooksListSubscriptionsHandler: ({ deps }: WebhookHandlerArgs, _optional?: {}) => ToolHandler;
10
+ export declare const webhooksGetDeliveriesHandler: ({ deps }: WebhookHandlerArgs, _optional?: {}) => ToolHandler;
11
+ export declare const webhooksCreateSubscriptionHandler: ({ deps }: WebhookHandlerArgs, _optional?: {}) => ToolHandler;
12
+ /** Uses the existing validation/egress owner and never exposes signing material. */
13
+ export declare const webhooksUpdateSubscriptionHandler: ({ deps, hostReads }: WebhookHandlerArgs, _optional?: {}) => ToolHandler;
14
+ export declare const webhooksPauseSubscriptionHandler: ({ deps }: WebhookHandlerArgs, _optional?: {}) => ToolHandler;
15
+ /**
16
+ * The MCP-UI-gated delete — migrated onto the shared held-open confirmation exchange
17
+ * (2026-09-08, ADS-memory/reports/2026-09-08-delete-confirmation-build.md).
18
+ * The snapshot check and confirmed version fence changes while confirmation is open.
19
+ */
20
+ export declare const webhooksDeleteSubscriptionHandler: ({ deps, surfaces }: WebhookHandlerArgs, _optional?: {}) => ToolHandler;
21
+ export {};
22
+ //# sourceMappingURL=tool-handlers.d.ts.map
@@ -0,0 +1,154 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import { ToolInputError, adaptLegacyAuthorize, optionalBoolean, optionalNumber, requireInputRecord, requireNoInput, requireString, requireToolPermission, resolveHostReadText, } from "@jini-ai/core";
3
+ import { RecordVersionConflictError, requireExpectedVersion } from "@jini-ai/core/optimistic-concurrency";
4
+ import { createSubscription, updateSubscription, deleteSubscription, pauseSubscription, WebhookSubscriptionNotFoundError, WebhookSubscriptionValidationError, } from "../subscriptions.js";
5
+ import { mostRecentDelivery, toSubscriptionToolView, toWebhookDeliveryView } from "./tool-views.js";
6
+ const MANAGE_INTEGRATIONS_PERMISSION = "admin.integrations.manage";
7
+ /**
8
+ * Bound on how many of a subscription's most recent deliveries are read to compute the
9
+ * "last delivery" summary shown per row in `webhooks_list_subscriptions`. Duplicated from
10
+ * the host's admin list route's own `LAST_DELIVERY_LOOKUP_LIMIT` (a literal, not logic —
11
+ * importing from a host route would invert the ports/adapters direction, so the value is repeated here).
12
+ */
13
+ const LAST_DELIVERY_LOOKUP_LIMIT = 50;
14
+ /** Default/cap for `webhooks_get_deliveries`' `limit` — duplicated from
15
+ * the host's admin deliveries route, same reasoning as above. */
16
+ const DEFAULT_DELIVERIES_LIMIT = 50;
17
+ const MAX_DELIVERIES_LIMIT = 200;
18
+ function clampDeliveriesLimit({ requested }, _optional = {}) {
19
+ if (requested === undefined || !Number.isFinite(requested) || requested <= 0)
20
+ return DEFAULT_DELIVERIES_LIMIT;
21
+ return Math.min(Math.floor(requested), MAX_DELIVERIES_LIMIT);
22
+ }
23
+ /** Whether a webhook target URL may be called from this workspace, per the verified-origin registry. */
24
+ function egressTargetCheck(routeDeps) {
25
+ return ({ url }, _optional = {}) => routeDeps.originRegistry.isAllowedEgressTarget({ context: { workspaceId: routeDeps.workspaceId }, url: url });
26
+ }
27
+ /** The deps bag the subscription write-service takes, over the route deps and its egress check. */
28
+ function subscriptionServiceDeps(deps, _optional = {}) {
29
+ return { clock: deps.clock, repo: deps.webhookSubscriptionRepo, idGenerator: deps.idGen, isAllowedTarget: egressTargetCheck(deps) };
30
+ }
31
+ export const webhooksListSubscriptionsHandler = ({ deps }, _optional = {}) => async (ctx) => {
32
+ requireNoInput({ input: ctx.input });
33
+ await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: MANAGE_INTEGRATIONS_PERMISSION }, { entityType: "webhook_subscription" });
34
+ const subscriptions = await deps.webhookSubscriptionRepo.listByWorkspace({ workspaceId: deps.workspaceId });
35
+ const views = await Promise.all(subscriptions.map(async (subscription) => {
36
+ const recentDeliveries = await deps.webhookDeliveryRepo.listBySubscription({
37
+ workspaceId: deps.workspaceId,
38
+ subscriptionId: subscription.id,
39
+ limit: LAST_DELIVERY_LOOKUP_LIMIT,
40
+ });
41
+ return toSubscriptionToolView({ subscription, lastDelivery: mostRecentDelivery(recentDeliveries) });
42
+ }));
43
+ return { subscriptions: views };
44
+ };
45
+ export const webhooksGetDeliveriesHandler = ({ deps }, _optional = {}) => async (ctx) => {
46
+ const input = requireInputRecord({ input: ctx.input });
47
+ const subscriptionId = requireString({ input, key: "subscriptionId" });
48
+ await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: MANAGE_INTEGRATIONS_PERMISSION }, { entityType: "webhook_subscription", entityId: subscriptionId });
49
+ const subscription = await deps.webhookSubscriptionRepo.findById({ workspaceId: deps.workspaceId, id: subscriptionId });
50
+ if (!subscription)
51
+ throw new WebhookSubscriptionNotFoundError({ message: `webhook subscription '${subscriptionId}' was not found` });
52
+ const deliveries = await deps.webhookDeliveryRepo.listBySubscription({
53
+ workspaceId: deps.workspaceId,
54
+ subscriptionId,
55
+ limit: clampDeliveriesLimit({ requested: optionalNumber({ input, key: "limit" }) }),
56
+ });
57
+ const newestFirst = [...deliveries].sort((a, b) => b.createdAt.localeCompare(a.createdAt));
58
+ return { deliveries: newestFirst.map((delivery) => toWebhookDeliveryView({ delivery })) };
59
+ };
60
+ export const webhooksCreateSubscriptionHandler = ({ deps }, _optional = {}) => async (ctx) => {
61
+ const input = requireInputRecord({ input: ctx.input });
62
+ await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: MANAGE_INTEGRATIONS_PERMISSION }, { entityType: "webhook_subscription" });
63
+ const rawTopics = input.topics;
64
+ ctx.signal.throwIfAborted();
65
+ const { subscription } = await createSubscription({
66
+ deps: subscriptionServiceDeps(deps),
67
+ input: {
68
+ workspaceId: deps.workspaceId,
69
+ // Mirrors the host's admin create route (its dev-mode placeholder): there is no per-agent-run
70
+ // owner-principal concept yet, so the owner is the same run principal the permission
71
+ // check above already authorized (never a caller-supplied id).
72
+ ownerPrincipalId: ctx.principal.id,
73
+ createdByPrincipalId: ctx.principal.id,
74
+ label: requireString({ input, key: "label" }),
75
+ targetUrl: requireString({ input, key: "targetUrl" }),
76
+ topics: Array.isArray(rawTopics) ? rawTopics.map(String) : [],
77
+ },
78
+ });
79
+ return { subscription: toSubscriptionToolView({ subscription, lastDelivery: null }) };
80
+ };
81
+ /** Uses the existing validation/egress owner and never exposes signing material. */
82
+ export const webhooksUpdateSubscriptionHandler = ({ deps, hostReads }, _optional = {}) => async (ctx) => {
83
+ const input = requireInputRecord({ input: ctx.input });
84
+ const expectedVersion = requireExpectedVersion({ value: input.expectedVersion, readToolId: resolveHostReadText({ text: "{{read:webhook_subscription}}" }, { hostReads }) });
85
+ const subscriptionId = requireString({ input, key: "subscriptionId" });
86
+ await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: MANAGE_INTEGRATIONS_PERMISSION }, { entityType: "webhook_subscription", entityId: subscriptionId });
87
+ if (!Array.isArray(input.topics) || !input.topics.every(topic => typeof topic === "string")) {
88
+ throw new WebhookSubscriptionValidationError({ message: "topics must be an array of strings" });
89
+ }
90
+ ctx.signal.throwIfAborted();
91
+ const { subscription } = await updateSubscription({
92
+ deps: subscriptionServiceDeps(deps),
93
+ input: { workspaceId: deps.workspaceId, id: subscriptionId, label: requireString({ input, key: "label" }), targetUrl: requireString({ input, key: "targetUrl" }), topics: input.topics },
94
+ }, { expectedVersion });
95
+ const deliveries = await deps.webhookDeliveryRepo.listBySubscription({
96
+ workspaceId: deps.workspaceId, subscriptionId, limit: 1,
97
+ });
98
+ return { subscription: toSubscriptionToolView({ subscription, lastDelivery: mostRecentDelivery(deliveries) }) };
99
+ };
100
+ export const webhooksPauseSubscriptionHandler = ({ deps }, _optional = {}) => async (ctx) => {
101
+ const input = requireInputRecord({ input: ctx.input });
102
+ const subscriptionId = requireString({ input, key: "subscriptionId" });
103
+ await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: MANAGE_INTEGRATIONS_PERMISSION }, { entityType: "webhook_subscription", entityId: subscriptionId });
104
+ const { subscription } = await pauseSubscription({
105
+ deps: subscriptionServiceDeps(deps),
106
+ input: { workspaceId: deps.workspaceId, id: subscriptionId },
107
+ }, { paused: optionalBoolean({ input, key: "paused" }) ?? true });
108
+ return { subscription: toSubscriptionToolView({ subscription, lastDelivery: null }) };
109
+ };
110
+ /**
111
+ * The MCP-UI-gated delete — migrated onto the shared held-open confirmation exchange
112
+ * (2026-09-08, ADS-memory/reports/2026-09-08-delete-confirmation-build.md).
113
+ * The snapshot check and confirmed version fence changes while confirmation is open.
114
+ */
115
+ export const webhooksDeleteSubscriptionHandler = ({ deps, surfaces }, _optional = {}) => deps.confirmDelete({ surfaces,
116
+ prepare: async ({ ctx }) => {
117
+ const subscriptionId = requireString({ input: requireInputRecord({ input: ctx.input }), key: "subscriptionId" });
118
+ await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: MANAGE_INTEGRATIONS_PERMISSION }, { entityType: "webhook_subscription", entityId: subscriptionId });
119
+ const existing = await deps.webhookSubscriptionRepo.findById({ workspaceId: deps.workspaceId, id: subscriptionId });
120
+ if (!existing)
121
+ throw new WebhookSubscriptionNotFoundError({ message: `webhook subscription '${subscriptionId}' was not found` });
122
+ return { subscriptionId, existing: structuredClone(existing) };
123
+ },
124
+ run: async ({ ctx, prepared: { subscriptionId, existing } }) => {
125
+ // Authorization can be revoked while the human reads the card; the service has no gate.
126
+ await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: MANAGE_INTEGRATIONS_PERMISSION }, { entityType: "webhook_subscription", entityId: subscriptionId });
127
+ if (ctx.signal.aborted)
128
+ return { deleted: false, ...deps.notConfirmedResult({ confirmed: false, reason: "abandoned" }) };
129
+ const current = await deps.webhookSubscriptionRepo.findById({ workspaceId: deps.workspaceId, id: subscriptionId });
130
+ if (!isDeepStrictEqual(current, existing))
131
+ throw new ToolInputError({ message: "webhooks_delete_subscription: target changed while confirmation was open. Request a new confirmation; nothing was deleted." });
132
+ ctx.signal.throwIfAborted();
133
+ try {
134
+ const { subscription } = await deleteSubscription({
135
+ deps: subscriptionServiceDeps(deps),
136
+ input: { workspaceId: deps.workspaceId, id: subscriptionId },
137
+ }, { expectedVersion: existing.version });
138
+ return { deleted: true, cancelled: false, subscription: toSubscriptionToolView({ subscription, lastDelivery: null }) };
139
+ }
140
+ catch (error) {
141
+ if (error instanceof RecordVersionConflictError)
142
+ throw new ToolInputError({ message: "webhooks_delete_subscription: target changed while confirmation was open. Request a new confirmation; nothing was deleted." }, { cause: error });
143
+ throw error;
144
+ }
145
+ },
146
+ declined: ({ reason, prepared }) => {
147
+ if (reason === "declined" && prepared)
148
+ return { deleted: false, cancelled: true, subscription: toSubscriptionToolView({ subscription: prepared.existing, lastDelivery: null }) };
149
+ return { deleted: false, cancelled: false, reason, note: reason === "expired"
150
+ ? "The user did not respond to the confirmation dialog before it expired. Nothing was deleted."
151
+ : "The confirmation dialog was closed because the run ended. Nothing was deleted." };
152
+ },
153
+ });
154
+ //# sourceMappingURL=tool-handlers.js.map