@aithos/sdk 0.1.0-alpha.16 → 0.1.0-alpha.18

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.
@@ -64,7 +64,7 @@ export interface InvokeBedrockResult {
64
64
  * to disambiguate text and image dispatch when a mandate's
65
65
  * `allowed_models` mixes both.
66
66
  */
67
- export type ImageModelId = "image:flux-schnell" | "image:flux-dev" | "image:flux-pro-1.1" | "image:flux-pro-1.1-ultra";
67
+ export type ImageModelId = "image:flux-schnell" | "image:flux-dev" | "image:flux-pro-1.1" | "image:flux-pro-1.1-ultra" | "image:imagen-3" | "image:imagen-4" | "image:nano-banana";
68
68
  /** Aspect ratios accepted by `invokeImage`. */
69
69
  export type ImageAspectRatio = "1:1" | "16:9" | "9:16" | "4:3" | "3:4" | "21:9";
70
70
  export interface InvokeImageArgs {
@@ -118,6 +118,43 @@ export interface InvokeImageResult {
118
118
  /** Audit log id for traceability. */
119
119
  readonly auditId: string;
120
120
  }
121
+ export interface InvokeSegmentationArgs {
122
+ /** Mandate id (optional for owner sessions — see InvokeImageArgs). */
123
+ readonly mandateId?: string;
124
+ /** Source image. Blob (recommended) or raw base64. */
125
+ readonly image: Blob | {
126
+ readonly base64: string;
127
+ readonly contentType: string;
128
+ };
129
+ /**
130
+ * Text phrase describing what to segment. Florence-2 is robust with
131
+ * natural-language descriptions: "the torso of the robot", "the
132
+ * dog's head", "the chest of the character".
133
+ */
134
+ readonly textInput: string;
135
+ readonly idempotencyKey?: string;
136
+ readonly signal?: AbortSignal;
137
+ }
138
+ export interface SegmentPolygon {
139
+ readonly points: ReadonlyArray<{
140
+ readonly x: number;
141
+ readonly y: number;
142
+ }>;
143
+ }
144
+ export interface InvokeSegmentationResult {
145
+ /** All polygons Florence-2 returned (typically 1, sometimes a few when the prompt matches multiple regions). */
146
+ readonly polygons: readonly SegmentPolygon[];
147
+ /** Bbox of the first polygon for callers that only need a coarse target. */
148
+ readonly bbox: {
149
+ readonly left: number;
150
+ readonly top: number;
151
+ readonly right: number;
152
+ readonly bottom: number;
153
+ } | null;
154
+ readonly creditsCharged: number;
155
+ readonly walletBalance: number;
156
+ readonly auditId: string;
157
+ }
121
158
  export interface ComputeNamespaceDeps {
122
159
  readonly auth: AithosAuth;
123
160
  readonly appDid: string;
@@ -182,5 +219,18 @@ export declare class ComputeNamespace {
182
219
  * - flux-pro-1.1-ultra: 60 000 mc + fee per image
183
220
  */
184
221
  invokeImage(args: InvokeImageArgs): Promise<InvokeImageResult>;
222
+ /**
223
+ * Run text-prompted segmentation (Florence-2 referring-expression)
224
+ * on a source image. Returns one or more polygons hugging the
225
+ * region matching the text prompt.
226
+ *
227
+ * Use cases: locate the chest/torso area of a generated mascot
228
+ * for logo compositing, find the face zone for a thumbnail crop,
229
+ * extract a product from a marketing shot — anything that needs
230
+ * a precise mask + bbox from natural-language description.
231
+ *
232
+ * Pricing: flat 5 000 mc per call (~$0.005 — Florence-2 is cheap).
233
+ */
234
+ invokeSegmentation(args: InvokeSegmentationArgs): Promise<InvokeSegmentationResult>;
185
235
  }
186
236
  //# sourceMappingURL=compute.d.ts.map
@@ -110,7 +110,10 @@ export class ComputeNamespace {
110
110
  const choice = this.#resolveSigner(args.mandateId);
111
111
  const url = computeInvokeUrl(endpoints);
112
112
  const idempotencyKey = args.idempotencyKey ?? generateIdempotencyKey();
113
- const model = args.model ?? "image:flux-pro-1.1";
113
+ // Default is Imagen 4 since alpha.17 flat-illustration style is
114
+ // the right match for brand-mascot use cases. FLUX Pro 1.1 remains
115
+ // available via explicit `model: "image:flux-pro-1.1"`.
116
+ const model = args.model ?? "image:imagen-4";
114
117
  const params = {
115
118
  app_did: this.#deps.appDid,
116
119
  mandate_id: this.#resolveMandateIdForWire(args.mandateId, choice),
@@ -135,6 +138,52 @@ export class ComputeNamespace {
135
138
  signal: args.signal,
136
139
  });
137
140
  }
141
+ /**
142
+ * Run text-prompted segmentation (Florence-2 referring-expression)
143
+ * on a source image. Returns one or more polygons hugging the
144
+ * region matching the text prompt.
145
+ *
146
+ * Use cases: locate the chest/torso area of a generated mascot
147
+ * for logo compositing, find the face zone for a thumbnail crop,
148
+ * extract a product from a marketing shot — anything that needs
149
+ * a precise mask + bbox from natural-language description.
150
+ *
151
+ * Pricing: flat 5 000 mc per call (~$0.005 — Florence-2 is cheap).
152
+ */
153
+ async invokeSegmentation(args) {
154
+ const { endpoints, fetch: fetchImpl } = this.#deps;
155
+ const choice = this.#resolveSigner(args.mandateId);
156
+ // Normalize image input to base64 + content type.
157
+ let imageBase64;
158
+ let imageContentType;
159
+ if ("base64" in args.image) {
160
+ imageBase64 = args.image.base64;
161
+ imageContentType = args.image.contentType;
162
+ }
163
+ else {
164
+ const buf = await args.image.arrayBuffer();
165
+ imageBase64 = arrayBufferToBase64(buf);
166
+ imageContentType = args.image.type || "image/png";
167
+ }
168
+ const url = computeInvokeUrl(endpoints);
169
+ const idempotencyKey = args.idempotencyKey ?? generateIdempotencyKey();
170
+ const params = {
171
+ app_did: this.#deps.appDid,
172
+ mandate_id: this.#resolveMandateIdForWire(args.mandateId, choice),
173
+ image_base64: imageBase64,
174
+ image_content_type: imageContentType,
175
+ text_input: args.textInput,
176
+ idempotency_key: idempotencyKey,
177
+ };
178
+ return await this.#signAndPost({
179
+ url,
180
+ method: "aithos.compute_invoke_segmentation",
181
+ params,
182
+ choice,
183
+ fetchImpl,
184
+ signal: args.signal,
185
+ });
186
+ }
138
187
  /**
139
188
  * Resolve the active signer (owner takes precedence over delegate).
140
189
  *
@@ -264,4 +313,19 @@ function generateIdempotencyKey() {
264
313
  }
265
314
  return hex;
266
315
  }
316
+ /**
317
+ * Encode an ArrayBuffer as base64 in environments where `Buffer` is
318
+ * not available (browser). Uses btoa over a binary string — safe for
319
+ * the small payload sizes the SDK deals with (≤ a few MB).
320
+ */
321
+ function arrayBufferToBase64(buf) {
322
+ const bytes = new Uint8Array(buf);
323
+ let bin = "";
324
+ // Process in chunks to avoid stack overflow on String.fromCharCode.apply
325
+ const CHUNK = 0x8000;
326
+ for (let i = 0; i < bytes.length; i += CHUNK) {
327
+ bin += String.fromCharCode.apply(null, Array.from(bytes.subarray(i, i + CHUNK)));
328
+ }
329
+ return btoa(bin);
330
+ }
267
331
  //# sourceMappingURL=compute.js.map
@@ -1,11 +1,11 @@
1
- export declare const VERSION = "0.1.0-alpha.16";
1
+ export declare const VERSION = "0.1.0-alpha.18";
2
2
  export { AithosSDK } from "./sdk.js";
3
3
  export type { AithosSDKConfig } from "./types.js";
4
4
  export { AithosSDKError } from "./types.js";
5
5
  export { AithosRpcError } from "@aithos/protocol-client";
6
6
  export type { AithosSdkEndpoints } from "./endpoints.js";
7
7
  export { DEFAULT_SDK_ENDPOINTS } from "./endpoints.js";
8
- export type { ComputeMessage, ImageAspectRatio, ImageModelId, InvokeBedrockArgs, InvokeBedrockResult, InvokeImageArgs, InvokeImageImage, InvokeImageResult, StopReason, } from "./compute.js";
8
+ export type { ComputeMessage, ImageAspectRatio, ImageModelId, InvokeBedrockArgs, InvokeBedrockResult, InvokeImageArgs, InvokeImageImage, InvokeImageResult, InvokeSegmentationArgs, InvokeSegmentationResult, SegmentPolygon, StopReason, } from "./compute.js";
9
9
  export { ComputeNamespace } from "./compute.js";
10
10
  export type { CreditPackId, CreateTopupSessionArgs, CreateTopupSessionResult, GetBalanceArgs, GetBalanceResult, } from "./wallet.js";
11
11
  export { WalletNamespace } from "./wallet.js";
package/dist/src/index.js CHANGED
@@ -17,7 +17,7 @@
17
17
  // Public types specific to the SDK (`AithosSDKConfig`, `AithosSDKError`)
18
18
  // are exported from here. Endpoint config (`AithosSdkEndpoints`,
19
19
  // `DEFAULT_SDK_ENDPOINTS`) likewise.
20
- export const VERSION = "0.1.0-alpha.16";
20
+ export const VERSION = "0.1.0-alpha.18";
21
21
  export { AithosSDK } from "./sdk.js";
22
22
  export { AithosSDKError } from "./types.js";
23
23
  // Re-export protocol-client's JSON-RPC error type so consumers can
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aithos/sdk",
3
- "version": "0.1.0-alpha.16",
3
+ "version": "0.1.0-alpha.18",
4
4
  "description": "Aithos SDK — high-level TypeScript developer kit for building agentic apps on the Aithos protocol. Wraps @aithos/protocol-client and exposes the Aithos compute proxy and wallet (Stripe top-up) endpoints.",
5
5
  "keywords": [
6
6
  "aithos",