@aithos/sdk 0.1.0-alpha.17 → 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.
- package/dist/src/compute.d.ts +50 -0
- package/dist/src/compute.js +61 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
package/dist/src/compute.d.ts
CHANGED
|
@@ -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
|
package/dist/src/compute.js
CHANGED
|
@@ -138,6 +138,52 @@ export class ComputeNamespace {
|
|
|
138
138
|
signal: args.signal,
|
|
139
139
|
});
|
|
140
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
|
+
}
|
|
141
187
|
/**
|
|
142
188
|
* Resolve the active signer (owner takes precedence over delegate).
|
|
143
189
|
*
|
|
@@ -267,4 +313,19 @@ function generateIdempotencyKey() {
|
|
|
267
313
|
}
|
|
268
314
|
return hex;
|
|
269
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
|
+
}
|
|
270
331
|
//# sourceMappingURL=compute.js.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.0-alpha.
|
|
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.
|
|
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.
|
|
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",
|