@nodetool-ai/together-nodes 0.8.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/README.md +70 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/together-base.d.ts +111 -0
- package/dist/together-base.d.ts.map +1 -0
- package/dist/together-base.js +432 -0
- package/dist/together-base.js.map +1 -0
- package/dist/together-factory.d.ts +40 -0
- package/dist/together-factory.d.ts.map +1 -0
- package/dist/together-factory.js +274 -0
- package/dist/together-factory.js.map +1 -0
- package/dist/together-manifest.json +4274 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @nodetool-ai/together-nodes
|
|
2
|
+
|
|
3
|
+
Together AI media nodes for [NodeTool](https://nodetool.ai) — one workflow node
|
|
4
|
+
per Together [serverless model](https://docs.together.ai/docs/serverless/models),
|
|
5
|
+
covering:
|
|
6
|
+
|
|
7
|
+
| Modality | Models | Nodes |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| Text → Image | FLUX.1/.2, Imagen 4, Flash Image, Gemini 3 Pro Image, Ideogram 3, Seedream 3/4, SD3 | 15 |
|
|
10
|
+
| Image → Image | FLUX.2 pro/dev/flex, FLUX.1 Kontext pro/max, Gemini 3 Pro Image | 6 |
|
|
11
|
+
| Text → Video | Veo 2/3, Sora 2, Kling 2.1, Seedance 1, MiniMax, PixVerse, Vidu | 15 |
|
|
12
|
+
| Image → Video | (same, minus Veo 3 + Audio) | 14 |
|
|
13
|
+
| Text → Speech | Orpheus 3B, Kokoro 82M, Cartesia Sonic | 3 |
|
|
14
|
+
| Transcribe (ASR) | Whisper Large v3, Voxtral Mini, Parakeet | 3 |
|
|
15
|
+
|
|
16
|
+
**56 nodes total.** Chat / LLM and embedding capabilities are not surfaced as
|
|
17
|
+
per-model nodes here — they are served by the generic Agent / Embedding nodes
|
|
18
|
+
through `TogetherProvider` in `@nodetool-ai/runtime`.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @nodetool-ai/together-nodes
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
Set `TOGETHER_API_KEY` in NodeTool's secret store (Settings → API Keys) or as an
|
|
29
|
+
environment variable.
|
|
30
|
+
|
|
31
|
+
## Architecture
|
|
32
|
+
|
|
33
|
+
This package is **self-contained**: `together-base.ts` re-implements the small
|
|
34
|
+
slice of the Together API the nodes need (images, speech, transcription, video
|
|
35
|
+
submit+poll) rather than importing the runtime's `TogetherProvider`. That mirrors
|
|
36
|
+
the `fal-nodes` / `atlascloud-nodes` / `replicate-nodes` convention and keeps the
|
|
37
|
+
package independently publishable.
|
|
38
|
+
|
|
39
|
+
- `src/together-manifest.json` — declarative catalog: one entry per
|
|
40
|
+
`(model × task)` with its modality, model id, output type, and typed input
|
|
41
|
+
fields. **Single source of truth.**
|
|
42
|
+
- `src/together-factory.ts` — turns each manifest entry into a `BaseNode`
|
|
43
|
+
subclass; `process()` resolves asset inputs (SSRF-guarded), dispatches on
|
|
44
|
+
modality to the base executors, and persists the result via NodeTool storage.
|
|
45
|
+
- `src/together-base.ts` — auth, asset→bytes resolution, and the per-modality
|
|
46
|
+
Together API executors.
|
|
47
|
+
- `src/index.ts` — `registerTogetherNodes(registry)` + exports.
|
|
48
|
+
|
|
49
|
+
The same manifest is read by `@nodetool-ai/runtime`'s `together-provider`
|
|
50
|
+
(via `manifest-models.ts`) for its image/video model lists, so the node catalog
|
|
51
|
+
and the provider's model catalog can never drift.
|
|
52
|
+
|
|
53
|
+
## Regenerating the catalog
|
|
54
|
+
|
|
55
|
+
The manifest is generated from the catalog + field templates in
|
|
56
|
+
`scripts/generate-manifest.mjs`:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
npm run gen:manifest # rewrites src/together-manifest.json
|
|
60
|
+
npm run build # tsc + copy manifest into dist/
|
|
61
|
+
npm test
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Edit the catalog (model ids / names / supported tasks) or the per-modality field
|
|
65
|
+
templates in that script, then re-run `gen:manifest`.
|
|
66
|
+
|
|
67
|
+
## Links
|
|
68
|
+
|
|
69
|
+
- [NodeTool](https://nodetool.ai)
|
|
70
|
+
- [GitHub](https://github.com/nodetool-ai/nodetool)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2026-09-28T09:19:07.033Z
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NodeClass } from "@nodetool-ai/node-sdk";
|
|
2
|
+
export { loadTogetherNodesFromManifest, createTogetherNodeClass } from "./together-factory.js";
|
|
3
|
+
export type { TogetherManifestEntry, TogetherFieldDef, TogetherFieldType, TogetherModality, TogetherOutputType } from "./together-factory.js";
|
|
4
|
+
export { getApiKey, isSafeHttpUrl, resolveAssetBytes, resolveVideoDimensions, togetherGenerateImage, togetherGenerateVideo, togetherTextToSpeech, togetherTranscribe } from "./together-base.js";
|
|
5
|
+
export declare const TOGETHER_NODES: readonly NodeClass[];
|
|
6
|
+
export declare function registerTogetherNodes(registry: {
|
|
7
|
+
register: (nodeClass: NodeClass) => void;
|
|
8
|
+
}): void;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAMvD,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAS5B,eAAO,MAAM,cAAc,EAAE,SAAS,SAAS,EACA,CAAC;AAEhD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE;IAC9C,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;CAC1C,GAAG,IAAI,CAIP"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { loadPackageAssetJson } from "@nodetool-ai/config";
|
|
2
|
+
import { loadTogetherNodesFromManifest } from "./together-factory.js";
|
|
3
|
+
export { loadTogetherNodesFromManifest, createTogetherNodeClass } from "./together-factory.js";
|
|
4
|
+
export { getApiKey, isSafeHttpUrl, resolveAssetBytes, resolveVideoDimensions, togetherGenerateImage, togetherGenerateVideo, togetherTextToSpeech, togetherTranscribe } from "./together-base.js";
|
|
5
|
+
function loadManifest() {
|
|
6
|
+
return loadPackageAssetJson({ pkg: "@nodetool-ai/together-nodes", path: "together-manifest.json" }, import.meta.url);
|
|
7
|
+
}
|
|
8
|
+
export const TOGETHER_NODES = loadTogetherNodesFromManifest(loadManifest());
|
|
9
|
+
export function registerTogetherNodes(registry) {
|
|
10
|
+
for (const nodeClass of TOGETHER_NODES) {
|
|
11
|
+
registry.register(nodeClass);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAGtE,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAS/B,OAAO,EACL,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,SAAS,YAAY;IACnB,OAAO,oBAAoB,CACzB,EAAE,GAAG,EAAE,6BAA6B,EAAE,IAAI,EAAE,wBAAwB,EAAE,EACtE,OAAO,IAAI,CAAC,GAAG,CAChB,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GACzB,6BAA6B,CAAC,YAAY,EAAE,CAAC,CAAC;AAEhD,MAAM,UAAU,qBAAqB,CAAC,QAErC;IACC,KAAK,MAAM,SAAS,IAAI,cAAc,EAAE,CAAC;QACvC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Together AI HTTP helpers, auth, asset resolution, and per-modality executors.
|
|
3
|
+
*
|
|
4
|
+
* This module is deliberately self-contained — it re-implements the small slice
|
|
5
|
+
* of the Together API the nodes need rather than importing `TogetherProvider`
|
|
6
|
+
* from `@nodetool-ai/runtime`. That mirrors the convention used by the FAL /
|
|
7
|
+
* AtlasCloud / Replicate node packages (their `-base.ts` files duplicate the
|
|
8
|
+
* provider's HTTP on purpose) so this package stays publishable on its own and
|
|
9
|
+
* free of a static dependency on the runtime's provider classes.
|
|
10
|
+
*
|
|
11
|
+
* Wire spec (https://docs.together.ai/docs/serverless/models):
|
|
12
|
+
* - Auth: `Authorization: Bearer <api_key>`.
|
|
13
|
+
* - Images: POST /v1/images/generations → { data: [{ b64_json | url }] } (sync)
|
|
14
|
+
* - Speech: POST /v1/audio/speech → raw audio bytes (sync)
|
|
15
|
+
* - Transcribe: POST /v1/audio/transcriptions (multipart) → { text } (sync)
|
|
16
|
+
* - Video: POST /v2/videos → { id }, then poll GET /v2/videos/{id} (async)
|
|
17
|
+
*/
|
|
18
|
+
import type { NodeValue } from "@nodetool-ai/node-sdk";
|
|
19
|
+
export declare function getApiKey(secrets: Record<string, string> | undefined): string;
|
|
20
|
+
/**
|
|
21
|
+
* Validate an http(s) URL for outbound fetching from the workflow runtime.
|
|
22
|
+
* Rejects hosts that point back at the runtime host or its private network —
|
|
23
|
+
* defense against SSRF via user-controllable asset URIs (workflow inputs can
|
|
24
|
+
* be set by anyone who can submit a graph).
|
|
25
|
+
*
|
|
26
|
+
* Hostname-string based (not resolved-IP), so a public DNS name resolving to a
|
|
27
|
+
* private IP (DNS rebinding) can still slip through — a known limitation shared
|
|
28
|
+
* with the canonical fal/replicate/atlascloud providers.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isSafeHttpUrl(uri: string): boolean;
|
|
31
|
+
export type AssetKind = "image" | "audio" | "video";
|
|
32
|
+
interface AssetStorageLike {
|
|
33
|
+
retrieve: (uri: string) => Promise<Uint8Array | null> | Uint8Array | null;
|
|
34
|
+
/** Present on the server's storage adapters; absent on read-only stubs. */
|
|
35
|
+
store?: (key: string, bytes: Uint8Array, mime?: string) => Promise<string>;
|
|
36
|
+
}
|
|
37
|
+
export interface AssetResolveContext {
|
|
38
|
+
storage?: AssetStorageLike | null;
|
|
39
|
+
/**
|
|
40
|
+
* Canonical ProcessingContext resolver for reference URIs (`asset://<id>`,
|
|
41
|
+
* `package://<pkg>/<path>`). Storage adapters return null for these, so this
|
|
42
|
+
* is the only path that resolves them. SSRF-safe (resolves from storage / the
|
|
43
|
+
* configured server, never an attacker-controlled host).
|
|
44
|
+
*/
|
|
45
|
+
resolveAssetBytes?: (uri: string) => Promise<{
|
|
46
|
+
bytes: Uint8Array | null;
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolve a NodeTool asset ref (ImageRef / AudioRef / VideoRef) to raw bytes.
|
|
51
|
+
* Order: inline data → storage.retrieve(uri) → SSRF-guarded fetch(uri).
|
|
52
|
+
* Returns null when the ref carries no usable source.
|
|
53
|
+
*/
|
|
54
|
+
export declare function resolveAssetBytes(ref: NodeValue, context: AssetResolveContext | undefined, kind: AssetKind): Promise<Uint8Array | null>;
|
|
55
|
+
interface ImageParams {
|
|
56
|
+
prompt: string;
|
|
57
|
+
width?: number | null;
|
|
58
|
+
height?: number | null;
|
|
59
|
+
steps?: number | null;
|
|
60
|
+
guidanceScale?: number | null;
|
|
61
|
+
seed?: number | null;
|
|
62
|
+
negativePrompt?: string | null;
|
|
63
|
+
/** Base64 data URI of the source image for image-to-image edits. */
|
|
64
|
+
imageUrl?: string | null;
|
|
65
|
+
}
|
|
66
|
+
export declare function togetherGenerateImage(apiKey: string, modelId: string, params: ImageParams): Promise<Uint8Array>;
|
|
67
|
+
export declare function imageBytesToDataUri(bytes: Uint8Array): string;
|
|
68
|
+
interface SpeechParams {
|
|
69
|
+
text: string;
|
|
70
|
+
voice?: string;
|
|
71
|
+
speed?: number | null;
|
|
72
|
+
format?: string;
|
|
73
|
+
}
|
|
74
|
+
export declare function togetherTextToSpeech(apiKey: string, modelId: string, params: SpeechParams): Promise<{
|
|
75
|
+
data: Uint8Array;
|
|
76
|
+
mimeType: string;
|
|
77
|
+
}>;
|
|
78
|
+
interface TranscribeParams {
|
|
79
|
+
audio: Uint8Array;
|
|
80
|
+
language?: string | null;
|
|
81
|
+
filename?: string;
|
|
82
|
+
}
|
|
83
|
+
export declare function togetherTranscribe(apiKey: string, modelId: string, params: TranscribeParams): Promise<string>;
|
|
84
|
+
interface VideoParams {
|
|
85
|
+
prompt?: string | null;
|
|
86
|
+
aspectRatio?: string | null;
|
|
87
|
+
resolution?: string | null;
|
|
88
|
+
durationSeconds?: number | null;
|
|
89
|
+
steps?: number | null;
|
|
90
|
+
guidanceScale?: number | null;
|
|
91
|
+
seed?: number | null;
|
|
92
|
+
negativePrompt?: string | null;
|
|
93
|
+
/** Base64 data URI of the first frame for image-to-video. */
|
|
94
|
+
firstFrameDataUri?: string | null;
|
|
95
|
+
}
|
|
96
|
+
interface VideoPollOptions {
|
|
97
|
+
pollIntervalMs?: number;
|
|
98
|
+
timeoutMs?: number;
|
|
99
|
+
/** The run's cancellation: a cancelled run stops polling the paid job. */
|
|
100
|
+
signal?: AbortSignal;
|
|
101
|
+
}
|
|
102
|
+
/** Pixel dimensions for a generated video. */
|
|
103
|
+
export interface VideoDimensions {
|
|
104
|
+
width: number;
|
|
105
|
+
height: number;
|
|
106
|
+
}
|
|
107
|
+
/** Map aspect-ratio + resolution hints to concrete pixel dimensions. */
|
|
108
|
+
export declare function resolveVideoDimensions(aspectRatio?: string | null, resolution?: string | null): VideoDimensions;
|
|
109
|
+
export declare function togetherGenerateVideo(apiKey: string, modelId: string, params: VideoParams, opts?: VideoPollOptions): Promise<Uint8Array>;
|
|
110
|
+
export {};
|
|
111
|
+
//# sourceMappingURL=together-base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"together-base.d.ts","sourceRoot":"","sources":["../src/together-base.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Together AI HTTP helpers, auth, asset resolution, and per-modality executors.
|
|
3
|
+
*
|
|
4
|
+
* This module is deliberately self-contained — it re-implements the small slice
|
|
5
|
+
* of the Together API the nodes need rather than importing `TogetherProvider`
|
|
6
|
+
* from `@nodetool-ai/runtime`. That mirrors the convention used by the FAL /
|
|
7
|
+
* AtlasCloud / Replicate node packages (their `-base.ts` files duplicate the
|
|
8
|
+
* provider's HTTP on purpose) so this package stays publishable on its own and
|
|
9
|
+
* free of a static dependency on the runtime's provider classes.
|
|
10
|
+
*
|
|
11
|
+
* Wire spec (https://docs.together.ai/docs/serverless/models):
|
|
12
|
+
* - Auth: `Authorization: Bearer <api_key>`.
|
|
13
|
+
* - Images: POST /v1/images/generations → { data: [{ b64_json | url }] } (sync)
|
|
14
|
+
* - Speech: POST /v1/audio/speech → raw audio bytes (sync)
|
|
15
|
+
* - Transcribe: POST /v1/audio/transcriptions (multipart) → { text } (sync)
|
|
16
|
+
* - Video: POST /v2/videos → { id }, then poll GET /v2/videos/{id} (async)
|
|
17
|
+
*/
|
|
18
|
+
import { fetchExternalMedia } from "@nodetool-ai/runtime";
|
|
19
|
+
import { sleep } from "@nodetool-ai/runtime/provider-transport";
|
|
20
|
+
import { isNonEmptyString, isObjectLike, isRecord, isString } from "@nodetool-ai/node-sdk";
|
|
21
|
+
const TOGETHER_BASE = "https://api.together.xyz";
|
|
22
|
+
export function getApiKey(secrets) {
|
|
23
|
+
const key = (secrets && secrets.TOGETHER_API_KEY) ||
|
|
24
|
+
process.env.TOGETHER_API_KEY ||
|
|
25
|
+
"";
|
|
26
|
+
if (!key.trim()) {
|
|
27
|
+
throw new Error("TOGETHER_API_KEY is not configured");
|
|
28
|
+
}
|
|
29
|
+
return key.trim();
|
|
30
|
+
}
|
|
31
|
+
function authHeaders(apiKey) {
|
|
32
|
+
return {
|
|
33
|
+
Authorization: `Bearer ${apiKey}`,
|
|
34
|
+
"Content-Type": "application/json"
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validate an http(s) URL for outbound fetching from the workflow runtime.
|
|
39
|
+
* Rejects hosts that point back at the runtime host or its private network —
|
|
40
|
+
* defense against SSRF via user-controllable asset URIs (workflow inputs can
|
|
41
|
+
* be set by anyone who can submit a graph).
|
|
42
|
+
*
|
|
43
|
+
* Hostname-string based (not resolved-IP), so a public DNS name resolving to a
|
|
44
|
+
* private IP (DNS rebinding) can still slip through — a known limitation shared
|
|
45
|
+
* with the canonical fal/replicate/atlascloud providers.
|
|
46
|
+
*/
|
|
47
|
+
export function isSafeHttpUrl(uri) {
|
|
48
|
+
let u;
|
|
49
|
+
try {
|
|
50
|
+
u = new URL(uri);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (u.protocol !== "http:" && u.protocol !== "https:")
|
|
56
|
+
return false;
|
|
57
|
+
return !isPrivateOrLocalHost(u.hostname);
|
|
58
|
+
}
|
|
59
|
+
function parseIpComponent(part) {
|
|
60
|
+
if (/^0x[0-9a-f]+$/i.test(part))
|
|
61
|
+
return parseInt(part.slice(2), 16);
|
|
62
|
+
if (/^0[0-7]+$/.test(part))
|
|
63
|
+
return parseInt(part, 8);
|
|
64
|
+
if (/^[0-9]+$/.test(part))
|
|
65
|
+
return parseInt(part, 10);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
function ipv4ToOctets(host) {
|
|
69
|
+
const parts = host.split(".");
|
|
70
|
+
if (parts.length === 0 || parts.length > 4)
|
|
71
|
+
return null;
|
|
72
|
+
const nums = [];
|
|
73
|
+
for (const part of parts) {
|
|
74
|
+
const n = parseIpComponent(part);
|
|
75
|
+
if (n === null || n < 0)
|
|
76
|
+
return null;
|
|
77
|
+
nums.push(n);
|
|
78
|
+
}
|
|
79
|
+
const n = nums.length;
|
|
80
|
+
for (let i = 0; i < n - 1; i++) {
|
|
81
|
+
if (nums[i] > 0xff)
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const tailOctets = 4 - (n - 1);
|
|
85
|
+
const tail = nums[n - 1];
|
|
86
|
+
if (tail < 0 || tail > 0xffffffff || tail >= 2 ** (tailOctets * 8)) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
let value = tail;
|
|
90
|
+
for (let i = 0; i < n - 1; i++) {
|
|
91
|
+
value += nums[i] * 256 ** (3 - i);
|
|
92
|
+
}
|
|
93
|
+
return [
|
|
94
|
+
(value >>> 24) & 0xff,
|
|
95
|
+
(value >>> 16) & 0xff,
|
|
96
|
+
(value >>> 8) & 0xff,
|
|
97
|
+
value & 0xff
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
function mappedIpv4ToOctets(host) {
|
|
101
|
+
const dotted = /^::(?:ffff:)?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/i.exec(host);
|
|
102
|
+
if (dotted)
|
|
103
|
+
return ipv4ToOctets(dotted[1]);
|
|
104
|
+
const hex = /^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(host);
|
|
105
|
+
if (hex) {
|
|
106
|
+
const hi = parseInt(hex[1], 16);
|
|
107
|
+
const lo = parseInt(hex[2], 16);
|
|
108
|
+
return [(hi >> 8) & 0xff, hi & 0xff, (lo >> 8) & 0xff, lo & 0xff];
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
function isPrivateV4(octets) {
|
|
113
|
+
const [o1, o2] = octets;
|
|
114
|
+
if (o1 === 0)
|
|
115
|
+
return true;
|
|
116
|
+
if (o1 === 10)
|
|
117
|
+
return true;
|
|
118
|
+
if (o1 === 127)
|
|
119
|
+
return true;
|
|
120
|
+
if (o1 === 169 && o2 === 254)
|
|
121
|
+
return true;
|
|
122
|
+
if (o1 === 172 && o2 >= 16 && o2 <= 31)
|
|
123
|
+
return true;
|
|
124
|
+
if (o1 === 192 && o2 === 168)
|
|
125
|
+
return true;
|
|
126
|
+
if (o1 === 100 && o2 >= 64 && o2 <= 127)
|
|
127
|
+
return true;
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
function isPrivateOrLocalHost(hostname) {
|
|
131
|
+
let h = hostname.toLowerCase();
|
|
132
|
+
if (h.startsWith("[") && h.endsWith("]"))
|
|
133
|
+
h = h.slice(1, -1);
|
|
134
|
+
if (h === "" || h === "localhost" || h.endsWith(".localhost"))
|
|
135
|
+
return true;
|
|
136
|
+
const octets = ipv4ToOctets(h) ?? mappedIpv4ToOctets(h);
|
|
137
|
+
if (octets)
|
|
138
|
+
return isPrivateV4(octets);
|
|
139
|
+
if (h === "::1" || h === "::")
|
|
140
|
+
return true;
|
|
141
|
+
if (h.startsWith("fe80:") || h.startsWith("fe80::"))
|
|
142
|
+
return true;
|
|
143
|
+
if (/^f[cd][0-9a-f]{2}:/i.test(h))
|
|
144
|
+
return true;
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
function decodeBase64(data) {
|
|
148
|
+
// Accept both raw base64 and `data:<mime>;base64,<...>` forms.
|
|
149
|
+
const comma = data.indexOf(",");
|
|
150
|
+
const raw = data.startsWith("data:") && comma >= 0 ? data.slice(comma + 1) : data;
|
|
151
|
+
return Uint8Array.from(Buffer.from(raw, "base64"));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Resolve a NodeTool asset ref (ImageRef / AudioRef / VideoRef) to raw bytes.
|
|
155
|
+
* Order: inline data → storage.retrieve(uri) → SSRF-guarded fetch(uri).
|
|
156
|
+
* Returns null when the ref carries no usable source.
|
|
157
|
+
*/
|
|
158
|
+
export async function resolveAssetBytes(ref, context, kind) {
|
|
159
|
+
if (ref === null || ref === undefined)
|
|
160
|
+
return null;
|
|
161
|
+
if (isString(ref)) {
|
|
162
|
+
if (ref === "")
|
|
163
|
+
return null;
|
|
164
|
+
return isSafeHttpUrl(ref) ? fetchBytes(ref) : null;
|
|
165
|
+
}
|
|
166
|
+
// Anything that is not a keyed ref (a number, a list) carries no source.
|
|
167
|
+
if (!isRecord(ref))
|
|
168
|
+
return null;
|
|
169
|
+
const data = ref.data;
|
|
170
|
+
if (isNonEmptyString(data))
|
|
171
|
+
return decodeBase64(data);
|
|
172
|
+
if (data instanceof Uint8Array && data.byteLength > 0)
|
|
173
|
+
return data;
|
|
174
|
+
const uri = isString(ref.uri) ? ref.uri : "";
|
|
175
|
+
// Empty placeholder ref (no uri, no data) → treat as "no asset provided" so
|
|
176
|
+
// the caller can surface a clear "<field> is required" error instead.
|
|
177
|
+
if (uri.length === 0)
|
|
178
|
+
return null;
|
|
179
|
+
// Reference URIs (`asset://<id>`, `package://<pkg>/<path>`) are not known to
|
|
180
|
+
// storage adapters — only the ProcessingContext resolver handles them.
|
|
181
|
+
if ((uri.startsWith("asset://") || uri.startsWith("package://")) &&
|
|
182
|
+
context?.resolveAssetBytes) {
|
|
183
|
+
const { bytes } = await context.resolveAssetBytes(uri);
|
|
184
|
+
if (bytes)
|
|
185
|
+
return new Uint8Array(bytes);
|
|
186
|
+
}
|
|
187
|
+
if (context?.storage) {
|
|
188
|
+
try {
|
|
189
|
+
const bytes = await context.storage.retrieve(uri);
|
|
190
|
+
if (bytes && bytes.byteLength > 0)
|
|
191
|
+
return new Uint8Array(bytes);
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
/* fall through to direct fetch */
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (isSafeHttpUrl(uri)) {
|
|
198
|
+
return fetchBytes(uri);
|
|
199
|
+
}
|
|
200
|
+
// A uri was supplied but can't be safely fetched (private/loopback/metadata
|
|
201
|
+
// host, or an unresolvable relative path with no storage) — fail loudly.
|
|
202
|
+
throw new Error(`Cannot resolve ${kind} asset for Together — '${uri}' is not a fetchable URL`);
|
|
203
|
+
}
|
|
204
|
+
async function fetchBytes(url) {
|
|
205
|
+
// `isSafeHttpUrl` has already judged the initial URL; it cannot judge the
|
|
206
|
+
// redirect hops, which is what the protected fetch is for.
|
|
207
|
+
const res = await fetchExternalMedia(url);
|
|
208
|
+
if (!res.ok) {
|
|
209
|
+
throw new Error(`Together asset fetch failed: HTTP ${res.status} for ${url}`);
|
|
210
|
+
}
|
|
211
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
212
|
+
}
|
|
213
|
+
function bytesToDataUri(bytes, mime) {
|
|
214
|
+
return `data:${mime};base64,${Buffer.from(bytes).toString("base64")}`;
|
|
215
|
+
}
|
|
216
|
+
export async function togetherGenerateImage(apiKey, modelId, params) {
|
|
217
|
+
if (!params.prompt)
|
|
218
|
+
throw new Error("The input prompt cannot be empty.");
|
|
219
|
+
const body = {
|
|
220
|
+
model: modelId,
|
|
221
|
+
prompt: params.prompt,
|
|
222
|
+
n: 1,
|
|
223
|
+
response_format: "b64_json"
|
|
224
|
+
};
|
|
225
|
+
if (params.imageUrl)
|
|
226
|
+
body.image_url = params.imageUrl;
|
|
227
|
+
if (params.width != null)
|
|
228
|
+
body.width = params.width;
|
|
229
|
+
if (params.height != null)
|
|
230
|
+
body.height = params.height;
|
|
231
|
+
if (params.steps != null)
|
|
232
|
+
body.steps = params.steps;
|
|
233
|
+
if (params.guidanceScale != null)
|
|
234
|
+
body.guidance_scale = params.guidanceScale;
|
|
235
|
+
if (params.seed != null)
|
|
236
|
+
body.seed = params.seed;
|
|
237
|
+
if (params.negativePrompt)
|
|
238
|
+
body.negative_prompt = params.negativePrompt;
|
|
239
|
+
const response = await fetch(`${TOGETHER_BASE}/v1/images/generations`, {
|
|
240
|
+
method: "POST",
|
|
241
|
+
headers: authHeaders(apiKey),
|
|
242
|
+
body: JSON.stringify(body)
|
|
243
|
+
});
|
|
244
|
+
if (!response.ok) {
|
|
245
|
+
throw new Error(`Together image generation failed: ${await response.text()}`);
|
|
246
|
+
}
|
|
247
|
+
const payload = await response.json();
|
|
248
|
+
const items = isObjectLike(payload) && Array.isArray(payload.data) ? payload.data : [];
|
|
249
|
+
const item = items[0];
|
|
250
|
+
if (!isObjectLike(item)) {
|
|
251
|
+
throw new Error("Together image generation returned no data.");
|
|
252
|
+
}
|
|
253
|
+
if (isNonEmptyString(item.b64_json)) {
|
|
254
|
+
return Uint8Array.from(Buffer.from(item.b64_json, "base64"));
|
|
255
|
+
}
|
|
256
|
+
if (isNonEmptyString(item.url))
|
|
257
|
+
return fetchBytes(item.url);
|
|
258
|
+
throw new Error("Together image generation returned no image data.");
|
|
259
|
+
}
|
|
260
|
+
export function imageBytesToDataUri(bytes) {
|
|
261
|
+
// Together accepts a base64 data URI for the source image of an edit.
|
|
262
|
+
return bytesToDataUri(bytes, "image/jpeg");
|
|
263
|
+
}
|
|
264
|
+
const SPEECH_FORMAT_MIME = {
|
|
265
|
+
mp3: "audio/mpeg",
|
|
266
|
+
wav: "audio/wav"
|
|
267
|
+
};
|
|
268
|
+
function isSpeechFormat(format) {
|
|
269
|
+
return Object.hasOwn(SPEECH_FORMAT_MIME, format);
|
|
270
|
+
}
|
|
271
|
+
export async function togetherTextToSpeech(apiKey, modelId, params) {
|
|
272
|
+
if (!params.text)
|
|
273
|
+
throw new Error("text must not be empty");
|
|
274
|
+
const fmt = (params.format ?? "mp3").toLowerCase();
|
|
275
|
+
const mime = isSpeechFormat(fmt) ? SPEECH_FORMAT_MIME[fmt] : "audio/mpeg";
|
|
276
|
+
const body = {
|
|
277
|
+
model: modelId,
|
|
278
|
+
input: params.text,
|
|
279
|
+
voice: params.voice ?? "tara",
|
|
280
|
+
response_format: fmt
|
|
281
|
+
};
|
|
282
|
+
if (params.speed != null)
|
|
283
|
+
body.speed = params.speed;
|
|
284
|
+
const response = await fetch(`${TOGETHER_BASE}/v1/audio/speech`, {
|
|
285
|
+
method: "POST",
|
|
286
|
+
headers: authHeaders(apiKey),
|
|
287
|
+
body: JSON.stringify(body)
|
|
288
|
+
});
|
|
289
|
+
if (!response.ok) {
|
|
290
|
+
throw new Error(`Together TTS failed: ${await response.text()}`);
|
|
291
|
+
}
|
|
292
|
+
const data = new Uint8Array(await response.arrayBuffer());
|
|
293
|
+
return { data, mimeType: mime };
|
|
294
|
+
}
|
|
295
|
+
export async function togetherTranscribe(apiKey, modelId, params) {
|
|
296
|
+
if (!params.audio || params.audio.byteLength === 0) {
|
|
297
|
+
throw new Error("audio must not be empty");
|
|
298
|
+
}
|
|
299
|
+
const form = new FormData();
|
|
300
|
+
// SAFETY: a Uint8Array is a BlobPart at runtime; the lib types disagree only
|
|
301
|
+
// over whether its buffer could be a SharedArrayBuffer, which this one — read
|
|
302
|
+
// from a node property — never is.
|
|
303
|
+
const blob = new Blob([params.audio], {
|
|
304
|
+
type: "application/octet-stream"
|
|
305
|
+
});
|
|
306
|
+
form.append("file", blob, params.filename ?? "audio.wav");
|
|
307
|
+
form.append("model", modelId);
|
|
308
|
+
form.append("response_format", "json");
|
|
309
|
+
if (params.language)
|
|
310
|
+
form.append("language", params.language);
|
|
311
|
+
const response = await fetch(`${TOGETHER_BASE}/v1/audio/transcriptions`, {
|
|
312
|
+
method: "POST",
|
|
313
|
+
headers: { Authorization: `Bearer ${apiKey}` }, // let fetch set multipart boundary
|
|
314
|
+
body: form
|
|
315
|
+
});
|
|
316
|
+
if (!response.ok) {
|
|
317
|
+
throw new Error(`Together transcription failed: ${await response.text()}`);
|
|
318
|
+
}
|
|
319
|
+
const payload = await response.json();
|
|
320
|
+
return isObjectLike(payload) ? String(payload.text ?? "") : "";
|
|
321
|
+
}
|
|
322
|
+
/** Keyed `<aspect-ratio>|<resolution>`, the two hints a node exposes. */
|
|
323
|
+
const VIDEO_DIMENSION_PRESETS = new Map([
|
|
324
|
+
["16:9|480p", { width: 854, height: 480 }],
|
|
325
|
+
["16:9|720p", { width: 1280, height: 720 }],
|
|
326
|
+
["16:9|1080p", { width: 1920, height: 1080 }],
|
|
327
|
+
["9:16|480p", { width: 480, height: 854 }],
|
|
328
|
+
["9:16|720p", { width: 720, height: 1280 }],
|
|
329
|
+
["9:16|1080p", { width: 1080, height: 1920 }],
|
|
330
|
+
["1:1|480p", { width: 480, height: 480 }],
|
|
331
|
+
["1:1|720p", { width: 720, height: 720 }],
|
|
332
|
+
["1:1|1080p", { width: 1080, height: 1080 }],
|
|
333
|
+
["4:3|480p", { width: 640, height: 480 }],
|
|
334
|
+
["4:3|720p", { width: 960, height: 720 }],
|
|
335
|
+
["4:3|1080p", { width: 1440, height: 1080 }]
|
|
336
|
+
]);
|
|
337
|
+
/** Map aspect-ratio + resolution hints to concrete pixel dimensions. */
|
|
338
|
+
export function resolveVideoDimensions(aspectRatio, resolution) {
|
|
339
|
+
const ar = (aspectRatio ?? "16:9").replace(/\s/g, "");
|
|
340
|
+
const res = (resolution ?? "720p").toLowerCase();
|
|
341
|
+
// Together's MiniMax default for a combination with no preset.
|
|
342
|
+
return (VIDEO_DIMENSION_PRESETS.get(`${ar}|${res}`) ?? { width: 1366, height: 768 });
|
|
343
|
+
}
|
|
344
|
+
async function pollVideoJob(apiKey, jobId, opts) {
|
|
345
|
+
const timeoutMs = opts.timeoutMs ?? 10 * 60 * 1000;
|
|
346
|
+
const intervalMs = opts.pollIntervalMs ?? 5_000;
|
|
347
|
+
const start = nowMs();
|
|
348
|
+
for (;;) {
|
|
349
|
+
opts.signal?.throwIfAborted();
|
|
350
|
+
if (nowMs() - start > timeoutMs) {
|
|
351
|
+
throw new Error(`Together video generation timed out after ${Math.round(timeoutMs / 1000)}s for job ${jobId}`);
|
|
352
|
+
}
|
|
353
|
+
await sleep(intervalMs, opts.signal);
|
|
354
|
+
opts.signal?.throwIfAborted();
|
|
355
|
+
const res = await fetch(`${TOGETHER_BASE}/v2/videos/${jobId}`, {
|
|
356
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
357
|
+
signal: opts.signal
|
|
358
|
+
});
|
|
359
|
+
if (!res.ok) {
|
|
360
|
+
throw new Error(`Together video status check failed: ${await res.text()}`);
|
|
361
|
+
}
|
|
362
|
+
const payload = await res.json();
|
|
363
|
+
if (!isObjectLike(payload))
|
|
364
|
+
continue;
|
|
365
|
+
const status = isString(payload.status) ? payload.status : "";
|
|
366
|
+
if (status !== "completed" &&
|
|
367
|
+
status !== "failed" &&
|
|
368
|
+
status !== "cancelled") {
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
const outputs = payload.outputs;
|
|
372
|
+
const error = payload.error;
|
|
373
|
+
return {
|
|
374
|
+
status,
|
|
375
|
+
videoUrl: isObjectLike(outputs) && isString(outputs.video_url)
|
|
376
|
+
? outputs.video_url
|
|
377
|
+
: null,
|
|
378
|
+
errorMessage: isObjectLike(error) && isString(error.message) ? error.message : null
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
export async function togetherGenerateVideo(apiKey, modelId, params, opts = {}) {
|
|
383
|
+
const { width, height } = resolveVideoDimensions(params.aspectRatio, params.resolution);
|
|
384
|
+
const body = {
|
|
385
|
+
model: modelId,
|
|
386
|
+
prompt: params.prompt ?? "",
|
|
387
|
+
width,
|
|
388
|
+
height
|
|
389
|
+
};
|
|
390
|
+
// Together expects seconds as a string (e.g. "6").
|
|
391
|
+
if (params.durationSeconds != null)
|
|
392
|
+
body.seconds = String(params.durationSeconds);
|
|
393
|
+
if (params.steps != null)
|
|
394
|
+
body.steps = params.steps;
|
|
395
|
+
if (params.guidanceScale != null)
|
|
396
|
+
body.guidance_scale = params.guidanceScale;
|
|
397
|
+
if (params.seed != null)
|
|
398
|
+
body.seed = params.seed;
|
|
399
|
+
if (params.negativePrompt)
|
|
400
|
+
body.negative_prompt = params.negativePrompt;
|
|
401
|
+
if (params.firstFrameDataUri) {
|
|
402
|
+
body.frame_images = [{ input_image: params.firstFrameDataUri, frame: "first" }];
|
|
403
|
+
}
|
|
404
|
+
const createResponse = await fetch(`${TOGETHER_BASE}/v2/videos`, {
|
|
405
|
+
method: "POST",
|
|
406
|
+
headers: authHeaders(apiKey),
|
|
407
|
+
body: JSON.stringify(body),
|
|
408
|
+
signal: opts.signal
|
|
409
|
+
});
|
|
410
|
+
if (!createResponse.ok) {
|
|
411
|
+
throw new Error(`Together video creation failed: ${await createResponse.text()}`);
|
|
412
|
+
}
|
|
413
|
+
const created = await createResponse.json();
|
|
414
|
+
const jobId = isObjectLike(created) && isString(created.id) ? created.id : "";
|
|
415
|
+
if (!jobId) {
|
|
416
|
+
throw new Error("Together video creation returned no job id.");
|
|
417
|
+
}
|
|
418
|
+
const finalStatus = await pollVideoJob(apiKey, jobId, opts);
|
|
419
|
+
if (finalStatus.status !== "completed") {
|
|
420
|
+
const reason = finalStatus.errorMessage ??
|
|
421
|
+
`job ended with status '${finalStatus.status}'`;
|
|
422
|
+
throw new Error(`Together video generation failed: ${reason}`);
|
|
423
|
+
}
|
|
424
|
+
if (!finalStatus.videoUrl) {
|
|
425
|
+
throw new Error("Together video generation returned no video URL.");
|
|
426
|
+
}
|
|
427
|
+
return fetchBytes(finalStatus.videoUrl);
|
|
428
|
+
}
|
|
429
|
+
function nowMs() {
|
|
430
|
+
return Date.now();
|
|
431
|
+
}
|
|
432
|
+
//# sourceMappingURL=together-base.js.map
|