gizlang:signin
the giz.ai sign-in that giz auth login saves, shared by the command line and gizai's "giz:" models: the credentials file, the OAuth device exchange, and the model API of a signed-in account.
import * as Signin from "gizlang:signin";Types
Failure
type Failure = { message: string; hint: string; status: i64; code: string; }Why a giz.ai account request failed: the message, a hint of what to do, the HTTP status (0: none) and the OAuth error code.
message:stringhint:stringstatus:i64code:string
Auth
type Auth = { token: string; base: string; }A bearer token and the giz.ai address it is for.
token:stringbase:string
Reply
type Reply = { status: i64; headers: Vec<Http.Header>; body: bytes; }An HTTP answer read whole.
status:i64headers:Vec<gizlang_http.Header>body:bytes
Listed
type Listed = { id: string; kind: string; tools: bool; context: i64; }A model an API lists: its id, its type ("language" for a chat model; "" when the API does not say) and whether it takes tools ("tools" in its supported_parameters; true when the API does not say), and its context window in tokens (0: the API does not say).
id:stringkind:stringtools:boolcontext:i64
Functions
send
function send(sys: System, method: string, url: string, headers: Vec<Http.Header>, body: bytes): Result<Reply, Failure>METHOD URL with HEADERS and BODY, its answer read whole.
Effects: fail, read, write, console, io.
postForm
function postForm(sys: System, url: string, names: Vec<string>, values: Vec<string>): Result<Reply, Failure>POST URL with the form NAMES = VALUES.
Effects: fail, read, write, console, io.
trimmedUrl
function trimmedUrl(url: string): stringURL without its trailing slashes.
Effects: fail.
credentialsPath
function credentialsPath(sys: System): stringThe credentials file: GIZ_CONFIG, else ~/.config/giz/credentials.json.
Effects: fail, io.
readCredentials
function readCredentials(sys: System): Result<Option<JsonValue>, Failure>The saved sign-in; none when there is no file.
Effects: fail, io.
lockCredentials
function lockCredentials(sys: System): Result<bool, Failure>proper-lockfile's lock, which the JavaScript CLI 2.0 takes too: the directory FILE.lock, stale after 10 s.
Effects: fail, io.
unlockCredentials
function unlockCredentials(sys: System): voidRemoves the lock on the credentials file that the last lockCredentials took.
Effects: fail, io.
writeCredentials
function writeCredentials(sys: System, config: Option<JsonValue>): Result<bool, Failure>Saves CONFIG (owner-only), or removes the file for none.
Effects: fail, read, write, console, io.
discovery
function discovery(sys: System, base: string): Result<JsonValue, Failure>The OAuth server metadata of BASE.
Effects: fail, read, write, console, io.
exchange
function exchange(sys: System, base: string, meta: JsonValue, resource: string, names: Vec<string>, values: Vec<string>, config: JsonValue): Result<JsonValue, Failure>CONFIG after a token grant (NAMES = VALUES) for RESOURCE, as CLI 2.0's exchangeToken records it.
Effects: fail, read, write, console, io.
gizBase
function gizBase(sys: System, computer: bool): stringThe giz.ai address to use: GIZ_URL, else the saved sign-in's, else (with COMPUTER) the Computer identity's, else giz.ai.
Effects: fail, read, write, console, io.
credentials
function credentials(sys: System, base: string, rejected: string): Result<Auth, Failure>The bearer for BASE: GIZ_TOKEN, else the saved sign-in (refreshed under the lock when it is expired or REJECTED), else the Computer's identity.
Effects: fail, read, write, console, io.
gizstackToken
function gizstackToken(sys: System): Result<Option<string>, string>GizStack's access token from the saved giz.ai sign-in: the refresh token's grant for https://gizstack.com, kept until a minute before it expires. None without a sign-in.
Effects: fail, read, write, console, io.
computerIdentity
function computerIdentity(sys: System): Result<Option<Auth>, Failure>The Computer's own identity, asked of the identity socket (never a path from options or the environment); none outside a Giz Computer.
Effects: fail, read, write, console, io.
gizApi
function gizApi(sys: System, base: string, pool: Http.Pool): ModelApi throws stringgiz.ai's OpenAI-compatible API (BASE/v1) with the account's bearer, refreshed when it has expired; through POOL.
Effects: fail, read, write, console, io.
listModels
function listModels(c: ModelApi): Vec<Listed> throws stringThe models c offers (GET /models), in its order.
Effects: fail, read, write, console, io.
signedIn
function signedIn(sys: System): boolWhether a giz.ai account is at hand: GIZ_TOKEN, or a sign-in giz auth login saved.
Effects: fail, io.
Constants
GIZ_URL
const GIZ_URL = "https://www.giz.ai"giz.ai's address when neither GIZ_URL nor a sign-in names one.
GIZ_CLIENT
const GIZ_CLIENT = "giz-cli"The OAuth client of giz auth login.
GIZSTACK
const GIZSTACK = "https://gizstack.com"GizStack, whose access token comes from the same giz.ai sign-in.