ugcinc 4.1.62 → 4.1.64

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.
@@ -1,5 +1,6 @@
1
1
  import type { PortValue } from '../types';
2
2
  import { type ObjectSchemaField, type OutputMode } from './types';
3
+ import { z } from 'zod';
3
4
  /** LLM inputs are dynamic (template variables + media refs). Input port IDs are user-defined. */
4
5
  export type LLMNodeInputs = Record<string, PortValue | PortValue[]>;
5
6
  /** LLM outputs are dynamic based on outputFields config. Output port IDs are user-defined. */
@@ -34,3 +35,14 @@ export default _default;
34
35
  export { LLMProviders };
35
36
  export type { LLMProvider, LLMApiKeys };
36
37
  export type LLMNodeConfig = typeof definition.defaults;
38
+ /**
39
+ * Convert ObjectSchemaField to Zod schema with description.
40
+ * @param field - The output field definition
41
+ * @param depth - Current nesting depth (for enforcing max depth)
42
+ */
43
+ export declare function outputFieldToZod(field: ObjectSchemaField, depth?: number): z.ZodTypeAny;
44
+ /**
45
+ * Convert ObjectSchemaField[] to Zod object schema.
46
+ * @param fields - Array of output field definitions
47
+ */
48
+ export declare function outputFieldsToZod(fields: ObjectSchemaField[]): z.ZodObject<Record<string, z.ZodTypeAny>>;
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LLMProviders = void 0;
4
+ exports.outputFieldToZod = outputFieldToZod;
5
+ exports.outputFieldsToZod = outputFieldsToZod;
4
6
  const utils_1 = require("../utils");
5
7
  const types_1 = require("./types");
8
+ const zod_1 = require("zod");
6
9
  // =============================================================================
7
10
  // Config Types
8
11
  // =============================================================================
@@ -98,3 +101,108 @@ const definition = (0, types_1.defineNode)({
98
101
  },
99
102
  });
100
103
  exports.default = definition;
104
+ // =============================================================================
105
+ // Utility Functions for LLM Execution
106
+ // =============================================================================
107
+ /**
108
+ * Maximum nesting depth for object arrays (3 levels allowed)
109
+ */
110
+ const MAX_NESTING_DEPTH = 3;
111
+ /**
112
+ * Convert ObjectSchemaField to Zod schema with description.
113
+ * @param field - The output field definition
114
+ * @param depth - Current nesting depth (for enforcing max depth)
115
+ */
116
+ function outputFieldToZod(field, depth = 0) {
117
+ let schema;
118
+ if (field.type === 'string') {
119
+ schema = zod_1.z.string();
120
+ }
121
+ else if (field.type === 'number') {
122
+ schema = zod_1.z.number();
123
+ }
124
+ else if (field.type === 'boolean') {
125
+ schema = zod_1.z.boolean();
126
+ }
127
+ else if (field.type === 'object') {
128
+ // Top-level object type
129
+ if (depth >= MAX_NESTING_DEPTH) {
130
+ throw new Error(`Maximum nesting depth of ${MAX_NESTING_DEPTH} exceeded for field "${field.name}"`);
131
+ }
132
+ if (field.objectSchema && field.objectSchema.length > 0) {
133
+ const shape = {};
134
+ for (const subField of field.objectSchema) {
135
+ shape[subField.name] = outputFieldToZod(subField, depth + 1);
136
+ }
137
+ schema = zod_1.z.object(shape);
138
+ }
139
+ else {
140
+ // Empty object schema - use passthrough for any object
141
+ schema = zod_1.z.record(zod_1.z.unknown());
142
+ }
143
+ }
144
+ else if (field.type === 'array') {
145
+ let itemSchema;
146
+ if (field.items === 'object' && field.objectSchema) {
147
+ // Check nesting depth
148
+ if (depth >= MAX_NESTING_DEPTH) {
149
+ throw new Error(`Maximum nesting depth of ${MAX_NESTING_DEPTH} exceeded for field "${field.name}"`);
150
+ }
151
+ // Build object schema from nested fields
152
+ const shape = {};
153
+ for (const subField of field.objectSchema) {
154
+ shape[subField.name] = outputFieldToZod(subField, depth + 1);
155
+ }
156
+ itemSchema = zod_1.z.object(shape);
157
+ }
158
+ else if (field.items === 'string') {
159
+ itemSchema = zod_1.z.string();
160
+ }
161
+ else if (field.items === 'number') {
162
+ itemSchema = zod_1.z.number();
163
+ }
164
+ else if (field.items === 'boolean') {
165
+ itemSchema = zod_1.z.boolean();
166
+ }
167
+ else {
168
+ // Default to string if items not specified
169
+ itemSchema = zod_1.z.string();
170
+ }
171
+ let arraySchema = zod_1.z.array(itemSchema);
172
+ // Apply length constraints
173
+ if (field.length !== undefined) {
174
+ arraySchema = arraySchema.length(field.length);
175
+ }
176
+ else {
177
+ if (field.minLength !== undefined) {
178
+ arraySchema = arraySchema.min(field.minLength);
179
+ }
180
+ if (field.maxLength !== undefined) {
181
+ arraySchema = arraySchema.max(field.maxLength);
182
+ }
183
+ }
184
+ schema = arraySchema;
185
+ }
186
+ else {
187
+ schema = zod_1.z.unknown();
188
+ }
189
+ if (field.description) {
190
+ schema = schema.describe(field.description);
191
+ }
192
+ return schema;
193
+ }
194
+ /**
195
+ * Convert ObjectSchemaField[] to Zod object schema.
196
+ * @param fields - Array of output field definitions
197
+ */
198
+ function outputFieldsToZod(fields) {
199
+ const shape = {};
200
+ fields.forEach(field => {
201
+ let schema = outputFieldToZod(field);
202
+ if (field.required === false) {
203
+ schema = schema.optional();
204
+ }
205
+ shape[field.name] = schema;
206
+ });
207
+ return zod_1.z.object(shape);
208
+ }
@@ -15,3 +15,16 @@ export declare function extractTemplateVariables(texts: string[]): string[];
15
15
  * @example processTemplate("Hello {{name}}", { name: "World" }) // "Hello World"
16
16
  */
17
17
  export declare function processTemplate(template: string, variables: Record<string, string>): string;
18
+ /**
19
+ * Substitute {{variables}} in text with values from inputs.
20
+ * Handles various types by converting them appropriately:
21
+ * - strings: returned as-is
22
+ * - numbers/booleans: converted via String()
23
+ * - null: converted to 'null'
24
+ * - objects/arrays: converted via JSON.stringify()
25
+ *
26
+ * @param text - Template string with {{variable}} placeholders
27
+ * @param inputs - Map of variable names to values of any type
28
+ * @returns Processed string with variables replaced
29
+ */
30
+ export declare function substituteVariables(text: string, inputs: Record<string, unknown>): string;
@@ -5,6 +5,7 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.extractTemplateVariables = extractTemplateVariables;
7
7
  exports.processTemplate = processTemplate;
8
+ exports.substituteVariables = substituteVariables;
8
9
  /**
9
10
  * Extract template variables from text (e.g., "Hello {{name}}" -> ["name"])
10
11
  * @param texts - Array of text strings to extract variables from
@@ -36,3 +37,31 @@ function processTemplate(template, variables) {
36
37
  }
37
38
  return result;
38
39
  }
40
+ /**
41
+ * Substitute {{variables}} in text with values from inputs.
42
+ * Handles various types by converting them appropriately:
43
+ * - strings: returned as-is
44
+ * - numbers/booleans: converted via String()
45
+ * - null: converted to 'null'
46
+ * - objects/arrays: converted via JSON.stringify()
47
+ *
48
+ * @param text - Template string with {{variable}} placeholders
49
+ * @param inputs - Map of variable names to values of any type
50
+ * @returns Processed string with variables replaced
51
+ */
52
+ function substituteVariables(text, inputs) {
53
+ return text.replace(/\{\{(\w+)\}\}/g, (match, varName) => {
54
+ const value = inputs[varName];
55
+ if (value === undefined)
56
+ return match; // Keep original if not found
57
+ // Handle all types explicitly to avoid [object Object]
58
+ if (typeof value === 'string')
59
+ return value;
60
+ if (typeof value === 'number' || typeof value === 'boolean')
61
+ return String(value);
62
+ if (value === null)
63
+ return 'null';
64
+ // For arrays and objects, JSON stringify
65
+ return JSON.stringify(value);
66
+ });
67
+ }
package/dist/index.d.ts CHANGED
@@ -21,7 +21,7 @@ export { isImageToVideoModel, ALL_VIDEO_MODELS, getModelAspectRatios, getModelDu
21
21
  export { selectFromPool } from './automations/selection';
22
22
  export { portId, isValidPortId, portIdToTitle, normalizeToPortId, PortIdSchema } from './port-id';
23
23
  export type { PortId } from './port-id';
24
- export { extractTemplateVariables, processTemplate } from './automations/utils';
24
+ export { extractTemplateVariables, processTemplate, substituteVariables } from './automations/utils';
25
25
  export type { InputType } from './automations/nodes/types';
26
26
  export type { ClientConfig } from './base';
27
27
  export type { Account, AccountStat, AccountTask, EditProfileInfo, GetAccountsParams, GetAccountStatsParams, GetAccountStatusParams, AccountInfoUpdate, UpdateAccountInfoParams, AccountInfoUpdateResult, UpdateAccountInfoResponse, AccountSocialUpdate, UpdateAccountSocialParams, AccountSocialUpdateResult, UpdateAccountSocialResponse, DeleteAccountPostsParams, DeleteAccountPostsResponse, ResetWarmupParams, ResetWarmupResponse, } from './accounts';
@@ -53,8 +53,8 @@ export type { GenerateImageNodeConfig, ImageGenerationTextModel, ImageGeneration
53
53
  export type { GenerateVideoNodeConfig, VideoGenerationTextToVideoModel, VideoGenerationImageToVideoModel, VideoGenerationModel, VideoModelProvider, VideoModelTier, VideoAspectRatioOption, VideoDurationOption, VideoModelOption, } from './automations/nodes/generate-video';
54
54
  export type { IfNodeConfig, IfLogicOperator, IfBooleanInput, } from './automations/nodes/if';
55
55
  export { IfLogicOperators, applyLogicOperator } from './automations/nodes/if';
56
- export type { LLMNodeConfig, LLMProvider, LLMApiKeys, } from './automations/nodes/llm';
57
- export { LLMProviders } from './automations/nodes/llm';
56
+ export type { LLMNodeConfig, LLMNodeOutputs, LLMProvider, LLMApiKeys, } from './automations/nodes/llm';
57
+ export { LLMProviders, outputFieldToZod, outputFieldsToZod } from './automations/nodes/llm';
58
58
  export type { ManualTriggerNodeConfig } from './automations/nodes/manual-trigger';
59
59
  export type { MediaNodeConfig, MediaNodeOutput } from './automations/nodes/media';
60
60
  export type { NotNodeConfig } from './automations/nodes/not';
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.extractWorkflowConfig = exports.generateNodeName = exports.shuffleNodePreview = exports.getPreviewValue = exports.removePreviewForConnection = exports.updatePreviewMapForConnection = exports.computePreviewMap = exports.computeAllNodePreviews = exports.resolveNodePreview = exports.getWorkflowOutputSchema = exports.hasMissingTerminalError = exports.hasMissingTriggerError = exports.getPortErrorsForNode = exports.getErrorNodeIds = exports.validateWorkflow = exports.checkCrossContextViolation = exports.getForEachContext = exports.getConnectedSource = exports.cleanupStaleConnections = exports.removeNodeConnections = exports.removeConnection = exports.addConnection = exports.deriveConnections = exports.createNode = exports.getOutputSchema = exports.getNodeByType = exports.getAllNodes = exports.getInputPreviewValue = exports.computeAllNodePortsWithPreviews = exports.computeAllNodePorts = exports.computePortsWithPreviews = exports.computePortsForNode = exports.areTypesCompatible = exports.submitIMessageDmRenderJob = exports.submitInstagramDmRenderJob = exports.submitAutoCaptionRenderJob = exports.submitScreenshotAnimationRenderJob = exports.submitDeduplicationJob = exports.getRenderJobStatus = exports.submitVideoRenderJob = exports.submitImageRenderJob = exports.CommentsClient = exports.MediaClient = exports.AutomationsClient = exports.OrganizationClient = exports.StatsClient = exports.PostsClient = exports.TasksClient = exports.AccountsClient = exports.UGCClient = void 0;
9
- exports.prepareVideoComposerInput = exports.LLMProviders = exports.applyLogicOperator = exports.IfLogicOperators = exports.resolvePath = exports.indexExpressionToIndexes = exports.resolveUnknownPath = exports.getOutputTypeFromCategory = exports.parseOpenAPIOutputPath = exports.parseOpenAPIInputs = exports.mapOpenAPIType = exports.nodeConfigToCaptionStyle = exports.prepareImageComposerInput = exports.processTemplate = exports.extractTemplateVariables = exports.PortIdSchema = exports.normalizeToPortId = exports.portIdToTitle = exports.isValidPortId = exports.portId = exports.selectFromPool = exports.getModelDurations = exports.getModelAspectRatios = exports.ALL_VIDEO_MODELS = exports.isImageToVideoModel = exports.IMAGE_ASPECT_RATIOS = exports.ALL_IMAGE_MODELS = exports.isEditModel = exports.getNodeDefinition = exports.isPortType = exports.formatPortType = exports.isAsyncExecutor = exports.internalNodeTypes = exports.nodeDefinitions = void 0;
9
+ exports.prepareVideoComposerInput = exports.outputFieldsToZod = exports.outputFieldToZod = exports.LLMProviders = exports.applyLogicOperator = exports.IfLogicOperators = exports.resolvePath = exports.indexExpressionToIndexes = exports.resolveUnknownPath = exports.getOutputTypeFromCategory = exports.parseOpenAPIOutputPath = exports.parseOpenAPIInputs = exports.mapOpenAPIType = exports.nodeConfigToCaptionStyle = exports.prepareImageComposerInput = exports.substituteVariables = exports.processTemplate = exports.extractTemplateVariables = exports.PortIdSchema = exports.normalizeToPortId = exports.portIdToTitle = exports.isValidPortId = exports.portId = exports.selectFromPool = exports.getModelDurations = exports.getModelAspectRatios = exports.ALL_VIDEO_MODELS = exports.isImageToVideoModel = exports.IMAGE_ASPECT_RATIOS = exports.ALL_IMAGE_MODELS = exports.isEditModel = exports.getNodeDefinition = exports.isPortType = exports.formatPortType = exports.isAsyncExecutor = exports.internalNodeTypes = exports.nodeDefinitions = void 0;
10
10
  // =============================================================================
11
11
  // Client Exports
12
12
  // =============================================================================
@@ -120,6 +120,7 @@ Object.defineProperty(exports, "PortIdSchema", { enumerable: true, get: function
120
120
  var utils_1 = require("./automations/utils");
121
121
  Object.defineProperty(exports, "extractTemplateVariables", { enumerable: true, get: function () { return utils_1.extractTemplateVariables; } });
122
122
  Object.defineProperty(exports, "processTemplate", { enumerable: true, get: function () { return utils_1.processTemplate; } });
123
+ Object.defineProperty(exports, "substituteVariables", { enumerable: true, get: function () { return utils_1.substituteVariables; } });
123
124
  var image_composer_1 = require("./automations/nodes/image-composer");
124
125
  Object.defineProperty(exports, "prepareImageComposerInput", { enumerable: true, get: function () { return image_composer_1.prepareImageComposerInput; } });
125
126
  var auto_caption_1 = require("./automations/nodes/auto-caption");
@@ -138,5 +139,7 @@ Object.defineProperty(exports, "IfLogicOperators", { enumerable: true, get: func
138
139
  Object.defineProperty(exports, "applyLogicOperator", { enumerable: true, get: function () { return if_1.applyLogicOperator; } });
139
140
  var llm_1 = require("./automations/nodes/llm");
140
141
  Object.defineProperty(exports, "LLMProviders", { enumerable: true, get: function () { return llm_1.LLMProviders; } });
142
+ Object.defineProperty(exports, "outputFieldToZod", { enumerable: true, get: function () { return llm_1.outputFieldToZod; } });
143
+ Object.defineProperty(exports, "outputFieldsToZod", { enumerable: true, get: function () { return llm_1.outputFieldsToZod; } });
141
144
  var video_composer_1 = require("./automations/nodes/video-composer");
142
145
  Object.defineProperty(exports, "prepareVideoComposerInput", { enumerable: true, get: function () { return video_composer_1.prepareVideoComposerInput; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugcinc",
3
- "version": "4.1.62",
3
+ "version": "4.1.64",
4
4
  "description": "TypeScript/JavaScript client for the UGC Inc API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",