@framers/agentos 0.1.164 → 0.1.166
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/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/types.d.ts +71 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/types.js.map +1 -1
- package/dist/core/llm/routing/UncensoredModelCatalog.d.ts.map +1 -1
- package/dist/core/llm/routing/UncensoredModelCatalog.js +19 -1
- package/dist/core/llm/routing/UncensoredModelCatalog.js.map +1 -1
- package/dist/media/avatar/AvatarPipeline.d.ts +56 -0
- package/dist/media/avatar/AvatarPipeline.d.ts.map +1 -0
- package/dist/media/avatar/AvatarPipeline.js +308 -0
- package/dist/media/avatar/AvatarPipeline.js.map +1 -0
- package/dist/media/avatar/index.d.ts +8 -0
- package/dist/media/avatar/index.d.ts.map +1 -0
- package/dist/media/avatar/index.js +7 -0
- package/dist/media/avatar/index.js.map +1 -0
- package/dist/media/avatar/prompts.d.ts +48 -0
- package/dist/media/avatar/prompts.d.ts.map +1 -0
- package/dist/media/avatar/prompts.js +88 -0
- package/dist/media/avatar/prompts.js.map +1 -0
- package/dist/media/avatar/types.d.ts +101 -0
- package/dist/media/avatar/types.d.ts.map +1 -0
- package/dist/media/avatar/types.js +8 -0
- package/dist/media/avatar/types.js.map +1 -0
- package/dist/media/images/face/IFaceEmbeddingService.d.ts +69 -0
- package/dist/media/images/face/IFaceEmbeddingService.d.ts.map +1 -0
- package/dist/media/images/face/IFaceEmbeddingService.js +40 -0
- package/dist/media/images/face/IFaceEmbeddingService.js.map +1 -0
- package/dist/media/images/face/ReplicateFaceEmbeddingService.d.ts +57 -0
- package/dist/media/images/face/ReplicateFaceEmbeddingService.d.ts.map +1 -0
- package/dist/media/images/face/ReplicateFaceEmbeddingService.js +151 -0
- package/dist/media/images/face/ReplicateFaceEmbeddingService.js.map +1 -0
- package/dist/media/images/face/index.d.ts +7 -0
- package/dist/media/images/face/index.d.ts.map +1 -0
- package/dist/media/images/face/index.js +7 -0
- package/dist/media/images/face/index.js.map +1 -0
- package/dist/media/images/index.d.ts +1 -0
- package/dist/media/images/index.d.ts.map +1 -1
- package/dist/media/images/index.js +1 -0
- package/dist/media/images/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AvatarPipeline.js","sourceRoot":"","sources":["../../../src/media/avatar/AvatarPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAWpC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AA4B7G,8EAA8E;AAC9E,qBAAqB;AACrB,8EAA8E;AAE9E,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAC5C,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAErC,MAAM,UAAU,GAA4B;IAC1C,kBAAkB;IAClB,gBAAgB;IAChB,kBAAkB;IAClB,iBAAiB;IACjB,WAAW;CACZ,CAAC;AAEF,8EAA8E;AAC9E,WAAW;AACX,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAM,OAAO,cAAc;IAIzB;;;OAGG;IACH,YAAY,WAAkC,EAAE,aAA+B;QAC7E,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,CAAC,OAAgC;QAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC;QAC5C,MAAM,IAAI,GAA0B,EAAE,CAAC;QAEvC,MAAM,WAAW,GAA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line.js';
|
|
6
|
+
export type { AvatarGenerationStage, AvatarGenerationRequest, AvatarGenerationJob, DriftAuditReport, AvatarGenerationResult, } from './types.js';
|
|
7
|
+
export { AVATAR_EMOTIONS, type AvatarEmotion, buildPortraitPrompt, buildExpressionPrompt, buildEmotePrompt, } from './prompts.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/media/avatar/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,YAAY,EACV,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,eAAe,EACf,KAAK,aAAa,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* Barrel export for the avatar generation pipeline.
|
|
4
|
+
*/
|
|
5
|
+
export { AvatarPipeline } from './AvatarPipeline.js';
|
|
6
|
+
export { AVATAR_EMOTIONS, buildPortraitPrompt, buildExpressionPrompt, buildEmotePrompt, } from './prompts.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/media/avatar/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAyB,MAAM,qBAAqB,CAAC;AAU5E,OAAO,EACL,eAAe,EAEf,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file prompts.ts
|
|
3
|
+
* Prompt construction utilities for avatar image generation.
|
|
4
|
+
*
|
|
5
|
+
* Builds deterministic text prompts from {@link AvatarIdentityDescriptor}
|
|
6
|
+
* fields, producing consistent character depictions across emotion variants,
|
|
7
|
+
* emote animations, and full-body shots.
|
|
8
|
+
*/
|
|
9
|
+
import type { AvatarIdentityDescriptor } from '../../api/types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Canonical set of emotions for expression sheets and animated emotes.
|
|
12
|
+
* The first entry is always "neutral" — it doubles as the anchor portrait.
|
|
13
|
+
*/
|
|
14
|
+
export declare const AVATAR_EMOTIONS: readonly ["neutral", "happy", "sad", "angry", "surprised", "flirty", "fearful"];
|
|
15
|
+
/** Union type of supported avatar emotions. */
|
|
16
|
+
export type AvatarEmotion = (typeof AVATAR_EMOTIONS)[number];
|
|
17
|
+
/**
|
|
18
|
+
* Concatenate all identity descriptor fields into a portrait prompt.
|
|
19
|
+
*
|
|
20
|
+
* Produces a detailed, comma-separated description suitable for
|
|
21
|
+
* text-to-image models. Omits undefined optional fields.
|
|
22
|
+
*
|
|
23
|
+
* @param identity - Character identity descriptors.
|
|
24
|
+
* @returns Prompt string for a neutral portrait.
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildPortraitPrompt(identity: AvatarIdentityDescriptor): string;
|
|
27
|
+
/**
|
|
28
|
+
* Build a prompt for a specific emotion expression of the character.
|
|
29
|
+
*
|
|
30
|
+
* Appends the emotion keyword to the base portrait prompt so the model
|
|
31
|
+
* generates the same face with the requested expression.
|
|
32
|
+
*
|
|
33
|
+
* @param identity - Character identity descriptors.
|
|
34
|
+
* @param emotion - Target emotion expression.
|
|
35
|
+
* @returns Prompt string for an emotion-specific portrait.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildExpressionPrompt(identity: AvatarIdentityDescriptor, emotion: AvatarEmotion | string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Build a prompt for an animated emote loop of a given emotion.
|
|
40
|
+
*
|
|
41
|
+
* Produces a concise prompt targeting short animation generation models
|
|
42
|
+
* (e.g. Stable Video Diffusion, AnimateDiff).
|
|
43
|
+
*
|
|
44
|
+
* @param emotion - The emotion to animate.
|
|
45
|
+
* @returns Prompt string for an animated emote.
|
|
46
|
+
*/
|
|
47
|
+
export declare function buildEmotePrompt(emotion: AvatarEmotion | string): string;
|
|
48
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/media/avatar/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAMnE;;;GAGG;AACH,eAAO,MAAM,eAAe,iFAQlB,CAAC;AAEX,+CAA+C;AAC/C,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAM7D;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,wBAAwB,GAAG,MAAM,CA6B9E;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,wBAAwB,EAClC,OAAO,EAAE,aAAa,GAAG,MAAM,GAC9B,MAAM,CAMR;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,MAAM,CAExE"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file prompts.ts
|
|
3
|
+
* Prompt construction utilities for avatar image generation.
|
|
4
|
+
*
|
|
5
|
+
* Builds deterministic text prompts from {@link AvatarIdentityDescriptor}
|
|
6
|
+
* fields, producing consistent character depictions across emotion variants,
|
|
7
|
+
* emote animations, and full-body shots.
|
|
8
|
+
*/
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Emotion catalogue
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
/**
|
|
13
|
+
* Canonical set of emotions for expression sheets and animated emotes.
|
|
14
|
+
* The first entry is always "neutral" — it doubles as the anchor portrait.
|
|
15
|
+
*/
|
|
16
|
+
export const AVATAR_EMOTIONS = [
|
|
17
|
+
'neutral',
|
|
18
|
+
'happy',
|
|
19
|
+
'sad',
|
|
20
|
+
'angry',
|
|
21
|
+
'surprised',
|
|
22
|
+
'flirty',
|
|
23
|
+
'fearful',
|
|
24
|
+
];
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Prompt builders
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
/**
|
|
29
|
+
* Concatenate all identity descriptor fields into a portrait prompt.
|
|
30
|
+
*
|
|
31
|
+
* Produces a detailed, comma-separated description suitable for
|
|
32
|
+
* text-to-image models. Omits undefined optional fields.
|
|
33
|
+
*
|
|
34
|
+
* @param identity - Character identity descriptors.
|
|
35
|
+
* @returns Prompt string for a neutral portrait.
|
|
36
|
+
*/
|
|
37
|
+
export function buildPortraitPrompt(identity) {
|
|
38
|
+
const parts = [];
|
|
39
|
+
parts.push(`portrait of ${identity.displayName}`);
|
|
40
|
+
parts.push(`${identity.ageBand.replace(/_/g, ' ')} age`);
|
|
41
|
+
if (identity.bodyType) {
|
|
42
|
+
parts.push(`${identity.bodyType} build`);
|
|
43
|
+
}
|
|
44
|
+
parts.push(identity.faceDescriptor);
|
|
45
|
+
if (identity.hairDescriptor) {
|
|
46
|
+
parts.push(identity.hairDescriptor);
|
|
47
|
+
}
|
|
48
|
+
if (identity.skinDescriptor) {
|
|
49
|
+
parts.push(identity.skinDescriptor);
|
|
50
|
+
}
|
|
51
|
+
if (identity.distinguishingFeatures) {
|
|
52
|
+
parts.push(identity.distinguishingFeatures);
|
|
53
|
+
}
|
|
54
|
+
if (identity.styleNotes) {
|
|
55
|
+
parts.push(identity.styleNotes);
|
|
56
|
+
}
|
|
57
|
+
return parts.join(', ');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build a prompt for a specific emotion expression of the character.
|
|
61
|
+
*
|
|
62
|
+
* Appends the emotion keyword to the base portrait prompt so the model
|
|
63
|
+
* generates the same face with the requested expression.
|
|
64
|
+
*
|
|
65
|
+
* @param identity - Character identity descriptors.
|
|
66
|
+
* @param emotion - Target emotion expression.
|
|
67
|
+
* @returns Prompt string for an emotion-specific portrait.
|
|
68
|
+
*/
|
|
69
|
+
export function buildExpressionPrompt(identity, emotion) {
|
|
70
|
+
const base = buildPortraitPrompt(identity);
|
|
71
|
+
if (emotion === 'neutral') {
|
|
72
|
+
return base;
|
|
73
|
+
}
|
|
74
|
+
return `${base}, ${emotion} expression`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Build a prompt for an animated emote loop of a given emotion.
|
|
78
|
+
*
|
|
79
|
+
* Produces a concise prompt targeting short animation generation models
|
|
80
|
+
* (e.g. Stable Video Diffusion, AnimateDiff).
|
|
81
|
+
*
|
|
82
|
+
* @param emotion - The emotion to animate.
|
|
83
|
+
* @returns Prompt string for an animated emote.
|
|
84
|
+
*/
|
|
85
|
+
export function buildEmotePrompt(emotion) {
|
|
86
|
+
return `animated emote loop, ${emotion} expression, character portrait, seamless loop`;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/media/avatar/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,SAAS;IACT,OAAO;IACP,KAAK;IACL,OAAO;IACP,WAAW;IACX,QAAQ;IACR,SAAS;CACD,CAAC;AAKX,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAkC;IACpE,MAAM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GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA+B;IAC9D,OAAO,wBAAwB,OAAO,gDAAgD,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file types.ts
|
|
3
|
+
* Type definitions for the avatar generation pipeline.
|
|
4
|
+
*
|
|
5
|
+
* Covers the full lifecycle: request → staged jobs → drift audit → result.
|
|
6
|
+
*/
|
|
7
|
+
import type { AvatarIdentityDescriptor, AvatarIdentityPackage } from '../../api/types.js';
|
|
8
|
+
import type { PolicyTier } from '../../core/llm/routing/UncensoredModelCatalog.js';
|
|
9
|
+
/**
|
|
10
|
+
* Discrete stages of the avatar generation pipeline, executed in order.
|
|
11
|
+
*
|
|
12
|
+
* - `neutral_portrait` — Generate the canonical neutral-expression portrait.
|
|
13
|
+
* - `face_embedding` — Extract a 512-dim face vector from the neutral portrait.
|
|
14
|
+
* - `expression_sheet` — Generate emotion variants and drift-check each one.
|
|
15
|
+
* - `animated_emotes` — Generate animated emote loops per emotion.
|
|
16
|
+
* - `full_body` — Generate a full-body reference image.
|
|
17
|
+
* - `additional_angles` — Generate extra viewpoint references (3/4, profile).
|
|
18
|
+
*/
|
|
19
|
+
export type AvatarGenerationStage = 'neutral_portrait' | 'face_embedding' | 'expression_sheet' | 'animated_emotes' | 'full_body' | 'additional_angles';
|
|
20
|
+
/** Input to the avatar generation pipeline. */
|
|
21
|
+
export interface AvatarGenerationRequest {
|
|
22
|
+
/** Character identifier for the generated identity package. */
|
|
23
|
+
characterId: string;
|
|
24
|
+
/** Identity descriptors driving image generation prompts. */
|
|
25
|
+
identity: AvatarIdentityDescriptor;
|
|
26
|
+
/** Which stages to execute (defaults to all). */
|
|
27
|
+
stages?: AvatarGenerationStage[];
|
|
28
|
+
/** Content policy tier forwarded to the image generator. */
|
|
29
|
+
policyTier?: PolicyTier;
|
|
30
|
+
/** Image generation parameters. */
|
|
31
|
+
generationConfig: {
|
|
32
|
+
/** Model identifier (e.g. "black-forest-labs/flux-schnell"). */
|
|
33
|
+
baseModel: string;
|
|
34
|
+
/** Provider identifier (e.g. "replicate"). */
|
|
35
|
+
provider: string;
|
|
36
|
+
/** Random seed for reproducible output. */
|
|
37
|
+
seed?: number;
|
|
38
|
+
/** Negative prompt to avoid unwanted artefacts. */
|
|
39
|
+
negativePrompt?: string;
|
|
40
|
+
/** Named style preset (provider-specific). */
|
|
41
|
+
stylePreset?: string;
|
|
42
|
+
};
|
|
43
|
+
/** Drift-guard thresholds. */
|
|
44
|
+
driftGuard?: {
|
|
45
|
+
/** Minimum cosine similarity to the anchor face embedding. */
|
|
46
|
+
faceSimilarity?: number;
|
|
47
|
+
/** Reject images below the similarity threshold. */
|
|
48
|
+
rejectBelowThreshold?: boolean;
|
|
49
|
+
/** Maximum retries when generated face drifts. */
|
|
50
|
+
maxRegenerationAttempts?: number;
|
|
51
|
+
};
|
|
52
|
+
/** Pre-existing anchors to reuse instead of regenerating. */
|
|
53
|
+
existingAnchors?: {
|
|
54
|
+
neutralPortrait?: string;
|
|
55
|
+
faceEmbedding?: number[];
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Tracking record for a single pipeline job. */
|
|
59
|
+
export interface AvatarGenerationJob {
|
|
60
|
+
/** Which stage this job belongs to. */
|
|
61
|
+
stage: AvatarGenerationStage;
|
|
62
|
+
/** Human-readable label (e.g. "neutral_portrait", "expression:happy"). */
|
|
63
|
+
label: string;
|
|
64
|
+
/** Job status. */
|
|
65
|
+
status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped';
|
|
66
|
+
/** Generated image URL on success. */
|
|
67
|
+
imageUrl?: string;
|
|
68
|
+
/** Drift similarity score (for expression/emote stages). */
|
|
69
|
+
driftScore?: number;
|
|
70
|
+
/** Number of regeneration attempts for this job. */
|
|
71
|
+
attempts: number;
|
|
72
|
+
/** Error message on failure. */
|
|
73
|
+
error?: string;
|
|
74
|
+
/** Wall-clock duration in milliseconds. */
|
|
75
|
+
durationMs?: number;
|
|
76
|
+
}
|
|
77
|
+
/** Aggregate drift audit across all generated assets. */
|
|
78
|
+
export interface DriftAuditReport {
|
|
79
|
+
/** Anchor face embedding used as the reference. */
|
|
80
|
+
anchorEmbeddingDim: number;
|
|
81
|
+
/** Per-image drift scores keyed by label. */
|
|
82
|
+
scores: Record<string, number>;
|
|
83
|
+
/** Labels of images that were rejected for excessive drift. */
|
|
84
|
+
rejected: string[];
|
|
85
|
+
/** Labels of images that were regenerated (at least once). */
|
|
86
|
+
regenerated: string[];
|
|
87
|
+
/** Overall pass/fail for the entire batch. */
|
|
88
|
+
passed: boolean;
|
|
89
|
+
}
|
|
90
|
+
/** Output of a complete avatar generation pipeline run. */
|
|
91
|
+
export interface AvatarGenerationResult {
|
|
92
|
+
/** The assembled identity package. */
|
|
93
|
+
identityPackage: AvatarIdentityPackage;
|
|
94
|
+
/** Per-stage job records for observability. */
|
|
95
|
+
jobs: AvatarGenerationJob[];
|
|
96
|
+
/** Drift audit report (present when face_embedding stage ran). */
|
|
97
|
+
driftReport?: DriftAuditReport;
|
|
98
|
+
/** Total wall-clock time in milliseconds. */
|
|
99
|
+
totalDurationMs: number;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/media/avatar/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kDAAkD,CAAC;AAMnF;;;;;;;;;GASG;AACH,MAAM,MAAM,qBAAqB,GAC7B,kBAAkB,GAClB,gBAAgB,GAChB,kBAAkB,GAClB,iBAAiB,GACjB,WAAW,GACX,mBAAmB,CAAC;AAMxB,+CAA+C;AAC/C,MAAM,WAAW,uBAAuB;IACtC,+DAA+D;IAC/D,WA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AM,CAAC;IACf,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,yDAAyD;AACzD,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,8CAA8C;IAC9C,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,2DAA2D;AAC3D,MAAM,WAAW,sBAAsB;IACrC,sCAAsC;IACtC,eAAe,EAAE,qBAAqB,CAAC;IACvC,+CAA+C;IAC/C,IAAI,EAAE,mBAAmB,EAAE,CAAC;IAC5B,kEAAkE;IAClE,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,6CAA6C;IAC7C,eAAe,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/media/avatar/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file IFaceEmbeddingService.ts
|
|
3
|
+
* Interface for face embedding extraction and comparison services.
|
|
4
|
+
*
|
|
5
|
+
* Provides a provider-agnostic contract for extracting facial feature vectors
|
|
6
|
+
* from images and computing similarity between two face embeddings.
|
|
7
|
+
*/
|
|
8
|
+
/** Bounding box coordinates for a detected face within an image. */
|
|
9
|
+
export interface FaceBoundingBox {
|
|
10
|
+
/** X-coordinate of the top-left corner. */
|
|
11
|
+
x: number;
|
|
12
|
+
/** Y-coordinate of the top-left corner. */
|
|
13
|
+
y: number;
|
|
14
|
+
/** Width of the bounding box in pixels. */
|
|
15
|
+
width: number;
|
|
16
|
+
/** Height of the bounding box in pixels. */
|
|
17
|
+
height: number;
|
|
18
|
+
}
|
|
19
|
+
/** Face embedding vector with optional detection metadata. */
|
|
20
|
+
export interface FaceEmbedding {
|
|
21
|
+
/** High-dimensional vector representing facial features. */
|
|
22
|
+
vector: number[];
|
|
23
|
+
/** Bounding box of the detected face in the source image. */
|
|
24
|
+
boundingBox?: FaceBoundingBox;
|
|
25
|
+
/** Detection confidence score in [0, 1]. */
|
|
26
|
+
confidence?: number;
|
|
27
|
+
}
|
|
28
|
+
/** Result of comparing two face embeddings. */
|
|
29
|
+
export interface FaceComparisonResult {
|
|
30
|
+
/** Cosine similarity score in [-1, 1]. */
|
|
31
|
+
similarity: number;
|
|
32
|
+
/** Whether the two faces belong to the same identity (above threshold). */
|
|
33
|
+
match: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Provider-agnostic service for extracting face embeddings from images
|
|
37
|
+
* and comparing them for identity consistency.
|
|
38
|
+
*/
|
|
39
|
+
export interface IFaceEmbeddingService {
|
|
40
|
+
/**
|
|
41
|
+
* Extract a face embedding vector from an image URL or data URI.
|
|
42
|
+
*
|
|
43
|
+
* @param imageUrl - Public URL or base64 data URI of the image.
|
|
44
|
+
* @returns The extracted face embedding.
|
|
45
|
+
*/
|
|
46
|
+
extractEmbedding(imageUrl: string): Promise<FaceEmbedding>;
|
|
47
|
+
/**
|
|
48
|
+
* Compare two face embeddings and return a similarity score.
|
|
49
|
+
*
|
|
50
|
+
* @param a - First face embedding vector.
|
|
51
|
+
* @param b - Second face embedding vector.
|
|
52
|
+
* @param threshold - Minimum similarity to consider a match (default 0.6).
|
|
53
|
+
* @returns Comparison result with similarity and match flag.
|
|
54
|
+
*/
|
|
55
|
+
compareFaces(a: number[], b: number[], threshold?: number): FaceComparisonResult;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Compute the cosine similarity between two equal-length numeric vectors.
|
|
59
|
+
*
|
|
60
|
+
* Returns a value in [-1, 1] where 1 means identical direction, 0 means
|
|
61
|
+
* orthogonal, and -1 means opposite direction. Returns 0 for zero-magnitude
|
|
62
|
+
* vectors to avoid division-by-zero.
|
|
63
|
+
*
|
|
64
|
+
* @param a - First vector.
|
|
65
|
+
* @param b - Second vector.
|
|
66
|
+
* @returns Cosine similarity score.
|
|
67
|
+
*/
|
|
68
|
+
export declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
69
|
+
//# sourceMappingURL=IFaceEmbeddingService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFaceEmbeddingService.d.ts","sourceRoot":"","sources":["../../../../src/media/images/face/IFaceEmbeddingService.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,oEAAoE;AACpE,MAAM,WAAW,eAAe;IAC9B,2CAA2C;IAC3C,CAAC,EAAE,MAAM,CAAC;IACV,2CAA2C;IAC3C,CAAC,EAAE,MAAM,CAAC;IACV,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC5B,4DAA4D;IAC5D,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,6DAA6D;IAC7D,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,+CAA+C;AAC/C,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,2EAA2E;IAC3E,KAAK,EAAE,OAAO,CAAC;CAChB;AAMD;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAE3D;;;;;;;OAOG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAAC;CAClF;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAqBjE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file IFaceEmbeddingService.ts
|
|
3
|
+
* Interface for face embedding extraction and comparison services.
|
|
4
|
+
*
|
|
5
|
+
* Provides a provider-agnostic contract for extracting facial feature vectors
|
|
6
|
+
* from images and computing similarity between two face embeddings.
|
|
7
|
+
*/
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Cosine similarity
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
/**
|
|
12
|
+
* Compute the cosine similarity between two equal-length numeric vectors.
|
|
13
|
+
*
|
|
14
|
+
* Returns a value in [-1, 1] where 1 means identical direction, 0 means
|
|
15
|
+
* orthogonal, and -1 means opposite direction. Returns 0 for zero-magnitude
|
|
16
|
+
* vectors to avoid division-by-zero.
|
|
17
|
+
*
|
|
18
|
+
* @param a - First vector.
|
|
19
|
+
* @param b - Second vector.
|
|
20
|
+
* @returns Cosine similarity score.
|
|
21
|
+
*/
|
|
22
|
+
export function cosineSimilarity(a, b) {
|
|
23
|
+
if (a.length !== b.length) {
|
|
24
|
+
throw new Error(`Vector dimension mismatch: ${a.length} vs ${b.length}`);
|
|
25
|
+
}
|
|
26
|
+
let dotProduct = 0;
|
|
27
|
+
let magnitudeA = 0;
|
|
28
|
+
let magnitudeB = 0;
|
|
29
|
+
for (let i = 0; i < a.length; i++) {
|
|
30
|
+
dotProduct += a[i] * b[i];
|
|
31
|
+
magnitudeA += a[i] * a[i];
|
|
32
|
+
magnitudeB += b[i] * b[i];
|
|
33
|
+
}
|
|
34
|
+
const denominator = Math.sqrt(magnitudeA) * Math.sqrt(magnitudeB);
|
|
35
|
+
if (denominator === 0) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
return dotProduct / denominator;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=IFaceEmbeddingService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFaceEmbeddingService.js","sourceRoot":"","sources":["../../../../src/media/images/face/IFaceEmbeddingService.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgEH,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,CAAW,EAAE,CAAW;IACvD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,UAAU,GAAG,CAAC,CAAC;IAEnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1B,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1B,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClE,IAAI,WAAW,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,OAAO,UAAU,GAAG,WAAW,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file ReplicateFaceEmbeddingService.ts
|
|
3
|
+
* Replicate-backed face embedding extraction using InsightFace.
|
|
4
|
+
*
|
|
5
|
+
* Posts image URLs to the Replicate predictions API, polls for completion,
|
|
6
|
+
* and returns 512-dimensional face embedding vectors for drift detection.
|
|
7
|
+
*/
|
|
8
|
+
import { type FaceComparisonResult, type FaceEmbedding, type IFaceEmbeddingService } from './IFaceEmbeddingService.js';
|
|
9
|
+
/** Constructor options for {@link ReplicateFaceEmbeddingService}. */
|
|
10
|
+
export interface ReplicateFaceEmbeddingConfig {
|
|
11
|
+
/** Replicate API token. */
|
|
12
|
+
apiKey: string;
|
|
13
|
+
/** Override the Replicate API base URL (default: https://api.replicate.com/v1). */
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
/** Override the InsightFace model version identifier. */
|
|
16
|
+
modelId?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Extracts face embeddings via the Replicate API using InsightFace.
|
|
20
|
+
*
|
|
21
|
+
* Sends a prediction request with the provided image URL, polls until the
|
|
22
|
+
* prediction completes, then parses the embedding vector from the response.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ReplicateFaceEmbeddingService implements IFaceEmbeddingService {
|
|
25
|
+
private readonly apiKey;
|
|
26
|
+
private readonly baseUrl;
|
|
27
|
+
private readonly modelId;
|
|
28
|
+
constructor(config: ReplicateFaceEmbeddingConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Extract a face embedding from an image.
|
|
31
|
+
*
|
|
32
|
+
* @param imageUrl - Public URL or base64 data URI of the image.
|
|
33
|
+
* @returns Face embedding with 512-dim vector and optional bounding box.
|
|
34
|
+
*/
|
|
35
|
+
extractEmbedding(imageUrl: string): Promise<FaceEmbedding>;
|
|
36
|
+
/**
|
|
37
|
+
* Compare two face embedding vectors using cosine similarity.
|
|
38
|
+
*
|
|
39
|
+
* @param a - First embedding vector.
|
|
40
|
+
* @param b - Second embedding vector.
|
|
41
|
+
* @param threshold - Minimum similarity to consider a match (default 0.6).
|
|
42
|
+
* @returns Comparison result with similarity score and match flag.
|
|
43
|
+
*/
|
|
44
|
+
compareFaces(a: number[], b: number[], threshold?: number): FaceComparisonResult;
|
|
45
|
+
/**
|
|
46
|
+
* Poll a Replicate prediction URL until it reaches a terminal state.
|
|
47
|
+
*/
|
|
48
|
+
private pollPrediction;
|
|
49
|
+
/**
|
|
50
|
+
* Parse the Replicate InsightFace output into a {@link FaceEmbedding}.
|
|
51
|
+
*
|
|
52
|
+
* InsightFace returns an array of detected faces. Each face object contains
|
|
53
|
+
* an `embedding` array and optionally a `bbox` array [x1, y1, x2, y2].
|
|
54
|
+
*/
|
|
55
|
+
private parseEmbeddingOutput;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=ReplicateFaceEmbeddingService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReplicateFaceEmbeddingService.d.ts","sourceRoot":"","sources":["../../../../src/media/images/face/ReplicateFaceEmbeddingService.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC3B,MAAM,4BAA4B,CAAC;AAMpC,qEAAqE;AACrE,MAAM,WAAW,4BAA4B;IAC3C,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA2BD;;;;;GAKG;AACH,qBAAa,6BAA8B,YAAW,qBAAqB;IACzE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,4BAA4B;IAShD;;;;;OAKG;IACG,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA8ChE;;;;;;;OAOG;IACH,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,SAAS,SAAM,GAAG,oBAAoB;IAY7E;;OAEG;YACW,cAAc;IAwB5B;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;CAoC7B"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file ReplicateFaceEmbeddingService.ts
|
|
3
|
+
* Replicate-backed face embedding extraction using InsightFace.
|
|
4
|
+
*
|
|
5
|
+
* Posts image URLs to the Replicate predictions API, polls for completion,
|
|
6
|
+
* and returns 512-dimensional face embedding vectors for drift detection.
|
|
7
|
+
*/
|
|
8
|
+
import { cosineSimilarity, } from './IFaceEmbeddingService.js';
|
|
9
|
+
const DEFAULT_BASE_URL = 'https://api.replicate.com/v1';
|
|
10
|
+
const DEFAULT_MODEL_ID = 'daanelson/insightface:da3ed9bc348e12dfe81e7cb3adcdee5a2ce23e2e854ec45e4109990f5132653b';
|
|
11
|
+
const POLL_INTERVAL_MS = 1500;
|
|
12
|
+
const POLL_TIMEOUT_MS = 120000;
|
|
13
|
+
function sleep(ms) {
|
|
14
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
15
|
+
}
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Service
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
/**
|
|
20
|
+
* Extracts face embeddings via the Replicate API using InsightFace.
|
|
21
|
+
*
|
|
22
|
+
* Sends a prediction request with the provided image URL, polls until the
|
|
23
|
+
* prediction completes, then parses the embedding vector from the response.
|
|
24
|
+
*/
|
|
25
|
+
export class ReplicateFaceEmbeddingService {
|
|
26
|
+
constructor(config) {
|
|
27
|
+
if (!config.apiKey) {
|
|
28
|
+
throw new Error('ReplicateFaceEmbeddingService requires an apiKey.');
|
|
29
|
+
}
|
|
30
|
+
this.apiKey = config.apiKey;
|
|
31
|
+
this.baseUrl = config.baseUrl?.replace(/\/+$/, '') ?? DEFAULT_BASE_URL;
|
|
32
|
+
this.modelId = config.modelId ?? DEFAULT_MODEL_ID;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extract a face embedding from an image.
|
|
36
|
+
*
|
|
37
|
+
* @param imageUrl - Public URL or base64 data URI of the image.
|
|
38
|
+
* @returns Face embedding with 512-dim vector and optional bounding box.
|
|
39
|
+
*/
|
|
40
|
+
async extractEmbedding(imageUrl) {
|
|
41
|
+
const body = {
|
|
42
|
+
version: this.modelId,
|
|
43
|
+
input: {
|
|
44
|
+
image: imageUrl,
|
|
45
|
+
return_embedding: true,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
// Create prediction
|
|
49
|
+
const createResponse = await fetch(`${this.baseUrl}/predictions`, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: {
|
|
52
|
+
Authorization: `Token ${this.apiKey}`,
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
Prefer: 'wait=60',
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify(body),
|
|
57
|
+
});
|
|
58
|
+
if (!createResponse.ok) {
|
|
59
|
+
const errorText = await createResponse.text();
|
|
60
|
+
throw new Error(`Replicate face embedding request failed (${createResponse.status}): ${errorText}`);
|
|
61
|
+
}
|
|
62
|
+
let prediction = (await createResponse.json());
|
|
63
|
+
// Poll for completion if not immediately resolved
|
|
64
|
+
if (prediction.status &&
|
|
65
|
+
!['succeeded', 'failed', 'canceled'].includes(prediction.status) &&
|
|
66
|
+
prediction.urls?.get) {
|
|
67
|
+
prediction = await this.pollPrediction(prediction.urls.get);
|
|
68
|
+
}
|
|
69
|
+
if (prediction.status === 'failed') {
|
|
70
|
+
throw new Error(`Face embedding extraction failed: ${prediction.error ?? 'unknown error'}`);
|
|
71
|
+
}
|
|
72
|
+
if (prediction.status === 'canceled') {
|
|
73
|
+
throw new Error('Face embedding extraction was canceled.');
|
|
74
|
+
}
|
|
75
|
+
return this.parseEmbeddingOutput(prediction.output);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Compare two face embedding vectors using cosine similarity.
|
|
79
|
+
*
|
|
80
|
+
* @param a - First embedding vector.
|
|
81
|
+
* @param b - Second embedding vector.
|
|
82
|
+
* @param threshold - Minimum similarity to consider a match (default 0.6).
|
|
83
|
+
* @returns Comparison result with similarity score and match flag.
|
|
84
|
+
*/
|
|
85
|
+
compareFaces(a, b, threshold = 0.6) {
|
|
86
|
+
const similarity = cosineSimilarity(a, b);
|
|
87
|
+
return {
|
|
88
|
+
similarity,
|
|
89
|
+
match: similarity >= threshold,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// -------------------------------------------------------------------------
|
|
93
|
+
// Private helpers
|
|
94
|
+
// -------------------------------------------------------------------------
|
|
95
|
+
/**
|
|
96
|
+
* Poll a Replicate prediction URL until it reaches a terminal state.
|
|
97
|
+
*/
|
|
98
|
+
async pollPrediction(url) {
|
|
99
|
+
const startedAt = Date.now();
|
|
100
|
+
while (Date.now() - startedAt < POLL_TIMEOUT_MS) {
|
|
101
|
+
const response = await fetch(url, {
|
|
102
|
+
headers: { Authorization: `Token ${this.apiKey}` },
|
|
103
|
+
});
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
const errorText = await response.text();
|
|
106
|
+
throw new Error(`Replicate prediction polling failed (${response.status}): ${errorText}`);
|
|
107
|
+
}
|
|
108
|
+
const prediction = (await response.json());
|
|
109
|
+
if (!prediction.status || ['succeeded', 'failed', 'canceled'].includes(prediction.status)) {
|
|
110
|
+
return prediction;
|
|
111
|
+
}
|
|
112
|
+
await sleep(POLL_INTERVAL_MS);
|
|
113
|
+
}
|
|
114
|
+
throw new Error('Face embedding extraction timed out while waiting for prediction.');
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Parse the Replicate InsightFace output into a {@link FaceEmbedding}.
|
|
118
|
+
*
|
|
119
|
+
* InsightFace returns an array of detected faces. Each face object contains
|
|
120
|
+
* an `embedding` array and optionally a `bbox` array [x1, y1, x2, y2].
|
|
121
|
+
*/
|
|
122
|
+
parseEmbeddingOutput(output) {
|
|
123
|
+
// The output is typically an array of face objects
|
|
124
|
+
const faces = Array.isArray(output) ? output : [output];
|
|
125
|
+
if (faces.length === 0 || !faces[0]) {
|
|
126
|
+
throw new Error('No face detected in the image.');
|
|
127
|
+
}
|
|
128
|
+
const face = faces[0];
|
|
129
|
+
// Extract the embedding vector
|
|
130
|
+
const embedding = face.embedding ?? face.embeddings ?? face.vector;
|
|
131
|
+
if (!Array.isArray(embedding)) {
|
|
132
|
+
throw new Error('Face embedding output does not contain a valid embedding vector.');
|
|
133
|
+
}
|
|
134
|
+
const vector = embedding.map(Number);
|
|
135
|
+
// Extract optional bounding box [x1, y1, x2, y2] → { x, y, width, height }
|
|
136
|
+
const bbox = face.bbox ?? face.bounding_box ?? face.boundingBox;
|
|
137
|
+
const boundingBox = Array.isArray(bbox) && bbox.length >= 4
|
|
138
|
+
? {
|
|
139
|
+
x: Number(bbox[0]),
|
|
140
|
+
y: Number(bbox[1]),
|
|
141
|
+
width: Number(bbox[2]) - Number(bbox[0]),
|
|
142
|
+
height: Number(bbox[3]) - Number(bbox[1]),
|
|
143
|
+
}
|
|
144
|
+
: undefined;
|
|
145
|
+
// Extract optional confidence
|
|
146
|
+
const det_score = face.det_score ?? face.confidence ?? face.score;
|
|
147
|
+
const confidence = typeof det_score === 'number' ? det_score : undefined;
|
|
148
|
+
return { vector, boundingBox, confidence };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=ReplicateFaceEmbeddingService.js.map
|