Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@ All notable changes to TYDAL are documented here. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/); this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.5.0] — 2026-10-08

### Added

- **AITY suggestions at the vault write boundary.** A gallery `ingest` with
`suggest: true` runs AITY on the stored photograph — opt-in per photograph,
because the consumer may hold the photographer's consent for some and not
others. AITY only proposes; what the consumer sent is never changed, and
AITY failing never fails the ingest. `GET …/w/suggestions?resources=…`
returns the proposed title and description per ingested resource (`off`,
`pending`, `done`, `failed`) to a key that may `update`; reading never
starts AITY.
`@tydal/client` gets `suggestions(resources)`. See
`docs/architecture/VAULT_WRITE_METHODS.md` §3.

### Upgrading

No migrations and no new configuration. Suggestions run on the existing AITY
pipeline, so they need what AITY already needs: a configured LLM driver and a
queue worker. `@tydal/client` goes to `1.7.0` (`suggestions`);
`@tydal/org-mcp` and `@tydal/vault-mcp` keep their versions.

## [1.4.1] — 2026-10-06

Expand Down Expand Up @@ -642,7 +662,8 @@ layer); as a shipped product it is version 1.0.0.
[`MIGRATION_V1_V2.md`](docs/planning/MIGRATION_V1_V2.md), CLI guide, and
OpenAPI 3.0 spec.

[Unreleased]: https://github.com/eonity-org/tydal/compare/v1.4.1...HEAD
[Unreleased]: https://github.com/eonity-org/tydal/compare/v1.5.0...HEAD
[1.5.0]: https://github.com/eonity-org/tydal/compare/v1.4.1...v1.5.0
[1.4.1]: https://github.com/eonity-org/tydal/compare/v1.4.0...v1.4.1
[1.4.0]: https://github.com/eonity-org/tydal/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/eonity-org/tydal/compare/v1.2.0...v1.3.0
Expand Down
51 changes: 50 additions & 1 deletion backend/app/Http/Controllers/API/VaultNamespaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,53 @@ private function writeInfo(?Vault $vault, Request $request, VaultIngest $ingest)
return $this->vaultJson($body);
}

/**
* AITY's proposals for resources this vault ingested (VAULT_WRITE_METHODS.md
* §5) — a read beside the write probe, for a key that may `update`: whoever
* can apply a suggestion may see it. Not a write, so it isn't audited and a
* consumer can poll it while the pipeline runs. `resources` is a
* comma-separated list of the hashes `ingest` returned. Reading never
* starts AITY: only an `ingest` with `suggest` does.
*/
public function hashVaultSuggestions(string $vaultHash, Request $request, VaultIngest $ingest): JsonResponse
{
return $this->suggestions(Vault::findByHashCached($vaultHash), $request, $ingest);
}

/** Human-form suggestions read — same gate as the hash form. */
public function vaultSuggestions(string $orgSlug, string $vaultSlug, Request $request, VaultIngest $ingest): JsonResponse
{
return $this->suggestions(Vault::findBySlugsCached($orgSlug, $vaultSlug), $request, $ingest);
}

private function suggestions(?Vault $vault, Request $request, VaultIngest $ingest): JsonResponse
{
$probe = $this->links->writeCapabilities($vault, $request->ip(), $this->vaultKey($request));

if ($probe['status'] !== 200 || ! $vault) {
return $this->vaultJson(
['ok' => false, 'error' => $probe['error'] ?? 'Not found or expired'],
$probe['status'] === 200 ? 404 : $probe['status'],
);
}
if (! in_array('update', $probe['methods'], true)) {
return $this->vaultJson(['ok' => false, 'error' => 'This key may not update resources here.'], 403);
}

$hashes = array_values(array_filter(array_map(
'trim',
explode(',', (string) $request->query('resources', '')),
)));
if ($hashes === [] || count($hashes) > VaultIngest::MAX_SUGGESTION_RESOURCES) {
return $this->vaultJson([
'ok' => false,
'error' => 'Give 1 to '.VaultIngest::MAX_SUGGESTION_RESOURCES.' resource hashes in `resources`.',
], 400);
}

return $this->vaultJson(['ok' => true, 'suggestions' => (object) $ingest->suggestions($vault, $hashes)]);
}

private function dispatchWrite(?Vault $vault, string $method, Request $request, GalleryVaultWriter $writer, AiVaultWriter $aiWriter, VaultIngest $ingest): JsonResponse
{
$auth = $this->links->authorizeWrite($vault, $method, $request->ip(), $this->vaultKey($request));
Expand Down Expand Up @@ -526,7 +573,9 @@ private function dispatchIngest(Vault $vault, Request $request, GalleryVaultWrit
return $aiWriter->ingest($vault, $document, $descriptor, $image);
}

return $writer->ingest($vault, $document, $image);
// AITY runs only when the consumer asks: it may hold the photographer's
// consent for some photographs and not for others.
return $writer->ingest($vault, $document, $image, $request->boolean('suggest'));
}

public function hashEntry(string $vaultHash, string $linkHash, Request $request): StreamedResponse|JsonResponse
Expand Down
33 changes: 27 additions & 6 deletions backend/app/Services/GalleryVaultWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Services\Interfaces\ResourceServiceInterface;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;

Expand All @@ -33,6 +34,7 @@ public function __construct(
private ResourceServiceInterface $resources,
private VaultLinkService $links,
private VaultIngest $ingest,
private AityEnrichmentService $aity,
) {}

/**
Expand All @@ -41,8 +43,12 @@ public function __construct(
* preview. The metadata document is already split by VaultIngest; the
* gallery requires `name` (the author owns the title). The stored filename
* is derived from it, so the uploader's filename (often a person's name)
* never reaches TYDAL. Nothing here rewrites what the consumer sent — no AI
* enrichment runs on it.
* never reaches TYDAL. Nothing here rewrites what the consumer sent. With
* `$suggest` (the consumer holds the photographer's consent to it), AITY
* runs on the stored photograph, but only *proposes* a title and a
* description, which the consumer reads back through `suggestions`
* (VaultIngest::suggestions) and applies, or not, with `update`. Without
* it, the photograph never reaches an AI service.
*
* Refused when the target workspace isn't projected by this vault — the
* photo would be written but never shown (e.g. after an `activate`, whose
Expand All @@ -51,7 +57,7 @@ public function __construct(
* @param array{columns: array<string, string|null>, metadata: array<string, scalar|null>} $document
* @return array{hash: string, name: string}
*/
public function ingest(Vault $vault, array $document, UploadedFile $image): array
public function ingest(Vault $vault, array $document, UploadedFile $image, bool $suggest = false): array
{
$name = $document['columns']['name'] ?? null;
if ($name === null) {
Expand All @@ -76,7 +82,7 @@ public function ingest(Vault $vault, array $document, UploadedFile $image): arra
]);
}

return DB::transaction(function () use ($vault, $document, $name, $image, $workspace, $collection): array {
[$summary, $file] = DB::transaction(function () use ($vault, $document, $name, $image, $workspace, $collection): array {
$metadata = array_filter($document['metadata'], fn ($v) => $v !== null);

$resource = $this->resources->createResource([
Expand All @@ -94,7 +100,7 @@ public function ingest(Vault $vault, array $document, UploadedFile $image): arra
$stem = Str::slug($name) ?: 'photograph';

// Images are their own snapshot (the preview every card shows).
$this->ingest->attachFile(
$file = $this->ingest->attachFile(
$resource,
(string) $image->getRealPath(),
"{$stem}.{$extension}",
Expand All @@ -111,8 +117,23 @@ public function ingest(Vault $vault, array $document, UploadedFile $image): arra

$link = $this->links->getOrCreateLink($vault, null, $resource->id, null);

return ['hash' => $link->hash, 'name' => $name];
return [['hash' => $link->hash, 'name' => $name], $file];
});

if (! $suggest) {
return $summary;
}

// After the commit, so the queued jobs find the rows. The photograph is
// stored either way: AITY failing (e.g. on a sync queue) must not turn
// a done ingest into an error the consumer would retry into a duplicate.
try {
$this->aity->enrich($file);
} catch (\Throwable $e) {
Log::warning('Vault ingest: AITY could not start', ['file_id' => $file->id, 'error' => $e->getMessage()]);
}

return $summary;
}

/**
Expand Down
73 changes: 73 additions & 0 deletions backend/app/Services/VaultIngest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Collection;
use App\Models\File;
use App\Models\Resource;
use App\Models\SystemFile;
use App\Models\Vault;
use App\Models\VaultLink;
use App\Models\VaultWrite;
Expand All @@ -29,6 +30,8 @@
* keys naming a resource column (`name`, `description`) are lifted into it,
* the rest are stored in `resources.metadata` as given. No AI and no scheme
* check touch it — the scheme only decides which keys get indexed/faceted.
* AITY may *propose* values when the consumer asks (`ingest` with `suggest`,
* read back with `suggestions`); only the consumer applies them.
* - **Provenance.** `update`/`withdraw` act only on resources this vault's
* `ingest` created; the `vault_writes` audit is the record.
*/
Expand All @@ -41,6 +44,9 @@ class VaultIngest

private const MAX_VALUE_LENGTH = 5000;

/** Most resources one `suggestions` read reports on. */
public const MAX_SUGGESTION_RESOURCES = 100;

public function __construct(
private ResourceServiceInterface $resources,
) {}
Expand Down Expand Up @@ -287,6 +293,73 @@ public function withdraw(Vault $vault, string $hash): array
return ['withdrawn' => $hash];
}

/**
* What AITY proposes for resources this vault ingested — the read beside
* the write probe (VAULT_WRITE_METHODS.md §5), for a consumer that may
* `update` them. Per hash: `status` (`off` when AITY was never asked to
* run on it, `pending` while the pipeline runs, `done` once it has
* finished — with or without a proposal — or `failed`) and the latest
* proposed `name` / `description` (null when none). Reading never starts
* AITY: whether a photograph may reach an AI service is the consumer's
* call, made at `ingest`. Hashes this vault did not ingest are left out,
* like everywhere else on the boundary.
*
* @param list<string> $hashes
* @return array<string, array{status: string, name: ?string, description: ?string}>
*/
public function suggestions(Vault $vault, array $hashes): array
{
$ingested = array_values(array_intersect(array_unique($hashes), $this->ingested($vault)));
if ($ingested === []) {
return [];
}

$links = VaultLink::where('vault_id', $vault->id)
->whereNull('file_id')
->whereIn('hash', $ingested)
->pluck('resource_id', 'hash');

$files = File::whereIn('resource_id', $links->values())
->committed()
->where('role', FileRole::CANONICAL)
->with([
'latestAiSuggestedNameSystemFileForDisplay',
'latestAiSuggestedDescriptionSystemFileForDisplay',
])
->get()
->keyBy('resource_id');

$report = [];
foreach ($links as $hash => $resourceId) {
$file = $files->get($resourceId);
if (! $file) {
continue;
}

$stage = $file->processing_status['stage'] ?? null;

$report[$hash] = [
'status' => match ($stage) {
null => 'off',
'done', 'not_applicable' => 'done',
'failed' => 'failed',
default => 'pending',
},
'name' => $this->suggested($file->latestAiSuggestedNameSystemFileForDisplay),
'description' => $this->suggested($file->latestAiSuggestedDescriptionSystemFileForDisplay),
];
}

return $report;
}

private function suggested(?SystemFile $suggestion): ?string
{
$value = $suggestion?->metadata['value'] ?? null;

return is_string($value) && trim($value) !== '' ? trim($value) : null;
}

private function ingestedResource(Vault $vault, string $hash): Resource
{
$ingested = VaultWrite::where('vault_id', $vault->id)
Expand Down
12 changes: 12 additions & 0 deletions backend/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
->middleware('throttle:30,1')
->name('h.vault.write.info');

// AITY's proposals for ingested resources — a read beside the write probe,
// gated by a key that may `update`. Polled while the pipeline runs, hence the
// looser throttle.
Route::get('/h/{vaultHash}/w/suggestions', [VaultNamespaceController::class, 'hashVaultSuggestions'])
->middleware('throttle:60,1')
->name('h.vault.write.suggestions');

Route::get('/h/{vaultHash}/{linkHash}', [VaultNamespaceController::class, 'hashEntry'])
->name('h.serve');

Expand Down Expand Up @@ -94,6 +101,11 @@
->middleware('throttle:30,1')
->name('v.write.info');

// Before {resourceSlug}/{fileSlug}, which would read it as a file.
Route::get('/w/suggestions', 'vaultSuggestions')
->middleware('throttle:60,1')
->name('v.write.suggestions');

Route::get('/{resourceSlug}', 'resourceEntry')->name('v.resource');

Route::get('/{resourceSlug}/{op}', 'resourceOperation')
Expand Down
Loading
Loading