@spekoai/sdk 0.2.1 โ 0.4.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/CHANGELOG.md +26 -0
- package/README.md +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/client.d.ts +12 -1
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/lib/client.js +21 -0
- package/dist/lib/http.d.ts +15 -0
- package/dist/lib/http.d.ts.map +1 -1
- package/dist/lib/http.js +169 -0
- package/dist/lib/resources/agents.d.ts +68 -0
- package/dist/lib/resources/agents.d.ts.map +1 -0
- package/dist/lib/resources/agents.js +90 -0
- package/dist/lib/resources/complete.d.ts +2 -1
- package/dist/lib/resources/complete.d.ts.map +1 -1
- package/dist/lib/resources/complete.js +27 -1
- package/dist/lib/resources/credits.d.ts +1 -2
- package/dist/lib/resources/credits.d.ts.map +1 -1
- package/dist/lib/resources/credits.js +1 -2
- package/dist/lib/resources/knowledge-bases.d.ts +60 -0
- package/dist/lib/resources/knowledge-bases.d.ts.map +1 -0
- package/dist/lib/resources/knowledge-bases.js +138 -0
- package/dist/lib/resources/phone-numbers.d.ts +49 -0
- package/dist/lib/resources/phone-numbers.d.ts.map +1 -0
- package/dist/lib/resources/phone-numbers.js +66 -0
- package/dist/lib/resources/synthesize.d.ts +2 -1
- package/dist/lib/resources/synthesize.d.ts.map +1 -1
- package/dist/lib/resources/synthesize.js +31 -3
- package/dist/lib/resources/transcribe.d.ts +2 -1
- package/dist/lib/resources/transcribe.d.ts.map +1 -1
- package/dist/lib/resources/transcribe.js +32 -1
- package/dist/lib/resources/voice.d.ts +29 -0
- package/dist/lib/resources/voice.d.ts.map +1 -0
- package/dist/lib/resources/voice.js +30 -0
- package/dist/lib/types/index.d.ts +411 -5
- package/dist/lib/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## 0.4.0 (2026-05-12)
|
|
2
|
+
|
|
3
|
+
### ๐ Features
|
|
4
|
+
|
|
5
|
+
- **sdk:** add `KnowledgeBases` resource โ `create`, `list`, `get`, `delete`, document CRUD (`listDocuments`, `getDocument`, `createDocument`, `finalizeDocument`, `deleteDocument`), plus ergonomic wrappers `uploadDocument` (3 round-trips collapsed into one) and `pollDocumentReady` (default 2 min timeout). Accessible as `speko.knowledgeBases`.
|
|
6
|
+
- **sdk:** add `Agents` resource โ full CRUD plus `attachPhoneNumber` / `detachPhoneNumber` helpers that route through `PATCH /v1/phone-numbers/:id`. Sub-resource `speko.agents.tools` mirrors the `/v1/agents/:agentId/tools` CRUD with typed inline / webhook / builtin source variants.
|
|
7
|
+
- **sdk:** narrower `AgentIntent.optimizeFor` union (`'latency' | 'quality' | 'cost'`) reflecting the actual server schema for agents โ distinct from the broader `RoutingIntent.optimizeFor`.
|
|
8
|
+
|
|
9
|
+
### โค๏ธ Thank You
|
|
10
|
+
|
|
11
|
+
- Baymurat785 @Baymurat785
|
|
12
|
+
- Claude Opus 4.7 (1M context)
|
|
13
|
+
|
|
14
|
+
## 0.3.0 (2026-05-02)
|
|
15
|
+
|
|
16
|
+
### ๐ Features
|
|
17
|
+
|
|
18
|
+
- **adapter-livekit:** wire tool calls through /v1/complete ([#105](https://github.com/SpekoAI/platform/pull/105))
|
|
19
|
+
- **dashboard:** /phone-numbers page โ buy + edit + release US numbers ([ec3d541](https://github.com/SpekoAI/platform/commit/ec3d541))
|
|
20
|
+
- **telephony:** Telnyx outbound + inbound + phone number CRUD ([c5cc1f0](https://github.com/SpekoAI/platform/commit/c5cc1f0))
|
|
21
|
+
|
|
22
|
+
### โค๏ธ Thank You
|
|
23
|
+
|
|
24
|
+
- Baymurat785 @Baymurat785
|
|
25
|
+
- Claude Opus 4.7 (1M context)
|
|
26
|
+
|
|
1
27
|
# Changelog
|
|
2
28
|
|
|
3
29
|
All notable changes to `@spekoai/sdk` will be documented in this file.
|
package/README.md
CHANGED
|
@@ -42,6 +42,9 @@ const { text: reply } = await speko.complete({
|
|
|
42
42
|
messages: [{ role: 'user', content: 'Hi!' }],
|
|
43
43
|
intent: { language: 'en' },
|
|
44
44
|
});
|
|
45
|
+
|
|
46
|
+
// Streaming variants are also available:
|
|
47
|
+
// speko.transcribeStream(...), speko.synthesizeStream(...), speko.completeStream(...)
|
|
45
48
|
```
|
|
46
49
|
|
|
47
50
|
## Documentation
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Speko } from './lib/client.js';
|
|
2
2
|
export { SpekoApiError, SpekoAuthError, SpekoRateLimitError } from './lib/errors.js';
|
|
3
|
-
export type { SpekoClientOptions, KeySource, UsageSummary, UsageByProvider, UsageQueryParams, OrganizationBalance, CreditLedgerEntry, CreditLedgerKind, CreditLedgerPage, CreditLedgerQueryParams, OptimizeFor, RoutingIntent, PipelineConstraints, TranscribeOptions, TranscribeResult, SynthesizeOptions, SynthesizeResult, ChatMessage, CompleteParams, CompleteResult, RealtimeProvider, RealtimeToolSpec, RealtimeConnectParams, RealtimeFrame, RealtimeEventHandler, RealtimeSessionHandle, } from './lib/types/index.js';
|
|
3
|
+
export type { SpekoClientOptions, KeySource, UsageSummary, UsageByProvider, UsageQueryParams, OrganizationBalance, CreditLedgerEntry, CreditLedgerKind, CreditLedgerPage, CreditLedgerQueryParams, OptimizeFor, RoutingIntent, PipelineConstraints, TranscribeOptions, TranscribeResult, TranscribeStreamEvent, SynthesizeOptions, SynthesizeResult, SynthesizeStreamResult, ChatMessage, ChatTool, ChatToolCall, ChatToolChoice, ChatToolExecutionMode, ChatToolSource, CompleteParams, CompleteResult, CompleteStreamEvent, RealtimeProvider, RealtimeToolSpec, RealtimeConnectParams, RealtimeFrame, RealtimeEventHandler, RealtimeSessionHandle, VoiceDialParams, VoiceDialResult, PhoneNumberDirection, PhoneNumberRow, PhoneNumberCreateParams, PhoneNumberUpdateParams, AvailablePhoneNumber, PhoneNumberSearchParams, AgentIntent, AgentLlmOptions, AgentStackPreferences, AgentSttOptions, AgentRow, AgentCreateParams, AgentUpdateParams, AgentToolSourceInline, AgentToolSourceWebhookCreate, AgentToolSourceWebhookSerialized, AgentToolSourceBuiltin, AgentToolSourceCreate, AgentToolSourceSerialized, AgentToolRow, AgentToolCreateParams, AgentToolUpdateParams, KnowledgeBaseRow, KnowledgeBaseCreateParams, KnowledgeBaseListParams, KnowledgeBaseDocumentStatus, KnowledgeBaseDocumentRow, KnowledgeBaseDocumentCreateParams, KnowledgeBaseDocumentUploadSpec, KnowledgeBaseDocumentCreateResult, KnowledgeBaseDocumentUploadParams, KnowledgeBaseDocumentPollOptions, } from './lib/types/index.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACrF,YAAY,EACV,kBAAkB,EAClB,SAAS,EACT,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACrF,YAAY,EACV,kBAAkB,EAClB,SAAS,EACT,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,EACvB,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,4BAA4B,EAC5B,gCAAgC,EAChC,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,yBAAyB,EACzB,uBAAuB,EACvB,2BAA2B,EAC3B,wBAAwB,EACxB,iCAAiC,EACjC,+BAA+B,EAC/B,iCAAiC,EACjC,iCAAiC,EACjC,gCAAgC,GACjC,MAAM,sBAAsB,CAAC"}
|
package/dist/lib/client.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { CompleteParams, CompleteResult, SpekoClientOptions, SynthesizeOptions, SynthesizeResult, TranscribeOptions, TranscribeResult } from './types/index.js';
|
|
1
|
+
import type { CompleteParams, CompleteResult, CompleteStreamEvent, SpekoClientOptions, SynthesizeOptions, SynthesizeResult, SynthesizeStreamResult, TranscribeOptions, TranscribeResult, TranscribeStreamEvent } from './types/index.js';
|
|
2
2
|
import { Usage } from './resources/usage.js';
|
|
3
3
|
import { Credits } from './resources/credits.js';
|
|
4
4
|
import { Realtime } from './resources/realtime.js';
|
|
5
|
+
import { Voice } from './resources/voice.js';
|
|
6
|
+
import { PhoneNumbers } from './resources/phone-numbers.js';
|
|
7
|
+
import { Agents } from './resources/agents.js';
|
|
8
|
+
import { KnowledgeBases } from './resources/knowledge-bases.js';
|
|
5
9
|
/**
|
|
6
10
|
* Speko client โ one API, every voice provider.
|
|
7
11
|
*
|
|
@@ -20,6 +24,10 @@ export declare class Speko {
|
|
|
20
24
|
readonly usage: Usage;
|
|
21
25
|
readonly credits: Credits;
|
|
22
26
|
readonly realtime: Realtime;
|
|
27
|
+
readonly voice: Voice;
|
|
28
|
+
readonly phoneNumbers: PhoneNumbers;
|
|
29
|
+
readonly agents: Agents;
|
|
30
|
+
readonly knowledgeBases: KnowledgeBases;
|
|
23
31
|
private readonly transcribeResource;
|
|
24
32
|
private readonly synthesizeResource;
|
|
25
33
|
private readonly completeResource;
|
|
@@ -32,16 +40,19 @@ export declare class Speko {
|
|
|
32
40
|
* calling framework (e.g. LiveKit Agents) tears down a session mid-call.
|
|
33
41
|
*/
|
|
34
42
|
transcribe(audio: Uint8Array, options: TranscribeOptions, abortSignal?: AbortSignal): Promise<TranscribeResult>;
|
|
43
|
+
transcribeStream(audio: Uint8Array, options: TranscribeOptions, abortSignal?: AbortSignal): AsyncIterableIterator<TranscribeStreamEvent>;
|
|
35
44
|
/**
|
|
36
45
|
* Synthesize text into audio. The router picks the best TTS provider and
|
|
37
46
|
* fails over automatically. The result includes the audio bytes plus the
|
|
38
47
|
* provider's native content type.
|
|
39
48
|
*/
|
|
40
49
|
synthesize(text: string, options: SynthesizeOptions, abortSignal?: AbortSignal): Promise<SynthesizeResult>;
|
|
50
|
+
synthesizeStream(text: string, options: SynthesizeOptions, abortSignal?: AbortSignal): Promise<SynthesizeStreamResult>;
|
|
41
51
|
/**
|
|
42
52
|
* Run an LLM completion. The router picks the best LLM provider and fails
|
|
43
53
|
* over automatically.
|
|
44
54
|
*/
|
|
45
55
|
complete(params: CompleteParams, abortSignal?: AbortSignal): Promise<CompleteResult>;
|
|
56
|
+
completeStream(params: CompleteParams, abortSignal?: AbortSignal): AsyncIterableIterator<CompleteStreamEvent>;
|
|
46
57
|
}
|
|
47
58
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/lib/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/lib/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/lib/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAIjD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAKhE;;;;;;;;;;;;;GAaG;AACH,qBAAa,KAAK;IAChB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;I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 +5,10 @@ import { Transcribe } from './resources/transcribe.js';
|
|
|
5
5
|
import { Synthesize } from './resources/synthesize.js';
|
|
6
6
|
import { Complete } from './resources/complete.js';
|
|
7
7
|
import { Realtime } from './resources/realtime.js';
|
|
8
|
+
import { Voice } from './resources/voice.js';
|
|
9
|
+
import { PhoneNumbers } from './resources/phone-numbers.js';
|
|
10
|
+
import { Agents } from './resources/agents.js';
|
|
11
|
+
import { KnowledgeBases } from './resources/knowledge-bases.js';
|
|
8
12
|
const DEFAULT_BASE_URL = 'https://api.speko.ai';
|
|
9
13
|
const DEFAULT_TIMEOUT = 30_000;
|
|
10
14
|
/**
|
|
@@ -25,6 +29,10 @@ export class Speko {
|
|
|
25
29
|
usage;
|
|
26
30
|
credits;
|
|
27
31
|
realtime;
|
|
32
|
+
voice;
|
|
33
|
+
phoneNumbers;
|
|
34
|
+
agents;
|
|
35
|
+
knowledgeBases;
|
|
28
36
|
transcribeResource;
|
|
29
37
|
synthesizeResource;
|
|
30
38
|
completeResource;
|
|
@@ -40,6 +48,10 @@ export class Speko {
|
|
|
40
48
|
this.usage = new Usage(http);
|
|
41
49
|
this.credits = new Credits(http);
|
|
42
50
|
this.realtime = new Realtime(http);
|
|
51
|
+
this.voice = new Voice(http);
|
|
52
|
+
this.phoneNumbers = new PhoneNumbers(http);
|
|
53
|
+
this.agents = new Agents(http);
|
|
54
|
+
this.knowledgeBases = new KnowledgeBases(http);
|
|
43
55
|
this.transcribeResource = new Transcribe(http);
|
|
44
56
|
this.synthesizeResource = new Synthesize(http);
|
|
45
57
|
this.completeResource = new Complete(http);
|
|
@@ -54,6 +66,9 @@ export class Speko {
|
|
|
54
66
|
transcribe(audio, options, abortSignal) {
|
|
55
67
|
return this.transcribeResource.call(audio, options, abortSignal);
|
|
56
68
|
}
|
|
69
|
+
transcribeStream(audio, options, abortSignal) {
|
|
70
|
+
return this.transcribeResource.stream(audio, options, abortSignal);
|
|
71
|
+
}
|
|
57
72
|
/**
|
|
58
73
|
* Synthesize text into audio. The router picks the best TTS provider and
|
|
59
74
|
* fails over automatically. The result includes the audio bytes plus the
|
|
@@ -62,6 +77,9 @@ export class Speko {
|
|
|
62
77
|
synthesize(text, options, abortSignal) {
|
|
63
78
|
return this.synthesizeResource.call(text, options, abortSignal);
|
|
64
79
|
}
|
|
80
|
+
synthesizeStream(text, options, abortSignal) {
|
|
81
|
+
return this.synthesizeResource.stream(text, options, abortSignal);
|
|
82
|
+
}
|
|
65
83
|
/**
|
|
66
84
|
* Run an LLM completion. The router picks the best LLM provider and fails
|
|
67
85
|
* over automatically.
|
|
@@ -69,4 +87,7 @@ export class Speko {
|
|
|
69
87
|
complete(params, abortSignal) {
|
|
70
88
|
return this.completeResource.call(params, abortSignal);
|
|
71
89
|
}
|
|
90
|
+
completeStream(params, abortSignal) {
|
|
91
|
+
return this.completeResource.stream(params, abortSignal);
|
|
92
|
+
}
|
|
72
93
|
}
|
package/dist/lib/http.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare class HttpClient {
|
|
|
13
13
|
get<T>(path: string, externalSignal?: AbortSignal): Promise<T>;
|
|
14
14
|
post<T>(path: string, body: unknown, externalSignal?: AbortSignal): Promise<T>;
|
|
15
15
|
delete<T>(path: string, externalSignal?: AbortSignal): Promise<T>;
|
|
16
|
+
patch<T>(path: string, body: unknown, externalSignal?: AbortSignal): Promise<T>;
|
|
16
17
|
/**
|
|
17
18
|
* Send raw bytes as the request body and parse a JSON response.
|
|
18
19
|
* Used by `speko.transcribe()` to upload audio and receive a transcript.
|
|
@@ -27,6 +28,20 @@ export declare class HttpClient {
|
|
|
27
28
|
bytes: Uint8Array;
|
|
28
29
|
headers: Record<string, string>;
|
|
29
30
|
}>;
|
|
31
|
+
requestSse(method: string, path: string, body: unknown, externalSignal?: AbortSignal, extraHeaders?: Record<string, string>): AsyncIterableIterator<{
|
|
32
|
+
event: string;
|
|
33
|
+
data: unknown;
|
|
34
|
+
}>;
|
|
35
|
+
requestRawSse(method: string, path: string, bodyBytes: Uint8Array, extraHeaders: Record<string, string>, externalSignal?: AbortSignal): Promise<AsyncIterableIterator<{
|
|
36
|
+
event: string;
|
|
37
|
+
data: unknown;
|
|
38
|
+
}>>;
|
|
39
|
+
requestBinaryStream(method: string, path: string, body: unknown, externalSignal?: AbortSignal): Promise<{
|
|
40
|
+
chunks: AsyncIterableIterator<Uint8Array>;
|
|
41
|
+
headers: Record<string, string>;
|
|
42
|
+
}>;
|
|
43
|
+
private readSseBody;
|
|
44
|
+
private readBinaryBody;
|
|
30
45
|
/**
|
|
31
46
|
* Compose the internal timeout signal with an optional external signal so
|
|
32
47
|
* that callers can cancel in-flight requests (e.g. LiveKit Agents tearing
|
package/dist/lib/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAID,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyB;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE,iBAAiB;IAWhC,OAAO,CAAC,CAAC,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,cAAc,CAAC,EAAE,WAAW,GAC3B,OAAO,CAAC,CAAC,CAAC;IAsBP,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAI9D,IAAI,CAAC,CAAC,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,c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,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;YAgC3E,WAAW;YA+BX,cAAc;IAiB7B;;;;OAIG;IACH,OAAO,CAAC,WAAW;YA6BL,WAAW;CA4B1B"}
|
package/dist/lib/http.js
CHANGED
|
@@ -43,6 +43,9 @@ export class HttpClient {
|
|
|
43
43
|
async delete(path, externalSignal) {
|
|
44
44
|
return this.request('DELETE', path, undefined, externalSignal);
|
|
45
45
|
}
|
|
46
|
+
async patch(path, body, externalSignal) {
|
|
47
|
+
return this.request('PATCH', path, body, externalSignal);
|
|
48
|
+
}
|
|
46
49
|
/**
|
|
47
50
|
* Send raw bytes as the request body and parse a JSON response.
|
|
48
51
|
* Used by `speko.transcribe()` to upload audio and receive a transcript.
|
|
@@ -100,6 +103,139 @@ export class HttpClient {
|
|
|
100
103
|
cleanup();
|
|
101
104
|
}
|
|
102
105
|
}
|
|
106
|
+
async *requestSse(method, path, body, externalSignal, extraHeaders) {
|
|
107
|
+
const url = `${this.baseUrl}${path}`;
|
|
108
|
+
const { signal, cleanup } = this.buildSignal(externalSignal);
|
|
109
|
+
let reader;
|
|
110
|
+
try {
|
|
111
|
+
const response = await fetch(url, {
|
|
112
|
+
method,
|
|
113
|
+
headers: { ...this.jsonHeaders, ...extraHeaders },
|
|
114
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
115
|
+
signal,
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
await this.handleError(response);
|
|
119
|
+
}
|
|
120
|
+
if (!response.body) {
|
|
121
|
+
throw new SpekoApiError('Response body is empty', response.status, 'EMPTY_BODY');
|
|
122
|
+
}
|
|
123
|
+
reader = response.body.getReader();
|
|
124
|
+
const decoder = new TextDecoder();
|
|
125
|
+
let buffer = '';
|
|
126
|
+
while (true) {
|
|
127
|
+
const { done, value } = await reader.read();
|
|
128
|
+
if (done)
|
|
129
|
+
break;
|
|
130
|
+
buffer += decoder.decode(value, { stream: true });
|
|
131
|
+
const events = drainSseEvents(buffer);
|
|
132
|
+
buffer = events.remainder;
|
|
133
|
+
for (const event of events.items) {
|
|
134
|
+
yield event;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
buffer += decoder.decode();
|
|
138
|
+
const events = drainSseEvents(buffer + '\n\n');
|
|
139
|
+
for (const event of events.items) {
|
|
140
|
+
yield event;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
reader?.releaseLock();
|
|
145
|
+
cleanup();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async requestRawSse(method, path, bodyBytes, extraHeaders, externalSignal) {
|
|
149
|
+
const url = `${this.baseUrl}${path}`;
|
|
150
|
+
const { signal, cleanup } = this.buildSignal(externalSignal);
|
|
151
|
+
const response = await fetch(url, {
|
|
152
|
+
method,
|
|
153
|
+
headers: {
|
|
154
|
+
Authorization: this.authHeader,
|
|
155
|
+
'User-Agent': USER_AGENT,
|
|
156
|
+
...extraHeaders,
|
|
157
|
+
},
|
|
158
|
+
body: bodyBytes,
|
|
159
|
+
signal,
|
|
160
|
+
});
|
|
161
|
+
if (!response.ok) {
|
|
162
|
+
cleanup();
|
|
163
|
+
await this.handleError(response);
|
|
164
|
+
}
|
|
165
|
+
if (!response.body) {
|
|
166
|
+
cleanup();
|
|
167
|
+
throw new SpekoApiError('Response body is empty', response.status, 'EMPTY_BODY');
|
|
168
|
+
}
|
|
169
|
+
return this.readSseBody(response.body, cleanup);
|
|
170
|
+
}
|
|
171
|
+
async requestBinaryStream(method, path, body, externalSignal) {
|
|
172
|
+
const url = `${this.baseUrl}${path}`;
|
|
173
|
+
const { signal, cleanup } = this.buildSignal(externalSignal);
|
|
174
|
+
const response = await fetch(url, {
|
|
175
|
+
method,
|
|
176
|
+
headers: this.jsonHeaders,
|
|
177
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
178
|
+
signal,
|
|
179
|
+
});
|
|
180
|
+
if (!response.ok) {
|
|
181
|
+
cleanup();
|
|
182
|
+
await this.handleError(response);
|
|
183
|
+
}
|
|
184
|
+
if (!response.body) {
|
|
185
|
+
cleanup();
|
|
186
|
+
throw new SpekoApiError('Response body is empty', response.status, 'EMPTY_BODY');
|
|
187
|
+
}
|
|
188
|
+
const headers = {};
|
|
189
|
+
response.headers.forEach((value, key) => {
|
|
190
|
+
headers[key] = value;
|
|
191
|
+
});
|
|
192
|
+
return {
|
|
193
|
+
headers,
|
|
194
|
+
chunks: this.readBinaryBody(response.body, cleanup),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
async *readSseBody(body, cleanup) {
|
|
198
|
+
const reader = body.getReader();
|
|
199
|
+
const decoder = new TextDecoder();
|
|
200
|
+
let buffer = '';
|
|
201
|
+
try {
|
|
202
|
+
while (true) {
|
|
203
|
+
const { done, value } = await reader.read();
|
|
204
|
+
if (done)
|
|
205
|
+
break;
|
|
206
|
+
buffer += decoder.decode(value, { stream: true });
|
|
207
|
+
const events = drainSseEvents(buffer);
|
|
208
|
+
buffer = events.remainder;
|
|
209
|
+
for (const event of events.items) {
|
|
210
|
+
yield event;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
buffer += decoder.decode();
|
|
214
|
+
const events = drainSseEvents(buffer + '\n\n');
|
|
215
|
+
for (const event of events.items) {
|
|
216
|
+
yield event;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
reader.releaseLock();
|
|
221
|
+
cleanup();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async *readBinaryBody(body, cleanup) {
|
|
225
|
+
const reader = body.getReader();
|
|
226
|
+
try {
|
|
227
|
+
while (true) {
|
|
228
|
+
const { done, value } = await reader.read();
|
|
229
|
+
if (done)
|
|
230
|
+
break;
|
|
231
|
+
yield value;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
reader.releaseLock();
|
|
236
|
+
cleanup();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
103
239
|
/**
|
|
104
240
|
* Compose the internal timeout signal with an optional external signal so
|
|
105
241
|
* that callers can cancel in-flight requests (e.g. LiveKit Agents tearing
|
|
@@ -152,3 +288,36 @@ export class HttpClient {
|
|
|
152
288
|
throw new SpekoApiError(message, response.status, code);
|
|
153
289
|
}
|
|
154
290
|
}
|
|
291
|
+
function drainSseEvents(buffer) {
|
|
292
|
+
const items = [];
|
|
293
|
+
let cursor = 0;
|
|
294
|
+
while (true) {
|
|
295
|
+
const next = buffer.indexOf('\n\n', cursor);
|
|
296
|
+
if (next === -1)
|
|
297
|
+
break;
|
|
298
|
+
const block = buffer.slice(cursor, next);
|
|
299
|
+
cursor = next + 2;
|
|
300
|
+
if (!block.trim())
|
|
301
|
+
continue;
|
|
302
|
+
let event = 'message';
|
|
303
|
+
const dataLines = [];
|
|
304
|
+
for (const line of block.split(/\r?\n/)) {
|
|
305
|
+
if (line.startsWith('event:')) {
|
|
306
|
+
event = line.slice('event:'.length).trim();
|
|
307
|
+
}
|
|
308
|
+
else if (line.startsWith('data:')) {
|
|
309
|
+
dataLines.push(line.slice('data:'.length).trimStart());
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const rawData = dataLines.join('\n');
|
|
313
|
+
let data = rawData;
|
|
314
|
+
try {
|
|
315
|
+
data = JSON.parse(rawData);
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
// Keep non-JSON SSE payloads as strings.
|
|
319
|
+
}
|
|
320
|
+
items.push({ event, data });
|
|
321
|
+
}
|
|
322
|
+
return { items, remainder: buffer.slice(cursor) };
|
|
323
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { HttpClient } from '../http.js';
|
|
2
|
+
import type { AgentCreateParams, AgentRow, AgentToolCreateParams, AgentToolRow, AgentToolUpdateParams, AgentUpdateParams, PhoneNumberRow } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Per-org agent definitions โ the system prompt, voice, intent, and
|
|
5
|
+
* routing constraints used when this agent answers (or places) a call.
|
|
6
|
+
*
|
|
7
|
+
* Every agent created via {@link create} auto-provisions a `Default`
|
|
8
|
+
* knowledge base, so callers can upload documents through
|
|
9
|
+
* {@link Speko.knowledgeBases} without an extra setup step.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const agent = await speko.agents.create({
|
|
14
|
+
* name: 'Support Bot',
|
|
15
|
+
* systemPrompt: 'You are a helpful support agent for Acme.',
|
|
16
|
+
* voice: 'sophia',
|
|
17
|
+
* intent: { language: 'en', optimizeFor: 'latency' },
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* await speko.agents.attachPhoneNumber(agent.id, num.id);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class Agents {
|
|
24
|
+
private readonly http;
|
|
25
|
+
readonly tools: AgentTools;
|
|
26
|
+
constructor(http: HttpClient);
|
|
27
|
+
list(): Promise<AgentRow[]>;
|
|
28
|
+
create(params: AgentCreateParams): Promise<AgentRow>;
|
|
29
|
+
get(agentId: string): Promise<AgentRow>;
|
|
30
|
+
update(agentId: string, params: AgentUpdateParams): Promise<AgentRow>;
|
|
31
|
+
delete(agentId: string): Promise<{
|
|
32
|
+
deleted: boolean;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Bind a phone number to this agent so inbound calls hydrate the
|
|
36
|
+
* agent's pipeline config from the agent row. Internally calls
|
|
37
|
+
* `PATCH /v1/phone-numbers/:id` with `{ agentId }`.
|
|
38
|
+
*/
|
|
39
|
+
attachPhoneNumber(agentId: string, phoneNumberId: string): Promise<PhoneNumberRow>;
|
|
40
|
+
/**
|
|
41
|
+
* Unlink a phone number from any agent. Inbound calls fall back to
|
|
42
|
+
* the number's `dispatchMetadataTemplate` (or fail if neither is
|
|
43
|
+
* configured). Internally calls `PATCH /v1/phone-numbers/:id` with
|
|
44
|
+
* `{ agentId: null }`.
|
|
45
|
+
*/
|
|
46
|
+
detachPhoneNumber(phoneNumberId: string): Promise<PhoneNumberRow>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Per-agent tool definitions exposed to the LLM mid-call. Three
|
|
50
|
+
* execution modes: `inline` (caller runs the tool), `webhook`
|
|
51
|
+
* (Speko POSTs to your URL with a Standard-Webhooks signature), and
|
|
52
|
+
* `builtin` (Speko-managed tools like `search_knowledge_base`).
|
|
53
|
+
*
|
|
54
|
+
* Webhook secrets are encrypted server-side at creation; the returned
|
|
55
|
+
* row carries a `secretRef` pointer instead of the plaintext.
|
|
56
|
+
*/
|
|
57
|
+
export declare class AgentTools {
|
|
58
|
+
private readonly http;
|
|
59
|
+
constructor(http: HttpClient);
|
|
60
|
+
list(agentId: string): Promise<AgentToolRow[]>;
|
|
61
|
+
create(agentId: string, params: AgentToolCreateParams): Promise<AgentToolRow>;
|
|
62
|
+
get(agentId: string, toolId: string): Promise<AgentToolRow>;
|
|
63
|
+
update(agentId: string, toolId: string, params: AgentToolUpdateParams): Promise<AgentToolRow>;
|
|
64
|
+
delete(agentId: string, toolId: string): Promise<{
|
|
65
|
+
deleted: boolean;
|
|
66
|
+
}>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../../src/lib/resources/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,iBAAiB,EACjB,QAAQ,EACR,qBAAqB,EACrB,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,MAAM;IAGL,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;gBAEE,IAAI,EAAE,UAAU;IAI7C,IA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-org agent definitions โ the system prompt, voice, intent, and
|
|
3
|
+
* routing constraints used when this agent answers (or places) a call.
|
|
4
|
+
*
|
|
5
|
+
* Every agent created via {@link create} auto-provisions a `Default`
|
|
6
|
+
* knowledge base, so callers can upload documents through
|
|
7
|
+
* {@link Speko.knowledgeBases} without an extra setup step.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const agent = await speko.agents.create({
|
|
12
|
+
* name: 'Support Bot',
|
|
13
|
+
* systemPrompt: 'You are a helpful support agent for Acme.',
|
|
14
|
+
* voice: 'sophia',
|
|
15
|
+
* intent: { language: 'en', optimizeFor: 'latency' },
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* await speko.agents.attachPhoneNumber(agent.id, num.id);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class Agents {
|
|
22
|
+
http;
|
|
23
|
+
tools;
|
|
24
|
+
constructor(http) {
|
|
25
|
+
this.http = http;
|
|
26
|
+
this.tools = new AgentTools(http);
|
|
27
|
+
}
|
|
28
|
+
list() {
|
|
29
|
+
return this.http.get('/v1/agents');
|
|
30
|
+
}
|
|
31
|
+
create(params) {
|
|
32
|
+
return this.http.post('/v1/agents', params);
|
|
33
|
+
}
|
|
34
|
+
get(agentId) {
|
|
35
|
+
return this.http.get(`/v1/agents/${encodeURIComponent(agentId)}`);
|
|
36
|
+
}
|
|
37
|
+
update(agentId, params) {
|
|
38
|
+
return this.http.patch(`/v1/agents/${encodeURIComponent(agentId)}`, params);
|
|
39
|
+
}
|
|
40
|
+
delete(agentId) {
|
|
41
|
+
return this.http.delete(`/v1/agents/${encodeURIComponent(agentId)}`);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Bind a phone number to this agent so inbound calls hydrate the
|
|
45
|
+
* agent's pipeline config from the agent row. Internally calls
|
|
46
|
+
* `PATCH /v1/phone-numbers/:id` with `{ agentId }`.
|
|
47
|
+
*/
|
|
48
|
+
attachPhoneNumber(agentId, phoneNumberId) {
|
|
49
|
+
return this.http.patch(`/v1/phone-numbers/${encodeURIComponent(phoneNumberId)}`, { agentId });
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Unlink a phone number from any agent. Inbound calls fall back to
|
|
53
|
+
* the number's `dispatchMetadataTemplate` (or fail if neither is
|
|
54
|
+
* configured). Internally calls `PATCH /v1/phone-numbers/:id` with
|
|
55
|
+
* `{ agentId: null }`.
|
|
56
|
+
*/
|
|
57
|
+
detachPhoneNumber(phoneNumberId) {
|
|
58
|
+
return this.http.patch(`/v1/phone-numbers/${encodeURIComponent(phoneNumberId)}`, { agentId: null });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Per-agent tool definitions exposed to the LLM mid-call. Three
|
|
63
|
+
* execution modes: `inline` (caller runs the tool), `webhook`
|
|
64
|
+
* (Speko POSTs to your URL with a Standard-Webhooks signature), and
|
|
65
|
+
* `builtin` (Speko-managed tools like `search_knowledge_base`).
|
|
66
|
+
*
|
|
67
|
+
* Webhook secrets are encrypted server-side at creation; the returned
|
|
68
|
+
* row carries a `secretRef` pointer instead of the plaintext.
|
|
69
|
+
*/
|
|
70
|
+
export class AgentTools {
|
|
71
|
+
http;
|
|
72
|
+
constructor(http) {
|
|
73
|
+
this.http = http;
|
|
74
|
+
}
|
|
75
|
+
list(agentId) {
|
|
76
|
+
return this.http.get(`/v1/agents/${encodeURIComponent(agentId)}/tools`);
|
|
77
|
+
}
|
|
78
|
+
create(agentId, params) {
|
|
79
|
+
return this.http.post(`/v1/agents/${encodeURIComponent(agentId)}/tools`, params);
|
|
80
|
+
}
|
|
81
|
+
get(agentId, toolId) {
|
|
82
|
+
return this.http.get(`/v1/agents/${encodeURIComponent(agentId)}/tools/${encodeURIComponent(toolId)}`);
|
|
83
|
+
}
|
|
84
|
+
update(agentId, toolId, params) {
|
|
85
|
+
return this.http.patch(`/v1/agents/${encodeURIComponent(agentId)}/tools/${encodeURIComponent(toolId)}`, params);
|
|
86
|
+
}
|
|
87
|
+
delete(agentId, toolId) {
|
|
88
|
+
return this.http.delete(`/v1/agents/${encodeURIComponent(agentId)}/tools/${encodeURIComponent(toolId)}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HttpClient } from '../http.js';
|
|
2
|
-
import type { CompleteParams, CompleteResult } from '../types/index.js';
|
|
2
|
+
import type { CompleteParams, CompleteResult, CompleteStreamEvent } from '../types/index.js';
|
|
3
3
|
export declare class Complete {
|
|
4
4
|
private readonly http;
|
|
5
5
|
constructor(http: HttpClient);
|
|
@@ -16,5 +16,6 @@ export declare class Complete {
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
call(params: CompleteParams, abortSignal?: AbortSignal): Promise<CompleteResult>;
|
|
19
|
+
stream(params: CompleteParams, abortSignal?: AbortSignal): AsyncIterableIterator<CompleteStreamEvent>;
|
|
19
20
|
}
|
|
20
21
|
//# sourceMappingURL=complete.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"complete.d.ts","sourceRoot":"","sources":["../../../src/lib/resources/complete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"complete.d.ts","sourceRoot":"","sources":["../../../src/lib/resources/complete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAG3B,qBAAa,QAAQ;IACP,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;;;;;;;;;;OAWG;IACG,IAAI,CACR,MAAM,EAAE,cAAc,EACtB,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,cAAc,CAAC;IAuBnB,MAAM,CACX,MAAM,EAAE,cAAc,EACtB,WAAW,CAAC,EAAE,WAAW,GACxB,qBAAqB,CAAC,mBAAmB,CAAC;CAU9C"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SpekoApiError } from '../errors.js';
|
|
1
2
|
export class Complete {
|
|
2
3
|
http;
|
|
3
4
|
constructor(http) {
|
|
@@ -16,6 +17,31 @@ export class Complete {
|
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
19
|
async call(params, abortSignal) {
|
|
19
|
-
|
|
20
|
+
let done;
|
|
21
|
+
for await (const event of this.stream(params, abortSignal)) {
|
|
22
|
+
if (event.type === 'done') {
|
|
23
|
+
done = {
|
|
24
|
+
text: event.text,
|
|
25
|
+
provider: event.provider,
|
|
26
|
+
model: event.model,
|
|
27
|
+
usage: event.usage,
|
|
28
|
+
failoverCount: event.failoverCount,
|
|
29
|
+
scoresRunId: event.scoresRunId,
|
|
30
|
+
...(event.toolCalls && { toolCalls: event.toolCalls }),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else if (event.type === 'error') {
|
|
34
|
+
throw new SpekoApiError(event.error, 200, event.code);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!done) {
|
|
38
|
+
throw new SpekoApiError('Complete stream ended without a done event', 200, 'STREAM_ENDED');
|
|
39
|
+
}
|
|
40
|
+
return done;
|
|
41
|
+
}
|
|
42
|
+
async *stream(params, abortSignal) {
|
|
43
|
+
for await (const event of this.http.requestSse('POST', '/v1/complete', params, abortSignal)) {
|
|
44
|
+
yield { ...event.data, type: event.event };
|
|
45
|
+
}
|
|
20
46
|
}
|
|
21
47
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { HttpClient } from '../http.js';
|
|
2
2
|
import type { CreditLedgerPage, CreditLedgerQueryParams, OrganizationBalance } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
|
-
* Prepaid credit balance + append-only ledger. Balance is reported in
|
|
5
|
-
* micro-USD (`1_000_000` ยต$ = $1) alongside a float USD helper.
|
|
4
|
+
* Prepaid credit balance + append-only ledger. Balance is reported in USD.
|
|
6
5
|
*/
|
|
7
6
|
export declare class Credits {
|
|
8
7
|
private readonly http;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credits.d.ts","sourceRoot":"","sources":["../../../src/lib/resources/credits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAE3B
|
|
1
|
+
{"version":3,"file":"credits.d.ts","sourceRoot":"","sources":["../../../src/lib/resources/credits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,qBAAa,OAAO;IACN,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;;;;;;;OAQG;IACH,UAAU,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAI1C;;;;;OAKG;IACH,SAAS,CAAC,MAAM,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAUvE"}
|