Skip to content

feat(flows): implement AI Segment Image step (SAM 3.1) - #1611

Merged
nguyenvantruc92 merged 1 commit into
mainfrom
feat/ai-segment-image-sam
Nov 1, 2026
Merged

nguyenvantruc92 merged 1 commit into
mainfrom
feat/ai-segment-image-sam

Conversation

@nguyenvantruc92

Copy link
Copy Markdown
Contributor

Adds the aiSegmentImage flow step: it finds an object in a contact's image with SAM 3.1 on the workspace Muse (Meta Model API) integration and saves a cropped PNG, routing Found / Not found / Failed.

  • packages/ai (@chatbotx.io/ai/sam, worker-only): streams /v1/responses and reads only boxes from the output text, parsed against the grammar Meta publishes for writing your own parser (dev.meta.ai/docs/sam). Mask tokens are skipped, so no SAM-licensed package is used. Inclusive x2/y2 become half-open bounds, the frame must match the source image, confidence comes from include_confidence, and failures carry retryable/status for the heavy retry policy.
  • flow-config/worker-config: step schema (target, largest/all, output and optional details fields) and the aiSegmentImage heavy job.
  • worker: downloads and normalizes the image, calls SAM, crops the largest box or the area covering all boxes with sharp, uploads the PNG and writes { count, boxes, crop, source } details.
  • builder: step editor/viewer under Muse AI actions, copy in all locales.
  • tests and scripts/test-ai-segment-image-e2e.mts; fixtures are hand-written streams plus ChatbotX's own live captures.

@github-actions github-actions Bot added the feature New feature or request label Nov 1, 2026
@nguyenvantruc92
nguyenvantruc92 force-pushed the feat/ai-segment-image-sam branch from 7ca09f3 to 7502882 Compare November 1, 2026 03:48
Adds the `aiSegmentImage` flow step: it finds an object in a contact's
image with SAM 3.1 on the workspace Muse (Meta Model API) integration and
saves a cropped image, routing Found / Not found / Failed.

- packages/ai (`@chatbotx.io/ai/sam`, worker-only): streams `/v1/responses`
  and reads only boxes from the output text, parsed against the grammar Meta
  publishes for writing your own parser (dev.meta.ai/docs/sam). Mask tokens
  are skipped, so no SAM-licensed package is used. Inclusive x2/y2 become
  half-open bounds, the frame must match the source image, confidence comes
  from include_confidence (an unreadable one is dropped, not fatal), and
  failures carry retryable/status for the heavy retry policy. HTTP and
  in-stream errors keep Meta's reason through the Muse error helpers shared
  with muse-transcribe (`muse-errors.ts`); only server_error and
  rate_limit_exceeded retry after HTTP 200. A completion without a streamed
  text lane is read from its own output and fails loudly when it has none.
- flow-config/worker-config: step schema (target, largest/all, output and
  optional details fields) and the `aiSegmentImage` heavy job.
- worker: downloads and normalizes the image, calls SAM, crops the largest
  box or the area covering all boxes with sharp from the source pixels, and
  uploads it channel-safe like edit-image (JPEG, PNG only for real
  transparency, bounded by HEAVY_MAX_IMAGE_BYTES) under the heavy job id,
  then writes `{ count, boxes, crop, source }` details.
- builder: step editor/viewer under Muse AI actions, copy in all locales.
- tests; fixtures are hand-written streams plus ChatbotX's own live
  captures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nguyenvantruc92
nguyenvantruc92 force-pushed the feat/ai-segment-image-sam branch from 7502882 to d00bb2f Compare November 1, 2026 03:53
@nguyenvantruc92
nguyenvantruc92 merged commit 16b3c3a into main Nov 1, 2026
14 checks passed
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
Adds the `aiSegmentImage` flow step: it finds an object in a contact's
image with SAM 3.1 on the workspace Muse (Meta Model API) integration and
saves a cropped image, routing Found / Not found / Failed.

- packages/ai (`@chatbotx.io/ai/sam`, worker-only): streams `/v1/responses`
  and reads only boxes from the output text, parsed against the grammar Meta
  publishes for writing your own parser (dev.meta.ai/docs/sam). Mask tokens
  are skipped, so no SAM-licensed package is used. Inclusive x2/y2 become
  half-open bounds, the frame must match the source image, confidence comes
  from include_confidence (an unreadable one is dropped, not fatal), and
  failures carry retryable/status for the heavy retry policy. HTTP and
  in-stream errors keep Meta's reason through the Muse error helpers shared
  with muse-transcribe (`muse-errors.ts`); only server_error and
  rate_limit_exceeded retry after HTTP 200. A completion without a streamed
  text lane is read from its own output and fails loudly when it has none.
- flow-config/worker-config: step schema (target, largest/all, output and
  optional details fields) and the `aiSegmentImage` heavy job.
- worker: downloads and normalizes the image, calls SAM, crops the largest
  box or the area covering all boxes with sharp from the source pixels, and
  uploads it channel-safe like edit-image (JPEG, PNG only for real
  transparency, bounded by HEAVY_MAX_IMAGE_BYTES) under the heavy job id,
  then writes `{ count, boxes, crop, source }` details.
- builder: step editor/viewer under Muse AI actions, copy in all locales.
- tests; fixtures are hand-written streams plus ChatbotX's own live
  captures.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant