$ cat node-template.py
L
List Artifacts
// List all Artifact ids on a Drive item (a Drive item can have many artifacts). Feed each id into Get Artifact to read its content.
Input
Storage
#artifact#document#list
template.py
1"""list-artifacts — list every Artifact id on a Drive item.23A Drive item (folder/Knowledge Base or document) can carry many artifacts — one4per generation run — so reading them needs an enumeration step first. This node5returns all artifact ids (via Gais.artifact.list, reusing the www-emblema6Artifact list API with the per-execution USER_TOKEN); fan each id into a Get7Artifact node, which takes only an artifact id and resolves its parent itself.89Imports no HTTP client — all privileged IO is in gais.backends._artifact.10"""1112from __future__ import annotations1314import json15import re16import sys17import traceback18from typing import Any1920from gais import Gais2122_UUID_RE = re.compile(23 r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",24 re.IGNORECASE,25)262728def _normalize_uuid(value: Any, field: str) -> str:29 """Accept a bare UUID or a ``mention://.../<uuid>`` URI; validate as UUID."""30 if not isinstance(value, str):31 raise ValueError(f"{field} must be a string, got {type(value).__name__}")32 s = value.strip()33 if "://" in s:34 s = s.rsplit("/", 1)[-1]35 if not _UUID_RE.match(s):36 raise ValueError(f"{field} is not a valid UUID: {value!r}")37 return s383940def process(inputs: dict[str, Any]) -> dict[str, Any]:41 drive_item_id = _normalize_uuid(inputs.get("driveItemId"), "driveItemId")4243 result = Gais.artifact.list(drive_item_id=drive_item_id)44 items = result.data.get("items", [])45 artifact_ids = [46 item["id"]47 for item in items48 if isinstance(item, dict) and item.get("id")49 ]5051 print(52 f"[list-artifacts] kb={drive_item_id} found={len(artifact_ids)}",53 file=sys.stderr,54 )5556 return {"artifactIds": artifact_ids}575859def main() -> None:60 try:61 envelope = json.loads(sys.stdin.read() or "{}")62 if not isinstance(envelope, dict):63 envelope = {}64 inputs = envelope.get("inputs", {}) or {}65 json.dump(process(inputs), sys.stdout)66 except Exception as e:67 print(68 json.dumps({69 "error": str(e),70 "errorType": type(e).__name__,71 "traceback": traceback.format_exc(),72 }),73 file=sys.stderr,74 )75 sys.exit(1)767778if __name__ == "__main__":79 main()80$ git log --oneline
v1.1.0
HEAD
2026-06-12