@tangle-network/tcloud 0.4.6 → 0.4.8

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,4 +1,7 @@
1
+ import { AgentProfile } from '@tangle-network/sandbox';
2
+
1
3
  /** Core types for the tcloud SDK */
4
+
2
5
  interface TCloudConfig {
3
6
  /** API base URL (default: https://router.tangle.tools/v1) */
4
7
  baseURL?: string;
@@ -94,6 +97,39 @@ interface ImageGenerateOptions {
94
97
  quality?: string;
95
98
  response_format?: 'url' | 'b64_json';
96
99
  }
100
+ /**
101
+ * OpenAI-compatible /v1/images/edits request. Accepts one or more
102
+ * reference images + a prompt describing how to transform them.
103
+ *
104
+ * For gpt-image-2, the supplied images are passed as `image[]` (the
105
+ * model supports multi-image composition); for dall-e-2 only a single
106
+ * image is honored. The optional `mask` is the OpenAI inpainting mask
107
+ * (PNG with alpha) used to constrain where edits are applied.
108
+ *
109
+ * Carrying both shapes here lets callers point at the same `imagesEdit`
110
+ * method regardless of upstream model; cli-bridge / tangle-router
111
+ * decide what to forward.
112
+ */
113
+ interface ImageEditOptions {
114
+ model?: string;
115
+ prompt: string;
116
+ /** One or more reference images. Pass as Blob (browser/Node 22+),
117
+ * ArrayBuffer (will be wrapped in a Blob), or `{data, mediaType}`
118
+ * for base64 + explicit mime. The first form is preferred. */
119
+ image: ImageEditAttachment | ImageEditAttachment[];
120
+ /** Optional inpainting mask — PNG with transparent pixels marking
121
+ * the editable region (OpenAI dall-e-2 / gpt-image-2 inpaint mode). */
122
+ mask?: ImageEditAttachment;
123
+ n?: number;
124
+ size?: string;
125
+ quality?: string;
126
+ response_format?: 'url' | 'b64_json';
127
+ }
128
+ type ImageEditAttachment = Blob | ArrayBuffer | {
129
+ data: string /** base64 */;
130
+ mediaType: string;
131
+ filename?: string;
132
+ };
97
133
  interface ImageResponse {
98
134
  created: number;
99
135
  data: {
@@ -189,9 +225,18 @@ interface BatchJobResponse {
189
225
  }
190
226
  interface VideoGenerateOptions {
191
227
  model?: string;
228
+ provider?: string | Record<string, unknown>;
192
229
  prompt: string;
193
230
  duration?: number;
194
231
  resolution?: string;
232
+ aspect_ratio?: string;
233
+ size?: string;
234
+ image_url?: string;
235
+ frame_images?: Array<Record<string, unknown>>;
236
+ input_references?: Array<Record<string, unknown>>;
237
+ generate_audio?: boolean;
238
+ seed?: number;
239
+ callback_url?: string;
195
240
  }
196
241
  interface VideoResponse {
197
242
  id: string;
@@ -338,8 +383,8 @@ interface BridgeOptions {
338
383
  harness: 'claude-code' | 'claudish' | 'codex' | 'opencode' | 'kimi-code' | 'sandbox' | 'openai' | 'anthropic' | 'moonshot' | 'zai';
339
384
  /** Model id inside the harness (e.g. `sonnet`, `kimi-for-coding`, `gpt-5-codex`). Omit for harness default. */
340
385
  model?: string;
341
- /** Router-issued unlock token. Required unless operator has disabled the gate. */
342
- unlock: string;
386
+ /** Router-issued unlock token. Required for router-mediated bridge calls; unused by direct cli-bridge clients. */
387
+ unlock?: string;
343
388
  /** Stable caller-owned id for session resume. Map one id per logical conversation. */
344
389
  resume?: string;
345
390
  /** BYOB: point at your own cli-bridge instance. Router must have BYOB enabled. */
@@ -347,6 +392,12 @@ interface BridgeOptions {
347
392
  /** BYOB: bearer your cli-bridge expects. */
348
393
  bridgeBearer?: string;
349
394
  }
395
+ interface SandboxChatOptions {
396
+ /** Inline sandbox AgentProfile. Serialized as cli-bridge/sandbox-api `agent_profile`. */
397
+ agentProfile?: AgentProfile;
398
+ /** Direct sandbox or cli-bridge session id. Serialized as `session_id`. */
399
+ sessionId?: string;
400
+ }
350
401
  interface ChatOptions {
351
402
  /** Model to use */
352
403
  model?: string;
@@ -386,10 +437,15 @@ interface ChatOptions {
386
437
  gateway?: GatewayOptions;
387
438
  /**
388
439
  * Provider-specific parameters passed through to the upstream API.
389
- * These are spread into the request body alongside standard fields.
440
+ * Protected OpenAI/Tangle fields cannot be overridden from this escape hatch.
390
441
  * Example: `{ thinking: { type: 'enabled', budget_tokens: 8000 } }`
391
442
  */
392
443
  providerOptions?: Record<string, unknown>;
444
+ /**
445
+ * Typed sandbox/cli-bridge extensions. Use this instead of smuggling
446
+ * `agent_profile` or `session_id` through providerOptions.
447
+ */
448
+ sandbox?: SandboxChatOptions;
393
449
  /**
394
450
  * Route this call through the Tangle Router's cli-bridge short-circuit.
395
451
  * See {@link BridgeOptions}. When set, `model` is rewritten to
@@ -696,9 +752,10 @@ declare class TCloudClient {
696
752
  * const reply = await client.ask('explain X', 'claude-code/sonnet')
697
753
  * ```
698
754
  *
699
- * For session-resumable agentic dispatches (file edits, multi-turn
700
- * coding), use the router-mediated `tcloud.bridge({...})` API instead
701
- * (or POST to cli-bridge directly with `session_id` in the body).
755
+ * For session-resumable agentic dispatches, use `client.bridge(...)` on
756
+ * the returned direct client. `resume` is serialized to cli-bridge's
757
+ * `session_id` body field and the model wire format stays
758
+ * `<harness>/<model>` without the router-only `bridge/` prefix.
702
759
  */
703
760
  static fromCliBridge(opts: {
704
761
  /** cli-bridge base URL — `http://127.0.0.1:3344` for default local; can be any reachable URL. */
@@ -718,7 +775,7 @@ declare class TCloudClient {
718
775
  *
719
776
  * ```ts
720
777
  * const tcloud = TCloudClient.rotating({
721
- * apiKey: process.env.TCLOUD_API_KEY,
778
+ * apiKey: process.env.TANGLE_API_KEY,
722
779
  * routing: { strategy: 'min-exposure' },
723
780
  * })
724
781
  * await tcloud.ask('hello')
@@ -816,6 +873,7 @@ declare class TCloudClient {
816
873
  * a rotating client throws.
817
874
  */
818
875
  bridge(cfg: BridgeOptions): BridgeSession;
876
+ private _isDirectCliBridge;
819
877
  /**
820
878
  * Rotation stats — populated only on clients created via
821
879
  * {@link TCloudClient.rotating}. Non-rotating clients return an empty
@@ -897,6 +955,18 @@ declare class TCloudClient {
897
955
  embeddings(options: EmbeddingOptions): Promise<EmbeddingResponse>;
898
956
  /** Generate images */
899
957
  imageGenerate(options: ImageGenerateOptions): Promise<ImageResponse>;
958
+ /**
959
+ * Edit / inpaint / variate an existing image with a text prompt.
960
+ * Sibling to `imageGenerate`; routes to `/v1/images/edits` via
961
+ * multipart/form-data per the OpenAI spec.
962
+ *
963
+ * Reference image attachments may be passed as `Blob`, `ArrayBuffer`,
964
+ * or `{data: base64, mediaType, filename?}`. Multi-image composition
965
+ * (e.g. gpt-image-2 with two reference frames + a prompt that fuses
966
+ * them) is supported by passing an array; for legacy models only the
967
+ * first image is honored upstream.
968
+ */
969
+ imagesEdit(options: ImageEditOptions): Promise<ImageResponse>;
900
970
  /** Rerank documents by relevance to a query */
901
971
  rerank(options: RerankOptions): Promise<RerankResponse>;
902
972
  /** Text-to-speech */
@@ -1167,7 +1237,8 @@ declare class TCloudClient {
1167
1237
  declare class BridgeSession {
1168
1238
  private readonly client;
1169
1239
  private readonly cfg;
1170
- constructor(client: TCloudClient, cfg: BridgeOptions);
1240
+ private readonly direct;
1241
+ constructor(client: TCloudClient, cfg: BridgeOptions, direct?: boolean);
1171
1242
  /** Full chat completion (non-streaming). */
1172
1243
  chat(options: Omit<ChatOptions, 'bridge'>): Promise<ChatCompletion>;
1173
1244
  /** Stream OpenAI chat.completion.chunks. */
@@ -1215,4 +1286,4 @@ declare class TCloudError extends Error {
1215
1286
  constructor(status: number, message: string);
1216
1287
  }
1217
1288
 
1218
- export { type ApiKeyInfo as A, type BatchJobResponse as B, type ChatCompletion as C, type RotatingRoutingConfig as D, type EmbeddingOptions as E, type FineTuningJob as F, type GatewayOptions as G, type RotationStats as H, type ImageGenerateOptions as I, type JobEvent as J, type RoutingConfig as K, type RoutingStrategy as L, type Model as M, type SpendAuth as N, type Operator as O, type PricingTier as P, type SpendingLimits as Q, type RotatingClientConfig as R, type ShieldedConfig as S, TCloudClient as T, TCloudError as U, type TierConfig as V, type TranscriptionResponse as W, type UpdateKeyOptions as X, type VideoGenerateOptions as Y, type VideoResponse as Z, type WatchJobOptions as _, type TCloudConfig as a, type AvatarGenerateRequest as b, type AvatarGenerateResponse as c, type AvatarJobStatus as d, type AvatarResult as e, type BatchRequest as f, type BridgeOptions as g, BridgeSession as h, type ChatCompletionChunk as i, type ChatMessage as j, type ChatOptions as k, type CompletionOptions as l, type CompletionResponse as m, type CreateKeyOptions as n, type CreatedKey as o, type CreditBalance as p, type EmbeddingResponse as q, type FineTuningJobOptions as r, type ImageResponse as s, type OperatorInfo as t, type PrivacyConfig as u, PrivateRouter as v, type PrivateRouterConfig as w, type RerankOptions as x, type RerankResponse as y, type RetryConfig as z };
1289
+ export { type VideoGenerateOptions as $, type ApiKeyInfo as A, type BatchJobResponse as B, type ChatCompletion as C, type RerankResponse as D, type EmbeddingOptions as E, type FineTuningJob as F, type GatewayOptions as G, type RetryConfig as H, type ImageEditAttachment as I, type JobEvent as J, type RotatingRoutingConfig as K, type RotationStats as L, type Model as M, type RoutingConfig as N, type Operator as O, type PricingTier as P, type RoutingStrategy as Q, type RotatingClientConfig as R, type SandboxChatOptions as S, TCloudClient as T, type ShieldedConfig as U, type SpendAuth as V, type SpendingLimits as W, TCloudError as X, type TierConfig as Y, type TranscriptionResponse as Z, type UpdateKeyOptions as _, type TCloudConfig as a, type VideoResponse as a0, type WatchJobOptions as a1, type AvatarGenerateRequest as b, type AvatarGenerateResponse as c, type AvatarJobStatus as d, type AvatarResult as e, type BatchRequest as f, type BridgeOptions as g, BridgeSession as h, type ChatCompletionChunk as i, type ChatMessage as j, type ChatOptions as k, type CompletionOptions as l, type CompletionResponse as m, type CreateKeyOptions as n, type CreatedKey as o, type CreditBalance as p, type EmbeddingResponse as q, type FineTuningJobOptions as r, type ImageEditOptions as s, type ImageGenerateOptions as t, type ImageResponse as u, type OperatorInfo as v, type PrivacyConfig as w, PrivateRouter as x, type PrivateRouterConfig as y, type RerankOptions as z };
@@ -1,4 +1,7 @@
1
+ import { AgentProfile } from '@tangle-network/sandbox';
2
+
1
3
  /** Core types for the tcloud SDK */
4
+
2
5
  interface TCloudConfig {
3
6
  /** API base URL (default: https://router.tangle.tools/v1) */
4
7
  baseURL?: string;
@@ -94,6 +97,39 @@ interface ImageGenerateOptions {
94
97
  quality?: string;
95
98
  response_format?: 'url' | 'b64_json';
96
99
  }
100
+ /**
101
+ * OpenAI-compatible /v1/images/edits request. Accepts one or more
102
+ * reference images + a prompt describing how to transform them.
103
+ *
104
+ * For gpt-image-2, the supplied images are passed as `image[]` (the
105
+ * model supports multi-image composition); for dall-e-2 only a single
106
+ * image is honored. The optional `mask` is the OpenAI inpainting mask
107
+ * (PNG with alpha) used to constrain where edits are applied.
108
+ *
109
+ * Carrying both shapes here lets callers point at the same `imagesEdit`
110
+ * method regardless of upstream model; cli-bridge / tangle-router
111
+ * decide what to forward.
112
+ */
113
+ interface ImageEditOptions {
114
+ model?: string;
115
+ prompt: string;
116
+ /** One or more reference images. Pass as Blob (browser/Node 22+),
117
+ * ArrayBuffer (will be wrapped in a Blob), or `{data, mediaType}`
118
+ * for base64 + explicit mime. The first form is preferred. */
119
+ image: ImageEditAttachment | ImageEditAttachment[];
120
+ /** Optional inpainting mask — PNG with transparent pixels marking
121
+ * the editable region (OpenAI dall-e-2 / gpt-image-2 inpaint mode). */
122
+ mask?: ImageEditAttachment;
123
+ n?: number;
124
+ size?: string;
125
+ quality?: string;
126
+ response_format?: 'url' | 'b64_json';
127
+ }
128
+ type ImageEditAttachment = Blob | ArrayBuffer | {
129
+ data: string /** base64 */;
130
+ mediaType: string;
131
+ filename?: string;
132
+ };
97
133
  interface ImageResponse {
98
134
  created: number;
99
135
  data: {
@@ -189,9 +225,18 @@ interface BatchJobResponse {
189
225
  }
190
226
  interface VideoGenerateOptions {
191
227
  model?: string;
228
+ provider?: string | Record<string, unknown>;
192
229
  prompt: string;
193
230
  duration?: number;
194
231
  resolution?: string;
232
+ aspect_ratio?: string;
233
+ size?: string;
234
+ image_url?: string;
235
+ frame_images?: Array<Record<string, unknown>>;
236
+ input_references?: Array<Record<string, unknown>>;
237
+ generate_audio?: boolean;
238
+ seed?: number;
239
+ callback_url?: string;
195
240
  }
196
241
  interface VideoResponse {
197
242
  id: string;
@@ -338,8 +383,8 @@ interface BridgeOptions {
338
383
  harness: 'claude-code' | 'claudish' | 'codex' | 'opencode' | 'kimi-code' | 'sandbox' | 'openai' | 'anthropic' | 'moonshot' | 'zai';
339
384
  /** Model id inside the harness (e.g. `sonnet`, `kimi-for-coding`, `gpt-5-codex`). Omit for harness default. */
340
385
  model?: string;
341
- /** Router-issued unlock token. Required unless operator has disabled the gate. */
342
- unlock: string;
386
+ /** Router-issued unlock token. Required for router-mediated bridge calls; unused by direct cli-bridge clients. */
387
+ unlock?: string;
343
388
  /** Stable caller-owned id for session resume. Map one id per logical conversation. */
344
389
  resume?: string;
345
390
  /** BYOB: point at your own cli-bridge instance. Router must have BYOB enabled. */
@@ -347,6 +392,12 @@ interface BridgeOptions {
347
392
  /** BYOB: bearer your cli-bridge expects. */
348
393
  bridgeBearer?: string;
349
394
  }
395
+ interface SandboxChatOptions {
396
+ /** Inline sandbox AgentProfile. Serialized as cli-bridge/sandbox-api `agent_profile`. */
397
+ agentProfile?: AgentProfile;
398
+ /** Direct sandbox or cli-bridge session id. Serialized as `session_id`. */
399
+ sessionId?: string;
400
+ }
350
401
  interface ChatOptions {
351
402
  /** Model to use */
352
403
  model?: string;
@@ -386,10 +437,15 @@ interface ChatOptions {
386
437
  gateway?: GatewayOptions;
387
438
  /**
388
439
  * Provider-specific parameters passed through to the upstream API.
389
- * These are spread into the request body alongside standard fields.
440
+ * Protected OpenAI/Tangle fields cannot be overridden from this escape hatch.
390
441
  * Example: `{ thinking: { type: 'enabled', budget_tokens: 8000 } }`
391
442
  */
392
443
  providerOptions?: Record<string, unknown>;
444
+ /**
445
+ * Typed sandbox/cli-bridge extensions. Use this instead of smuggling
446
+ * `agent_profile` or `session_id` through providerOptions.
447
+ */
448
+ sandbox?: SandboxChatOptions;
393
449
  /**
394
450
  * Route this call through the Tangle Router's cli-bridge short-circuit.
395
451
  * See {@link BridgeOptions}. When set, `model` is rewritten to
@@ -696,9 +752,10 @@ declare class TCloudClient {
696
752
  * const reply = await client.ask('explain X', 'claude-code/sonnet')
697
753
  * ```
698
754
  *
699
- * For session-resumable agentic dispatches (file edits, multi-turn
700
- * coding), use the router-mediated `tcloud.bridge({...})` API instead
701
- * (or POST to cli-bridge directly with `session_id` in the body).
755
+ * For session-resumable agentic dispatches, use `client.bridge(...)` on
756
+ * the returned direct client. `resume` is serialized to cli-bridge's
757
+ * `session_id` body field and the model wire format stays
758
+ * `<harness>/<model>` without the router-only `bridge/` prefix.
702
759
  */
703
760
  static fromCliBridge(opts: {
704
761
  /** cli-bridge base URL — `http://127.0.0.1:3344` for default local; can be any reachable URL. */
@@ -718,7 +775,7 @@ declare class TCloudClient {
718
775
  *
719
776
  * ```ts
720
777
  * const tcloud = TCloudClient.rotating({
721
- * apiKey: process.env.TCLOUD_API_KEY,
778
+ * apiKey: process.env.TANGLE_API_KEY,
722
779
  * routing: { strategy: 'min-exposure' },
723
780
  * })
724
781
  * await tcloud.ask('hello')
@@ -816,6 +873,7 @@ declare class TCloudClient {
816
873
  * a rotating client throws.
817
874
  */
818
875
  bridge(cfg: BridgeOptions): BridgeSession;
876
+ private _isDirectCliBridge;
819
877
  /**
820
878
  * Rotation stats — populated only on clients created via
821
879
  * {@link TCloudClient.rotating}. Non-rotating clients return an empty
@@ -897,6 +955,18 @@ declare class TCloudClient {
897
955
  embeddings(options: EmbeddingOptions): Promise<EmbeddingResponse>;
898
956
  /** Generate images */
899
957
  imageGenerate(options: ImageGenerateOptions): Promise<ImageResponse>;
958
+ /**
959
+ * Edit / inpaint / variate an existing image with a text prompt.
960
+ * Sibling to `imageGenerate`; routes to `/v1/images/edits` via
961
+ * multipart/form-data per the OpenAI spec.
962
+ *
963
+ * Reference image attachments may be passed as `Blob`, `ArrayBuffer`,
964
+ * or `{data: base64, mediaType, filename?}`. Multi-image composition
965
+ * (e.g. gpt-image-2 with two reference frames + a prompt that fuses
966
+ * them) is supported by passing an array; for legacy models only the
967
+ * first image is honored upstream.
968
+ */
969
+ imagesEdit(options: ImageEditOptions): Promise<ImageResponse>;
900
970
  /** Rerank documents by relevance to a query */
901
971
  rerank(options: RerankOptions): Promise<RerankResponse>;
902
972
  /** Text-to-speech */
@@ -1167,7 +1237,8 @@ declare class TCloudClient {
1167
1237
  declare class BridgeSession {
1168
1238
  private readonly client;
1169
1239
  private readonly cfg;
1170
- constructor(client: TCloudClient, cfg: BridgeOptions);
1240
+ private readonly direct;
1241
+ constructor(client: TCloudClient, cfg: BridgeOptions, direct?: boolean);
1171
1242
  /** Full chat completion (non-streaming). */
1172
1243
  chat(options: Omit<ChatOptions, 'bridge'>): Promise<ChatCompletion>;
1173
1244
  /** Stream OpenAI chat.completion.chunks. */
@@ -1215,4 +1286,4 @@ declare class TCloudError extends Error {
1215
1286
  constructor(status: number, message: string);
1216
1287
  }
1217
1288
 
1218
- export { type ApiKeyInfo as A, type BatchJobResponse as B, type ChatCompletion as C, type RotatingRoutingConfig as D, type EmbeddingOptions as E, type FineTuningJob as F, type GatewayOptions as G, type RotationStats as H, type ImageGenerateOptions as I, type JobEvent as J, type RoutingConfig as K, type RoutingStrategy as L, type Model as M, type SpendAuth as N, type Operator as O, type PricingTier as P, type SpendingLimits as Q, type RotatingClientConfig as R, type ShieldedConfig as S, TCloudClient as T, TCloudError as U, type TierConfig as V, type TranscriptionResponse as W, type UpdateKeyOptions as X, type VideoGenerateOptions as Y, type VideoResponse as Z, type WatchJobOptions as _, type TCloudConfig as a, type AvatarGenerateRequest as b, type AvatarGenerateResponse as c, type AvatarJobStatus as d, type AvatarResult as e, type BatchRequest as f, type BridgeOptions as g, BridgeSession as h, type ChatCompletionChunk as i, type ChatMessage as j, type ChatOptions as k, type CompletionOptions as l, type CompletionResponse as m, type CreateKeyOptions as n, type CreatedKey as o, type CreditBalance as p, type EmbeddingResponse as q, type FineTuningJobOptions as r, type ImageResponse as s, type OperatorInfo as t, type PrivacyConfig as u, PrivateRouter as v, type PrivateRouterConfig as w, type RerankOptions as x, type RerankResponse as y, type RetryConfig as z };
1289
+ export { type VideoGenerateOptions as $, type ApiKeyInfo as A, type BatchJobResponse as B, type ChatCompletion as C, type RerankResponse as D, type EmbeddingOptions as E, type FineTuningJob as F, type GatewayOptions as G, type RetryConfig as H, type ImageEditAttachment as I, type JobEvent as J, type RotatingRoutingConfig as K, type RotationStats as L, type Model as M, type RoutingConfig as N, type Operator as O, type PricingTier as P, type RoutingStrategy as Q, type RotatingClientConfig as R, type SandboxChatOptions as S, TCloudClient as T, type ShieldedConfig as U, type SpendAuth as V, type SpendingLimits as W, TCloudError as X, type TierConfig as Y, type TranscriptionResponse as Z, type UpdateKeyOptions as _, type TCloudConfig as a, type VideoResponse as a0, type WatchJobOptions as a1, type AvatarGenerateRequest as b, type AvatarGenerateResponse as c, type AvatarJobStatus as d, type AvatarResult as e, type BatchRequest as f, type BridgeOptions as g, BridgeSession as h, type ChatCompletionChunk as i, type ChatMessage as j, type ChatOptions as k, type CompletionOptions as l, type CompletionResponse as m, type CreateKeyOptions as n, type CreatedKey as o, type CreditBalance as p, type EmbeddingResponse as q, type FineTuningJobOptions as r, type ImageEditOptions as s, type ImageGenerateOptions as t, type ImageResponse as u, type OperatorInfo as v, type PrivacyConfig as w, PrivateRouter as x, type PrivateRouterConfig as y, type RerankOptions as z };