Automations editor:
- {{ }} expression autocomplete in CodeMirror, scoped to the braces and
graph-aware (suggests only what upstream nodes provide + variables + now);
migrate the Generate prompt to CodeMirror so it shares the same completions
- Expandable editors: an expand button slides out a side-by-side panel
(matching the sidebar card), with a minimize control; the inline field
collapses to a hint while editing in the panel
- Hover-revealed editor toolbar (expand/copy) with styled tooltips so the
buttons no longer obscure the text while reading
- Beta badge on the Automations sidebar item
- Delete a single connection with Backspace/Delete (edge selection)
- Re-key node config so switching between same-type nodes refreshes the form
HTTP fetch node — cover every JSON response shape:
- Top-level array, object map (items_path=*), array of primitives, and NDJSON
- Key-based dedup via item_key_path (seen-set, FIFO-capped) for feeds without
dates; first poll records a baseline and emits nothing (date path too)
Fan-out test visibility:
- root_run_id links every forked branch back to the run that started a test,
so the test panel aggregates all branches instead of one
Fix a few pre-existing type issues (ScheduleData import, padded minute,
optional created_at).
91 lines
2.6 KiB
PHP
91 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Automation\Run\Status;
|
|
use App\Observers\AutomationRunObserver;
|
|
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[ObservedBy([AutomationRunObserver::class])]
|
|
class AutomationRun extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUuids;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'status' => Status::class,
|
|
'context' => 'array',
|
|
'error' => 'array',
|
|
'is_manual' => 'boolean',
|
|
'is_dry_run' => 'boolean',
|
|
'next_action_at' => 'datetime',
|
|
'started_at' => 'datetime',
|
|
'finished_at' => 'datetime',
|
|
];
|
|
|
|
public function automation(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Automation::class);
|
|
}
|
|
|
|
/**
|
|
* Id of the run that started this execution. Fan-out forks sibling runs that
|
|
* all point back at the same root, so callers can treat every branch of one
|
|
* test/trigger as a single family. The root run points at itself.
|
|
*/
|
|
public function rootId(): string
|
|
{
|
|
return $this->root_run_id ?? $this->id;
|
|
}
|
|
|
|
/**
|
|
* Context for template (`{{ ... }}`) resolution: the run context plus the
|
|
* automation's workflow variables, merged in-memory. Variables are NEVER
|
|
* persisted into the run context (they're encrypted at rest and would
|
|
* otherwise leak in plaintext via the run/node-run API), so we compute this
|
|
* on demand at resolve time only.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function resolverContext(): array
|
|
{
|
|
return array_merge(
|
|
$this->context ?? [],
|
|
['variables' => $this->automation->resolvedVariables()],
|
|
);
|
|
}
|
|
|
|
public function triggerItem(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AutomationTriggerItem::class, 'trigger_item_id');
|
|
}
|
|
|
|
public function generatedPost(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Post::class, 'generated_post_id');
|
|
}
|
|
|
|
public function nodeRuns(): HasMany
|
|
{
|
|
return $this->hasMany(AutomationNodeRun::class, 'run_id');
|
|
}
|
|
|
|
/**
|
|
* Hides dry-run rows from user-facing history queries. Internal/analytics
|
|
* queries can ignore the scope to see every row.
|
|
*/
|
|
public function scopeExcludingDryRuns(Builder $query): Builder
|
|
{
|
|
return $query->where('is_dry_run', false);
|
|
}
|
|
}
|