@transloadit/utils 4.3.0 → 4.4.1
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/dist/assemblyInstructionsCompiler.d.ts +104 -0
- package/dist/assemblyInstructionsCompiler.d.ts.map +1 -0
- package/dist/assemblyInstructionsCompiler.js +215 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/node.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export declare const COMPILE_ASSEMBLY_INSTRUCTIONS_DEFAULT_MODEL = "openai/gpt-5.6-sol";
|
|
2
|
+
export declare const COMPILE_ASSEMBLY_INSTRUCTIONS_DEFAULT_REASONING_EFFORT = "medium";
|
|
3
|
+
export declare const COMPILE_ASSEMBLY_INSTRUCTIONS_DEFAULT_MAX_ATTEMPTS = 3;
|
|
4
|
+
export declare const COMPILE_ASSEMBLY_INSTRUCTIONS_MCP_ALLOWED_TOOLS: readonly ["transloadit_get_robot_help", "transloadit_lint_assembly_instructions", "transloadit_list_robots"];
|
|
5
|
+
export type CompileAssemblyInstructionsMessage = {
|
|
6
|
+
role: 'assistant' | 'user';
|
|
7
|
+
content: string;
|
|
8
|
+
};
|
|
9
|
+
export type CompileAssemblyInstructionsMcpServer = string | {
|
|
10
|
+
type: string;
|
|
11
|
+
url: string;
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
auth?: string;
|
|
14
|
+
allowed_tools?: string | string[];
|
|
15
|
+
};
|
|
16
|
+
export type CompileAssemblyInstructionsLintIssue = {
|
|
17
|
+
type?: string;
|
|
18
|
+
code?: string;
|
|
19
|
+
message?: string;
|
|
20
|
+
summary?: string;
|
|
21
|
+
desc?: string;
|
|
22
|
+
};
|
|
23
|
+
export type CompileAssemblyInstructionsAiStep = {
|
|
24
|
+
robot: '/ai/chat';
|
|
25
|
+
result: true;
|
|
26
|
+
model: string;
|
|
27
|
+
reasoning_effort: string;
|
|
28
|
+
test_credentials: true;
|
|
29
|
+
format: 'json';
|
|
30
|
+
schema: string;
|
|
31
|
+
system_message: string;
|
|
32
|
+
interpolate: {
|
|
33
|
+
system_message: false;
|
|
34
|
+
};
|
|
35
|
+
messages: CompileAssemblyInstructionsMessage[];
|
|
36
|
+
mcp_servers?: CompileAssemblyInstructionsMcpServer[];
|
|
37
|
+
};
|
|
38
|
+
export type CompileAssemblyInstructionsRunInput = {
|
|
39
|
+
aiStep: CompileAssemblyInstructionsAiStep;
|
|
40
|
+
};
|
|
41
|
+
export type CompileAssemblyInstructionsRunResult = {
|
|
42
|
+
response: unknown;
|
|
43
|
+
assemblyUrl?: string;
|
|
44
|
+
billedChargeUsd?: number;
|
|
45
|
+
usageBytes?: number;
|
|
46
|
+
};
|
|
47
|
+
export type CompileAssemblyInstructionsClient = {
|
|
48
|
+
runAssemblyInstructionsCompiler(input: CompileAssemblyInstructionsRunInput): Promise<CompileAssemblyInstructionsRunResult>;
|
|
49
|
+
lintAssemblyInstructions(instructionsJson: string): Promise<CompileAssemblyInstructionsLintIssue[]>;
|
|
50
|
+
};
|
|
51
|
+
export type CompileAssemblyInstructionsResponse = {
|
|
52
|
+
message: string;
|
|
53
|
+
instructions?: {
|
|
54
|
+
steps: Record<string, unknown>;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export type CompileAssemblyInstructionsAttempt = {
|
|
58
|
+
attempt: number;
|
|
59
|
+
error: string;
|
|
60
|
+
generatedInstructions?: string;
|
|
61
|
+
lintIssues?: CompileAssemblyInstructionsLintIssue[];
|
|
62
|
+
};
|
|
63
|
+
export type CompileAssemblyInstructionsResult = {
|
|
64
|
+
assemblyUrl?: string;
|
|
65
|
+
billedChargeUsd?: number;
|
|
66
|
+
instructions: {
|
|
67
|
+
steps: Record<string, unknown>;
|
|
68
|
+
};
|
|
69
|
+
instructionsJson: string;
|
|
70
|
+
message: string;
|
|
71
|
+
usageBytes?: number;
|
|
72
|
+
validationAttempts: CompileAssemblyInstructionsAttempt[];
|
|
73
|
+
};
|
|
74
|
+
export type CompileAssemblyInstructionsOptions = {
|
|
75
|
+
client: CompileAssemblyInstructionsClient;
|
|
76
|
+
docs?: string;
|
|
77
|
+
indent?: number;
|
|
78
|
+
maxAttempts?: number;
|
|
79
|
+
mcpServerUrl?: string;
|
|
80
|
+
mcpServers?: CompileAssemblyInstructionsMcpServer[];
|
|
81
|
+
messages?: CompileAssemblyInstructionsMessage[];
|
|
82
|
+
model?: string;
|
|
83
|
+
prompt: string;
|
|
84
|
+
reasoningEffort?: string;
|
|
85
|
+
systemPrompt?: string;
|
|
86
|
+
};
|
|
87
|
+
export declare class CompileAssemblyInstructionsError extends Error {
|
|
88
|
+
generatedInstructions?: string;
|
|
89
|
+
lintIssues?: CompileAssemblyInstructionsLintIssue[];
|
|
90
|
+
validationAttempts: CompileAssemblyInstructionsAttempt[];
|
|
91
|
+
constructor(message: string, opts?: {
|
|
92
|
+
cause?: unknown;
|
|
93
|
+
generatedInstructions?: string;
|
|
94
|
+
lintIssues?: CompileAssemblyInstructionsLintIssue[];
|
|
95
|
+
validationAttempts?: CompileAssemblyInstructionsAttempt[];
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
export declare const COMPILE_ASSEMBLY_INSTRUCTIONS_RESPONSE_JSON_SCHEMA: string;
|
|
99
|
+
export declare function buildCompileAssemblyInstructionsSystemPrompt({ docs, }?: {
|
|
100
|
+
docs?: string;
|
|
101
|
+
}): string;
|
|
102
|
+
export declare function parseCompileAssemblyInstructionsResponse(value: unknown): CompileAssemblyInstructionsResponse;
|
|
103
|
+
export declare function compileAssemblyInstructionsFromPrompt(options: CompileAssemblyInstructionsOptions): Promise<CompileAssemblyInstructionsResult>;
|
|
104
|
+
//# sourceMappingURL=assemblyInstructionsCompiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assemblyInstructionsCompiler.d.ts","sourceRoot":"","sources":["../src/assem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_DEFAULT_REASONING_EFFORT = 'medium';
|
|
3
|
+
export const COMPILE_ASSEMBLY_INSTRUCTIONS_DEFAULT_MAX_ATTEMPTS = 3;
|
|
4
|
+
export const COMPILE_ASSEMBLY_INSTRUCTIONS_MCP_ALLOWED_TOOLS = [
|
|
5
|
+
'transloadit_get_robot_help',
|
|
6
|
+
'transloadit_lint_assembly_instructions',
|
|
7
|
+
'transloadit_list_robots',
|
|
8
|
+
];
|
|
9
|
+
export class CompileAssemblyInstructionsError extends Error {
|
|
10
|
+
generatedInstructions;
|
|
11
|
+
lintIssues;
|
|
12
|
+
validationAttempts;
|
|
13
|
+
constructor(message, opts = {}) {
|
|
14
|
+
super(message, opts.cause === undefined ? undefined : { cause: opts.cause });
|
|
15
|
+
this.name = 'CompileAssemblyInstructionsError';
|
|
16
|
+
this.generatedInstructions = opts.generatedInstructions;
|
|
17
|
+
this.lintIssues = opts.lintIssues;
|
|
18
|
+
this.validationAttempts = opts.validationAttempts ?? [];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export const COMPILE_ASSEMBLY_INSTRUCTIONS_RESPONSE_JSON_SCHEMA = JSON.stringify({
|
|
22
|
+
type: 'object',
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
required: ['message'],
|
|
25
|
+
properties: {
|
|
26
|
+
message: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
description: 'A brief explanation or conversational reply. Mention assumptions, missing credentials, or placeholders when relevant.',
|
|
29
|
+
},
|
|
30
|
+
instructions: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
required: ['steps'],
|
|
34
|
+
properties: {
|
|
35
|
+
steps: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
additionalProperties: true,
|
|
38
|
+
description: 'The complete Transloadit Assembly Instructions steps object. Always include every step, not just changed parts.',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
45
|
+
export function buildCompileAssemblyInstructionsSystemPrompt({ docs, } = {}) {
|
|
46
|
+
const docsSuffix = docs?.trim() ? `\n\n${docs.trim()}` : '';
|
|
47
|
+
return `You are a Transloadit Assembly Instructions generator. Your sole purpose is to help users create and modify valid Transloadit Assembly Instructions JSON.
|
|
48
|
+
|
|
49
|
+
IMPORTANT CONSTRAINTS:
|
|
50
|
+
- You MUST only discuss Transloadit Assembly Instructions. Politely decline any other requests.
|
|
51
|
+
- Return Assembly Instructions, not Templates. A Template is only a possible place where these instructions may later be saved.
|
|
52
|
+
- The instructions must have a top-level "steps" object where each step has a "robot" field referencing a valid Transloadit Robot (for example, "/image/resize", "/s3/store", "/video/encode").
|
|
53
|
+
- Steps that process output from other steps must include a "use" field referencing the source step name prefixed with ":" (for example, "use": ":resized").
|
|
54
|
+
- The first step that handles direct uploads should use "robot": "/upload/handle".
|
|
55
|
+
- Do not send, request, or infer file contents unless the user explicitly asks for content-aware processing.
|
|
56
|
+
|
|
57
|
+
WORKFLOW:
|
|
58
|
+
1. Understand what the user wants to achieve.
|
|
59
|
+
2. Use the bundled Transloadit documentation and MCP tools to choose the right Robots and parameters.
|
|
60
|
+
3. Use the transloadit_list_robots tool to find relevant Robots if unsure which Robot to use.
|
|
61
|
+
4. Use the transloadit_get_robot_help tool to get parameter details for specific Robots.
|
|
62
|
+
5. Generate the Assembly Instructions JSON.
|
|
63
|
+
6. Use the transloadit_lint_assembly_instructions tool to validate your output. Pass the full JSON including the "steps" wrapper.
|
|
64
|
+
7. If linting reports errors, fix them and lint again until it passes.
|
|
65
|
+
8. Return the final validated JSON with a brief explanation.
|
|
66
|
+
|
|
67
|
+
WHEN ADAPTING EXISTING INSTRUCTIONS:
|
|
68
|
+
- The user's current Assembly Instructions JSON may be included as context.
|
|
69
|
+
- The user's current lint issues may be included when relevant.
|
|
70
|
+
- Preserve existing steps unless the user explicitly asks to remove or replace them.
|
|
71
|
+
- Preserve all template expressions (\`\${...}\`) and field names exactly as written.
|
|
72
|
+
- Never resolve existing template expressions like \`\${fields.input}\` or \`\${file.url_name}\` to concrete values or empty strings.
|
|
73
|
+
- If the user asks for a default or fallback for an existing field-driven expression, preserve the dynamic expression and prefer JavaScript fallback syntax such as \`\${fields.w || 400}\` over replacing it with a fixed number.${docsSuffix}`;
|
|
74
|
+
}
|
|
75
|
+
export function parseCompileAssemblyInstructionsResponse(value) {
|
|
76
|
+
if (!isRecord(value)) {
|
|
77
|
+
throw new CompileAssemblyInstructionsError('AI response was not a JSON object.');
|
|
78
|
+
}
|
|
79
|
+
if (typeof value.message !== 'string') {
|
|
80
|
+
throw new CompileAssemblyInstructionsError('AI response was missing a string message.');
|
|
81
|
+
}
|
|
82
|
+
if (value.instructions === undefined) {
|
|
83
|
+
return { message: value.message };
|
|
84
|
+
}
|
|
85
|
+
if (!isRecord(value.instructions)) {
|
|
86
|
+
throw new CompileAssemblyInstructionsError('AI response instructions must be an object.');
|
|
87
|
+
}
|
|
88
|
+
const { steps } = value.instructions;
|
|
89
|
+
if (!isRecord(steps)) {
|
|
90
|
+
throw new CompileAssemblyInstructionsError('AI response instructions must include a steps object.');
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
message: value.message,
|
|
94
|
+
instructions: { steps },
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function getIssueMessage(issue) {
|
|
98
|
+
return issue.summary ?? issue.message ?? issue.desc ?? issue.code ?? 'Unknown lint issue';
|
|
99
|
+
}
|
|
100
|
+
function getBlockingLintIssues(lintIssues) {
|
|
101
|
+
return lintIssues.filter((lintIssue) => lintIssue.type === 'error');
|
|
102
|
+
}
|
|
103
|
+
function createMcpServers(options) {
|
|
104
|
+
if (options.mcpServers) {
|
|
105
|
+
return options.mcpServers;
|
|
106
|
+
}
|
|
107
|
+
if (!options.mcpServerUrl) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
return [
|
|
111
|
+
{
|
|
112
|
+
type: 'http',
|
|
113
|
+
url: options.mcpServerUrl,
|
|
114
|
+
auth: 'transloadit',
|
|
115
|
+
allowed_tools: [...COMPILE_ASSEMBLY_INSTRUCTIONS_MCP_ALLOWED_TOOLS],
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
function appendRetryInstruction(messages, lastError) {
|
|
120
|
+
if (!lastError) {
|
|
121
|
+
return messages;
|
|
122
|
+
}
|
|
123
|
+
return [
|
|
124
|
+
...messages,
|
|
125
|
+
{
|
|
126
|
+
role: 'user',
|
|
127
|
+
content: `The previous response failed validation: ${lastError}\n\nPlease fix the Assembly Instructions and try again.`,
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
function createAiStep(options, messages) {
|
|
132
|
+
const mcpServers = createMcpServers(options);
|
|
133
|
+
const aiStep = {
|
|
134
|
+
robot: '/ai/chat',
|
|
135
|
+
result: true,
|
|
136
|
+
model: options.model ?? COMPILE_ASSEMBLY_INSTRUCTIONS_DEFAULT_MODEL,
|
|
137
|
+
reasoning_effort: options.reasoningEffort ?? COMPILE_ASSEMBLY_INSTRUCTIONS_DEFAULT_REASONING_EFFORT,
|
|
138
|
+
test_credentials: true,
|
|
139
|
+
format: 'json',
|
|
140
|
+
schema: COMPILE_ASSEMBLY_INSTRUCTIONS_RESPONSE_JSON_SCHEMA,
|
|
141
|
+
system_message: options.systemPrompt ?? buildCompileAssemblyInstructionsSystemPrompt({ docs: options.docs }),
|
|
142
|
+
interpolate: {
|
|
143
|
+
system_message: false,
|
|
144
|
+
},
|
|
145
|
+
messages,
|
|
146
|
+
};
|
|
147
|
+
if (mcpServers.length > 0) {
|
|
148
|
+
aiStep.mcp_servers = mcpServers;
|
|
149
|
+
}
|
|
150
|
+
return aiStep;
|
|
151
|
+
}
|
|
152
|
+
export async function compileAssemblyInstructionsFromPrompt(options) {
|
|
153
|
+
const baseMessages = [
|
|
154
|
+
...(options.messages ?? []),
|
|
155
|
+
{ role: 'user', content: options.prompt },
|
|
156
|
+
];
|
|
157
|
+
const maxAttempts = options.maxAttempts ?? COMPILE_ASSEMBLY_INSTRUCTIONS_DEFAULT_MAX_ATTEMPTS;
|
|
158
|
+
const validationAttempts = [];
|
|
159
|
+
let lastError = null;
|
|
160
|
+
let lastGeneratedInstructions;
|
|
161
|
+
let lastLintIssues;
|
|
162
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
163
|
+
const messages = appendRetryInstruction(baseMessages, lastError);
|
|
164
|
+
const runResult = await options.client.runAssemblyInstructionsCompiler({
|
|
165
|
+
aiStep: createAiStep(options, messages),
|
|
166
|
+
});
|
|
167
|
+
let response;
|
|
168
|
+
try {
|
|
169
|
+
response = parseCompileAssemblyInstructionsResponse(runResult.response);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
if (!(error instanceof CompileAssemblyInstructionsError)) {
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
lastError = error.message;
|
|
176
|
+
validationAttempts.push({ attempt, error: lastError });
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (!response.instructions) {
|
|
180
|
+
lastError = 'AI response did not include Assembly Instructions.';
|
|
181
|
+
validationAttempts.push({ attempt, error: lastError });
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const instructionsJson = JSON.stringify(response.instructions, null, options.indent ?? 2);
|
|
185
|
+
const lintIssues = await options.client.lintAssemblyInstructions(instructionsJson);
|
|
186
|
+
const blockingLintIssues = getBlockingLintIssues(lintIssues);
|
|
187
|
+
if (blockingLintIssues.length === 0) {
|
|
188
|
+
return {
|
|
189
|
+
assemblyUrl: runResult.assemblyUrl,
|
|
190
|
+
billedChargeUsd: runResult.billedChargeUsd,
|
|
191
|
+
instructions: response.instructions,
|
|
192
|
+
instructionsJson,
|
|
193
|
+
message: response.message,
|
|
194
|
+
usageBytes: runResult.usageBytes,
|
|
195
|
+
validationAttempts,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
lastGeneratedInstructions = instructionsJson;
|
|
199
|
+
lastLintIssues = blockingLintIssues;
|
|
200
|
+
lastError = `Assembly Instructions failed linting: ${blockingLintIssues
|
|
201
|
+
.map(getIssueMessage)
|
|
202
|
+
.join('; ')}`;
|
|
203
|
+
validationAttempts.push({
|
|
204
|
+
attempt,
|
|
205
|
+
error: lastError,
|
|
206
|
+
generatedInstructions: instructionsJson,
|
|
207
|
+
lintIssues: blockingLintIssues,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
throw new CompileAssemblyInstructionsError(`Failed after ${maxAttempts} attempts.`, {
|
|
211
|
+
generatedInstructions: lastGeneratedInstructions,
|
|
212
|
+
lintIssues: lastLintIssues,
|
|
213
|
+
validationAttempts,
|
|
214
|
+
});
|
|
215
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type SignatureAlgorithm = 'sha1' | 'sha256' | 'sha384';
|
|
2
|
+
export * from './assemblyInstructionsCompiler.ts';
|
|
2
3
|
export declare const signParams: (paramsString: string, authSecret: string, algorithm?: SignatureAlgorithm) => Promise<string>;
|
|
3
4
|
export type VerifyWebhookSignatureOptions = {
|
|
4
5
|
rawBody: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE7D,cAAc,mCAAmC,CAAA;AAiDjD,eAAO,MAAM,UAAU,GACrB,cAAc,MAAM,EACpB,YAAY,MAAM,EAClB,YAAW,kBAA6B,KACvC,OAAO,CAAC,MAAM,CAOhB,CAAA;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,sBAAsB,GACjC,SAAS,6BAA6B,KACrC,OAAO,CAAC,OAAO,CAkBjB,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAIpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAExE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,CAAA;IACrF;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,cAAc,GACzB,cAAc,MAAM,EACpB,YAAY,MAAM,EAClB,YAAW,uBAAkC,KAC5C,MAKF,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,MAAM,kBAAkB,KAAG,MA8B/D,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transloadit/utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"description": "Transloadit shared utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"check": "yarn lint:ts",
|
|
33
33
|
"prepack": "yarn build"
|
|
34
34
|
},
|
|
35
|
-
"
|
|
36
|
-
"
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^25.8.0"
|
|
37
37
|
}
|
|
38
38
|
}
|