mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 18:07:00 +01:00
Merge origin/master and renumber additive Speko migrations
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
commit
bf1ead3772
65 files changed
+5336
-56682
No files matched your search
@@ -19,6 +19,17 @@ That's it. On first start the server:
|
||||
|
||||
Data persists across restarts in `~/.paperclip/instances/default/db/`. To reset local dev data, delete that directory.
|
||||
|
||||
Subscription reporting adds `ai_subscriptions` (company-scoped account identity),
|
||||
`ai_subscription_prices` (immutable price revisions), and
|
||||
`ai_subscription_connections` (selected grant-to-account bindings). New managed
|
||||
subscription receipts also have a nullable `cost_events.subscription_id`.
|
||||
Migration `0322_reflective_kree.sql` is replay-safe and leaves existing cost
|
||||
amounts and receipts untouched. No historical account attribution is inferred.
|
||||
Deleting a connection removes its binding but retains subscription price history;
|
||||
disconnecting is not proof that provider billing ended. See
|
||||
[subscription cost reporting](connections/AI-CONNECTIONS.md#subscription-cost-reporting)
|
||||
for the reporting and ownership rules.
|
||||
|
||||
If you need to apply pending migrations manually, run:
|
||||
|
||||
```sh
|
||||
|
||||
+11
-1
@@ -1271,7 +1271,7 @@ It owns bounded run projections, database encoding checks, task session reads an
|
||||
writes, explicit resumes, session compaction, and usage/billing helpers.
|
||||
`createHeartbeatRunState(db)` binds these operations without doing database work
|
||||
during construction. The encoding-check cache belongs to each factory instance.
|
||||
`heartbeat.ts` keeps run execution and session-goal recovery, and re-exports the
|
||||
`heartbeat.ts` keeps run execution and re-exports the
|
||||
existing public helpers. Keep session policy changes separate from run
|
||||
orchestration changes.
|
||||
|
||||
@@ -1321,6 +1321,16 @@ Forwarding callbacks preserve construction order for budget, retry, recovery,
|
||||
and queue services. Existing public helpers remain re-exported by `heartbeat.ts`.
|
||||
Keep cancellation policy changes separate from this extraction and execution.
|
||||
|
||||
Scheduling is in `server/src/services/heartbeat/scheduling.ts`. It owns timer
|
||||
ticks, issue-monitor claims and dispatch, exhausted-monitor recovery, and
|
||||
session-goal recovery. `createHeartbeatScheduling` binds explicit dependencies
|
||||
without querying or starting timers. Queue admission, heartbeat policy parsing,
|
||||
and atomic timer claims stay in `queue.ts`; the service supplies those operations
|
||||
and the current scheduling-suppression and worktree-cutoff callbacks. Monitor
|
||||
claims remain database-scoped so separate scheduler instances cannot dispatch
|
||||
the same claim. The public heartbeat methods keep their existing signatures.
|
||||
Keep scheduling policy changes separate from this extraction and execution.
|
||||
|
||||
## Wake Context Delivery
|
||||
|
||||
Built-in adapters deliver wake context through the run prompt, including structured
|
||||
|
||||
@@ -717,3 +717,120 @@ requires a complete `response_wake` object.
|
||||
|
||||
Task-card account repair uses the provider reconnect form for routed accounts,
|
||||
retaining the saved endpoint, protocol, model aliases, and connection identity.
|
||||
|
||||
## Subscription cost reporting
|
||||
|
||||
The Costs page shows metered API spend beside the **current monthly subscription
|
||||
commitment**. API dollars and both token totals follow the selected date range;
|
||||
monthly subscription fees do not. Tokens measure Paperclip work only, while a
|
||||
subscription fee covers the entire provider account, including other usage.
|
||||
Recorded subscription overages remain separate from the recurring fee.
|
||||
|
||||
Agent, user, project, and model cost rows use a right-aligned amount with any
|
||||
estimate badge underneath. Each badge reflects that row's own ledger events in
|
||||
the selected date range.
|
||||
|
||||
Discovery uses the managed AI connection actually selected for a run, or the
|
||||
connected accounts visible to the user viewing Costs. An administrator cannot
|
||||
probe another user's private credentials. OpenAI identity combines workspace and
|
||||
seat claims from the exact bearer token accepted by its usage endpoint, with
|
||||
the selected workspace checked against those claims. An editable ID token cannot
|
||||
establish identity or grant price-edit access. Claude's OAuth profile combines
|
||||
organization and account identity when the token allows profile access. Identity
|
||||
keys are company-scoped hashes; reporting never exposes tokens, raw provider IDs,
|
||||
or credential hashes. Multiple agents and connections sharing a known paid seat
|
||||
count once. Distinct seats remain separate even in the same workspace. Before
|
||||
provider verification, each connection grant has its own unconfirmed record;
|
||||
local claims alone cannot combine another user's account or billing editors.
|
||||
|
||||
Supported exact plan identifiers with a stable account identity map to dated, USD, before-tax web list prices
|
||||
in `packages/shared/src/subscriptions.ts`. The UI labels these **Estimated** (or
|
||||
**Partially estimated** when combined with user-supplied prices). A generic
|
||||
OpenAI Pro, Claude Max, team, or enterprise entitlement does not reliably
|
||||
identify the price: it stays **Price unknown** until its owner enters an amount.
|
||||
Annual prices are divided by 12 using exact decimal arithmetic. Supported
|
||||
currencies are totaled separately; Paperclip does not estimate exchange rates.
|
||||
|
||||
Use **Subscriptions → View details → Edit price** to record the amount paid,
|
||||
billing cadence, and tracking status. Personal prices are editable by their
|
||||
owner; shared prices require AI-connection management permission. When the same
|
||||
seat is connected both personally and shared, both its personal owners and
|
||||
company connection managers can edit the single fee, regardless of discovery
|
||||
order. These billing permissions survive disconnecting a connection; they do
|
||||
not grant access to its credentials. Viewers cannot
|
||||
edit. Updates append an immutable price revision and reject stale concurrent
|
||||
edits. Ending or excluding tracking does not cancel the provider subscription.
|
||||
Disconnecting a connection also does not prove that billing stopped, so the fee
|
||||
continues until explicitly ended or excluded.
|
||||
|
||||
Claude setup tokens can lack profile permission. Grok plan observations currently
|
||||
do not supply a verified billing identity. Such connections retain an unconfirmed
|
||||
identity and may need manual linking after a credential change. An unconfirmed
|
||||
identity requires a user-supplied price before contributing a monthly fee, so
|
||||
credential rotations cannot multiply automatic list-price estimates. **Link accounts**
|
||||
combines usage and keeps the selected account's price; it is restricted to accounts
|
||||
the caller can edit and should only join the same subscription or paid seat.
|
||||
Provider observations never overwrite a user-supplied price. Conflicting manual
|
||||
prices prevent automatic linking rather than silently choosing one.
|
||||
|
||||
Monthly totals and account details include only accounts the viewer may see:
|
||||
personal billing owners, company managers of shared fees, and the authorized
|
||||
audience of active shared grants. Revoking a grant removes its audience's access
|
||||
to the fee. Cost-read permission alone does not reveal
|
||||
another member's personal plan, price, owner, or account-linked activity. Billing
|
||||
editors retain visibility after disconnection so they can end tracking. Aggregate
|
||||
API and subscription run-token totals remain company-wide, as in existing cost
|
||||
reports; hidden private accounts are not mislabeled as missing attribution.
|
||||
Fixed-price, credit-billed, and unknown usage remain in the inference ledger.
|
||||
They are reported separately from API and subscription tokens as other or unknown
|
||||
billing types; the API retains the `unknown` field name for this combined total.
|
||||
|
||||
Provider lookups run in the background, with a six-hour attempt cache shared by
|
||||
server replicas, at most four active provider lookups per process, a 15-second
|
||||
request deadline, and a 256 KiB response limit. Failed checks preserve the last
|
||||
observed plan and price. The report reads the database only and loads just the
|
||||
current price for each account; earlier revisions remain stored for auditing.
|
||||
Accepted discovery requests wait for provider capacity instead of skipping accounts.
|
||||
At most twenty discovery requests run per process; additional requests receive
|
||||
HTTP 429 and can be retried using **Retry account check**.
|
||||
Failed background UI reloads retain the last loaded values and show a short
|
||||
status message. Failed discovery offers **Retry account check**.
|
||||
|
||||
Each new managed subscription run snapshots its subscription ID. Its cost receipt
|
||||
inherits that server-derived ID, outside the immutable monetary receipt hash.
|
||||
Switching accounts cannot move an earlier run to the new subscription. Linking
|
||||
duplicates resolves historical IDs in reports without rewriting receipts.
|
||||
Legacy and unmanaged subscription usage still contributes to the subscription
|
||||
token total but is not retroactively assigned to a guessed account. Subscription
|
||||
estimates never create finance events, change the inference ledger's dollar
|
||||
amounts, or consume agent budgets.
|
||||
|
||||
The company-scoped API is documented in OpenAPI:
|
||||
|
||||
- `GET /api/companies/:companyId/costs/subscriptions`: current fees and usage for
|
||||
`from`/`to` (inclusive, matching existing cost reports), or `period=all`.
|
||||
- `POST /api/companies/:companyId/costs/subscriptions/refresh`: request background
|
||||
discovery for the caller's authorized connections; returns `202` immediately.
|
||||
- `PATCH /api/companies/:companyId/costs/subscriptions/:subscriptionId`: save a
|
||||
price with `expectedRevision`, plan, nullable `amountCents`, currency, cadence,
|
||||
and tracking status.
|
||||
- `POST /api/companies/:companyId/costs/subscriptions/:subscriptionId/link`: link
|
||||
a duplicate using `targetId`, `expectedRevision`, and `targetRevision`.
|
||||
|
||||
Storybook **Costs / Subscriptions** renders the production Costs page with
|
||||
interactive fixtures for normal estimates, unknown prices, provider failures,
|
||||
and mobile layouts. Its edits affect fixture data only. Focused verification:
|
||||
|
||||
```sh
|
||||
pnpm exec vitest run server/src/__tests__/subscriptions.test.ts \
|
||||
server/src/__tests__/subscription-routes.test.ts \
|
||||
ui/src/components/SubscriptionCostCard.test.tsx ui/src/pages/Costs.test.tsx
|
||||
pnpm check:token-gates
|
||||
pnpm storybook
|
||||
```
|
||||
|
||||
These tests include real PostgreSQL persistence, migration replay, concurrent
|
||||
updates, account changes, duplicate identity resolution, ownership, monetary
|
||||
receipt replay, unknown prices, and failed provider observations. Provider payloads
|
||||
are fixtures; live provider access still depends on the deployment's credentials
|
||||
and scopes.
|
||||
@@ -6,9 +6,10 @@ owns the assignment lifecycle and durable tool receipts. Dot uses Paperclip's
|
||||
existing agent permissions and task tools, including document writes and
|
||||
completion feedback.
|
||||
|
||||
This first version supports a self-hosted instance with a local Runner
|
||||
controller and a stable public HTTPS origin. Hosted agent-broker and remote
|
||||
controller deployments are not qualified. The feature is off by default.
|
||||
Dot supports a self-hosted instance with a local Runner controller and a stable
|
||||
public HTTPS origin, or a Cloud instance with a managed sandbox Runner and the
|
||||
tenant Dot ingress. The feature is off by default. Cloud requires the native
|
||||
Runner setting in addition to Dot and Assistant connections (MCP).
|
||||
|
||||
## Enable and pair
|
||||
|
||||
@@ -418,6 +419,12 @@ The setup prompt asks Dot to upload its own current image only if it can obtain
|
||||
|
||||
### Invite from the agent picker
|
||||
|
||||
A new Dot remains in hire preparation until pairing and the event check finish.
|
||||
Setup can issue its prompt during preparation and verification; the compatibility
|
||||
status `paused` does not require an operator resume in these states. The live
|
||||
checks continue until the binding and agent lifecycle are both ready. A manual
|
||||
pause or pending hire approval still blocks setup.
|
||||
|
||||
Enable **OpenAI Dot** and **Assistant connections (MCP)**, then choose **New Agent → Invite an external agent → Dot**. Copy the setup prompt into your Dot. Paperclip creates a scoped Runner agent and watches connection, event subscription, and a harmless event round trip. If your company requires hire approval, approve the agent before copying its pairing prompt. The test event is sent automatically after the callback is verified; Retry test event remains available if confirmation times out.
|
||||
|
||||
Reopening setup resumes the operator's unfinished invitation. Pairing codes are not stored in browser persistence. After refreshing or when an open prompt expires, setup automatically prepares a fresh prompt to copy. It first checks current connection state and replaces only the pending capability, without revoking an established connection. A failed renewal offers a retry rather than looping. If another browser window replaces the prompt, the current window asks before replacing it again. Hermes and Other continue to use the ordinary external-agent invitation flow.
|
||||
@@ -447,3 +454,12 @@ pnpm exec vitest run server/src/__tests__/dot-runner.test.ts -t 'private Daytona
|
||||
```
|
||||
|
||||
The fixture creates a private, bounded sandbox and deletes it in `finally`. Default tests do not contact Daytona. This test uses a scripted MCP client; a separate real OpenAI Dot walkthrough is required to qualify provider behavior.
|
||||
|
||||
### Public Cloud consent
|
||||
|
||||
The Dot consent page is intentionally accessible without a Paperclip board
|
||||
session. Background UI probes may receive `tenant_session_required` or
|
||||
`tenant_session_invalid` there; they must not reload the public consent document.
|
||||
The public request and pairing endpoints still enforce the OAuth request and
|
||||
one-use pairing code. Normal board routes retain Cloud session recovery, and
|
||||
archived stacks still redirect through a document reload.
|
||||
Reference in new issue
Block a user