@replicer/sdk 0.1.1 → 0.3.0
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 +81 -17
- package/dist/chunk-CIXVIMX2.js +54 -0
- package/dist/index.cjs +136 -42
- package/dist/index.d.cts +499 -548
- package/dist/index.d.ts +499 -548
- package/dist/index.js +136 -42
- package/dist/tools.cjs +179 -0
- package/dist/tools.d.cts +79 -0
- package/dist/tools.d.ts +79 -0
- package/dist/tools.js +101 -0
- package/dist/types-DXQsrvOU.d.cts +1251 -0
- package/dist/types-DXQsrvOU.d.ts +1251 -0
- package/dist/webhooks.cjs +98 -14
- package/dist/webhooks.d.cts +36 -17
- package/dist/webhooks.d.ts +36 -17
- package/dist/webhooks.js +49 -14
- package/package.json +16 -2
package/dist/index.js
CHANGED
|
@@ -34,45 +34,78 @@ var ReplicerError = class extends Error {
|
|
|
34
34
|
|
|
35
35
|
// src/routes.ts
|
|
36
36
|
var ROUTES = [
|
|
37
|
-
{ method: "POST", path: "/v1/create-phone-call", sdk: "call.createPhoneCall" },
|
|
38
|
-
{ method: "POST", path: "/v1/
|
|
39
|
-
{ method: "POST", path: "/v1/cancel-
|
|
40
|
-
{ method: "
|
|
41
|
-
{ method: "GET", path: "/v1/
|
|
42
|
-
{ method: "
|
|
43
|
-
{ method: "
|
|
44
|
-
{ method: "GET", path: "/v1/
|
|
45
|
-
{ method: "
|
|
46
|
-
{ method: "
|
|
47
|
-
{ method: "
|
|
48
|
-
{ method: "
|
|
49
|
-
{ method: "
|
|
50
|
-
{ method: "
|
|
51
|
-
{ method: "
|
|
52
|
-
{ method: "
|
|
53
|
-
{ method: "
|
|
54
|
-
{ method: "
|
|
55
|
-
{ method: "
|
|
56
|
-
{ method: "POST", path: "/v1/
|
|
57
|
-
{ method: "
|
|
58
|
-
{ method: "
|
|
59
|
-
{ method: "
|
|
60
|
-
{ method: "
|
|
61
|
-
{ method: "
|
|
62
|
-
{ method: "
|
|
63
|
-
{ method: "
|
|
64
|
-
{ method: "
|
|
65
|
-
{ method: "
|
|
66
|
-
{ method: "GET", path: "/v1/
|
|
67
|
-
{ method: "GET", path: "/v1/list-
|
|
68
|
-
{ method: "POST", path: "/v1/create-
|
|
69
|
-
{ method: "GET", path: "/v1/list-
|
|
70
|
-
{ method: "
|
|
71
|
-
{ method: "POST", path: "/v1/
|
|
72
|
-
{ method: "
|
|
73
|
-
{ method: "POST", path: "/v1/
|
|
74
|
-
{ method: "GET", path: "/v1/list-
|
|
75
|
-
{ method: "
|
|
37
|
+
{ method: "POST", path: "/v1/create-phone-call", sdk: "call.createPhoneCall", request: "CreatePhoneCallInput", response: "EnqueueCallResponse", status: 202, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [422, "idempotency_key_reuse"], [429, "rate_limit_exceeded"], [429, "rate_limited"], [502, "bad_gateway"]] },
|
|
38
|
+
{ method: "POST", path: "/v1/simulate-inbound-call", sdk: "call.simulateInbound", request: "SimulateInboundCallInput", response: "SimulateInboundCallResponse", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [403, "test_mode_unsupported"], [404, "not_found"], [409, "conflict"], [422, "idempotency_key_reuse"], [429, "rate_limit_exceeded"], [429, "rate_limited"]] },
|
|
39
|
+
{ method: "POST", path: "/v1/cancel-call", sdk: "call.cancel", request: "CancelCallInput", response: "OkResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"], [502, "bad_gateway"]] },
|
|
40
|
+
{ method: "POST", path: "/v1/cancel-campaign-pending", sdk: "call.cancelCampaignPending", request: "CancelCampaignPendingInput", response: "CancelCampaignPendingResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
41
|
+
{ method: "GET", path: "/v1/list-calls", sdk: "call.list", request: "ListCallsParams", response: "Page<Call>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
42
|
+
{ method: "GET", path: "/v1/get-call/:id", sdk: "call.get", request: "none", response: "Call", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
43
|
+
{ method: "POST", path: "/v1/campaigns", sdk: "campaign.create", request: "CreateCampaignInput", response: "CreateCampaignResponse", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "forbidden"], [403, "insufficient_scope"], [404, "not_found"], [409, "conflict"], [422, "idempotency_key_reuse"], [422, "validation_error"], [429, "rate_limit_exceeded"]] },
|
|
44
|
+
{ method: "GET", path: "/v1/campaigns/:id", sdk: "campaign.get", request: "none", response: "GetCampaignResponse", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
45
|
+
{ method: "GET", path: "/v1/list-campaigns", sdk: "campaign.list", request: "ListCampaignsParams", response: "Page<Campaign>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
46
|
+
{ method: "POST", path: "/v1/start-campaign/:id", sdk: "campaign.start", request: "none", response: "StartCampaignResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [402, "insufficient_balance"], [403, "forbidden"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
47
|
+
{ method: "GET", path: "/v1/list-phone-numbers", sdk: "phoneNumber.list", request: "PageParams", response: "Page<PhoneNumber>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
48
|
+
{ method: "POST", path: "/v1/phone-numbers/inbound", sdk: "phoneNumber.provisionInbound", request: "ProvisionInboundInput", response: "ProvisionInboundResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [403, "test_mode_unsupported"], [404, "not_found"], [409, "conflict"], [429, "rate_limit_exceeded"], [502, "bad_gateway"]] },
|
|
49
|
+
{ method: "DELETE", path: "/v1/phone-numbers/inbound/:id", sdk: "phoneNumber.deprovisionInbound", request: "DeprovisionInboundParams", response: "OkResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [403, "test_mode_unsupported"], [404, "not_found"], [429, "rate_limit_exceeded"], [502, "bad_gateway"]] },
|
|
50
|
+
{ method: "PATCH", path: "/v1/update-phone-number/:id", sdk: "phoneNumber.update", request: "UpdatePhoneNumberInput", response: "PhoneNumber", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [403, "test_mode_unsupported"], [404, "not_found"], [409, "conflict"], [429, "rate_limit_exceeded"], [502, "bad_gateway"]] },
|
|
51
|
+
{ method: "POST", path: "/v1/import-phone-number", sdk: "phoneNumber.import", request: "ImportPhoneNumberInput", response: "PhoneNumber", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [403, "test_mode_unsupported"], [409, "conflict"], [429, "rate_limit_exceeded"], [502, "bad_gateway"]] },
|
|
52
|
+
{ method: "POST", path: "/v1/create-knowledge-base", sdk: "knowledgeBase.create", request: "KnowledgeBaseCreateInput", response: "KnowledgeBaseSourcesResponse", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [403, "quota_exceeded"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
53
|
+
{ method: "GET", path: "/v1/get-knowledge-base/:id", sdk: "knowledgeBase.retrieve", request: "none", response: "KnowledgeBaseResponse", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
54
|
+
{ method: "GET", path: "/v1/list-knowledge-bases", sdk: "knowledgeBase.list", request: "none", response: "KnowledgeBaseListResponse", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
55
|
+
{ method: "DELETE", path: "/v1/delete-knowledge-base/:id", sdk: "knowledgeBase.delete", request: "none", response: "none", status: 204, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
56
|
+
{ method: "POST", path: "/v1/add-knowledge-base-sources/:id", sdk: "knowledgeBase.addSources", request: "KnowledgeBaseAddSourcesInput", response: "KnowledgeBaseSourcesResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [403, "quota_exceeded"], [404, "not_found"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
57
|
+
{ method: "DELETE", path: "/v1/delete-knowledge-base-source/:source_id", sdk: "knowledgeBase.deleteSource", request: "DeleteKnowledgeBaseSourceParams", response: "KnowledgeBaseResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
58
|
+
{ method: "PATCH", path: "/v1/update-knowledge-base/:id", sdk: "knowledgeBase.update", request: "KnowledgeBaseUpdateInput", response: "KnowledgeBaseResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
59
|
+
{ method: "POST", path: "/v1/presign-knowledge-base-file/:id", sdk: "knowledgeBase.presignFile", request: "PresignFileInput", response: "PresignFileResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [403, "quota_exceeded"], [404, "not_found"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
60
|
+
{ method: "POST", path: "/v1/complete-knowledge-base-file/:id/:source_id", sdk: "knowledgeBase.completeFile", request: "none", response: "KnowledgeBaseResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "conflict"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
61
|
+
{ method: "POST", path: "/v1/fail-knowledge-base-file/:id/:source_id", sdk: "knowledgeBase.failFile", request: "FailFileInput", response: "KnowledgeBaseResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "conflict"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
62
|
+
{ method: "PUT", path: "/v1/reindex-knowledge-base/:id", sdk: "knowledgeBase.reindex", request: "none", response: "KnowledgeBaseResponse", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "conflict"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
63
|
+
{ method: "PATCH", path: "/v1/update-knowledge-base-source/:id/:source_id", sdk: "knowledgeBase.updateSource", request: "UpdateSourceInput", response: "KnowledgeBaseResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
64
|
+
{ method: "PATCH", path: "/v1/update-knowledge-base-chunk/:id/:chunk_id", sdk: "knowledgeBase.updateChunk", request: "UpdateChunkInput", response: "OkResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
65
|
+
{ method: "GET", path: "/v1/get-knowledge-base-source/:id/:source_id", sdk: "knowledgeBase.getSource", request: "none", response: "KnowledgeBaseSourceDetail", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
66
|
+
{ method: "GET", path: "/v1/presign-knowledge-base-file-download/:id/:source_id", sdk: "knowledgeBase.presignFileDownload", request: "none", response: "PresignFileDownloadResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "conflict"], [429, "rate_limit_exceeded"], [503, "internal_error"]] },
|
|
67
|
+
{ method: "GET", path: "/v1/list-contacts", sdk: "contact.list", request: "ListContactsParams", response: "Page<Contact>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
68
|
+
{ method: "POST", path: "/v1/create-contact", sdk: "contact.create", request: "CreateContactInput", response: "CreateContactResponse", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
69
|
+
{ method: "GET", path: "/v1/list-agents", sdk: "agent.list", request: "ListAgentsParams", response: "Page<Agent>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
70
|
+
{ method: "GET", path: "/v1/get-agent/:id", sdk: "agent.get", request: "none", response: "AgentDetail", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
71
|
+
{ method: "POST", path: "/v1/create-agent", sdk: "agent.create", request: "CreateAgentInput", response: "AgentDetail", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [403, "quota_exceeded"], [403, "test_mode_unsupported"], [409, "conflict"], [429, "rate_limit_exceeded"]] },
|
|
72
|
+
{ method: "PATCH", path: "/v1/update-agent/:id", sdk: "agent.update", request: "UpdateAgentInput", response: "AgentDetail", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [403, "quota_exceeded"], [403, "test_mode_unsupported"], [404, "not_found"], [409, "agent_tool_name_conflict"], [409, "conflict"], [429, "rate_limit_exceeded"]] },
|
|
73
|
+
{ method: "POST", path: "/v1/deactivate-agent/:id", sdk: "agent.deactivate", request: "none", response: "AgentDetail", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [403, "test_mode_unsupported"], [404, "not_found"], [409, "agent_in_use"], [429, "rate_limit_exceeded"]] },
|
|
74
|
+
{ method: "GET", path: "/v1/list-calendars", sdk: "calendar.listCalendars", request: "PageParams", response: "Page<Calendar>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
75
|
+
{ method: "POST", path: "/v1/create-calendar", sdk: "calendar.create", request: "CreateCalendarInput", response: "CalendarDetail", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
76
|
+
{ method: "PATCH", path: "/v1/update-calendar/:id", sdk: "calendar.update", request: "UpdateCalendarInput", response: "CalendarDetail", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
77
|
+
{ method: "POST", path: "/v1/create-event-type", sdk: "calendar.createEventType", request: "CreateEventTypeInput", response: "EventTypeDetail", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
78
|
+
{ method: "PATCH", path: "/v1/update-event-type/:id", sdk: "calendar.updateEventType", request: "UpdateEventTypeInput", response: "EventTypeDetail", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
79
|
+
{ method: "GET", path: "/v1/list-calendar-events", sdk: "calendar.listEvents", request: "ListCalendarEventsParams", response: "Page<CalendarEvent>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
80
|
+
{ method: "POST", path: "/v1/create-calendar-event", sdk: "calendar.createEvent", request: "CreateCalendarEventInput", response: "CreateCalendarEventResponse", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [409, "conflict"], [429, "rate_limit_exceeded"]] },
|
|
81
|
+
{ method: "PATCH", path: "/v1/update-calendar-event/:id", sdk: "calendar.updateEvent", request: "UpdateCalendarEventInput", response: "CalendarEvent", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "conflict"], [429, "rate_limit_exceeded"]] },
|
|
82
|
+
{ method: "POST", path: "/v1/cancel-calendar-event/:id", sdk: "calendar.cancelEvent", request: "none", response: "CalendarEvent", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "conflict"], [429, "rate_limit_exceeded"]] },
|
|
83
|
+
{ method: "GET", path: "/v1/list-messages", sdk: "message.list", request: "ListMessagesParams", response: "Page<Message>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
84
|
+
{ method: "GET", path: "/v1/get-message/:id", sdk: "message.get", request: "none", response: "Message", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
85
|
+
{ method: "POST", path: "/v1/send-sms", sdk: "message.sendSms", request: "SendSmsInput", response: "SendMessageResponse", status: 202, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [409, "conflict"], [422, "channel_not_configured"], [422, "idempotency_key_reuse"], [422, "sender_not_supported"], [422, "validation_error"], [429, "rate_limit_exceeded"], [502, "bad_gateway"]] },
|
|
86
|
+
{ method: "POST", path: "/v1/send-whatsapp", sdk: "message.sendWhatsapp", request: "SendWhatsappInput", response: "SendMessageResponse", status: 202, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [409, "conflict"], [422, "channel_not_configured"], [422, "idempotency_key_reuse"], [422, "media_not_supported"], [422, "validation_error"], [429, "rate_limit_exceeded"], [502, "bad_gateway"]] },
|
|
87
|
+
{ method: "POST", path: "/v1/send-email", sdk: "message.sendEmail", request: "SendEmailInput", response: "SendMessageResponse", status: 202, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [409, "conflict"], [422, "channel_not_configured"], [422, "email_provider_not_supported"], [422, "idempotency_key_reuse"], [422, "validation_error"], [429, "rate_limit_exceeded"], [502, "bad_gateway"]] },
|
|
88
|
+
{ method: "POST", path: "/v1/create-tts", sdk: "tts.create", request: "CreateTtsInput", response: "CreateTtsResponse", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [409, "conflict"], [422, "idempotency_key_reuse"], [422, "validation_error"], [429, "rate_limit_exceeded"], [502, "bad_gateway"], [503, "service_unavailable"]] },
|
|
89
|
+
{ method: "GET", path: "/v1/list-tts", sdk: "tts.list", request: "ListTtsParams", response: "Page<TtsGeneration>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
90
|
+
{ method: "GET", path: "/v1/get-tts/:id", sdk: "tts.get", request: "none", response: "TtsGeneration", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
91
|
+
{ method: "POST", path: "/v1/create-webhook-endpoint", sdk: "webhookEndpoint.create", request: "CreateWebhookEndpointInput", response: "WebhookEndpointWithSecret", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [409, "conflict"], [409, "webhook_endpoint_limit"], [422, "idempotency_key_reuse"], [422, "validation_error"], [429, "rate_limit_exceeded"], [503, "service_unavailable"]] },
|
|
92
|
+
{ method: "GET", path: "/v1/list-webhook-endpoints", sdk: "webhookEndpoint.list", request: "PageParams", response: "Page<WebhookEndpoint>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
93
|
+
{ method: "GET", path: "/v1/get-webhook-endpoint/:id", sdk: "webhookEndpoint.get", request: "none", response: "WebhookEndpoint", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
94
|
+
{ method: "PATCH", path: "/v1/update-webhook-endpoint/:id", sdk: "webhookEndpoint.update", request: "UpdateWebhookEndpointInput", response: "WebhookEndpoint", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "webhook_endpoint_key_revoked"], [409, "webhook_endpoint_admin_disabled"], [429, "rate_limit_exceeded"]] },
|
|
95
|
+
{ method: "DELETE", path: "/v1/delete-webhook-endpoint/:id", sdk: "webhookEndpoint.delete", request: "none", response: "OkResponse", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "webhook_endpoint_in_use"], [429, "rate_limit_exceeded"]] },
|
|
96
|
+
{ method: "POST", path: "/v1/rotate-webhook-endpoint-secret/:id", sdk: "webhookEndpoint.rotateSecret", request: "none", response: "WebhookEndpointWithSecret", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "conflict"], [429, "rate_limit_exceeded"], [503, "service_unavailable"]] },
|
|
97
|
+
{ method: "POST", path: "/v1/test-webhook-endpoint/:id", sdk: "webhookEndpoint.test", request: "TestWebhookEndpointInput", response: "TestWebhookEndpointResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "conflict"], [429, "rate_limit_exceeded"], [429, "rate_limited"]] },
|
|
98
|
+
{ method: "GET", path: "/v1/list-webhook-deliveries", sdk: "webhookEndpoint.listDeliveries", request: "ListWebhookDeliveriesParams", response: "Page<WebhookDelivery>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
99
|
+
{ method: "GET", path: "/v1/list-webhook-delivery-attempts", sdk: "webhookEndpoint.listDeliveryAttempts", request: "ListWebhookDeliveryAttemptsParams", response: "Page<WebhookDeliveryAttempt>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
100
|
+
{ method: "POST", path: "/v1/redeliver-webhook-delivery/:id", sdk: "webhookEndpoint.redeliver", request: "none", response: "WebhookDelivery", status: 201, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "conflict"], [409, "redelivery_limit"], [409, "webhook_endpoint_key_revoked"], [429, "rate_limit_exceeded"]] },
|
|
101
|
+
{ method: "POST", path: "/v1/create-agent-tool", sdk: "agentTool.create", request: "CreateAgentToolInput", response: "AgentTool", status: 201, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "agent_tool_limit"], [409, "agent_tool_name_conflict"], [409, "agent_tool_name_taken"], [409, "conflict"], [422, "idempotency_key_reuse"], [422, "validation_error"], [429, "rate_limit_exceeded"]] },
|
|
102
|
+
{ method: "GET", path: "/v1/list-agent-tools", sdk: "agentTool.list", request: "ListAgentToolsParams", response: "Page<AgentTool>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
103
|
+
{ method: "GET", path: "/v1/get-agent-tool/:id", sdk: "agentTool.get", request: "none", response: "AgentTool", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
104
|
+
{ method: "PATCH", path: "/v1/update-agent-tool/:id", sdk: "agentTool.update", request: "UpdateAgentToolInput", response: "AgentTool", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [409, "agent_tool_limit"], [409, "agent_tool_name_conflict"], [409, "agent_tool_name_taken"], [422, "validation_error"], [429, "rate_limit_exceeded"]] },
|
|
105
|
+
{ method: "DELETE", path: "/v1/delete-agent-tool/:id", sdk: "agentTool.delete", request: "none", response: "OkResponse", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] },
|
|
106
|
+
{ method: "POST", path: "/v1/test-agent-tool/:id", sdk: "agentTool.test", request: "TestAgentToolInput", response: "TestAgentToolResponse", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"], [429, "rate_limited"]] },
|
|
107
|
+
{ method: "GET", path: "/v1/list-events", sdk: "event.list", request: "ListEventsParams", response: "Page<WebhookEventEnvelope>", status: 200, errors: [[400, "validation_error"], [401, "unauthorized"], [403, "insufficient_scope"], [429, "rate_limit_exceeded"]] },
|
|
108
|
+
{ method: "GET", path: "/v1/get-event/:id", sdk: "event.get", request: "none", response: "WebhookEventEnvelope", status: 200, errors: [[401, "unauthorized"], [403, "insufficient_scope"], [404, "not_found"], [429, "rate_limit_exceeded"]] }
|
|
76
109
|
];
|
|
77
110
|
|
|
78
111
|
// src/client.ts
|
|
@@ -96,6 +129,8 @@ var Replicer = class {
|
|
|
96
129
|
}
|
|
97
130
|
call = {
|
|
98
131
|
createPhoneCall: (input) => this.request("call.createPhoneCall", { body: input }),
|
|
132
|
+
/** Test keys only: simulates an inbound call to the agent of one of your numbers; `call.ended` and `call.analyzed` follow with `livemode: false`. */
|
|
133
|
+
simulateInbound: (input) => this.request("call.simulateInbound", { body: input }),
|
|
99
134
|
cancel: (call_id) => this.request("call.cancel", { body: { call_id } }),
|
|
100
135
|
cancelCampaignPending: (campaign_id) => this.request("call.cancelCampaignPending", { body: { campaign_id } }),
|
|
101
136
|
list: (params) => this.request("call.list", { query: params }),
|
|
@@ -113,7 +148,11 @@ var Replicer = class {
|
|
|
113
148
|
/** Your organization's phone numbers; `id` is the `from_number_id` for `call.createPhoneCall`. */
|
|
114
149
|
list: (params) => this.request("phoneNumber.list", { query: params }),
|
|
115
150
|
provisionInbound: (input) => this.request("phoneNumber.provisionInbound", { body: input }),
|
|
116
|
-
deprovisionInbound: (id, trunk_id, rule_id) => this.request("phoneNumber.deprovisionInbound", { params: { id }, query: { trunk_id, rule_id } })
|
|
151
|
+
deprovisionInbound: (id, trunk_id, rule_id) => this.request("phoneNumber.deprovisionInbound", { params: { id }, query: { trunk_id, rule_id } }),
|
|
152
|
+
/** Connects a number you own (SIP trunk or forwarding). Live keys only. Not idempotent: a number already connected → `409 conflict`. Search, purchase and release stay in the dashboard. */
|
|
153
|
+
import: (input) => this.request("phoneNumber.import", { body: input }),
|
|
154
|
+
/** Sets (or clears, with `null`) the fallback number (inbound calls over the concurrent-call limit, or that the agent cannot take, are forwarded there) and/or the inbound agent. Live keys only. */
|
|
155
|
+
update: (id, input) => this.request("phoneNumber.update", { params: { id }, body: input })
|
|
117
156
|
};
|
|
118
157
|
knowledgeBase = {
|
|
119
158
|
create: (input) => this.request("knowledgeBase.create", { body: input }),
|
|
@@ -156,14 +195,37 @@ var Replicer = class {
|
|
|
156
195
|
create: (input) => this.request("contact.create", { body: input })
|
|
157
196
|
};
|
|
158
197
|
agent = {
|
|
159
|
-
list: (params) => this.request("agent.list", { query: params })
|
|
198
|
+
list: (params) => this.request("agent.list", { query: params }),
|
|
199
|
+
get: (id) => this.request("agent.get", { params: { id } }),
|
|
200
|
+
/** Live keys only. Not idempotent. Basic agents only: workflow agents and AI-written prompts stay in the dashboard. */
|
|
201
|
+
create: (input) => this.request("agent.create", { body: input }),
|
|
202
|
+
/** Live keys only. */
|
|
203
|
+
update: (id, input) => this.request("agent.update", { params: { id }, body: input }),
|
|
204
|
+
/** Live keys only. `409 agent_in_use` while a scheduled, running or paused campaign uses the agent. Reactivate with `update`. */
|
|
205
|
+
deactivate: (id) => this.request("agent.deactivate", { params: { id }, body: {} })
|
|
160
206
|
};
|
|
161
207
|
calendar = {
|
|
208
|
+
/** Active calendars with their active event types: the source of `calendar_id` and `event_type_id`. */
|
|
209
|
+
listCalendars: (params) => this.request("calendar.listCalendars", { query: params }),
|
|
210
|
+
/** Creates a calendar, optionally with its event types and weekly hours. Not idempotent: a retried create makes a second calendar. */
|
|
211
|
+
create: (input) => this.request("calendar.create", { body: input }),
|
|
212
|
+
/** Edits a calendar. `availability` replaces all weekly hours; `is_active: false` deactivates it (there is no delete). */
|
|
213
|
+
update: (id, input) => this.request("calendar.update", { params: { id }, body: input }),
|
|
214
|
+
/** Adds an event type to a calendar. Not idempotent. */
|
|
215
|
+
createEventType: (input) => this.request("calendar.createEventType", { body: input }),
|
|
216
|
+
/** Edits an event type; `is_active: false` deactivates it (there is no delete). */
|
|
217
|
+
updateEventType: (id, input) => this.request("calendar.updateEventType", { params: { id }, body: input }),
|
|
162
218
|
listEvents: (params) => this.request("calendar.listEvents", { query: params }),
|
|
163
|
-
createEvent: (input) => this.request("calendar.createEvent", { body: input })
|
|
219
|
+
createEvent: (input) => this.request("calendar.createEvent", { body: input }),
|
|
220
|
+
/** Reschedules a confirmed event (`start_time`) and/or edits customer fields, notes and metadata. */
|
|
221
|
+
updateEvent: (id, input) => this.request("calendar.updateEvent", { params: { id }, body: input }),
|
|
222
|
+
/** Soft cancel: the event stays listed with status `cancelled`. Cancelling twice is a no-op. */
|
|
223
|
+
cancelEvent: (id) => this.request("calendar.cancelEvent", { params: { id }, body: {} })
|
|
164
224
|
};
|
|
165
225
|
message = {
|
|
166
226
|
list: (params) => this.request("message.list", { query: params }),
|
|
227
|
+
/** One message by id (the `id` of a send response), with its current delivery `status`. */
|
|
228
|
+
get: (id) => this.request("message.get", { params: { id } }),
|
|
167
229
|
sendSms: (input) => this.request("message.sendSms", { body: input }),
|
|
168
230
|
sendWhatsapp: (input) => this.request("message.sendWhatsapp", { body: input }),
|
|
169
231
|
sendEmail: (input) => this.request("message.sendEmail", { body: input })
|
|
@@ -173,6 +235,38 @@ var Replicer = class {
|
|
|
173
235
|
list: (params) => this.request("tts.list", { query: params }),
|
|
174
236
|
get: (id) => this.request("tts.get", { params: { id } })
|
|
175
237
|
};
|
|
238
|
+
webhookEndpoint = {
|
|
239
|
+
/** Resolves with the signing `secret`, shown only here and in `rotateSecret`. */
|
|
240
|
+
create: (input) => this.request("webhookEndpoint.create", { body: input }),
|
|
241
|
+
list: (params) => this.request("webhookEndpoint.list", { query: params }),
|
|
242
|
+
get: (id) => this.request("webhookEndpoint.get", { params: { id } }),
|
|
243
|
+
update: (id, input) => this.request("webhookEndpoint.update", { params: { id }, body: input }),
|
|
244
|
+
delete: (id) => this.request("webhookEndpoint.delete", { params: { id } }),
|
|
245
|
+
/** New secret now; the previous one keeps signing deliveries for 24 hours. */
|
|
246
|
+
rotateSecret: (id) => this.request("webhookEndpoint.rotateSecret", { params: { id }, body: {} }),
|
|
247
|
+
/** Sends a test event (`livemode: false`) and waits up to 12 seconds for its first attempt. */
|
|
248
|
+
test: (id, input) => this.request("webhookEndpoint.test", { params: { id }, body: input ?? {} }),
|
|
249
|
+
listDeliveries: (params) => this.request("webhookEndpoint.listDeliveries", { query: params }),
|
|
250
|
+
/** HTTP attempts of one delivery, oldest first. */
|
|
251
|
+
listDeliveryAttempts: (params) => this.request("webhookEndpoint.listDeliveryAttempts", { query: params }),
|
|
252
|
+
/** Sends the event of a delivery again (same event id and body) as a new delivery. Events from the last 30 days only. */
|
|
253
|
+
redeliver: (deliveryId) => this.request("webhookEndpoint.redeliver", { params: { id: deliveryId }, body: {} })
|
|
254
|
+
};
|
|
255
|
+
agentTool = {
|
|
256
|
+
/** A signed API tool of an agent; requests are signed with the secret of `webhook_endpoint_id`. */
|
|
257
|
+
create: (input) => this.request("agentTool.create", { body: input }),
|
|
258
|
+
list: (params) => this.request("agentTool.list", { query: params }),
|
|
259
|
+
get: (id) => this.request("agentTool.get", { params: { id } }),
|
|
260
|
+
update: (id, input) => this.request("agentTool.update", { params: { id }, body: input }),
|
|
261
|
+
delete: (id) => this.request("agentTool.delete", { params: { id } }),
|
|
262
|
+
/** Sends one signed sample call to the tool URL and reports the outcome. */
|
|
263
|
+
test: (id, input) => this.request("agentTool.test", { params: { id }, body: input ?? {} })
|
|
264
|
+
};
|
|
265
|
+
event = {
|
|
266
|
+
/** Events of the last 30 days as delivered (each item is the parsed envelope). */
|
|
267
|
+
list: (params) => this.request("event.list", { query: params }),
|
|
268
|
+
get: (id) => this.request("event.get", { params: { id } })
|
|
269
|
+
};
|
|
176
270
|
async request(sdk, opts = {}) {
|
|
177
271
|
const route = ROUTE_BY_SDK.get(sdk);
|
|
178
272
|
if (!route) throw new Error(`Replicer: unknown route ${sdk}`);
|
package/dist/tools.cjs
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/tools.ts
|
|
21
|
+
var tools_exports = {};
|
|
22
|
+
__export(tools_exports, {
|
|
23
|
+
DEFAULT_TOOL_TOLERANCE_SECONDS: () => DEFAULT_TOOL_TOLERANCE_SECONDS,
|
|
24
|
+
TOOL_CALL_ID_HEADER: () => TOOL_CALL_ID_HEADER,
|
|
25
|
+
TOOL_NAME_HEADER: () => TOOL_NAME_HEADER,
|
|
26
|
+
TOOL_SIGNATURE_HEADER: () => TOOL_SIGNATURE_HEADER,
|
|
27
|
+
ToolSignatureError: () => ToolSignatureError,
|
|
28
|
+
createToolCallProcessor: () => createToolCallProcessor,
|
|
29
|
+
createToolHandler: () => createToolHandler,
|
|
30
|
+
handleToolCall: () => handleToolCall,
|
|
31
|
+
verifyToolCall: () => verifyToolCall
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(tools_exports);
|
|
34
|
+
|
|
35
|
+
// src/signature.ts
|
|
36
|
+
var import_node_crypto = require("crypto");
|
|
37
|
+
var SIGNATURE_HEADER = "Replicer-Signature";
|
|
38
|
+
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
39
|
+
var HEX_SHA256 = /^[0-9a-f]{64}$/i;
|
|
40
|
+
var UNIX_SECONDS = /^\d{1,12}$/;
|
|
41
|
+
function parseHeader(header) {
|
|
42
|
+
let timestamp = null;
|
|
43
|
+
const signatures = [];
|
|
44
|
+
for (const part of header.split(",")) {
|
|
45
|
+
const eq = part.indexOf("=");
|
|
46
|
+
if (eq <= 0) continue;
|
|
47
|
+
const key = part.slice(0, eq).trim();
|
|
48
|
+
const value = part.slice(eq + 1).trim();
|
|
49
|
+
if (key === "t") {
|
|
50
|
+
if (timestamp !== null || !UNIX_SECONDS.test(value)) return null;
|
|
51
|
+
timestamp = Number(value);
|
|
52
|
+
} else if (key === "v1" && HEX_SHA256.test(value)) {
|
|
53
|
+
signatures.push(Buffer.from(value, "hex"));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (timestamp === null || signatures.length === 0) return null;
|
|
57
|
+
return { timestamp, signatures };
|
|
58
|
+
}
|
|
59
|
+
function sign(secret, timestamp, payload) {
|
|
60
|
+
return (0, import_node_crypto.createHmac)("sha256", secret).update(`${timestamp}.`).update(payload).digest();
|
|
61
|
+
}
|
|
62
|
+
function verifySignatureHeader(input) {
|
|
63
|
+
if (!input || typeof input.header !== "string") return false;
|
|
64
|
+
const payload = input.payload;
|
|
65
|
+
if (typeof payload !== "string" && !(payload instanceof Uint8Array)) return false;
|
|
66
|
+
const secrets = [input.secret, ...Array.isArray(input.secrets) ? input.secrets : []].filter((s) => typeof s === "string" && s !== "");
|
|
67
|
+
if (secrets.length === 0) return false;
|
|
68
|
+
const parsed = parseHeader(input.header);
|
|
69
|
+
if (!parsed) return false;
|
|
70
|
+
const tolerance = typeof input.toleranceSeconds === "number" && Number.isFinite(input.toleranceSeconds) && input.toleranceSeconds >= 0 ? input.toleranceSeconds : DEFAULT_TOLERANCE_SECONDS;
|
|
71
|
+
const nowMs = (input.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
72
|
+
if (!Number.isFinite(nowMs)) return false;
|
|
73
|
+
if (Math.abs(nowMs / 1e3 - parsed.timestamp) > tolerance) return false;
|
|
74
|
+
let match = false;
|
|
75
|
+
for (const secret of secrets) {
|
|
76
|
+
const expected = sign(secret, parsed.timestamp, payload);
|
|
77
|
+
for (const received of parsed.signatures) {
|
|
78
|
+
if ((0, import_node_crypto.timingSafeEqual)(expected, received)) match = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return match;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/tools.ts
|
|
85
|
+
var TOOL_SIGNATURE_HEADER = SIGNATURE_HEADER;
|
|
86
|
+
var TOOL_CALL_ID_HEADER = "Replicer-Tool-Call-Id";
|
|
87
|
+
var TOOL_NAME_HEADER = "Replicer-Tool-Name";
|
|
88
|
+
var DEFAULT_TOOL_TOLERANCE_SECONDS = DEFAULT_TOLERANCE_SECONDS;
|
|
89
|
+
var ToolSignatureError = class extends Error {
|
|
90
|
+
constructor(message) {
|
|
91
|
+
super(message);
|
|
92
|
+
this.name = "ToolSignatureError";
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
function verifyToolCall(input) {
|
|
96
|
+
if (!verifySignatureHeader(input)) {
|
|
97
|
+
throw new ToolSignatureError("Invalid tool call signature");
|
|
98
|
+
}
|
|
99
|
+
const text = typeof input.payload === "string" ? input.payload : new TextDecoder().decode(input.payload);
|
|
100
|
+
let parsed;
|
|
101
|
+
try {
|
|
102
|
+
parsed = JSON.parse(text);
|
|
103
|
+
} catch {
|
|
104
|
+
throw new ToolSignatureError("Tool call payload is not valid JSON");
|
|
105
|
+
}
|
|
106
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
107
|
+
throw new ToolSignatureError("Tool call payload is not a JSON object");
|
|
108
|
+
}
|
|
109
|
+
const call = parsed;
|
|
110
|
+
if (call.object !== "tool_call" || typeof call.tool?.name !== "string") {
|
|
111
|
+
throw new ToolSignatureError("Payload is not a tool call");
|
|
112
|
+
}
|
|
113
|
+
return call;
|
|
114
|
+
}
|
|
115
|
+
function readHeader(headers, name) {
|
|
116
|
+
if (typeof headers.get === "function") {
|
|
117
|
+
return headers.get(name) ?? void 0;
|
|
118
|
+
}
|
|
119
|
+
const wanted = name.toLowerCase();
|
|
120
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
121
|
+
if (key.toLowerCase() === wanted) return Array.isArray(value) ? value.join(",") : value;
|
|
122
|
+
}
|
|
123
|
+
return void 0;
|
|
124
|
+
}
|
|
125
|
+
function createToolCallProcessor(options) {
|
|
126
|
+
return async ({ rawBody, headers, now }) => {
|
|
127
|
+
let call;
|
|
128
|
+
try {
|
|
129
|
+
call = verifyToolCall({
|
|
130
|
+
payload: rawBody,
|
|
131
|
+
header: readHeader(headers, SIGNATURE_HEADER),
|
|
132
|
+
secret: options.secret,
|
|
133
|
+
secrets: options.secrets,
|
|
134
|
+
toleranceSeconds: options.toleranceSeconds,
|
|
135
|
+
now
|
|
136
|
+
});
|
|
137
|
+
} catch {
|
|
138
|
+
return { status: 401, body: { error: "Invalid signature", code: "invalid_signature" } };
|
|
139
|
+
}
|
|
140
|
+
const fn = Object.prototype.hasOwnProperty.call(options.tools, call.tool.name) ? options.tools[call.tool.name] : void 0;
|
|
141
|
+
if (!fn) {
|
|
142
|
+
return { status: 404, body: { error: "Unknown tool", code: "unknown_tool" } };
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const result = await fn(call.arguments, call);
|
|
146
|
+
return { status: 200, body: { result: result === void 0 ? null : result } };
|
|
147
|
+
} catch (error) {
|
|
148
|
+
try {
|
|
149
|
+
options.onError?.(error, call);
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
return { status: 500, body: { error: "Tool failed", code: "tool_error" } };
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function handleToolCall(input) {
|
|
157
|
+
const { rawBody, headers, now, ...options } = input;
|
|
158
|
+
return createToolCallProcessor(options)({ rawBody, headers, now });
|
|
159
|
+
}
|
|
160
|
+
function createToolHandler(options) {
|
|
161
|
+
const process = createToolCallProcessor(options);
|
|
162
|
+
return async (request) => {
|
|
163
|
+
const rawBody = new Uint8Array(await request.arrayBuffer());
|
|
164
|
+
const { status, body } = await process({ rawBody, headers: request.headers });
|
|
165
|
+
return new Response(JSON.stringify(body), { status, headers: { "Content-Type": "application/json" } });
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
169
|
+
0 && (module.exports = {
|
|
170
|
+
DEFAULT_TOOL_TOLERANCE_SECONDS,
|
|
171
|
+
TOOL_CALL_ID_HEADER,
|
|
172
|
+
TOOL_NAME_HEADER,
|
|
173
|
+
TOOL_SIGNATURE_HEADER,
|
|
174
|
+
ToolSignatureError,
|
|
175
|
+
createToolCallProcessor,
|
|
176
|
+
createToolHandler,
|
|
177
|
+
handleToolCall,
|
|
178
|
+
verifyToolCall
|
|
179
|
+
});
|
package/dist/tools.d.cts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { b6 as ToolCall } from './types-DXQsrvOU.cjs';
|
|
2
|
+
export { b7 as ToolCallResponse } from './types-DXQsrvOU.cjs';
|
|
3
|
+
|
|
4
|
+
/** Name of the signature header (same as webhooks). */
|
|
5
|
+
declare const TOOL_SIGNATURE_HEADER = "Replicer-Signature";
|
|
6
|
+
/** Header carrying the unique id of this invocation (`tcall_…`, same as the body `id`). */
|
|
7
|
+
declare const TOOL_CALL_ID_HEADER = "Replicer-Tool-Call-Id";
|
|
8
|
+
/** Header carrying the tool name. */
|
|
9
|
+
declare const TOOL_NAME_HEADER = "Replicer-Tool-Name";
|
|
10
|
+
/** Default accepted distance, in seconds, between the signed timestamp and now. */
|
|
11
|
+
declare const DEFAULT_TOOL_TOLERANCE_SECONDS = 300;
|
|
12
|
+
/** Thrown by `verifyToolCall` for a missing, invalid or expired signature, or a body that is not a tool call. */
|
|
13
|
+
declare class ToolSignatureError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
interface VerifyToolCallInput {
|
|
17
|
+
/** The raw request body exactly as received (never re-serialized JSON). */
|
|
18
|
+
payload: string | Uint8Array;
|
|
19
|
+
/** Value of the `Replicer-Signature` header. */
|
|
20
|
+
header: string | null | undefined;
|
|
21
|
+
/** The signing secret of the tool's webhook endpoint (`whsec_…`). One of `secret` / `secrets` is required. */
|
|
22
|
+
secret?: string;
|
|
23
|
+
/** Several secrets, any of which may match (the new and the old one during a rotation). */
|
|
24
|
+
secrets?: string[];
|
|
25
|
+
/** Maximum distance between the signed timestamp and now (default 300). */
|
|
26
|
+
toleranceSeconds?: number;
|
|
27
|
+
/** Current time (default `new Date()`), for tests. */
|
|
28
|
+
now?: Date;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Verify the signature, then parse the body as a tool call. Throws `ToolSignatureError` when the
|
|
32
|
+
* signature is missing, invalid or stale, or the body is not a JSON tool call.
|
|
33
|
+
*/
|
|
34
|
+
declare function verifyToolCall<Args = Record<string, unknown>>(input: VerifyToolCallInput): ToolCall<Args>;
|
|
35
|
+
/** A tool implementation: gets the typed arguments and the full call, returns the `result` the agent reads. */
|
|
36
|
+
type ToolFunction<Args = Record<string, unknown>> = (args: Args, call: ToolCall<Args>) => unknown | Promise<unknown>;
|
|
37
|
+
/** Map of tool name to implementation. Type the arguments per tool: `{ book_table: async (a: { time: string }) => … }`. */
|
|
38
|
+
type ToolMap = Record<string, ToolFunction<any>>;
|
|
39
|
+
interface ToolHandlerOptions<Tools extends ToolMap = ToolMap> {
|
|
40
|
+
secret?: string;
|
|
41
|
+
/** Several secrets, any of which may match (rotation overlap). */
|
|
42
|
+
secrets?: string[];
|
|
43
|
+
toleranceSeconds?: number;
|
|
44
|
+
tools: Tools;
|
|
45
|
+
/** Called with the error a tool threw (the client always gets a generic 500). */
|
|
46
|
+
onError?: (error: unknown, call: ToolCall) => void;
|
|
47
|
+
}
|
|
48
|
+
interface HandleToolCallInput {
|
|
49
|
+
rawBody: string | Uint8Array;
|
|
50
|
+
/** Request headers: a `Headers`, or a plain Node object (`req.headers`). */
|
|
51
|
+
headers: Headers | Record<string, string | string[] | undefined>;
|
|
52
|
+
now?: Date;
|
|
53
|
+
}
|
|
54
|
+
interface ToolHandlerResult {
|
|
55
|
+
status: number;
|
|
56
|
+
body: {
|
|
57
|
+
result: unknown;
|
|
58
|
+
} | {
|
|
59
|
+
error: string;
|
|
60
|
+
code: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Framework-agnostic handler for Express and plain Node: pass the raw body and the headers, send
|
|
65
|
+
* back `status` and `body` as JSON. 401 for a bad signature, 404 for an unknown tool, 500 (generic
|
|
66
|
+
* message) when the tool throws, else 200 `{ result }`.
|
|
67
|
+
*/
|
|
68
|
+
declare function createToolCallProcessor<Tools extends ToolMap>(options: ToolHandlerOptions<Tools>): (input: HandleToolCallInput) => Promise<ToolHandlerResult>;
|
|
69
|
+
/** One-shot variant of `createToolCallProcessor` for Express and plain Node. */
|
|
70
|
+
declare function handleToolCall<Tools extends ToolMap>(input: HandleToolCallInput & ToolHandlerOptions<Tools>): Promise<ToolHandlerResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Fetch-API handler (Next.js route handlers, Hono, Cloudflare Workers, Deno, Bun):
|
|
73
|
+
* `export const POST = createToolHandler({ secret, tools: { book_table: async (args, call) => … } })`.
|
|
74
|
+
* It verifies the signature, routes on `tool.name` and answers `{ result }` (401 bad signature,
|
|
75
|
+
* 404 unknown tool, 500 when the tool throws, without leaking the error message).
|
|
76
|
+
*/
|
|
77
|
+
declare function createToolHandler<Tools extends ToolMap>(options: ToolHandlerOptions<Tools>): (request: Request) => Promise<Response>;
|
|
78
|
+
|
|
79
|
+
export { DEFAULT_TOOL_TOLERANCE_SECONDS, type HandleToolCallInput, TOOL_CALL_ID_HEADER, TOOL_NAME_HEADER, TOOL_SIGNATURE_HEADER, ToolCall, type ToolFunction, type ToolHandlerOptions, type ToolHandlerResult, type ToolMap, ToolSignatureError, type VerifyToolCallInput, createToolCallProcessor, createToolHandler, handleToolCall, verifyToolCall };
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { b6 as ToolCall } from './types-DXQsrvOU.js';
|
|
2
|
+
export { b7 as ToolCallResponse } from './types-DXQsrvOU.js';
|
|
3
|
+
|
|
4
|
+
/** Name of the signature header (same as webhooks). */
|
|
5
|
+
declare const TOOL_SIGNATURE_HEADER = "Replicer-Signature";
|
|
6
|
+
/** Header carrying the unique id of this invocation (`tcall_…`, same as the body `id`). */
|
|
7
|
+
declare const TOOL_CALL_ID_HEADER = "Replicer-Tool-Call-Id";
|
|
8
|
+
/** Header carrying the tool name. */
|
|
9
|
+
declare const TOOL_NAME_HEADER = "Replicer-Tool-Name";
|
|
10
|
+
/** Default accepted distance, in seconds, between the signed timestamp and now. */
|
|
11
|
+
declare const DEFAULT_TOOL_TOLERANCE_SECONDS = 300;
|
|
12
|
+
/** Thrown by `verifyToolCall` for a missing, invalid or expired signature, or a body that is not a tool call. */
|
|
13
|
+
declare class ToolSignatureError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
interface VerifyToolCallInput {
|
|
17
|
+
/** The raw request body exactly as received (never re-serialized JSON). */
|
|
18
|
+
payload: string | Uint8Array;
|
|
19
|
+
/** Value of the `Replicer-Signature` header. */
|
|
20
|
+
header: string | null | undefined;
|
|
21
|
+
/** The signing secret of the tool's webhook endpoint (`whsec_…`). One of `secret` / `secrets` is required. */
|
|
22
|
+
secret?: string;
|
|
23
|
+
/** Several secrets, any of which may match (the new and the old one during a rotation). */
|
|
24
|
+
secrets?: string[];
|
|
25
|
+
/** Maximum distance between the signed timestamp and now (default 300). */
|
|
26
|
+
toleranceSeconds?: number;
|
|
27
|
+
/** Current time (default `new Date()`), for tests. */
|
|
28
|
+
now?: Date;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Verify the signature, then parse the body as a tool call. Throws `ToolSignatureError` when the
|
|
32
|
+
* signature is missing, invalid or stale, or the body is not a JSON tool call.
|
|
33
|
+
*/
|
|
34
|
+
declare function verifyToolCall<Args = Record<string, unknown>>(input: VerifyToolCallInput): ToolCall<Args>;
|
|
35
|
+
/** A tool implementation: gets the typed arguments and the full call, returns the `result` the agent reads. */
|
|
36
|
+
type ToolFunction<Args = Record<string, unknown>> = (args: Args, call: ToolCall<Args>) => unknown | Promise<unknown>;
|
|
37
|
+
/** Map of tool name to implementation. Type the arguments per tool: `{ book_table: async (a: { time: string }) => … }`. */
|
|
38
|
+
type ToolMap = Record<string, ToolFunction<any>>;
|
|
39
|
+
interface ToolHandlerOptions<Tools extends ToolMap = ToolMap> {
|
|
40
|
+
secret?: string;
|
|
41
|
+
/** Several secrets, any of which may match (rotation overlap). */
|
|
42
|
+
secrets?: string[];
|
|
43
|
+
toleranceSeconds?: number;
|
|
44
|
+
tools: Tools;
|
|
45
|
+
/** Called with the error a tool threw (the client always gets a generic 500). */
|
|
46
|
+
onError?: (error: unknown, call: ToolCall) => void;
|
|
47
|
+
}
|
|
48
|
+
interface HandleToolCallInput {
|
|
49
|
+
rawBody: string | Uint8Array;
|
|
50
|
+
/** Request headers: a `Headers`, or a plain Node object (`req.headers`). */
|
|
51
|
+
headers: Headers | Record<string, string | string[] | undefined>;
|
|
52
|
+
now?: Date;
|
|
53
|
+
}
|
|
54
|
+
interface ToolHandlerResult {
|
|
55
|
+
status: number;
|
|
56
|
+
body: {
|
|
57
|
+
result: unknown;
|
|
58
|
+
} | {
|
|
59
|
+
error: string;
|
|
60
|
+
code: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Framework-agnostic handler for Express and plain Node: pass the raw body and the headers, send
|
|
65
|
+
* back `status` and `body` as JSON. 401 for a bad signature, 404 for an unknown tool, 500 (generic
|
|
66
|
+
* message) when the tool throws, else 200 `{ result }`.
|
|
67
|
+
*/
|
|
68
|
+
declare function createToolCallProcessor<Tools extends ToolMap>(options: ToolHandlerOptions<Tools>): (input: HandleToolCallInput) => Promise<ToolHandlerResult>;
|
|
69
|
+
/** One-shot variant of `createToolCallProcessor` for Express and plain Node. */
|
|
70
|
+
declare function handleToolCall<Tools extends ToolMap>(input: HandleToolCallInput & ToolHandlerOptions<Tools>): Promise<ToolHandlerResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Fetch-API handler (Next.js route handlers, Hono, Cloudflare Workers, Deno, Bun):
|
|
73
|
+
* `export const POST = createToolHandler({ secret, tools: { book_table: async (args, call) => … } })`.
|
|
74
|
+
* It verifies the signature, routes on `tool.name` and answers `{ result }` (401 bad signature,
|
|
75
|
+
* 404 unknown tool, 500 when the tool throws, without leaking the error message).
|
|
76
|
+
*/
|
|
77
|
+
declare function createToolHandler<Tools extends ToolMap>(options: ToolHandlerOptions<Tools>): (request: Request) => Promise<Response>;
|
|
78
|
+
|
|
79
|
+
export { DEFAULT_TOOL_TOLERANCE_SECONDS, type HandleToolCallInput, TOOL_CALL_ID_HEADER, TOOL_NAME_HEADER, TOOL_SIGNATURE_HEADER, ToolCall, type ToolFunction, type ToolHandlerOptions, type ToolHandlerResult, type ToolMap, ToolSignatureError, type VerifyToolCallInput, createToolCallProcessor, createToolHandler, handleToolCall, verifyToolCall };
|