@voctiv/agent-sdk 0.2.6 → 0.2.8

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.
@@ -10,13 +10,15 @@ import type { LegacySavePhraseOptions } from './legacy-phrase';
10
10
  */
11
11
  export type TtsStrategy = 'sentence' | 'streaming' | 'full';
12
12
  /**
13
- * Internal TTS vendor code used by the connector factory.
13
+ * TTS vendor alias understood by ScriptEngine.
14
14
  *
15
- * - **`A`**: default / Neuro-style path.
16
- * - **`E`** / **`ES`**: ElevenLabs (`ES` = persistent streaming session where supported).
17
- * - **`V`**, **`G`**: host-specific vendors (e.g. Voctiv, Google).
15
+ * Dedicated TTS connectors are selected by aliases such as **`"elevenlabs"`**,
16
+ * **`"google"`**, and **`"voctiv"`**. The default TTS path can also accept
17
+ * compatible aliases such as **`"azure"`** or **`"neuro_v3"`**, depending on
18
+ * deployment configuration. The open string form keeps the SDK compatible with
19
+ * deployment-specific aliases.
18
20
  */
19
- export type TtsVendor = 'A' | 'E' | 'ES' | 'V' | 'G';
21
+ export type TtsVendor = 'elevenlabs' | 'google' | 'azure' | 'yandex' | 'sber' | 'viettel' | 'voctiv' | 'neuro' | 'neuro_v2' | 'neuro_v3' | 'neuro_service' | 'async_azure' | 'stc' | (string & Record<never, never>);
20
22
  /**
21
23
  * Options for {@link import('./media-channel').ChannelAudio.say},
22
24
  * {@link import('./media-channel').ChannelAudio.play}, and
@@ -1 +1 @@
1
- {"version":3,"file":"mixer.d.ts","sourceRoot":"","sources":["../../src/types/mixer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,MAAM,CAAC;AAE5D;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG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CAAC,YAAY,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAC1C,yFAAyF;IACzF,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAC3C,uFAAuF;IACvF,QAAQ,CAAC,WAAW,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAEvC;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,uDAAuD;IACvD,KAAK,IAAI,IAAI,CAAC;CACf"}
@@ -0,0 +1,164 @@
1
+ import type { Observable } from 'rxjs';
2
+ import type { NluExtractOptions, NluInferResult } from './nlu';
3
+ import type { LegacyGetRecordsParams, LegacyPhraseRecord } from './legacy-phrase';
4
+ /**
5
+ * NLU (Natural Language Understanding) API.
6
+ *
7
+ * Provides intent/entity extraction through the legacy NLU v3 `/infer` endpoint.
8
+ * ScriptEngine allows this API when `context.legacyV3Compat` is `true` and NLU
9
+ * runtime settings are configured (`NLU_V3_BASE_URL` plus a resolved numeric
10
+ * agent id). Calls fail fast with a descriptive error otherwise.
11
+ *
12
+ * Compatible with logic-executor `nn.extract()` request/response shape.
13
+ */
14
+ export interface NluScriptApi {
15
+ /**
16
+ * Extract intents and entities from one user utterance.
17
+ *
18
+ * The runtime sends `{ phrase, context, agent_id }` to NLU v3. If
19
+ * `options.context` is omitted, it serializes the current dialog params
20
+ * (`context.dialogParams`, then legacy fallbacks) as the request context.
21
+ *
22
+ * @param utterance - User input text to analyze.
23
+ * @param options - Optional NLU filters and flags. `entities`, `intents`,
24
+ * `use_neuro_api`, and `use_synonyms` are forwarded by ScriptEngine.
25
+ * @returns Raw parsed JSON response from the NLU `/infer` endpoint.
26
+ */
27
+ extract(utterance: string, options?: NluExtractOptions): Promise<NluInferResult>;
28
+ /**
29
+ * Observable wrapper around {@link extract}.
30
+ *
31
+ * This is not a streaming NLU session: every subscription performs one
32
+ * `extract()` call and emits exactly one result or one error.
33
+ */
34
+ extract$(utterance: string, options?: NluExtractOptions): Observable<NluInferResult>;
35
+ }
36
+ /** Options for scheduling an outbound call via {@link PlatformApi.call}. */
37
+ export interface ScheduleCallOptions {
38
+ /** When to place the call. Defaults to now. */
39
+ date?: string | Date;
40
+ /** Deadline — don't call after this time. */
41
+ dateEnd?: string | Date;
42
+ /**
43
+ * Entry point to pass to the script when the call connects.
44
+ *
45
+ * Stored in the created call params as `entry_point`.
46
+ */
47
+ entryPoint?: string;
48
+ /**
49
+ * Legacy compatibility field for callers that schedule without a current `scriptId`.
50
+ *
51
+ * ScriptEngine uses this to allow scheduling when the current script id is not
52
+ * available. It does not resolve script names or paths from this field.
53
+ */
54
+ script?: string;
55
+ /** Reserved SIP channel/trunk hint. Not used by the default ScriptEngine scheduler. */
56
+ channel?: string;
57
+ /** How many times to retry on failure. Stored as `recall_count` in call params. */
58
+ recallCount?: number;
59
+ /** Delay in seconds between retries. Stored as `recall_delay` in call params. */
60
+ recallDelay?: number;
61
+ /** Entry point to use after a successful call. Stored as `on_success_call`. */
62
+ onSuccessCall?: string;
63
+ /** Entry point to use after a failed call. Stored as `on_failed_call`. */
64
+ onFailedCall?: string;
65
+ /** Call priority (higher = processed sooner by dialer). */
66
+ priority?: number;
67
+ /** Timezone offset passed to the legacy call row as `timeZone`. */
68
+ timezone?: number;
69
+ /** Extra SIP headers or protocol-level params. Stored as `proto_additional` in call params. */
70
+ protoAdditional?: Record<string, string>;
71
+ }
72
+ /**
73
+ * Dialog state API — read and update dialog routing metadata.
74
+ *
75
+ * Setting `entryPoint` or `result` updates the local value immediately and asks
76
+ * the Voctiv platform database to persist the change asynchronously. In worker
77
+ * sessions the setter sends an RPC to the main thread; in direct sessions errors
78
+ * are logged. There is no awaitable setter, so do not use it for transactional flow.
79
+ */
80
+ export interface DialogApi {
81
+ /** Current script entry point (e.g. `"on_recall"`). Set to change routing for the next call. */
82
+ entryPoint: string | undefined;
83
+ /** Dialog outcome (e.g. `"done"`, `"busy"`, `"no_answer"`). Set to finalize dialog. */
84
+ result: string | undefined;
85
+ /** Dialog UUID (read-only). */
86
+ readonly uuid: string;
87
+ /** Caller msisdn (read-only). */
88
+ readonly msisdn: string;
89
+ }
90
+ /** Options for sending an outbound message via {@link MessagingApi.send}. */
91
+ export interface SendMessageOptions {
92
+ /** Sender identifier (service id, bot id, or phone number expected by the MA consumer). */
93
+ src: string;
94
+ /** Recipient identifier (phone number, user id, or channel-specific address). */
95
+ destination: string;
96
+ /** Text body of the message. When present in legacy mode, it is also mirrored to dialog stats. */
97
+ text?: string;
98
+ /** URL of an attachment (image, document, etc.). */
99
+ attachment?: string;
100
+ /** Quick-reply button labels. */
101
+ buttons?: string[];
102
+ }
103
+ /** Inbound message received from an external messaging channel. */
104
+ export interface InboundMessage {
105
+ /** Sender identifier (who sent the message). */
106
+ src: string;
107
+ /** Recipient identifier (your service endpoint). */
108
+ dst: string;
109
+ /** Channel type, e.g. `"api"`. */
110
+ channelType: string;
111
+ /** Full raw payload from the messaging transport. */
112
+ payload: Record<string, unknown>;
113
+ }
114
+ /**
115
+ * Messaging API — send and receive messages through external channels.
116
+ *
117
+ * Outbound messages are transported via Redis Streams (`ma_send` / `ma_receive`),
118
+ * compatible with the old LE messaging architecture. `message$` is currently a
119
+ * one-shot replay of the inbound message that started a headless messaging script,
120
+ * not a live subscription to all future Redis messages.
121
+ */
122
+ export interface MessagingApi {
123
+ /**
124
+ * Send an outbound message.
125
+ * Published to Redis stream for delivery by external consumer.
126
+ */
127
+ send(options: SendMessageOptions): Promise<void>;
128
+ /**
129
+ * Observable of inbound messages.
130
+ * Emits the triggering message when the script is started by an incoming message
131
+ * (entry point `on_message_api_received`).
132
+ */
133
+ readonly message$: Observable<InboundMessage>;
134
+ }
135
+ /**
136
+ * Platform API — Voctiv platform–compatible operations available to scripts.
137
+ *
138
+ * Provides access to NLU, dialog state management, outbound call scheduling,
139
+ * phrase records, and messaging. These operations are legacy-platform backed and
140
+ * require `context.legacyV3Compat === true`.
141
+ */
142
+ export interface PlatformApi {
143
+ /** NLU intent/entity extraction API; throws outside legacy V3 compatibility mode. */
144
+ readonly nlu: NluScriptApi;
145
+ /** Dialog state — read/write entry point and result. */
146
+ readonly dialog: DialogApi;
147
+ /** Messaging API — send and receive external messages. */
148
+ readonly messaging: MessagingApi;
149
+ /**
150
+ * Schedule an outbound call.
151
+ * Creates a record in the `call` table; the dialer picks it up and originates the SIP call.
152
+ * @param msisdn - Destination phone number (E.164).
153
+ * @param options - Scheduling, routing, and retry options.
154
+ */
155
+ call(msisdn: string, options?: ScheduleCallOptions): Promise<void>;
156
+ /**
157
+ * Voctiv platform only: load `record_phrase` / `record_phrase_file` rows from the LE PostgreSQL database
158
+ * (same filters as old `RecordPhrase.get_records`). Returns playable phrase record objects.
159
+ * Requires numeric `agent_id` on the dialog (params or `NLU_DEFAULT_AGENT_ID`) and
160
+ * `LEGACY_V3_RECORD_PHRASE_ROOT` pointing at the phrase file storage root.
161
+ */
162
+ getRecords?(params: LegacyGetRecordsParams): Promise<LegacyPhraseRecord[]>;
163
+ }
164
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/types/platform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,KAAK,EACV,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;;;OAWG;IACH,OAAO,CACL,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CACN,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,UAAU,CAAC,cAAc,CAAC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MAAM,CAAC;IACpB,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,IAAI,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC;CAC/C;AAED;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,qFAAqF;IACrF,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC;IAC3B,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,0DAA0D;IAC1D,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC;IACjC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE;;;;;OAKG;IACH,UAAU,CAAC,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;CAC5E"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/types/platform.ts"],"names":[],"mappings":""}
@@ -0,0 +1,170 @@
1
+ import type { BehaviorSubject } from 'rxjs';
2
+ import type { InboundMessage } from './platform';
3
+ /**
4
+ * First-level **`context`** passed to every **`defineScript`** handler.
5
+ *
6
+ * Combines **identity** (dialog, script, agent), **telephony** (caller/destination),
7
+ * **payload** (**`initialData`** vs **`dialogParams`**), **Voctiv platform** rows (**`dialogEntity`**),
8
+ * and **runtime** (**`env$`**, **`runTime`**). The index signature allows extra host-specific keys.
9
+ */
10
+ export interface ScriptDialogContext {
11
+ /** Short language code, e.g. `"ru"`, `"en"`. */
12
+ lang: string;
13
+ /** Full BCP-47 language tag, e.g. `"ru-RU"`, `"en-US"`. */
14
+ language: string;
15
+ /** Business flag for routing (e.g. `"default"`, `"vip"`). */
16
+ flag: string;
17
+ /** Unique dialog identifier (UUID). */
18
+ dialogUuid: string;
19
+ /** Caller phone number or messaging source ID. */
20
+ msisdn: string;
21
+ /** Inbound caller ID (same as msisdn for inbound calls). */
22
+ callerId: string;
23
+ /** Called number (DID / destination for inbound calls). */
24
+ destinationNumber: string;
25
+ /** Script record ID in the system. */
26
+ scriptId: string;
27
+ /** Human-readable script name. */
28
+ scriptName: string;
29
+ /** Agent UUID from Omni platform (links script to an NLU agent). */
30
+ agentUuid?: string;
31
+ /**
32
+ * Numeric NLU agent id used for `platform.nlu.extract()` and legacy DB operations.
33
+ *
34
+ * Resolved by the server from Omni/LE mapping or env (`NLU_DEFAULT_AGENT_ID` /
35
+ * `AGENT_ID`). Client/session params named `agent_id`, `agentId`, `agentUuid`,
36
+ * and `agent_uuid` are stripped before context construction and cannot spoof it.
37
+ * May be `0` when no agent id is configured; NLU and `platform.call()` will then fail.
38
+ */
39
+ agentId: number;
40
+ /**
41
+ * **Snapshot** of dialog/session payload when the script run started.
42
+ *
43
+ * Shallow copy of the merge **`channelParams` + `sessionParams`** after the server removes
44
+ * untrusted keys (e.g. client cannot spoof **`agentUuid`** here). **Do not mutate** — use
45
+ * **`dialogParams`** for the live map. Compare with **`dialogParams`** to see what changed
46
+ * during the call (if the host updates the live object).
47
+ */
48
+ initialData: Record<string, unknown>;
49
+ /**
50
+ * **Live** dialog/session parameter map for this run (same merge as **`initialData`** at start).
51
+ *
52
+ * The host may add or overwrite keys while the session progresses. For media scripts this
53
+ * aligns with {@link import('./media-channel').MediaChannel.params} (Omni defaults, route,
54
+ * Voctiv platform ASR/TTS: **`defaultAsrName`**, **`defaultTtsName`**, **`asrVendor`**, **`ttsVendor`**,
55
+ * **`asrConfig`**, **`ttsConfig`**, **`authentication_data`**, **`legacyAsrKeysByName`** /
56
+ * **`legacyTtsKeysByName`**, etc.). **Read/write** according to your integration; scripts should
57
+ * treat unknown keys as opaque.
58
+ */
59
+ dialogParams: Record<string, unknown>;
60
+ /** Whether Voctiv platform compatibility mode is active. */
61
+ legacyV3Compat: boolean;
62
+ /**
63
+ * `true` when the script runs without a real media channel (offline / queue / messaging).
64
+ *
65
+ * In this mode ASR/TTS/audio/SIP operations are inert or synthetic. Use text payloads,
66
+ * `platform.nlu`, `platform.messaging`, `platform.call`, `channel.llm`, and `env$`
67
+ * for background dialog logic.
68
+ */
69
+ headless: boolean;
70
+ /**
71
+ * Persisted dialog environment for this conversation. ScriptEngine converts the
72
+ * plain persisted `env` snapshot into this `BehaviorSubject` before invoking the script.
73
+ * On the first call the value is `undefined`.
74
+ *
75
+ * **Read/write only via `env$`:** use `env$.getValue()`, `env$.next(partialOrNext)`, or
76
+ * `env$.subscribe(...)`. Do not use a plain `context.env` — it is not provided.
77
+ *
78
+ * **Persistence:** On script completion (success or error), the runtime snapshots `env$` and
79
+ * attaches it to the persisted result; the script return value must not carry env
80
+ * (see {@link ScriptResult}).
81
+ *
82
+ * Session runners decide where that snapshot is stored. In Voctiv platform compatibility
83
+ * mode it is used as the LE-style dialog environment.
84
+ */
85
+ env$?: BehaviorSubject<Record<string, unknown> | undefined>;
86
+ /** Raw `dialog` table row from the Voctiv platform database. */
87
+ dialogEntity?: Record<string, unknown>;
88
+ /** Raw `call` table row from the Voctiv platform database. */
89
+ callEntity?: Record<string, unknown>;
90
+ /**
91
+ * Optional catalog of media keys exposed to the script (Voctiv platform / Omni), e.g. UUIDs or labels
92
+ * for UI or logging. **Credentials** still come from **`dialogParams.authentication_data`**
93
+ * (and the channel mirror); use **`name`** on {@link import('./asr-handle').AsrConfig} /
94
+ * {@link import('./mixer').PlayOptions} to select **`key_storage.name`** when LE credential maps exist.
95
+ */
96
+ availableMediaKeys?: string[];
97
+ /** Script entry point for routing (e.g. `"on_recall"`, `"on_message_api_received"`). */
98
+ entryPoint?: string;
99
+ /** Current recall attempt number (starts at 0). */
100
+ attempt?: number;
101
+ /** Max recall attempts configured for this dialog. */
102
+ recallCount?: number;
103
+ /** Delay in seconds between recall attempts. */
104
+ recallDelay?: number;
105
+ /**
106
+ * Inbound message that triggered this headless session.
107
+ *
108
+ * Present for messaging-driven offline runs, commonly with
109
+ * `entryPoint === "on_message_api_received"`. The `payload` field is the raw
110
+ * provider payload; normalize text defensively because transports may use
111
+ * different keys such as `text`, `message`, `body`, or `content`.
112
+ */
113
+ inboundMessage?: InboundMessage;
114
+ /**
115
+ * Async-phase execution budget: remaining time, extension pool, {@link ScriptRunTime.extend}.
116
+ * Injected by the runtime; absent only in tests or non-standard hosts.
117
+ */
118
+ runTime?: ScriptRunTime;
119
+ /** Opaque NLU runtime config managed by ScriptEngine. */
120
+ _nlu?: unknown;
121
+ [key: string]: unknown;
122
+ }
123
+ /**
124
+ * Time budget for the script async phase (after VM load). Lets scripts check remaining time
125
+ * and request limited extensions (capped by the runtime).
126
+ */
127
+ export interface ScriptRunTime {
128
+ /** Initial budget in ms before any {@link extend}. */
129
+ readonly budgetMs: number;
130
+ /** Maximum total extra ms grantable across all {@link extend} calls for this session. */
131
+ readonly maxExtendMs: number;
132
+ /** Milliseconds left until the runtime stops the async script phase. */
133
+ remainingMs(): number;
134
+ /** Extension quota not yet granted (ms). */
135
+ remainingExtendMs(): number;
136
+ /**
137
+ * Grants up to `requestedMs` additional runtime, limited by remaining extension quota.
138
+ * @returns Granted milliseconds (0 if nothing could be granted).
139
+ */
140
+ extend(requestedMs: number): number;
141
+ }
142
+ /** Error info attached to {@link ScriptResult} when a script fails. */
143
+ export interface ScriptError {
144
+ /**
145
+ * Machine-readable category, e.g. `script_error`, `script_load_failed`, `time_limit_exceeded`.
146
+ */
147
+ code: string;
148
+ /** Human-readable error description. */
149
+ message: string;
150
+ /** Stack trace (when available). */
151
+ stack?: string;
152
+ }
153
+ /**
154
+ * Value returned by a script function. Only `output` and `error` are valid fields.
155
+ * Session state is updated via `context.env$`; the runtime snapshots it separately.
156
+ */
157
+ export interface ScriptResult {
158
+ /** Output data to store in dialog_stats. */
159
+ output?: Record<string, unknown>;
160
+ /** Error details (auto-populated on script crash, or set manually). */
161
+ error?: ScriptError;
162
+ }
163
+ /**
164
+ * Result after the runtime attaches the final `env$` snapshot (Voctiv platform persistence).
165
+ * Scripts never construct this type — use {@link ScriptResult} from `defineScript` handlers.
166
+ */
167
+ export interface PersistedScriptResult extends ScriptResult {
168
+ env?: Record<string, unknown>;
169
+ }
170
+ //# sourceMappingURL=script-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-context.d.ts","sourceRoot":"","sources":["../../src/types/script-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sCAAsC;IACtC,QAAQ,EA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,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,yFAAyF;IACzF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,wEAAwE;IACxE,WAAW,IAAI,MAAM,CAAC;IACtB,4CAA4C;IAC5C,iBAAiB,IAAI,MAAM,CAAC;IAC5B;;;OAGG;IACH,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;CACrC;AAED,uEAAuE;AACvE,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,uEAAuE;IACvE,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAsB,SAAQ,YAAY;IACzD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=script-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-context.js","sourceRoot":"","sources":["../../src/types/script-context.ts"],"names":[],"mappings":""}