@fabric-harness/sdk 6.4.0 → 6.6.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/connector-spec/voice-telephony.md +120 -104
- package/dist/agent-route.d.ts +20 -2
- package/dist/agent-route.d.ts.map +1 -1
- package/dist/agent-route.js +31 -1
- package/dist/agent-route.js.map +1 -1
- package/dist/agent-router.d.ts +42 -0
- package/dist/agent-router.d.ts.map +1 -1
- package/dist/agent-router.js +49 -1
- package/dist/agent-router.js.map +1 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +7 -2
- package/dist/agent.js.map +1 -1
- package/dist/attachment-store.d.ts +69 -0
- package/dist/attachment-store.d.ts.map +1 -1
- package/dist/attachment-store.js +183 -14
- package/dist/attachment-store.js.map +1 -1
- package/dist/attachments.d.ts +136 -0
- package/dist/attachments.d.ts.map +1 -0
- package/dist/attachments.js +332 -0
- package/dist/attachments.js.map +1 -0
- package/dist/channel.d.ts.map +1 -1
- package/dist/channel.js +26 -3
- package/dist/channel.js.map +1 -1
- package/dist/conversation-history.d.ts +186 -0
- package/dist/conversation-history.d.ts.map +1 -0
- package/dist/conversation-history.js +481 -0
- package/dist/conversation-history.js.map +1 -0
- package/dist/conversation-ui.d.ts +43 -2
- package/dist/conversation-ui.d.ts.map +1 -1
- package/dist/conversation-ui.js +44 -14
- package/dist/conversation-ui.js.map +1 -1
- package/dist/cost-budget.d.ts +50 -0
- package/dist/cost-budget.d.ts.map +1 -1
- package/dist/cost-budget.js +74 -4
- package/dist/cost-budget.js.map +1 -1
- package/dist/cost-enforcement.d.ts +32 -0
- package/dist/cost-enforcement.d.ts.map +1 -0
- package/dist/cost-enforcement.js +116 -0
- package/dist/cost-enforcement.js.map +1 -0
- package/dist/delivered-message.d.ts +20 -6
- package/dist/delivered-message.d.ts.map +1 -1
- package/dist/delivered-message.js +37 -8
- package/dist/delivered-message.js.map +1 -1
- package/dist/events.d.ts +13 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/experimental.d.ts +2 -2
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +1 -1
- package/dist/experimental.js.map +1 -1
- package/dist/governed-voice.d.ts +6 -0
- package/dist/governed-voice.d.ts.map +1 -1
- package/dist/governed-voice.js +142 -35
- package/dist/governed-voice.js.map +1 -1
- package/dist/history.d.ts +3 -2
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +57 -23
- package/dist/history.js.map +1 -1
- package/dist/index.d.ts +21 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/loop.d.ts +25 -2
- package/dist/loop.d.ts.map +1 -1
- package/dist/loop.js +409 -60
- package/dist/loop.js.map +1 -1
- package/dist/model-pricing.d.ts +77 -4
- package/dist/model-pricing.d.ts.map +1 -1
- package/dist/model-pricing.js +259 -18
- package/dist/model-pricing.js.map +1 -1
- package/dist/model.d.ts +115 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +487 -75
- package/dist/model.js.map +1 -1
- package/dist/pi-document-attachments.d.ts +43 -0
- package/dist/pi-document-attachments.d.ts.map +1 -0
- package/dist/pi-document-attachments.js +155 -0
- package/dist/pi-document-attachments.js.map +1 -0
- package/dist/pi-loop-runtime.d.ts +103 -1
- package/dist/pi-loop-runtime.d.ts.map +1 -1
- package/dist/pi-loop-runtime.js +907 -114
- package/dist/pi-loop-runtime.js.map +1 -1
- package/dist/prompt-attachments.d.ts +98 -0
- package/dist/prompt-attachments.d.ts.map +1 -0
- package/dist/prompt-attachments.js +279 -0
- package/dist/prompt-attachments.js.map +1 -0
- package/dist/session.d.ts +55 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +443 -41
- package/dist/session.js.map +1 -1
- package/dist/stream-chunks.d.ts +15 -1
- package/dist/stream-chunks.d.ts.map +1 -1
- package/dist/stream-chunks.js +39 -18
- package/dist/stream-chunks.js.map +1 -1
- package/dist/strict.d.ts +23 -16
- package/dist/strict.d.ts.map +1 -1
- package/dist/strict.js +12 -8
- package/dist/strict.js.map +1 -1
- package/dist/submission-context.d.ts +7 -0
- package/dist/submission-context.d.ts.map +1 -1
- package/dist/submission-context.js.map +1 -1
- package/dist/submission-runner.d.ts +5 -0
- package/dist/submission-runner.d.ts.map +1 -1
- package/dist/submission-runner.js +11 -2
- package/dist/submission-runner.js.map +1 -1
- package/dist/tools.d.ts +9 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +1 -0
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/usage-completeness.d.ts +39 -0
- package/dist/usage-completeness.d.ts.map +1 -0
- package/dist/usage-completeness.js +135 -0
- package/dist/usage-completeness.js.map +1 -0
- package/dist/voice-openai-realtime.d.ts +24 -2
- package/dist/voice-openai-realtime.d.ts.map +1 -1
- package/dist/voice-openai-realtime.js +266 -49
- package/dist/voice-openai-realtime.js.map +1 -1
- package/dist/voice-pipeline.d.ts +81 -3
- package/dist/voice-pipeline.d.ts.map +1 -1
- package/dist/voice-pipeline.js +429 -60
- package/dist/voice-pipeline.js.map +1 -1
- package/dist/voice-stt-cartesia.d.ts +8 -0
- package/dist/voice-stt-cartesia.d.ts.map +1 -1
- package/dist/voice-stt-cartesia.js +77 -17
- package/dist/voice-stt-cartesia.js.map +1 -1
- package/dist/voice-stt-deepgram.d.ts +10 -2
- package/dist/voice-stt-deepgram.d.ts.map +1 -1
- package/dist/voice-stt-deepgram.js +78 -18
- package/dist/voice-stt-deepgram.js.map +1 -1
- package/dist/voice-stt.d.ts +13 -3
- package/dist/voice-stt.d.ts.map +1 -1
- package/dist/voice-tts-cartesia.d.ts +8 -0
- package/dist/voice-tts-cartesia.d.ts.map +1 -1
- package/dist/voice-tts-cartesia.js +48 -105
- package/dist/voice-tts-cartesia.js.map +1 -1
- package/dist/voice-tts-elevenlabs.d.ts +10 -1
- package/dist/voice-tts-elevenlabs.d.ts.map +1 -1
- package/dist/voice-tts-elevenlabs.js +50 -113
- package/dist/voice-tts-elevenlabs.js.map +1 -1
- package/dist/voice-ws-client.js +16 -3
- package/dist/voice-ws-client.js.map +1 -1
- package/dist/voice-ws-shared.d.ts +205 -6
- package/dist/voice-ws-shared.d.ts.map +1 -1
- package/dist/voice-ws-shared.js +510 -15
- package/dist/voice-ws-shared.js.map +1 -1
- package/dist/voice.d.ts +98 -4
- package/dist/voice.d.ts.map +1 -1
- package/dist/voice.js +71 -1
- package/dist/voice.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage completeness rules shared by cost budgets and by every path that
|
|
3
|
+
* synthesizes a cost from the static price table (`applyEstimatedCost`
|
|
4
|
+
* in `model-pricing.ts`). Kept free of other SDK imports so both modules can
|
|
5
|
+
* depend on it without an import cycle.
|
|
6
|
+
*/
|
|
7
|
+
/** Whether `value` is a usable USD amount: a finite, non-negative number. */
|
|
8
|
+
export declare function isValidCostUsd(value: unknown): value is number;
|
|
9
|
+
/**
|
|
10
|
+
* Whether `usage` carries enough valid token or unit counts for the static
|
|
11
|
+
* price table to compute its cost:
|
|
12
|
+
*
|
|
13
|
+
* - at least one of input tokens, output tokens, audio tokens, STT seconds,
|
|
14
|
+
* or TTS characters, and every priced field that is present is a finite,
|
|
15
|
+
* non-negative number;
|
|
16
|
+
* - a reported `totalTokens` is a finite, non-negative number that the
|
|
17
|
+
* reported token counts account for (it may exceed their sum only by a
|
|
18
|
+
* small rounding slack). `{ outputTokens: 0, totalTokens: 1_000_000 }`
|
|
19
|
+
* leaves a million tokens unpriced, so it is incomplete;
|
|
20
|
+
* - a text call (no voice fields) that consumed tokens reports prompt tokens
|
|
21
|
+
* (input, cached-input or cache-write): every model request has a prompt,
|
|
22
|
+
* so no prompt tokens beside non-zero output or total tokens means the
|
|
23
|
+
* input count was dropped;
|
|
24
|
+
* - a text call reports its output count. `{ inputTokens: 1 }` would price
|
|
25
|
+
* the output at `$0`, so an absent `outputTokens` is incomplete unless a
|
|
26
|
+
* reported `totalTokens` is no larger than `inputTokens`, which proves the
|
|
27
|
+
* call produced no output. An explicit `outputTokens: 0` is a reported
|
|
28
|
+
* count; adapters leave the field unset when the provider did not send it,
|
|
29
|
+
* and set `totalTokens` only when the provider reported it or from both an
|
|
30
|
+
* input and an output count, never from an input count alone.
|
|
31
|
+
*
|
|
32
|
+
* Cached reads are counted once, as part of `inputTokens` (see
|
|
33
|
+
* `countWithCached` for the convention), so a total that only a second count
|
|
34
|
+
* of the cached prompt would explain, such as Gemini's
|
|
35
|
+
* `{ inputTokens: 1000, cachedInputTokens: 1000, outputTokens: 10, totalTokens: 1510 }`,
|
|
36
|
+
* is incomplete rather than silently priced without its missing output.
|
|
37
|
+
*/
|
|
38
|
+
export declare function hasPriceableUsage(usage: object | undefined): boolean;
|
|
39
|
+
//# sourceMappingURL=usage-completeness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-completeness.d.ts","sourceRoot":"","sources":["../src/usage-completeness.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D;AAkED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CA8BpE"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage completeness rules shared by cost budgets and by every path that
|
|
3
|
+
* synthesizes a cost from the static price table (`applyEstimatedCost`
|
|
4
|
+
* in `model-pricing.ts`). Kept free of other SDK imports so both modules can
|
|
5
|
+
* depend on it without an import cycle.
|
|
6
|
+
*/
|
|
7
|
+
/** Whether `value` is a usable USD amount: a finite, non-negative number. */
|
|
8
|
+
export function isValidCostUsd(value) {
|
|
9
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
|
|
10
|
+
}
|
|
11
|
+
/** Usage fields the static price table bills. */
|
|
12
|
+
const PRICED_USAGE_FIELDS = [
|
|
13
|
+
'inputTokens',
|
|
14
|
+
'outputTokens',
|
|
15
|
+
'cachedInputTokens',
|
|
16
|
+
'cacheWriteTokens',
|
|
17
|
+
'audioInputTokens',
|
|
18
|
+
'cachedAudioInputTokens',
|
|
19
|
+
'audioOutputTokens',
|
|
20
|
+
'sttSeconds',
|
|
21
|
+
'ttsCharacters',
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Fields whose presence lets the price table compute a call's cost. Text
|
|
25
|
+
* calls report input or output tokens; voice calls report audio tokens,
|
|
26
|
+
* STT seconds, or TTS characters. `totalTokens` alone is not enough: the
|
|
27
|
+
* table prices input and output at different rates, and a call priced from
|
|
28
|
+
* missing fields would count as a known `$0`.
|
|
29
|
+
*/
|
|
30
|
+
const SUFFICIENT_USAGE_FIELDS = [
|
|
31
|
+
'inputTokens',
|
|
32
|
+
'outputTokens',
|
|
33
|
+
'audioInputTokens',
|
|
34
|
+
'audioOutputTokens',
|
|
35
|
+
'sttSeconds',
|
|
36
|
+
'ttsCharacters',
|
|
37
|
+
];
|
|
38
|
+
/** Voice usage fields; usage carrying any of them is not a text-only call. */
|
|
39
|
+
const VOICE_USAGE_FIELDS = [
|
|
40
|
+
'audioInputTokens',
|
|
41
|
+
'cachedAudioInputTokens',
|
|
42
|
+
'audioOutputTokens',
|
|
43
|
+
'sttSeconds',
|
|
44
|
+
'ttsCharacters',
|
|
45
|
+
];
|
|
46
|
+
/**
|
|
47
|
+
* A token count together with its cached count, counting cached tokens once.
|
|
48
|
+
*
|
|
49
|
+
* Convention (`ModelUsage`): `inputTokens` includes prompt-cache reads, so
|
|
50
|
+
* `cachedInputTokens` is a subset of it, as `cachedAudioInputTokens` is of
|
|
51
|
+
* `audioInputTokens`; `cacheWriteTokens` is reported separately. Adapters for
|
|
52
|
+
* providers that report cache reads outside the input count (Anthropic,
|
|
53
|
+
* Bedrock, Pi) fold them in. A cached count larger than its base count cannot
|
|
54
|
+
* be a subset, so it is read as reported separately (a custom provider using
|
|
55
|
+
* the Anthropic convention) and added.
|
|
56
|
+
*/
|
|
57
|
+
function countWithCached(base, cached) {
|
|
58
|
+
const baseCount = base ?? 0;
|
|
59
|
+
const cachedCount = cached ?? 0;
|
|
60
|
+
return cachedCount > baseCount ? baseCount + cachedCount : baseCount;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Tokens a reported `totalTokens` may exceed the sum of its reported parts by
|
|
64
|
+
* before the usage counts as incomplete: 1% plus 16 tokens, for providers that
|
|
65
|
+
* round or add a small request overhead to the total.
|
|
66
|
+
*/
|
|
67
|
+
function totalTokensSlack(total) {
|
|
68
|
+
return Math.ceil(total * 0.01) + 16;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Whether `usage` carries enough valid token or unit counts for the static
|
|
72
|
+
* price table to compute its cost:
|
|
73
|
+
*
|
|
74
|
+
* - at least one of input tokens, output tokens, audio tokens, STT seconds,
|
|
75
|
+
* or TTS characters, and every priced field that is present is a finite,
|
|
76
|
+
* non-negative number;
|
|
77
|
+
* - a reported `totalTokens` is a finite, non-negative number that the
|
|
78
|
+
* reported token counts account for (it may exceed their sum only by a
|
|
79
|
+
* small rounding slack). `{ outputTokens: 0, totalTokens: 1_000_000 }`
|
|
80
|
+
* leaves a million tokens unpriced, so it is incomplete;
|
|
81
|
+
* - a text call (no voice fields) that consumed tokens reports prompt tokens
|
|
82
|
+
* (input, cached-input or cache-write): every model request has a prompt,
|
|
83
|
+
* so no prompt tokens beside non-zero output or total tokens means the
|
|
84
|
+
* input count was dropped;
|
|
85
|
+
* - a text call reports its output count. `{ inputTokens: 1 }` would price
|
|
86
|
+
* the output at `$0`, so an absent `outputTokens` is incomplete unless a
|
|
87
|
+
* reported `totalTokens` is no larger than `inputTokens`, which proves the
|
|
88
|
+
* call produced no output. An explicit `outputTokens: 0` is a reported
|
|
89
|
+
* count; adapters leave the field unset when the provider did not send it,
|
|
90
|
+
* and set `totalTokens` only when the provider reported it or from both an
|
|
91
|
+
* input and an output count, never from an input count alone.
|
|
92
|
+
*
|
|
93
|
+
* Cached reads are counted once, as part of `inputTokens` (see
|
|
94
|
+
* `countWithCached` for the convention), so a total that only a second count
|
|
95
|
+
* of the cached prompt would explain, such as Gemini's
|
|
96
|
+
* `{ inputTokens: 1000, cachedInputTokens: 1000, outputTokens: 10, totalTokens: 1510 }`,
|
|
97
|
+
* is incomplete rather than silently priced without its missing output.
|
|
98
|
+
*/
|
|
99
|
+
export function hasPriceableUsage(usage) {
|
|
100
|
+
if (!usage)
|
|
101
|
+
return false;
|
|
102
|
+
const record = usage;
|
|
103
|
+
for (const field of PRICED_USAGE_FIELDS) {
|
|
104
|
+
const value = record[field];
|
|
105
|
+
if (value !== undefined && !isValidCostUsd(value))
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (!SUFFICIENT_USAGE_FIELDS.some((field) => record[field] !== undefined))
|
|
109
|
+
return false;
|
|
110
|
+
const total = record.totalTokens;
|
|
111
|
+
if (total !== undefined && !isValidCostUsd(total))
|
|
112
|
+
return false;
|
|
113
|
+
// Prompt tokens: input (with cache reads) plus separately reported writes.
|
|
114
|
+
const input = countWithCached(record.inputTokens, record.cachedInputTokens) +
|
|
115
|
+
(record.cacheWriteTokens ?? 0);
|
|
116
|
+
const output = record.outputTokens ?? 0;
|
|
117
|
+
const parts = input +
|
|
118
|
+
output +
|
|
119
|
+
countWithCached(record.audioInputTokens, record.cachedAudioInputTokens) +
|
|
120
|
+
(record.audioOutputTokens ?? 0);
|
|
121
|
+
if (typeof total === 'number' && total > parts + totalTokensSlack(total))
|
|
122
|
+
return false;
|
|
123
|
+
const isVoice = VOICE_USAGE_FIELDS.some((field) => record[field] !== undefined);
|
|
124
|
+
if (!isVoice) {
|
|
125
|
+
if (input === 0 && (output > 0 || (typeof total === 'number' && total > 0)))
|
|
126
|
+
return false;
|
|
127
|
+
if (record.outputTokens === undefined) {
|
|
128
|
+
const promptOnly = typeof total === 'number' && total <= input;
|
|
129
|
+
if (!promptOnly)
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=usage-completeness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-completeness.js","sourceRoot":"","sources":["../src/usage-completeness.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type VoiceSocketFactory } from './voice-ws-shared.js';
|
|
1
2
|
import type { VoiceConnectOptions, VoiceProvider, VoiceSession } from './voice.js';
|
|
2
3
|
export interface OpenAIRealtimeVoiceProviderOptions {
|
|
3
4
|
apiKey: string;
|
|
@@ -9,12 +10,32 @@ export interface OpenAIRealtimeVoiceProviderOptions {
|
|
|
9
10
|
name?: string;
|
|
10
11
|
/** Extra headers (e.g. organization id). */
|
|
11
12
|
headers?: Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* Opens the provider WebSocket. Defaults to the Node `ws` peer; pass
|
|
15
|
+
* `createWorkersVoiceSocketFactory()` from `@fabric-harness/cloudflare/voice`
|
|
16
|
+
* on Cloudflare Workers and Durable Objects.
|
|
17
|
+
*/
|
|
18
|
+
socketFactory?: VoiceSocketFactory;
|
|
12
19
|
}
|
|
13
20
|
/**
|
|
14
21
|
* OpenAI Realtime voice provider. Connects via WebSocket; emits
|
|
15
22
|
* `audio_delta` / `text_delta` / `transcript` / `tool_call` / `response_done`
|
|
16
|
-
* events. Server-only: loads the optional `ws` peer to send
|
|
17
|
-
* headers
|
|
23
|
+
* events. Server-only: by default loads the optional `ws` peer to send
|
|
24
|
+
* authorization headers; inject `socketFactory` on other runtimes. Never
|
|
25
|
+
* instantiate with a provider API key in a browser.
|
|
26
|
+
*
|
|
27
|
+
* Cost budget: while a reply's budget check is in flight, `sendText` and
|
|
28
|
+
* `submitToolResult` add their items but hold `response.create` until it
|
|
29
|
+
* settles. `tool_call` is emitted before its response's `response.done` (and
|
|
30
|
+
* so before that response's cost is known): a tool result submitted early
|
|
31
|
+
* adds its `function_call_output` at once, but the continuation
|
|
32
|
+
* `response.create` waits until that `response.done` has been processed and
|
|
33
|
+
* its budget check has settled. While an `onExceed: 'approve'` approval is pending, caller audio is
|
|
34
|
+
* also discarded, so server VAD cannot start a response. On approval one held
|
|
35
|
+
* `response.create` is sent; on denial, or when the approver rejects, the
|
|
36
|
+
* session emits `error` and closes. A response the server had already started
|
|
37
|
+
* when the check began is not cancelled (its cost is observed on its own
|
|
38
|
+
* `response_done`).
|
|
18
39
|
*
|
|
19
40
|
* ```ts
|
|
20
41
|
* const provider = new OpenAIRealtimeVoiceProvider({ apiKey });
|
|
@@ -39,6 +60,7 @@ export declare class OpenAIRealtimeVoiceProvider implements VoiceProvider {
|
|
|
39
60
|
private readonly model;
|
|
40
61
|
private readonly baseUrl;
|
|
41
62
|
private readonly extraHeaders;
|
|
63
|
+
private readonly socketFactory;
|
|
42
64
|
constructor(options: OpenAIRealtimeVoiceProviderOptions);
|
|
43
65
|
connect(options?: VoiceConnectOptions): Promise<VoiceSession>;
|
|
44
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"voice-openai-realtime.d.ts","sourceRoot":"","sources":["../src/voice-openai-realtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"voice-openai-realtime.d.ts","sourceRoot":"","sources":["../src/voice-openai-realtime.ts"],"names":[],"mappings":"AAKA,OAAO,EAAgJ,KAAK,kBAAkB,EAAuB,MAAM,sBAAsB,CAAC;AAGlO,OAAO,KAAK,EAGV,mBAAmB,EAEnB,aAAa,EACb,YAAY,EAGb,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,kCAAkC;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;;OAIG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACpC;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,2BAA4B,YAAW,aAAa;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAyB;IACtD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiC;gBAEnD,OAAO,EAAE,kCAAkC;IAUjD,OAAO,CAAC,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,YAAY,CAAC;CAOxE"}
|