@spekoai/sdk 0.4.3 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +88 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/lib/client.d.ts +13 -1
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/lib/client.js +22 -2
- package/dist/lib/http.d.ts +12 -4
- package/dist/lib/http.d.ts.map +1 -1
- package/dist/lib/http.js +31 -14
- package/dist/lib/resources/agents.d.ts +12 -2
- package/dist/lib/resources/agents.d.ts.map +1 -1
- package/dist/lib/resources/agents.js +12 -4
- package/dist/lib/resources/calls.d.ts +19 -1
- package/dist/lib/resources/calls.d.ts.map +1 -1
- package/dist/lib/resources/calls.js +22 -0
- package/dist/lib/resources/knowledge-bases.d.ts +1 -1
- package/dist/lib/resources/knowledge-bases.js +1 -1
- package/dist/lib/resources/phone-numbers.d.ts +2 -1
- package/dist/lib/resources/phone-numbers.d.ts.map +1 -1
- package/dist/lib/resources/phone-numbers.js +2 -1
- package/dist/lib/resources/realtime.d.ts +3 -5
- package/dist/lib/resources/realtime.d.ts.map +1 -1
- package/dist/lib/resources/realtime.js +829 -91
- package/dist/lib/resources/sessions.d.ts +53 -0
- package/dist/lib/resources/sessions.d.ts.map +1 -0
- package/dist/lib/resources/sessions.js +166 -0
- package/dist/lib/resources/sms.d.ts +80 -0
- package/dist/lib/resources/sms.d.ts.map +1 -0
- package/dist/lib/resources/sms.js +152 -0
- package/dist/lib/resources/synthesize.d.ts.map +1 -1
- package/dist/lib/resources/synthesize.js +12 -6
- package/dist/lib/resources/transcribe.d.ts.map +1 -1
- package/dist/lib/resources/transcribe.js +9 -2
- package/dist/lib/resources/voice.d.ts +283 -1
- package/dist/lib/resources/voice.d.ts.map +1 -1
- package/dist/lib/resources/voice.js +345 -0
- package/dist/lib/resources/webhooks.d.ts +25 -0
- package/dist/lib/resources/webhooks.d.ts.map +1 -0
- package/dist/lib/resources/webhooks.js +46 -0
- package/dist/lib/types/index.d.ts +998 -9
- package/dist/lib/types/index.d.ts.map +1 -1
- package/dist/lib/voice-contract.d.ts +280 -0
- package/dist/lib/voice-contract.d.ts.map +1 -0
- package/dist/lib/voice-contract.js +115 -0
- package/package.json +2 -1
- package/src/index.ts +212 -0
- package/src/lib/client.ts +169 -0
- package/src/lib/errors.ts +28 -0
- package/src/lib/http.ts +442 -0
- package/src/lib/resources/agents.ts +211 -0
- package/src/lib/resources/callbacks.ts +40 -0
- package/src/lib/resources/calls.ts +113 -0
- package/src/lib/resources/complete.ts +63 -0
- package/src/lib/resources/credits.ts +41 -0
- package/src/lib/resources/knowledge-bases.ts +199 -0
- package/src/lib/resources/phone-numbers.ts +109 -0
- package/src/lib/resources/realtime-globals.d.ts +31 -0
- package/src/lib/resources/realtime.spec.ts +565 -0
- package/src/lib/resources/realtime.ts +1169 -0
- package/src/lib/resources/sessions.ts +191 -0
- package/src/lib/resources/sms.ts +214 -0
- package/src/lib/resources/synthesize.ts +101 -0
- package/src/lib/resources/transcribe.ts +91 -0
- package/src/lib/resources/usage.ts +24 -0
- package/src/lib/resources/voice.ts +426 -0
- package/src/lib/resources/voices.ts +32 -0
- package/src/lib/resources/webhooks.ts +67 -0
- package/src/lib/types/index.ts +2409 -0
- package/src/lib/voice-contract.ts +358 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
export { Speko } from './lib/client.js';
|
|
2
|
+
export { SpekoApiError, SpekoAuthError, SpekoRateLimitError } from './lib/errors.js';
|
|
3
|
+
export type {
|
|
4
|
+
AgentAmbientClip,
|
|
5
|
+
AgentBackgroundAudio,
|
|
6
|
+
AgentCallListEntry,
|
|
7
|
+
AgentCallListPage,
|
|
8
|
+
AgentCallListParams,
|
|
9
|
+
AgentCreateParams,
|
|
10
|
+
AgentExtractionField,
|
|
11
|
+
AgentIntent,
|
|
12
|
+
AgentLifecycleWebhookCreate,
|
|
13
|
+
AgentLifecycleWebhookSerialized,
|
|
14
|
+
AgentLifecycleWebhookUpdate,
|
|
15
|
+
AgentLlmOptions,
|
|
16
|
+
AgentRow,
|
|
17
|
+
AgentStackPreferences,
|
|
18
|
+
AgentSttOptions,
|
|
19
|
+
AgentToolCreateParams,
|
|
20
|
+
AgentToolRow,
|
|
21
|
+
AgentToolSourceBuiltin,
|
|
22
|
+
AgentToolSourceCreate,
|
|
23
|
+
AgentToolSourceInline,
|
|
24
|
+
AgentToolSourceIntegration,
|
|
25
|
+
AgentToolSourceSerialized,
|
|
26
|
+
AgentToolSourceUpdate,
|
|
27
|
+
AgentToolSourceWebhookCreate,
|
|
28
|
+
AgentToolSourceWebhookSerialized,
|
|
29
|
+
AgentToolSourceWebhookUpdate,
|
|
30
|
+
AgentToolUpdateParams,
|
|
31
|
+
AgentUpdateParams,
|
|
32
|
+
AgentWebhookAuthHeader,
|
|
33
|
+
AgentWebhookAuthHeaderInput,
|
|
34
|
+
AgentWebhooksCreate,
|
|
35
|
+
AgentWebhooksSerialized,
|
|
36
|
+
AgentWebhooksUpdate,
|
|
37
|
+
AvailablePhoneNumber,
|
|
38
|
+
BlindTransferParams,
|
|
39
|
+
CallControlDialParams,
|
|
40
|
+
CallControlDialResult,
|
|
41
|
+
CallControlListParams,
|
|
42
|
+
CallCostLine,
|
|
43
|
+
CallDetail,
|
|
44
|
+
CallEvent,
|
|
45
|
+
CallRecording,
|
|
46
|
+
CallReport,
|
|
47
|
+
CallReportWebhookDelivery,
|
|
48
|
+
CallTranscriptEntry,
|
|
49
|
+
CallTransfer,
|
|
50
|
+
CallTransferResponse,
|
|
51
|
+
CancelScheduledCallbackParams,
|
|
52
|
+
CancelWarmTransferParams,
|
|
53
|
+
ChatMessage,
|
|
54
|
+
ChatTool,
|
|
55
|
+
ChatToolCall,
|
|
56
|
+
ChatToolChoice,
|
|
57
|
+
ChatToolExecutionMode,
|
|
58
|
+
ChatToolSource,
|
|
59
|
+
CompleteParams,
|
|
60
|
+
CompleteResult,
|
|
61
|
+
CompleteStreamEvent,
|
|
62
|
+
CompleteWarmTransferParams,
|
|
63
|
+
CreditLedgerEntry,
|
|
64
|
+
CreditLedgerKind,
|
|
65
|
+
CreditLedgerPage,
|
|
66
|
+
CreditLedgerQueryParams,
|
|
67
|
+
EndCallResult,
|
|
68
|
+
FinalizeCallReportParams,
|
|
69
|
+
FinalizeCallReportResult,
|
|
70
|
+
KeySource,
|
|
71
|
+
KnowledgeBaseCreateParams,
|
|
72
|
+
KnowledgeBaseDocumentCreateParams,
|
|
73
|
+
KnowledgeBaseDocumentCreateResult,
|
|
74
|
+
KnowledgeBaseDocumentPollOptions,
|
|
75
|
+
KnowledgeBaseDocumentRow,
|
|
76
|
+
KnowledgeBaseDocumentStatus,
|
|
77
|
+
KnowledgeBaseDocumentUploadParams,
|
|
78
|
+
KnowledgeBaseDocumentUploadSpec,
|
|
79
|
+
KnowledgeBaseListParams,
|
|
80
|
+
KnowledgeBaseRow,
|
|
81
|
+
OptimizeFor,
|
|
82
|
+
OrganizationBalance,
|
|
83
|
+
PhoneNumberCreateParams,
|
|
84
|
+
PhoneNumberDirection,
|
|
85
|
+
PhoneNumberImportSipTrunkParams,
|
|
86
|
+
PhoneNumberKybAttestationContract,
|
|
87
|
+
PhoneNumberKybAttestor,
|
|
88
|
+
PhoneNumberKybAuthorizedRepresentative,
|
|
89
|
+
PhoneNumberKybBusinessProfile,
|
|
90
|
+
PhoneNumberKybDeclaration,
|
|
91
|
+
PhoneNumberKybDraftParams,
|
|
92
|
+
PhoneNumberKybOverview,
|
|
93
|
+
PhoneNumberKybSlackNotificationStatus,
|
|
94
|
+
PhoneNumberKybStatus,
|
|
95
|
+
PhoneNumberKybSubmission,
|
|
96
|
+
PhoneNumberKybSubmissionStatus,
|
|
97
|
+
PhoneNumberKybSubmitParams,
|
|
98
|
+
PhoneNumberRow,
|
|
99
|
+
PhoneNumberSearchParams,
|
|
100
|
+
PhoneNumberSetupStatus,
|
|
101
|
+
PhoneNumberSmsAssignmentStatus,
|
|
102
|
+
PhoneNumberSource,
|
|
103
|
+
PhoneNumberUpdateParams,
|
|
104
|
+
PipelineConstraints,
|
|
105
|
+
RealtimeConnectParams,
|
|
106
|
+
RealtimeEventHandler,
|
|
107
|
+
RealtimeFrame,
|
|
108
|
+
RealtimeProvider,
|
|
109
|
+
RealtimeSessionHandle,
|
|
110
|
+
RealtimeToolSpec,
|
|
111
|
+
RoutingIntent,
|
|
112
|
+
ScheduledCallback,
|
|
113
|
+
ScheduledCallbackStatus,
|
|
114
|
+
ScheduledCallbacksListParams,
|
|
115
|
+
SessionStreamEvent,
|
|
116
|
+
SessionStreamOptions,
|
|
117
|
+
SessionTranscript,
|
|
118
|
+
SessionTranscriptEntry,
|
|
119
|
+
SmsBatch,
|
|
120
|
+
SmsBatchCreateParams,
|
|
121
|
+
SmsBatchRecipient,
|
|
122
|
+
SmsConsent,
|
|
123
|
+
SmsConsentInput,
|
|
124
|
+
SmsConsentListParams,
|
|
125
|
+
SmsConsentSource,
|
|
126
|
+
SmsConversation,
|
|
127
|
+
SmsConversationListParams,
|
|
128
|
+
SmsConversationNote,
|
|
129
|
+
SmsConversationSendParams,
|
|
130
|
+
SmsConversationUpdate,
|
|
131
|
+
SmsMessage,
|
|
132
|
+
SmsMessageDirection,
|
|
133
|
+
SmsMessageListParams,
|
|
134
|
+
SmsMessageOrigin,
|
|
135
|
+
SmsMessageStatus,
|
|
136
|
+
SmsPage,
|
|
137
|
+
SmsSegmentEstimate,
|
|
138
|
+
SmsSendParams,
|
|
139
|
+
SmsSettings,
|
|
140
|
+
SmsSettingsUpdate,
|
|
141
|
+
SmsStreamEvent,
|
|
142
|
+
SmsSuppression,
|
|
143
|
+
SpekoClientOptions,
|
|
144
|
+
SynthesizeOptions,
|
|
145
|
+
SynthesizeResult,
|
|
146
|
+
SynthesizeStreamResult,
|
|
147
|
+
TranscribeOptions,
|
|
148
|
+
TranscribeResult,
|
|
149
|
+
TranscribeStreamEvent,
|
|
150
|
+
UsageByProvider,
|
|
151
|
+
UsageQueryParams,
|
|
152
|
+
UsageSummary,
|
|
153
|
+
VoiceCatalogEntry,
|
|
154
|
+
VoiceDialParams,
|
|
155
|
+
VoiceDialResult,
|
|
156
|
+
VoicesListParams,
|
|
157
|
+
VoicesListResult,
|
|
158
|
+
VoicesProviderEntry,
|
|
159
|
+
WarmTransferDestination,
|
|
160
|
+
WarmTransferFallback,
|
|
161
|
+
WarmTransferFallbackResult,
|
|
162
|
+
WarmTransferParams,
|
|
163
|
+
WarmTransferVoicemailDetection,
|
|
164
|
+
WebhookDelivery,
|
|
165
|
+
WebhookDeliveryAttempt,
|
|
166
|
+
WebhookDeliveryDetail,
|
|
167
|
+
WebhookDeliveryEndpointOption,
|
|
168
|
+
WebhookDeliveryListParams,
|
|
169
|
+
WebhookDeliveryPage,
|
|
170
|
+
WebhookDeliveryStatus,
|
|
171
|
+
WebhookEndpoint,
|
|
172
|
+
WebhookEndpointAuthHeaderInput,
|
|
173
|
+
WebhookEndpointAuthHeaderUpdate,
|
|
174
|
+
WebhookEndpointInput,
|
|
175
|
+
WebhookEndpointUpdate,
|
|
176
|
+
WebhookEventType,
|
|
177
|
+
WebJoinParams,
|
|
178
|
+
WebJoinResult,
|
|
179
|
+
WorkspaceWebhookEventType,
|
|
180
|
+
} from './lib/types/index.js';
|
|
181
|
+
export type {
|
|
182
|
+
BridgeCommandPayload,
|
|
183
|
+
BrokerPresenceResource,
|
|
184
|
+
BrokerPresenceStatus,
|
|
185
|
+
CallCommand,
|
|
186
|
+
CallCommandPayload,
|
|
187
|
+
CallCommandResult,
|
|
188
|
+
CallDirection,
|
|
189
|
+
CallEventNotice,
|
|
190
|
+
CallEventResource,
|
|
191
|
+
CallEventType,
|
|
192
|
+
CallJoinCredentials,
|
|
193
|
+
CallLegKind,
|
|
194
|
+
CallLegResource,
|
|
195
|
+
CallLegStatus,
|
|
196
|
+
CallResource,
|
|
197
|
+
CallStatus,
|
|
198
|
+
DtmfCommandPayload,
|
|
199
|
+
HangupCommandPayload,
|
|
200
|
+
PresenceMessage,
|
|
201
|
+
RingOffer,
|
|
202
|
+
TransferCommandPayload,
|
|
203
|
+
VoiceErrorCode,
|
|
204
|
+
} from './lib/voice-contract.js';
|
|
205
|
+
export {
|
|
206
|
+
BROKER_ID_PATTERN,
|
|
207
|
+
CALL_COMMANDS,
|
|
208
|
+
CALL_EVENTS,
|
|
209
|
+
DTMF_PATTERN,
|
|
210
|
+
PRESENCE_STALE_AFTER_MS,
|
|
211
|
+
VOICE_ERROR_CODES,
|
|
212
|
+
} from './lib/voice-contract.js';
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { HttpClient } from './http.js';
|
|
2
|
+
import { Agents } from './resources/agents.js';
|
|
3
|
+
import { Callbacks } from './resources/callbacks.js';
|
|
4
|
+
import { Calls } from './resources/calls.js';
|
|
5
|
+
import { Complete } from './resources/complete.js';
|
|
6
|
+
import { Credits } from './resources/credits.js';
|
|
7
|
+
import { KnowledgeBases } from './resources/knowledge-bases.js';
|
|
8
|
+
import { PhoneNumbers } from './resources/phone-numbers.js';
|
|
9
|
+
import { Realtime } from './resources/realtime.js';
|
|
10
|
+
import { Sessions } from './resources/sessions.js';
|
|
11
|
+
import { Sms } from './resources/sms.js';
|
|
12
|
+
import { Synthesize } from './resources/synthesize.js';
|
|
13
|
+
import { Transcribe } from './resources/transcribe.js';
|
|
14
|
+
import { Usage } from './resources/usage.js';
|
|
15
|
+
import { CallControl, Voice } from './resources/voice.js';
|
|
16
|
+
import { Voices } from './resources/voices.js';
|
|
17
|
+
import { Webhooks } from './resources/webhooks.js';
|
|
18
|
+
import type {
|
|
19
|
+
CompleteParams,
|
|
20
|
+
CompleteResult,
|
|
21
|
+
CompleteStreamEvent,
|
|
22
|
+
SpekoClientOptions,
|
|
23
|
+
SynthesizeOptions,
|
|
24
|
+
SynthesizeResult,
|
|
25
|
+
SynthesizeStreamResult,
|
|
26
|
+
TranscribeOptions,
|
|
27
|
+
TranscribeResult,
|
|
28
|
+
TranscribeStreamEvent,
|
|
29
|
+
} from './types/index.js';
|
|
30
|
+
import { BROKER_ID_PATTERN } from './voice-contract.js';
|
|
31
|
+
|
|
32
|
+
const DEFAULT_BASE_URL = 'https://api.speko.dev';
|
|
33
|
+
const DEFAULT_TIMEOUT = 30_000;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Speko client — one API, every voice provider.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { Speko } from '@spekoai/sdk';
|
|
41
|
+
*
|
|
42
|
+
* const speko = new Speko({ apiKey: process.env.SPEKO_API_KEY });
|
|
43
|
+
*
|
|
44
|
+
* const { text, provider } = await speko.transcribe(audioBytes, {
|
|
45
|
+
* language: 'es-MX',
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export class Speko {
|
|
50
|
+
readonly usage: Usage;
|
|
51
|
+
readonly credits: Credits;
|
|
52
|
+
readonly realtime: Realtime;
|
|
53
|
+
readonly voice: Voice;
|
|
54
|
+
/**
|
|
55
|
+
* Programmable voice: `controlId`-addressed call control for human calls,
|
|
56
|
+
* plus broker presence. See {@link CallControl} for the Telnyx Call Control
|
|
57
|
+
* mapping — including where it deliberately differs.
|
|
58
|
+
*/
|
|
59
|
+
readonly callControl: CallControl;
|
|
60
|
+
readonly voices: Voices;
|
|
61
|
+
readonly phoneNumbers: PhoneNumbers;
|
|
62
|
+
readonly agents: Agents;
|
|
63
|
+
readonly knowledgeBases: KnowledgeBases;
|
|
64
|
+
readonly calls: Calls;
|
|
65
|
+
readonly callbacks: Callbacks;
|
|
66
|
+
readonly sessions: Sessions;
|
|
67
|
+
readonly webhooks: Webhooks;
|
|
68
|
+
readonly sms: Sms;
|
|
69
|
+
|
|
70
|
+
private readonly transcribeResource: Transcribe;
|
|
71
|
+
private readonly synthesizeResource: Synthesize;
|
|
72
|
+
private readonly completeResource: Complete;
|
|
73
|
+
|
|
74
|
+
constructor(options: SpekoClientOptions) {
|
|
75
|
+
if (!options.apiKey) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
'Speko: apiKey is required. Get one at https://platform.speko.dev/agents/keys',
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (options.brokerId !== undefined && !BROKER_ID_PATTERN.test(options.brokerId)) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
'Speko: brokerId must start with a letter or digit and contain only letters, digits, dot, underscore, or hyphen (max 128 characters)',
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const http = new HttpClient({
|
|
87
|
+
baseUrl: options.baseUrl ?? options.baseURL ?? DEFAULT_BASE_URL,
|
|
88
|
+
apiKey: options.apiKey,
|
|
89
|
+
timeout: options.timeout ?? DEFAULT_TIMEOUT,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
this.usage = new Usage(http);
|
|
93
|
+
this.credits = new Credits(http);
|
|
94
|
+
this.realtime = new Realtime(http);
|
|
95
|
+
this.voice = new Voice(http);
|
|
96
|
+
this.callControl = new CallControl(http, options.brokerId);
|
|
97
|
+
this.voices = new Voices(http);
|
|
98
|
+
this.phoneNumbers = new PhoneNumbers(http);
|
|
99
|
+
this.agents = new Agents(http);
|
|
100
|
+
this.knowledgeBases = new KnowledgeBases(http);
|
|
101
|
+
this.calls = new Calls(http);
|
|
102
|
+
this.callbacks = new Callbacks(http);
|
|
103
|
+
this.sessions = new Sessions(http);
|
|
104
|
+
this.webhooks = new Webhooks(http);
|
|
105
|
+
this.sms = new Sms(http);
|
|
106
|
+
this.transcribeResource = new Transcribe(http);
|
|
107
|
+
this.synthesizeResource = new Synthesize(http);
|
|
108
|
+
this.completeResource = new Complete(http);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Transcribe audio. The router picks the best STT provider for your
|
|
113
|
+
* `(language, region, optimizeFor)` and fails over automatically.
|
|
114
|
+
*
|
|
115
|
+
* Pass an `AbortSignal` to cancel the in-flight request — useful when a
|
|
116
|
+
* calling framework (e.g. LiveKit Agents) tears down a session mid-call.
|
|
117
|
+
*/
|
|
118
|
+
transcribe(
|
|
119
|
+
audio: Uint8Array,
|
|
120
|
+
options: TranscribeOptions,
|
|
121
|
+
abortSignal?: AbortSignal,
|
|
122
|
+
): Promise<TranscribeResult> {
|
|
123
|
+
return this.transcribeResource.call(audio, options, abortSignal);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
transcribeStream(
|
|
127
|
+
audio: Uint8Array,
|
|
128
|
+
options: TranscribeOptions,
|
|
129
|
+
abortSignal?: AbortSignal,
|
|
130
|
+
): AsyncIterableIterator<TranscribeStreamEvent> {
|
|
131
|
+
return this.transcribeResource.stream(audio, options, abortSignal);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Synthesize text into audio. The router picks the best TTS provider and
|
|
136
|
+
* fails over automatically. The result includes the audio bytes plus the
|
|
137
|
+
* provider's native content type.
|
|
138
|
+
*/
|
|
139
|
+
synthesize(
|
|
140
|
+
text: string,
|
|
141
|
+
options: SynthesizeOptions,
|
|
142
|
+
abortSignal?: AbortSignal,
|
|
143
|
+
): Promise<SynthesizeResult> {
|
|
144
|
+
return this.synthesizeResource.call(text, options, abortSignal);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
synthesizeStream(
|
|
148
|
+
text: string,
|
|
149
|
+
options: SynthesizeOptions,
|
|
150
|
+
abortSignal?: AbortSignal,
|
|
151
|
+
): Promise<SynthesizeStreamResult> {
|
|
152
|
+
return this.synthesizeResource.stream(text, options, abortSignal);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Run an LLM completion. The router picks the best LLM provider and fails
|
|
157
|
+
* over automatically.
|
|
158
|
+
*/
|
|
159
|
+
complete(params: CompleteParams, abortSignal?: AbortSignal): Promise<CompleteResult> {
|
|
160
|
+
return this.completeResource.call(params, abortSignal);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
completeStream(
|
|
164
|
+
params: CompleteParams,
|
|
165
|
+
abortSignal?: AbortSignal,
|
|
166
|
+
): AsyncIterableIterator<CompleteStreamEvent> {
|
|
167
|
+
return this.completeResource.stream(params, abortSignal);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class SpekoApiError extends Error {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
readonly code: string;
|
|
4
|
+
|
|
5
|
+
constructor(message: string, status: number, code: string) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'SpekoApiError';
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class SpekoAuthError extends SpekoApiError {
|
|
14
|
+
constructor(message = 'Invalid or missing API key') {
|
|
15
|
+
super(message, 401, 'AUTH_ERROR');
|
|
16
|
+
this.name = 'SpekoAuthError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class SpekoRateLimitError extends SpekoApiError {
|
|
21
|
+
readonly retryAfter: number | null;
|
|
22
|
+
|
|
23
|
+
constructor(message = 'Rate limit exceeded', retryAfter: number | null = null) {
|
|
24
|
+
super(message, 429, 'RATE_LIMITED');
|
|
25
|
+
this.name = 'SpekoRateLimitError';
|
|
26
|
+
this.retryAfter = retryAfter;
|
|
27
|
+
}
|
|
28
|
+
}
|