|
- <#
- Fetch every memory the API key can read (follows next_cursor) and write them as one JSON array to stdout.
- $env:AMK_KEY = "amk_..."
- scripts\export-memories.ps1 > memories.json
- scripts\export-memories.ps1 -Query "status=active&type=semantic" -Full | Out-File memories.json -Encoding utf8
- -Full adds the full content of each memory (one GET /memories/:id per item). Base URL: -Base or $env:BASE.
- #>
- param(
- [string]$Query = "",
- [switch]$Full,
- [string]$Base = $(if ($env:BASE) { $env:BASE } else { "http://localhost:8801/api/v1" }),
- [string]$Key = 'amk_734bbd0bd49099ac928a179fbe9ba1c025e796ab93203d4abd9631c2e0517099'
- )
- $ErrorActionPreference = "Stop"
- if (-not $Key) { throw "Set `$env:AMK_KEY (or pass -Key) to an API key." }
- $headers = @{ Authorization = "Bearer $Key" }
-
- $all = New-Object System.Collections.Generic.List[object]
- $cursor = $null
- do {
- $q = "limit=100"
- if ($Query) { $q += "&$Query" }
- if ($cursor) { $q += "&cursor=" + [uri]::EscapeDataString($cursor) }
- $page = Invoke-RestMethod -Uri "$Base/memories?$q" -Headers $headers
- foreach ($m in $page.data) { $all.Add($m) }
- $cursor = $page.next_cursor
- } while ($cursor)
-
- if ($Full) {
- $detailed = foreach ($m in $all) {
- $d = Invoke-RestMethod -Uri "$Base/memories/$($m.id)" -Headers $headers
- if ($d.data) { $d.data } else { $d }
- }
- $all = New-Object System.Collections.Generic.List[object]
- foreach ($d in $detailed) { $all.Add($d) }
- }
- ConvertTo-Json -InputObject ([object[]]$all.ToArray()) -Depth 20
|