Class: Assistant::PinterestToolBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/services/assistant/pinterest_tool_builder.rb

Overview

Read-only Pinterest tools for the Sunny assistant: fetch existing pins and
boards from the WarmlyYours brand account through the Pinterest v5 API.

Only read scopes are exercised (pins:read / boards:read), which work
on the app's current Trial access tier. Creating or editing pins is gated
by Pinterest (Standard access + the restricted pin_edit feature) and is
deliberately NOT exposed here — see
PinterestBoardDescriptionUpdater and doc/tasks for the write roadmap.

Why this exists: pasting pinterest.com/pin/... URLs at Sunny used to fail —
it fell back to fetch_url, which Pinterest blocks, so no content came back
(conversation 3871). This tool reads the pin straight from the API instead.

Constant Summary collapse

API_BASE =

Production Pinterest API base (matches PinterestBoardDescriptionUpdater;
the system OAuth token is a production token).

'https://api.pinterest.com/v5'
MAX_PINS_PER_CALL =

Cap on pins fetched in one call — a user can paste a long list of URLs.

25
BATCH_DEADLINE =

Overall wall-clock budget for a batch pin read. Reads run serially and each
can wait up to the connection timeout, so without a deadline a stalled batch
of 25 could hold the Sunny executor for minutes. Bounds it to ~deadline + one
request timeout. ponytail: single overall deadline, not per-request slicing.

60.seconds
MAX_BOARD_PAGES =

Safety cap on board pages (page_size 100 → 10k boards) so a misbehaving
bookmark never loops forever. ponytail: real accounts have <100 boards.

100

Class Method Summary collapse

Class Method Details

.toolsArray<RubyLLM::Tool>

Returns the read-only Pinterest tools.

Returns:

  • (Array<RubyLLM::Tool>)

    the read-only Pinterest tools



38
39
40
41
42
43
# File 'app/services/assistant/pinterest_tool_builder.rb', line 38

def tools
  @tools ||= [build_read_pins_tool, build_list_boards_tool]
rescue StandardError => e
  Rails.logger.warn("[PinterestToolBuilder] Failed to build Pinterest tools: #{e.message}")
  []
end