Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

38 строки
1.5KB

  1. <#
  2. Fetch every memory the API key can read (follows next_cursor) and write them as one JSON array to stdout.
  3. $env:AMK_KEY = "amk_..."
  4. scripts\export-memories.ps1 > memories.json
  5. scripts\export-memories.ps1 -Query "status=active&type=semantic" -Full | Out-File memories.json -Encoding utf8
  6. -Full adds the full content of each memory (one GET /memories/:id per item). Base URL: -Base or $env:BASE.
  7. #>
  8. param(
  9. [string]$Query = "",
  10. [switch]$Full,
  11. [string]$Base = $(if ($env:BASE) { $env:BASE } else { "http://localhost:8801/api/v1" }),
  12. [string]$Key = 'amk_734bbd0bd49099ac928a179fbe9ba1c025e796ab93203d4abd9631c2e0517099'
  13. )
  14. $ErrorActionPreference = "Stop"
  15. if (-not $Key) { throw "Set `$env:AMK_KEY (or pass -Key) to an API key." }
  16. $headers = @{ Authorization = "Bearer $Key" }
  17. $all = New-Object System.Collections.Generic.List[object]
  18. $cursor = $null
  19. do {
  20. $q = "limit=100"
  21. if ($Query) { $q += "&$Query" }
  22. if ($cursor) { $q += "&cursor=" + [uri]::EscapeDataString($cursor) }
  23. $page = Invoke-RestMethod -Uri "$Base/memories?$q" -Headers $headers
  24. foreach ($m in $page.data) { $all.Add($m) }
  25. $cursor = $page.next_cursor
  26. } while ($cursor)
  27. if ($Full) {
  28. $detailed = foreach ($m in $all) {
  29. $d = Invoke-RestMethod -Uri "$Base/memories/$($m.id)" -Headers $headers
  30. if ($d.data) { $d.data } else { $d }
  31. }
  32. $all = New-Object System.Collections.Generic.List[object]
  33. foreach ($d in $detailed) { $all.Add($d) }
  34. }
  35. ConvertTo-Json -InputObject ([object[]]$all.ToArray()) -Depth 20

Powered by TurnKey Linux.