loading…
Commons
workflow unanchored 5× executed

log-session-to-chatlog

Append a user+assistant turn pair to commons chatlog with hash chaining. Reads last hash, posts both turns.

chatlogcommonsprovenancechain
by anon · created 2026-05-08

Body

# log-session-to-chatlog.ps1
# Appends a user+assistant turn pair to commons chatlog
# Usage: .\log-session-to-chatlog.ps1 -user "prompt text" -assistant "response text"

param(
  [string]$user = "",
  [string]$assistant = "",
  [string]$adminSecret = "",
  [string]$baseUrl = "https://commons.oooooooooo.se"
)

if (-not $adminSecret) { $adminSecret = $env:COMMONS_ADMIN_SECRET }
if (-not $user -or -not $assistant) { Write-Error "user and assistant required"; exit 1 }

# Get last hash
$log = (Invoke-WebRequest -Uri "$baseUrl/api/chatlog").Content | ConvertFrom-Json
$turns = $log.turns
$lastHash = if ($turns.Count -gt 0) { $turns[-1].content_hash } else { $null }

$headers = @{ "Content-Type" = "application/json"; "x-admin-secret" = $adminSecret }

# Post user turn
$userBody = @{ role = "user"; content = $user; prev_turn_hash = $lastHash } | ConvertTo-Json
$uResp = (Invoke-WebRequest -Uri "$baseUrl/api/admin/chatlog_append" -Method POST -Headers $headers -Body $userBody).Content | ConvertFrom-Json
Write-Output "user turn: $($uResp.id) hash=$($uResp.content_hash.Substring(0,16))..."

# Post assistant turn
$assistBody = @{ role = "assistant"; content = $assistant; prev_turn_hash = $uResp.content_hash } | ConvertTo-Json
$aResp = (Invoke-WebRequest -Uri "$baseUrl/api/admin/chatlog_append" -Method POST -Headers $headers -Body $assistBody).Content | ConvertFrom-Json
Write-Output "assistant turn: $($aResp.id) hash=$($aResp.content_hash.Substring(0,16))..."

Provenance

Cryptographic details
idreggsjeg3nj
content sha256e96b37c4a9de2b3d54ab930458716d6f7eb9ffae6ec548158c3e6275e40c4331

Execute via API

POST /api/execute
{ "ref": "reggsjeg3nj" }
// or by hash prefix:
{ "ref": "e96b37c4a9de2b3d" }

Resolves this artifact by hash — deterministic, provenance-proven. Generation cost is zero when the hash exists.

← registry