@mux/ai 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -12
- package/dist/{index-D3fZHu0h.d.ts → index-BdpEVCbj.d.ts} +74 -39
- package/dist/{index-BcNDGOI6.d.ts → index-Dmo55n-5.d.ts} +24 -5
- package/dist/index.d.ts +17 -6
- package/dist/index.js +29206 -521
- package/dist/index.js.map +1 -1
- package/dist/primitives/index.d.ts +2 -2
- package/dist/primitives/index.js +28318 -33
- package/dist/primitives/index.js.map +1 -1
- package/dist/types-KcVfWtUl.d.ts +202 -0
- package/dist/workflows/index.d.ts +2 -3
- package/dist/workflows/index.js +29119 -490
- package/dist/workflows/index.js.map +1 -1
- package/package.json +4 -1
- package/dist/types-DzOQNn9R.d.ts +0 -115
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import Mux from '@mux/mux-node';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Workflow Crypto
|
|
5
|
+
*
|
|
6
|
+
* Provides AES-256-GCM encryption for securely passing credentials to workflows.
|
|
7
|
+
* Encrypted payloads are JSON-serializable and include version/algorithm metadata
|
|
8
|
+
* for forward compatibility.
|
|
9
|
+
*/
|
|
10
|
+
declare const WORKFLOW_ENCRYPTION_VERSION = 1;
|
|
11
|
+
declare const WORKFLOW_ENCRYPTION_ALGORITHM: "aes-256-gcm";
|
|
12
|
+
/**
|
|
13
|
+
* Structure of an encrypted payload (all fields are base64-encoded where applicable).
|
|
14
|
+
*
|
|
15
|
+
* The optional `kid` (key ID) field supports key rotation scenarios:
|
|
16
|
+
* - Include a `kid` when encrypting to identify which key was used
|
|
17
|
+
* - On decryption, read `payload.kid` to look up the correct key
|
|
18
|
+
* - Keys should be invalidated/deleted after rotation, not kept indefinitely
|
|
19
|
+
*
|
|
20
|
+
* Security notes:
|
|
21
|
+
* - `kid` is stored in plaintext (not encrypted) — don't put sensitive data in it
|
|
22
|
+
* - Tampering with `kid` doesn't weaken security — wrong key = decryption fails
|
|
23
|
+
*/
|
|
24
|
+
interface EncryptedPayload {
|
|
25
|
+
v: typeof WORKFLOW_ENCRYPTION_VERSION;
|
|
26
|
+
alg: typeof WORKFLOW_ENCRYPTION_ALGORITHM;
|
|
27
|
+
kid?: string;
|
|
28
|
+
iv: string;
|
|
29
|
+
tag: string;
|
|
30
|
+
ciphertext: string;
|
|
31
|
+
}
|
|
32
|
+
/** Branded type that preserves the original type information for decryption */
|
|
33
|
+
type Encrypted<T> = EncryptedPayload & {
|
|
34
|
+
__type?: T;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Encrypts a value for secure transport to a workflow.
|
|
38
|
+
*
|
|
39
|
+
* @param value - Any JSON-serializable value (typically WorkflowCredentials)
|
|
40
|
+
* @param key - 32-byte secret key (base64 string or Uint8Array)
|
|
41
|
+
* @param keyId - Optional key identifier for rotation support (stored in plaintext)
|
|
42
|
+
* @returns Encrypted payload with metadata, safe to pass through untrusted channels
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Without key ID
|
|
46
|
+
* const encrypted = await encryptForWorkflow(credentials, secretKey);
|
|
47
|
+
*
|
|
48
|
+
* // With key ID for rotation support
|
|
49
|
+
* const encrypted = await encryptForWorkflow(credentials, secretKey, "key-2024-01");
|
|
50
|
+
*/
|
|
51
|
+
declare function encryptForWorkflow<T>(value: T, key: Uint8Array | string, keyId?: string): Promise<Encrypted<T>>;
|
|
52
|
+
/**
|
|
53
|
+
* Decrypts and deserializes a workflow payload.
|
|
54
|
+
*
|
|
55
|
+
* @param payload - Encrypted payload from `encryptForWorkflow`
|
|
56
|
+
* @param key - Same 32-byte secret key used for encryption
|
|
57
|
+
* @returns The original decrypted value
|
|
58
|
+
* @throws If payload is invalid, tampered with, or key is wrong
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // With key rotation: read kid to look up the correct key
|
|
62
|
+
* const keyId = payload.kid ?? "default";
|
|
63
|
+
* const key = keyStore.get(keyId);
|
|
64
|
+
* const credentials = await decryptFromWorkflow(payload, key);
|
|
65
|
+
*/
|
|
66
|
+
declare function decryptFromWorkflow<T>(payload: EncryptedPayload, key: Uint8Array | string): Promise<T>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Base options mixed into every higher-level workflow configuration.
|
|
70
|
+
*/
|
|
71
|
+
interface MuxAIOptions {
|
|
72
|
+
/** Optional timeout (ms) for helper utilities that support request limits. */
|
|
73
|
+
timeout?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Optional cancellation signal passed through to underlying AI SDK calls.
|
|
76
|
+
* When aborted, in-flight model requests will be
|
|
77
|
+
* cancelled where supported.
|
|
78
|
+
*/
|
|
79
|
+
abortSignal?: AbortSignal;
|
|
80
|
+
/**
|
|
81
|
+
* Optional credentials for workflow execution.
|
|
82
|
+
* Use encryptForWorkflow when running in Workflow Dev Kit environments.
|
|
83
|
+
*/
|
|
84
|
+
credentials?: WorkflowCredentialsInput;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Plaintext workflow credentials. Avoid passing these to Workflow Dev Kit start()
|
|
88
|
+
* unless you are not using workflow serialization.
|
|
89
|
+
*/
|
|
90
|
+
interface WorkflowCredentials {
|
|
91
|
+
muxTokenId?: string;
|
|
92
|
+
muxTokenSecret?: string;
|
|
93
|
+
muxSigningKey?: string;
|
|
94
|
+
muxPrivateKey?: string;
|
|
95
|
+
openaiApiKey?: string;
|
|
96
|
+
anthropicApiKey?: string;
|
|
97
|
+
googleApiKey?: string;
|
|
98
|
+
hiveApiKey?: string;
|
|
99
|
+
elevenLabsApiKey?: string;
|
|
100
|
+
}
|
|
101
|
+
/** Credentials that are safe to serialize across workflow boundaries. */
|
|
102
|
+
type WorkflowCredentialsInput = WorkflowCredentials | Encrypted<WorkflowCredentials>;
|
|
103
|
+
/** Tone controls for the summarization helper. */
|
|
104
|
+
type ToneType = "neutral" | "playful" | "professional";
|
|
105
|
+
/** Common transport for image-based workflows. */
|
|
106
|
+
type ImageSubmissionMode = "url" | "base64";
|
|
107
|
+
/** Result of calling mux-node's asset retrieval helper. */
|
|
108
|
+
type MuxAsset = Awaited<ReturnType<Mux["video"]["assets"]["retrieve"]>>;
|
|
109
|
+
/** Single ready track extracted from a Mux asset. */
|
|
110
|
+
type AssetTextTrack = NonNullable<MuxAsset["tracks"]>[number];
|
|
111
|
+
/** Playback policy type for Mux assets. */
|
|
112
|
+
type PlaybackPolicy = "public" | "signed";
|
|
113
|
+
/** Convenience bundle returned by `getPlaybackIdForAsset`. */
|
|
114
|
+
interface PlaybackAsset {
|
|
115
|
+
asset: MuxAsset;
|
|
116
|
+
playbackId: string;
|
|
117
|
+
/** The policy type of the playback ID ('public' or 'signed'). */
|
|
118
|
+
policy: PlaybackPolicy;
|
|
119
|
+
}
|
|
120
|
+
/** Configuration for token-based chunking. */
|
|
121
|
+
interface TokenChunkingConfig {
|
|
122
|
+
type: "token";
|
|
123
|
+
/** Maximum tokens per chunk. */
|
|
124
|
+
maxTokens: number;
|
|
125
|
+
/** Number of overlapping tokens between chunks. */
|
|
126
|
+
overlap?: number;
|
|
127
|
+
}
|
|
128
|
+
/** Configuration for VTT-aware chunking that respects cue boundaries. */
|
|
129
|
+
interface VTTChunkingConfig {
|
|
130
|
+
type: "vtt";
|
|
131
|
+
/** Maximum tokens per chunk. */
|
|
132
|
+
maxTokens: number;
|
|
133
|
+
/** Number of cues to overlap between chunks (default: 2). */
|
|
134
|
+
overlapCues?: number;
|
|
135
|
+
}
|
|
136
|
+
/** Union type for all chunking strategy configurations. */
|
|
137
|
+
type ChunkingStrategy = TokenChunkingConfig | VTTChunkingConfig;
|
|
138
|
+
/** A single chunk of text extracted from a transcript. */
|
|
139
|
+
interface TextChunk {
|
|
140
|
+
/** Unique identifier for this chunk. */
|
|
141
|
+
id: string;
|
|
142
|
+
/** The text content of the chunk. */
|
|
143
|
+
text: string;
|
|
144
|
+
/** Number of tokens in this chunk. */
|
|
145
|
+
tokenCount: number;
|
|
146
|
+
/** Start time in seconds (if available from timestamped transcript). */
|
|
147
|
+
startTime?: number;
|
|
148
|
+
/** End time in seconds (if available from timestamped transcript). */
|
|
149
|
+
endTime?: number;
|
|
150
|
+
}
|
|
151
|
+
/** A chunk with its embedding vector. */
|
|
152
|
+
interface ChunkEmbedding {
|
|
153
|
+
/** Reference to the chunk ID. */
|
|
154
|
+
chunkId: string;
|
|
155
|
+
/** The embedding vector. */
|
|
156
|
+
embedding: number[];
|
|
157
|
+
/** Optional metadata for this chunk. */
|
|
158
|
+
metadata: {
|
|
159
|
+
startTime?: number;
|
|
160
|
+
endTime?: number;
|
|
161
|
+
tokenCount: number;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/** Result of generating embeddings for a video asset. */
|
|
165
|
+
interface VideoEmbeddingsResult {
|
|
166
|
+
/** The Mux asset ID. */
|
|
167
|
+
assetId: string;
|
|
168
|
+
/** Individual chunk embeddings. */
|
|
169
|
+
chunks: ChunkEmbedding[];
|
|
170
|
+
/** Averaged embedding across all chunks. */
|
|
171
|
+
averagedEmbedding: number[];
|
|
172
|
+
/** AI provider used. */
|
|
173
|
+
provider: string;
|
|
174
|
+
/** Model used for embedding generation. */
|
|
175
|
+
model: string;
|
|
176
|
+
/** Additional metadata about the generation. */
|
|
177
|
+
metadata: {
|
|
178
|
+
totalChunks: number;
|
|
179
|
+
totalTokens: number;
|
|
180
|
+
chunkingStrategy: string;
|
|
181
|
+
embeddingDimensions: number;
|
|
182
|
+
generatedAt: string;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Token usage breakdown returned by AI SDK providers.
|
|
187
|
+
* Used for efficiency and cost analysis.
|
|
188
|
+
*/
|
|
189
|
+
interface TokenUsage {
|
|
190
|
+
/** Number of tokens in the input prompt (text + image). */
|
|
191
|
+
inputTokens?: number;
|
|
192
|
+
/** Number of tokens generated in the output. */
|
|
193
|
+
outputTokens?: number;
|
|
194
|
+
/** Total tokens consumed (input + output). */
|
|
195
|
+
totalTokens?: number;
|
|
196
|
+
/** Tokens used for chain-of-thought reasoning (if applicable). */
|
|
197
|
+
reasoningTokens?: number;
|
|
198
|
+
/** Input tokens served from cache (reduces cost). */
|
|
199
|
+
cachedInputTokens?: number;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export { type AssetTextTrack as A, type ChunkingStrategy as C, type Encrypted as E, type ImageSubmissionMode as I, type MuxAIOptions as M, type PlaybackPolicy as P, type ToneType as T, type VTTChunkingConfig as V, type WorkflowCredentials as W, type EncryptedPayload as a, type WorkflowCredentialsInput as b, type MuxAsset as c, decryptFromWorkflow as d, encryptForWorkflow as e, type PlaybackAsset as f, type TokenChunkingConfig as g, type TextChunk as h, type ChunkEmbedding as i, type VideoEmbeddingsResult as j, type TokenUsage as k };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { J as AudioTranslationOptions, I as AudioTranslationResult, e as BurnedInCaptionsAnalysis, c as BurnedInCaptionsOptions, b as BurnedInCaptionsPromptOverrides, a as BurnedInCaptionsPromptSections, B as BurnedInCaptionsResult, C as Chapter, o as ChapterSystemPromptSections, n as ChaptersOptions, m as ChaptersPromptOverrides, l as ChaptersPromptSections, k as ChaptersResult, j as ChaptersType, E as EmbeddingsOptions, q as EmbeddingsResult, u as HiveModerationOutput, H as HiveModerationSource, v as ModerationOptions, t as ModerationProvider, M as ModerationResult, S as SUMMARY_KEYWORD_LIMIT, F as SummarizationOptions, D as SummarizationPromptOverrides, A as SummarizationPromptSections, z as SummaryAndTagsResult, y as SummaryType, T as ThumbnailModerationScore, N as TranslationOptions, P as TranslationPayload, L as TranslationResult, d as burnedInCaptionsSchema, f as chapterSchema, g as chaptersSchema, p as generateChapters, r as generateEmbeddings, s as generateVideoEmbeddings, w as getModerationScores, G as getSummaryAndTags, h as hasBurnedInCaptions, x as summarySchema, K as translateAudio, Q as translateCaptions, O as translationSchema } from '../index-BdpEVCbj.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import '@ai-sdk/anthropic';
|
|
4
4
|
import '@ai-sdk/google';
|
|
5
5
|
import '@ai-sdk/openai';
|
|
6
|
-
import '../types-
|
|
6
|
+
import '../types-KcVfWtUl.js';
|
|
7
7
|
import '@mux/mux-node';
|
|
8
|
-
import 'node:buffer';
|