@nodetool-ai/fal-nodes 0.7.0-rc.23 → 0.8.2
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 +40 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/fal-base.d.ts +62 -3
- package/dist/fal-base.d.ts.map +1 -1
- package/dist/fal-base.js +166 -21
- package/dist/fal-base.js.map +1 -1
- package/dist/fal-billing.d.ts +27 -0
- package/dist/fal-billing.d.ts.map +1 -0
- package/dist/fal-billing.js +54 -0
- package/dist/fal-billing.js.map +1 -0
- package/dist/fal-cost.d.ts +44 -0
- package/dist/fal-cost.d.ts.map +1 -0
- package/dist/fal-cost.js +178 -0
- package/dist/fal-cost.js.map +1 -0
- package/dist/fal-dynamic.d.ts +10 -7
- package/dist/fal-dynamic.d.ts.map +1 -1
- package/dist/fal-dynamic.js +29 -20
- package/dist/fal-dynamic.js.map +1 -1
- package/dist/fal-factory.d.ts +1 -1
- package/dist/fal-factory.d.ts.map +1 -1
- package/dist/fal-factory.js +274 -136
- package/dist/fal-factory.js.map +1 -1
- package/dist/fal-manifest.json +275864 -150911
- package/dist/fal-provider.d.ts +5 -1
- package/dist/fal-provider.d.ts.map +1 -1
- package/dist/fal-provider.js +102 -11
- package/dist/fal-provider.js.map +1 -1
- package/dist/fal-types.d.ts +0 -60
- package/dist/fal-types.d.ts.map +1 -1
- package/dist/generated/fal-node-type-pricing.json +8526 -0
- package/dist/generated/fal-unit-pricing.json +7101 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/unit-pricing-catalog.d.ts +16 -0
- package/dist/unit-pricing-catalog.d.ts.map +1 -0
- package/dist/unit-pricing-catalog.js +12 -0
- package/dist/unit-pricing-catalog.js.map +1 -0
- package/package.json +36 -10
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @nodetool-ai/fal-nodes
|
|
2
|
+
|
|
3
|
+
FAL AI nodes for [NodeTool](https://nodetool.ai).
|
|
4
|
+
|
|
5
|
+
Run [fal.ai](https://fal.ai) models inside NodeTool workflows: FLUX and other text-to-image and image-to-image models, text-to-video and image-to-video, text-to-speech, speech-to-text, audio generation, and image-to-3D. The pack generates every node from a bundled manifest, so it tracks the fal.ai endpoint catalog.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @nodetool-ai/fal-nodes
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Nodes
|
|
14
|
+
|
|
15
|
+
Over 1,000 nodes, one per fal.ai endpoint, named `fal.<category>.<Model>`.
|
|
16
|
+
|
|
17
|
+
| Category | Node type prefix | Example |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| Text to image | `fal.text_to_image.*` | `fal.text_to_image.FluxDev` |
|
|
20
|
+
| Image to image | `fal.image_to_image.*` | `fal.image_to_image.FluxSchnellRedux` |
|
|
21
|
+
| Text to video | `fal.text_to_video.*` | `fal.text_to_video.HunyuanVideo` |
|
|
22
|
+
| Image to video | `fal.image_to_video.*` | `fal.image_to_video.PixverseV56ImageToVideo` |
|
|
23
|
+
| Video to video | `fal.video_to_video.*` | `fal.video_to_video.AMTInterpolation` |
|
|
24
|
+
| Text to audio | `fal.text_to_audio.*` | `fal.text_to_audio.ACEStepPromptToAudio` |
|
|
25
|
+
| Text to speech | `fal.text_to_speech.*` | `fal.text_to_speech.Qwen3TtsTextToSpeech17B` |
|
|
26
|
+
| Speech to text | `fal.speech_to_text.*` | `fal.speech_to_text.ElevenLabsSpeechToText` |
|
|
27
|
+
| Vision | `fal.vision.*` | `fal.vision.ArbiterImageText` |
|
|
28
|
+
| Image to 3D | `fal.image_to_3d.*` | `fal.image_to_3d.Trellis2` |
|
|
29
|
+
| Training | `fal.training.*` | `fal.training.ZImageBaseTrainer` |
|
|
30
|
+
|
|
31
|
+
Remaining categories: `audio_to_audio`, `audio_to_video`, `video_to_audio`, `video_to_text`, `text_to_3d`, `3d_to_3d`, `llm`, `text_to_json`, and more.
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
Set `FAL_API_KEY` in NodeTool's secret store (Settings → API Keys) or as an environment variable.
|
|
36
|
+
|
|
37
|
+
## Links
|
|
38
|
+
|
|
39
|
+
- [NodeTool](https://nodetool.ai)
|
|
40
|
+
- [GitHub](https://github.com/nodetool-ai/nodetool)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2026-10-07T23:09:35.687Z
|
package/dist/fal-base.d.ts
CHANGED
|
@@ -2,11 +2,53 @@
|
|
|
2
2
|
* Shared FAL AI API utilities.
|
|
3
3
|
* Uses @fal-ai/client SDK for queue submit/poll and file uploads.
|
|
4
4
|
*/
|
|
5
|
+
import { type FalQueueSubmission, type GenerationRequest, type ProcessingContext } from "@nodetool-ai/runtime";
|
|
5
6
|
export declare function getFalApiKey(secrets: Record<string, string>): string;
|
|
6
7
|
export declare function falSubmit(apiKey: string, endpoint: string, args: Record<string, unknown>, onProgress?: (message: string) => void): Promise<Record<string, unknown>>;
|
|
8
|
+
/**
|
|
9
|
+
* Like {@link falSubmit} but also surfaces the FAL queue `requestId`, used to
|
|
10
|
+
* look up the request's actual billed cost via the billing-events API.
|
|
11
|
+
*/
|
|
12
|
+
export declare function falSubmitWithMeta(apiKey: string, endpoint: string, args: Record<string, unknown>, onProgress?: (message: string) => void, options?: {
|
|
13
|
+
readonly webhookUrl?: string;
|
|
14
|
+
readonly signal?: AbortSignal;
|
|
15
|
+
readonly onAccepted?: (submission: FalQueueSubmission) => void | Promise<void>;
|
|
16
|
+
readonly onBound?: (binding: {
|
|
17
|
+
readonly providerRequestId: string;
|
|
18
|
+
readonly endpoint: string;
|
|
19
|
+
}) => void | Promise<void>;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
data: Record<string, unknown>;
|
|
22
|
+
requestId: string | null;
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Submit a FAL request through the processing context's generation seam.
|
|
26
|
+
*
|
|
27
|
+
* FAL nodes are provider-specific nodes, so they cannot use one of the
|
|
28
|
+
* capability helpers on ProcessingContext. Keeping the call here gives the
|
|
29
|
+
* generated, raw, and schema-driven nodes the same acceptance and binding
|
|
30
|
+
* ordering as the higher-level provider while preserving their endpoint
|
|
31
|
+
* shaped output. When an enclosing durable seam already supplied provider
|
|
32
|
+
* request options, the request is already inside that seam and must not open
|
|
33
|
+
* a second ledger row.
|
|
34
|
+
*/
|
|
35
|
+
export declare function falSubmitWithGeneration(apiKey: string, endpoint: string, args: Record<string, unknown>, context: ProcessingContext | undefined, nodeType: string, capability: GenerationRequest["capability"], onProgress?: (message: string) => void): Promise<{
|
|
36
|
+
data: Record<string, unknown>;
|
|
37
|
+
requestId: string | null;
|
|
38
|
+
}>;
|
|
39
|
+
/** Map manifest output metadata to the closest protocol capability. */
|
|
40
|
+
export declare function falCapabilityForOutputType(outputType: string): GenerationRequest["capability"];
|
|
7
41
|
export declare function falUpload(apiKey: string, data: Uint8Array, contentType: string): Promise<string>;
|
|
8
|
-
|
|
9
|
-
|
|
42
|
+
interface UploadContext {
|
|
43
|
+
storage?: {
|
|
44
|
+
retrieve(uri: string): Promise<Uint8Array | null | undefined>;
|
|
45
|
+
} | null;
|
|
46
|
+
resolveAssetBytes?: (uri: string) => Promise<{
|
|
47
|
+
bytes: Uint8Array | null;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
export declare function assetToFalUrl(apiKey: string, ref: Record<string, unknown>, context?: UploadContext): Promise<string | null>;
|
|
51
|
+
export declare function imageToDataUrl(ref: Record<string, unknown>, context?: UploadContext): Promise<string | null>;
|
|
10
52
|
export declare function inferContentType(assetType: string | undefined): string;
|
|
11
53
|
export declare function isRefSet(ref: unknown): boolean;
|
|
12
54
|
export interface FalImageResult {
|
|
@@ -15,6 +57,23 @@ export interface FalImageResult {
|
|
|
15
57
|
height?: number;
|
|
16
58
|
content_type?: string;
|
|
17
59
|
}
|
|
18
|
-
export declare function falImageToRef(img: FalImageResult):
|
|
60
|
+
export declare function falImageToRef(img: FalImageResult): {
|
|
61
|
+
type: string;
|
|
62
|
+
uri: string;
|
|
63
|
+
width: number | undefined;
|
|
64
|
+
height: number | undefined;
|
|
65
|
+
mimeType: string | undefined;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Delete `null`/`undefined`/empty-string keys from the top level of an object.
|
|
69
|
+
*
|
|
70
|
+
* Intentionally NON-recursive, matching `replicate-base.ts`: a FAL arg bag is a
|
|
71
|
+
* flat set of parameters, and its only nested objects are pass-through
|
|
72
|
+
* `dict[...]` inputs the user supplied. Recursing mutated those in place and
|
|
73
|
+
* silently stripped sub-keys they meant to send — a deliberate
|
|
74
|
+
* `"negative_prompt": ""` inside one is a value, not an omission. `0` and
|
|
75
|
+
* `false` are kept.
|
|
76
|
+
*/
|
|
19
77
|
export declare function removeNulls(obj: Record<string, unknown>): void;
|
|
78
|
+
export {};
|
|
20
79
|
//# sourceMappingURL=fal-base.d.ts.map
|
package/dist/fal-base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fal-base.d.ts","sourceRoot":"","sources":["../src/fal-base.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"fal-base.d.ts","sourceRoot":"","sources":["../src/fal-base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAM9B,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAIpE;AAqBD,wBAAsB,SAAS,CAC7B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CA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;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,cAAc;IAE7C,IAAI;IACJ,GAAG;IACH,KAAK;IACL,MAAM;IACN,QAAQ;EAEX;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAM9D"}
|
package/dist/fal-base.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Uses @fal-ai/client SDK for queue submit/poll and file uploads.
|
|
4
4
|
*/
|
|
5
5
|
import { createFalClient } from "@fal-ai/client";
|
|
6
|
+
import { createFalQueueOperations, currentGenerationProviderRequestOptions, falSubmitAndWait, recordGenerationBindingAsync, recordGenerationProviderResult, recordGenerationReceiptAsync, fetchExternalMedia } from "@nodetool-ai/runtime";
|
|
6
7
|
// ---------------------------------------------------------------------------
|
|
7
8
|
// API Key extraction
|
|
8
9
|
// ---------------------------------------------------------------------------
|
|
@@ -28,21 +29,123 @@ function getClient(apiKey) {
|
|
|
28
29
|
// Submit job to FAL queue, poll until complete, return result
|
|
29
30
|
// ---------------------------------------------------------------------------
|
|
30
31
|
export async function falSubmit(apiKey, endpoint, args, onProgress) {
|
|
32
|
+
return (await falSubmitWithMeta(apiKey, endpoint, args, onProgress)).data;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Like {@link falSubmit} but also surfaces the FAL queue `requestId`, used to
|
|
36
|
+
* look up the request's actual billed cost via the billing-events API.
|
|
37
|
+
*/
|
|
38
|
+
export async function falSubmitWithMeta(apiKey, endpoint, args, onProgress, options = {}) {
|
|
31
39
|
const client = getClient(apiKey);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
// `subscribe()` performs submit, polling, and result retrieval as one opaque
|
|
41
|
+
// operation. Prefer the explicit queue adapter so the paid POST is issued
|
|
42
|
+
// exactly once and the request id is available before waiting. Older test
|
|
43
|
+
// doubles and hosts may only expose subscribe(), so retain that fallback.
|
|
44
|
+
if ("queue" in client && client.queue) {
|
|
45
|
+
const operations = createFalQueueOperations({ apiKey });
|
|
46
|
+
const providerRequestOptions = currentGenerationProviderRequestOptions();
|
|
47
|
+
const request = {
|
|
48
|
+
endpoint,
|
|
49
|
+
input: args
|
|
50
|
+
};
|
|
51
|
+
const webhookUrl = options.webhookUrl ?? providerRequestOptions?.webhookUrl;
|
|
52
|
+
if (webhookUrl)
|
|
53
|
+
request.webhookUrl = webhookUrl;
|
|
54
|
+
if (options.signal)
|
|
55
|
+
request.signal = options.signal;
|
|
56
|
+
const result = await falSubmitAndWait(operations, request, {
|
|
57
|
+
signal: options.signal,
|
|
58
|
+
onAccepted: async (submission) => {
|
|
59
|
+
await recordGenerationReceiptAsync({ provider_request_id: submission.providerRequestId }, submission);
|
|
60
|
+
await options.onAccepted?.(submission);
|
|
61
|
+
},
|
|
62
|
+
onBound: async (binding) => {
|
|
63
|
+
await recordGenerationBindingAsync(binding);
|
|
64
|
+
await options.onBound?.(binding);
|
|
65
|
+
},
|
|
66
|
+
onUpdate: (observation) => {
|
|
67
|
+
const rawStatus = observation.rawStatus;
|
|
68
|
+
if (typeof rawStatus === "object" &&
|
|
69
|
+
rawStatus !== null &&
|
|
70
|
+
"logs" in rawStatus &&
|
|
71
|
+
Array.isArray(rawStatus.logs)) {
|
|
72
|
+
for (const entry of rawStatus.logs) {
|
|
73
|
+
if (typeof entry === "object" &&
|
|
74
|
+
entry !== null &&
|
|
75
|
+
"message" in entry &&
|
|
76
|
+
typeof entry.message === "string") {
|
|
77
|
+
onProgress?.(entry.message);
|
|
78
|
+
}
|
|
40
79
|
}
|
|
41
80
|
}
|
|
42
81
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
82
|
+
});
|
|
83
|
+
recordGenerationProviderResult(result.data);
|
|
84
|
+
return { data: result.data, requestId: result.requestId };
|
|
85
|
+
}
|
|
86
|
+
const subscribeOptions = onProgress
|
|
87
|
+
? {
|
|
88
|
+
input: args,
|
|
89
|
+
logs: true,
|
|
90
|
+
onQueueUpdate: (update) => {
|
|
91
|
+
if (update.status !== "IN_PROGRESS")
|
|
92
|
+
return;
|
|
93
|
+
for (const entry of update.logs ?? [])
|
|
94
|
+
onProgress(entry.message);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
: { input: args, logs: true };
|
|
98
|
+
if (options.signal) {
|
|
99
|
+
Object.assign(subscribeOptions, { abortSignal: options.signal });
|
|
100
|
+
}
|
|
101
|
+
const result = await client.subscribe(endpoint, subscribeOptions);
|
|
102
|
+
const data = (result.data ?? result);
|
|
103
|
+
recordGenerationProviderResult(data);
|
|
104
|
+
const requestId = result?.requestId ?? null;
|
|
105
|
+
return { data, requestId };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Submit a FAL request through the processing context's generation seam.
|
|
109
|
+
*
|
|
110
|
+
* FAL nodes are provider-specific nodes, so they cannot use one of the
|
|
111
|
+
* capability helpers on ProcessingContext. Keeping the call here gives the
|
|
112
|
+
* generated, raw, and schema-driven nodes the same acceptance and binding
|
|
113
|
+
* ordering as the higher-level provider while preserving their endpoint
|
|
114
|
+
* shaped output. When an enclosing durable seam already supplied provider
|
|
115
|
+
* request options, the request is already inside that seam and must not open
|
|
116
|
+
* a second ledger row.
|
|
117
|
+
*/
|
|
118
|
+
export async function falSubmitWithGeneration(apiKey, endpoint, args, context, nodeType, capability, onProgress) {
|
|
119
|
+
if (!context || currentGenerationProviderRequestOptions()) {
|
|
120
|
+
return falSubmitWithMeta(apiKey, endpoint, args, onProgress);
|
|
121
|
+
}
|
|
122
|
+
const generation = await context.runGenerationWith({
|
|
123
|
+
provider: "fal_ai",
|
|
124
|
+
capability,
|
|
125
|
+
model: endpoint,
|
|
126
|
+
nodeId: nodeType,
|
|
127
|
+
params: args,
|
|
128
|
+
origin: { surface: "workflow", node_id: nodeType }
|
|
129
|
+
}, async (_provider, signal) => (await falSubmitWithMeta(apiKey, endpoint, args, onProgress, { signal }))
|
|
130
|
+
.data);
|
|
131
|
+
return {
|
|
132
|
+
data: generation.output,
|
|
133
|
+
requestId: generation.receipt?.provider_request_id ?? null
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** Map manifest output metadata to the closest protocol capability. */
|
|
137
|
+
export function falCapabilityForOutputType(outputType) {
|
|
138
|
+
switch (outputType.toLowerCase()) {
|
|
139
|
+
case "video":
|
|
140
|
+
return "text_to_video";
|
|
141
|
+
case "audio":
|
|
142
|
+
return "text_to_speech";
|
|
143
|
+
case "model_3d":
|
|
144
|
+
return "text_to_3d";
|
|
145
|
+
case "image":
|
|
146
|
+
default:
|
|
147
|
+
return "text_to_image";
|
|
148
|
+
}
|
|
46
149
|
}
|
|
47
150
|
// ---------------------------------------------------------------------------
|
|
48
151
|
// Upload to FAL CDN via SDK
|
|
@@ -54,11 +157,14 @@ export async function falUpload(apiKey, data, contentType) {
|
|
|
54
157
|
});
|
|
55
158
|
return client.storage.upload(blob);
|
|
56
159
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
160
|
+
export async function assetToFalUrl(apiKey, ref, context) {
|
|
161
|
+
let uri = ref.uri;
|
|
162
|
+
// A library-picked or generated ref may carry only `asset_id` (empty `uri`).
|
|
163
|
+
// Encode it as an `asset://<id>` URI so the trusted context-resolver branch
|
|
164
|
+
// below uploads it instead of dropping the ref.
|
|
165
|
+
if (!uri && typeof ref.asset_id === "string" && ref.asset_id) {
|
|
166
|
+
uri = `asset://${ref.asset_id}`;
|
|
167
|
+
}
|
|
62
168
|
// Only pass through URLs that FAL can definitely access (their own CDN)
|
|
63
169
|
if (uri?.includes("fal.media") || uri?.includes("fal.run"))
|
|
64
170
|
return uri;
|
|
@@ -70,6 +176,20 @@ export async function assetToFalUrl(apiKey, ref) {
|
|
|
70
176
|
}
|
|
71
177
|
// For non-HTTPS URIs (http://, file://, relative paths, etc.), try to fetch and upload
|
|
72
178
|
if (uri) {
|
|
179
|
+
// Asset/package reference URIs are resolved via the context's canonical
|
|
180
|
+
// resolver — storage adapters only understand their own schemes and return
|
|
181
|
+
// null for `asset://<id>` / `package://<pkg>/<path>` references.
|
|
182
|
+
if ((uri.startsWith("asset://") || uri.startsWith("package://")) &&
|
|
183
|
+
context?.resolveAssetBytes) {
|
|
184
|
+
const { bytes } = await context.resolveAssetBytes(uri);
|
|
185
|
+
if (bytes) {
|
|
186
|
+
return falUpload(apiKey, bytes, inferContentType(ref.type));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const bytes = await context?.storage?.retrieve(uri);
|
|
190
|
+
if (bytes) {
|
|
191
|
+
return falUpload(apiKey, bytes, inferContentType(ref.type));
|
|
192
|
+
}
|
|
73
193
|
try {
|
|
74
194
|
// Resolve relative paths (e.g. /api/storage/...) against local server
|
|
75
195
|
const fetchUrl = uri.startsWith("/")
|
|
@@ -92,18 +212,33 @@ export async function assetToFalUrl(apiKey, ref) {
|
|
|
92
212
|
// ---------------------------------------------------------------------------
|
|
93
213
|
// Convert image ref to data:image/...;base64,... URL
|
|
94
214
|
// ---------------------------------------------------------------------------
|
|
95
|
-
export async function imageToDataUrl(ref) {
|
|
215
|
+
export async function imageToDataUrl(ref, context) {
|
|
96
216
|
const data = ref.data;
|
|
97
217
|
const mime = inferMimeFromRef(ref) ?? "image/png";
|
|
98
218
|
if (data)
|
|
99
219
|
return `data:${mime};base64,${data}`;
|
|
100
220
|
const uri = ref.uri;
|
|
101
221
|
if (uri?.startsWith("https://")) {
|
|
102
|
-
|
|
222
|
+
// The ref's uri is workflow data — the media-ref egress policy decides.
|
|
223
|
+
const res = await fetchExternalMedia(uri);
|
|
103
224
|
const contentType = res.headers?.get?.("content-type") ?? mime;
|
|
104
225
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
105
226
|
return `data:${contentType};base64,${buf.toString("base64")}`;
|
|
106
227
|
}
|
|
228
|
+
// Asset/package refs — including a library-picked ref carrying only
|
|
229
|
+
// `asset_id` — resolve through the trusted context resolver, never a direct
|
|
230
|
+
// fetch (storage adapters return null for these schemes).
|
|
231
|
+
const assetUri = uri?.startsWith("asset://") || uri?.startsWith("package://")
|
|
232
|
+
? uri
|
|
233
|
+
: typeof ref.asset_id === "string" && ref.asset_id
|
|
234
|
+
? `asset://${ref.asset_id}`
|
|
235
|
+
: null;
|
|
236
|
+
if (assetUri && context?.resolveAssetBytes) {
|
|
237
|
+
const { bytes } = await context.resolveAssetBytes(assetUri);
|
|
238
|
+
if (bytes) {
|
|
239
|
+
return `data:${mime};base64,${Buffer.from(bytes).toString("base64")}`;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
107
242
|
return null;
|
|
108
243
|
}
|
|
109
244
|
/** Infer MIME type from an asset ref's uri extension. */
|
|
@@ -144,6 +279,9 @@ export function isRefSet(ref) {
|
|
|
144
279
|
if (!ref || typeof ref !== "object")
|
|
145
280
|
return false;
|
|
146
281
|
const r = ref;
|
|
282
|
+
// A library-picked or freshly-generated ref carries only `asset_id` (with an
|
|
283
|
+
// empty `uri`); it still resolves to bytes via the processing context, so
|
|
284
|
+
// treat a non-empty `asset_id` as a source. `null`/`""` stay unset.
|
|
147
285
|
return Boolean(r.data || r.uri || r.asset_id);
|
|
148
286
|
}
|
|
149
287
|
export function falImageToRef(img) {
|
|
@@ -155,14 +293,21 @@ export function falImageToRef(img) {
|
|
|
155
293
|
mimeType: img.content_type
|
|
156
294
|
};
|
|
157
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* Delete `null`/`undefined`/empty-string keys from the top level of an object.
|
|
298
|
+
*
|
|
299
|
+
* Intentionally NON-recursive, matching `replicate-base.ts`: a FAL arg bag is a
|
|
300
|
+
* flat set of parameters, and its only nested objects are pass-through
|
|
301
|
+
* `dict[...]` inputs the user supplied. Recursing mutated those in place and
|
|
302
|
+
* silently stripped sub-keys they meant to send — a deliberate
|
|
303
|
+
* `"negative_prompt": ""` inside one is a value, not an omission. `0` and
|
|
304
|
+
* `false` are kept.
|
|
305
|
+
*/
|
|
158
306
|
export function removeNulls(obj) {
|
|
159
307
|
for (const k of Object.keys(obj)) {
|
|
160
308
|
if (obj[k] == null || obj[k] === "") {
|
|
161
309
|
delete obj[k];
|
|
162
310
|
}
|
|
163
|
-
else if (typeof obj[k] === "object" && !Array.isArray(obj[k])) {
|
|
164
|
-
removeNulls(obj[k]);
|
|
165
|
-
}
|
|
166
311
|
}
|
|
167
312
|
}
|
|
168
313
|
//# sourceMappingURL=fal-base.js.map
|
package/dist/fal-base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fal-base.js","sourceRoot":"","sources":["../src/fal-base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"fal-base.js","sourceRoot":"","sources":["../src/fal-base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,wBAAwB,EACxB,uCAAuC,EACvC,gBAAgB,EAChB,4BAA4B,EAC5B,8BAA8B,EAC9B,4BAA4B,EAC5B,kBAAkB,EAKnB,MAAM,sBAAsB,CAAC;AAE9B,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E,MAAM,UAAU,YAAY,CAAC,OAA+B;IAC1D,MAAM,GAAG,GAAG,OAAO,EAAE,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;IAClE,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAC3D,OAAO,GAAG,CAAC;AACb,CAAC;AAED,8EAA8E;AAC9E,wCAAwC;AACxC,8EAA8E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,CAAC,CAAC;AAChD,CAAC;AAaD,MAAM,UAAU,aAAa,CAAC,GAAmB;IAC/C,OAAO;QACL,IAAI,EAAE,OAAO;QACb,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,QAAQ,EAAE,GAAG,CAAC,YAAY;KAC3B,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,GAA4B;IACtD,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACjC,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;YACpC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FAL billing-events client for cost reconciliation.
|
|
3
|
+
*
|
|
4
|
+
* Looks up the *actual* billed cost of a single FAL request, so the estimate
|
|
5
|
+
* recorded at call time can be reconciled into the real charge. The wire call
|
|
6
|
+
* is `falRequestCost` in `@nodetool-ai/runtime` — the same Platform API client
|
|
7
|
+
* the provider's `listGenerations` / `getGeneration` use, so there is one
|
|
8
|
+
* client for `GET /v1/models/billing-events` and not two that drift.
|
|
9
|
+
*
|
|
10
|
+
* The billing API requires an admin-scoped key. We reuse the configured
|
|
11
|
+
* `FAL_API_KEY`; if it lacks admin scope the request 401s/403s and we fall
|
|
12
|
+
* back to the estimate. Billing events also lag the request by seconds to a
|
|
13
|
+
* minute, so the lookup retries with backoff.
|
|
14
|
+
*/
|
|
15
|
+
import { type ReconciledCost } from "@nodetool-ai/runtime";
|
|
16
|
+
/**
|
|
17
|
+
* Fetch the actual billed cost (USD) for a single FAL request id. Returns
|
|
18
|
+
* `null` when the key is not admin-scoped, the event never appears, or any
|
|
19
|
+
* error occurs — callers keep the estimate in that case.
|
|
20
|
+
*/
|
|
21
|
+
export declare function fetchFalBillingCost(apiKey: string, requestId: string, opts?: {
|
|
22
|
+
retries?: number;
|
|
23
|
+
retryDelayMs?: number;
|
|
24
|
+
}): Promise<ReconciledCost | null>;
|
|
25
|
+
/** Register the FAL reconciler so the runner can refine FAL estimates. */
|
|
26
|
+
export declare function registerFalCostReconciler(): void;
|
|
27
|
+
//# sourceMappingURL=fal-billing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fal-billing.d.ts","sourceRoot":"","sources":["../src/fal-billing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,sBAAsB,CAAC;AAK9B;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAO,GACrD,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAiBhC;AAED,0EAA0E;AAC1E,wBAAgB,yBAAyB,IAAI,IAAI,CAQhD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FAL billing-events client for cost reconciliation.
|
|
3
|
+
*
|
|
4
|
+
* Looks up the *actual* billed cost of a single FAL request, so the estimate
|
|
5
|
+
* recorded at call time can be reconciled into the real charge. The wire call
|
|
6
|
+
* is `falRequestCost` in `@nodetool-ai/runtime` — the same Platform API client
|
|
7
|
+
* the provider's `listGenerations` / `getGeneration` use, so there is one
|
|
8
|
+
* client for `GET /v1/models/billing-events` and not two that drift.
|
|
9
|
+
*
|
|
10
|
+
* The billing API requires an admin-scoped key. We reuse the configured
|
|
11
|
+
* `FAL_API_KEY`; if it lacks admin scope the request 401s/403s and we fall
|
|
12
|
+
* back to the estimate. Billing events also lag the request by seconds to a
|
|
13
|
+
* minute, so the lookup retries with backoff.
|
|
14
|
+
*/
|
|
15
|
+
import { FalPlatformAuthError, falRequestCost, registerCostReconciler } from "@nodetool-ai/runtime";
|
|
16
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
17
|
+
/**
|
|
18
|
+
* Fetch the actual billed cost (USD) for a single FAL request id. Returns
|
|
19
|
+
* `null` when the key is not admin-scoped, the event never appears, or any
|
|
20
|
+
* error occurs — callers keep the estimate in that case.
|
|
21
|
+
*/
|
|
22
|
+
export async function fetchFalBillingCost(apiKey, requestId, opts = {}) {
|
|
23
|
+
const retries = opts.retries ?? 5;
|
|
24
|
+
const retryDelayMs = opts.retryDelayMs ?? 6000;
|
|
25
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
26
|
+
try {
|
|
27
|
+
const billed = await falRequestCost(apiKey, requestId);
|
|
28
|
+
if (billed)
|
|
29
|
+
return billed;
|
|
30
|
+
// No event posted yet — fall through to retry.
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
// A key without billing scope will not gain it by being asked again.
|
|
34
|
+
if (err instanceof FalPlatformAuthError)
|
|
35
|
+
return null;
|
|
36
|
+
// Network / parse error — retry.
|
|
37
|
+
}
|
|
38
|
+
if (attempt < retries)
|
|
39
|
+
await sleep(retryDelayMs);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
/** Register the FAL reconciler so the runner can refine FAL estimates. */
|
|
44
|
+
export function registerFalCostReconciler() {
|
|
45
|
+
const reconcile = async ({ requestId, secrets }) => {
|
|
46
|
+
const apiKey = secrets?.FAL_API_KEY || process.env.FAL_API_KEY || "";
|
|
47
|
+
if (!apiKey)
|
|
48
|
+
return null;
|
|
49
|
+
return fetchFalBillingCost(apiKey, requestId);
|
|
50
|
+
};
|
|
51
|
+
registerCostReconciler("fal", reconcile);
|
|
52
|
+
registerCostReconciler("fal_ai", reconcile);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=fal-billing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fal-billing.js","sourceRoot":"","sources":["../src/fal-billing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,sBAAsB,EAGvB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,KAAK,GAAG,CAAC,EAAU,EAAiB,EAAE,CAC1C,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAEpD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAc,EACd,SAAiB,EACjB,IAAI,GAAgD,EAAE;IAEtD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;IAClC,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC;IAE/C,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC;QACpD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YACvD,IAAI,MAAM;gBAAE,OAAO,MAAM,CAAC;YAC1B,+CAA+C;QACjD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,qEAAqE;YACrE,IAAI,GAAG,YAAY,oBAAoB;gBAAE,OAAO,IAAI,CAAC;YACrD,iCAAiC;QACnC,CAAC;QACD,IAAI,OAAO,GAAG,OAAO;YAAE,MAAM,KAAK,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,yBAAyB;IACvC,MAAM,SAAS,GAAmB,KAAK,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE;QACjE,MAAM,MAAM,GAAG,OAAO,EAAE,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;QACrE,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QACzB,OAAO,mBAAmB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAChD,CAAC,CAAC;IACF,sBAAsB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACzC,sBAAsB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Estimated cost tracking for FAL nodes.
|
|
3
|
+
*
|
|
4
|
+
* FAL bills per endpoint in varying units (per image, per megapixel, per second
|
|
5
|
+
* of video, per generation, …). The generated `fal-node-type-pricing.json` maps
|
|
6
|
+
* each node type to its `unit_price` + `billing_unit`. We estimate the spend of
|
|
7
|
+
* a completed call as `unit_price * quantity`, inferring `quantity` from the
|
|
8
|
+
* call's output where it is observable (image dimensions, media duration, output
|
|
9
|
+
* count) and otherwise treating the call as a single billable unit.
|
|
10
|
+
*
|
|
11
|
+
* These are estimates — surfaced as "~$" in the UI — not invoiced charges.
|
|
12
|
+
*/
|
|
13
|
+
export interface FalPricingEntry {
|
|
14
|
+
endpoint_id: string;
|
|
15
|
+
unit_price: number;
|
|
16
|
+
billing_unit: string;
|
|
17
|
+
currency: string;
|
|
18
|
+
}
|
|
19
|
+
export interface FalCostEstimate {
|
|
20
|
+
provider: "fal";
|
|
21
|
+
/** FAL endpoint id the charge applies to. */
|
|
22
|
+
model: string;
|
|
23
|
+
/** Estimated cost, `unit_price * quantity`, in `currency`. */
|
|
24
|
+
cost: number;
|
|
25
|
+
unitPrice: number;
|
|
26
|
+
quantity: number;
|
|
27
|
+
billingUnit: string;
|
|
28
|
+
currency: string;
|
|
29
|
+
}
|
|
30
|
+
/** Look up the static pricing entry for a FAL node type. */
|
|
31
|
+
export declare function getFalPricing(nodeType: string): FalPricingEntry | null;
|
|
32
|
+
/**
|
|
33
|
+
* Estimate the cost of a completed FAL call. Returns `null` when no pricing is
|
|
34
|
+
* known for the node type, or when the billing unit is vague (e.g. "units" or
|
|
35
|
+
* "credits") and the unit_price doesn't represent a meaningful per-output cost.
|
|
36
|
+
*/
|
|
37
|
+
export declare function estimateFalCost(nodeType: string, res: Record<string, unknown>, args?: Record<string, unknown>): FalCostEstimate | null;
|
|
38
|
+
/**
|
|
39
|
+
* Estimate and report a FAL call's cost onto the processing context, so it is
|
|
40
|
+
* attached to the node's completed update and persisted by the runner. No-op
|
|
41
|
+
* when pricing is unknown or the context can't receive provider costs.
|
|
42
|
+
*/
|
|
43
|
+
export declare function reportFalCost(context: unknown, nodeType: string, res: Record<string, unknown>, args?: Record<string, unknown>, requestId?: string | null): void;
|
|
44
|
+
//# sourceMappingURL=fal-cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fal-cost.d.ts","sourceRoot":"","sources":["../src/fal-cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,KAAK,CAAC;IAChB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAoBD,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAEtE;AA4GD;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACjC,eAAe,GAAG,IAAI,CAqBxB;AAgBD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAClC,SAAS,GAAE,MAAM,GAAG,IAAW,GAC9B,IAAI,CA0BN"}
|