query
Import
Section titled “Import”import * as api from "@fungi.computer/agar/query";Exports
Section titled “Exports”| Kind | Export | Description |
|---|---|---|
| type alias | FeedSnapshot | A feed can lose its connection without losing its last owner snapshot. |
| type alias | FeedWatch | Start a live feed, calling onChange with each snapshot until signal aborts;
the returned (or resolved) Disposer tears it down. |
| type alias | QueryApp | The App-owned identity and grants needed by the query integration. |
| constant | queryKeys | Cache identity belongs to an App surface and its selected Computer. |
| function | useFeedQuery() | Query owns sharing and teardown; Effect supplies a bounded latest-snapshot queue. |
| function | createQueryClient() | App defaults and grant lifetime binding, using the host’s ordinary cache. |
| function | capabilityQuery() | Decode capabilities through their owner; Query owns cancellation and retries. |
| function | optimisticMutation() | Optimistic writes for one cache entry, followed by owner reconciliation. Apply must return new data. Concurrent writes to this key run in order; queued writes wait for reconciliation instead of stacking rollback snapshots. |
| function | useMemberInbox() | One shared inbox watch; reloads and stream failures retain the last live rows. |
FeedSnapshottype alias
Section titled “FeedSnapshot”type FeedSnapshot<T> = | Readonly<{ status: "live"; data: T; }> | Readonly<{ status: "loading" | "error"; data?: T; }>;A feed can lose its connection without losing its last owner snapshot.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
FeedWatchtype alias
Section titled “FeedWatch”type FeedWatch<T> = (onChange, signal) => Disposer | Promise<Disposer>;Start a live feed, calling onChange with each snapshot until signal aborts;
the returned (or resolved) Disposer tears it down.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
onChange |
(snapshot) => void |
signal |
AbortSignal |
Returns
Section titled “Returns”| Disposer |
Promise<Disposer>
QueryApptype alias
Section titled “QueryApp”type QueryApp = Pick<AppRoot, "identity" | "context" | "capabilities">;The App-owned identity and grants needed by the query integration.
queryKeysconstant
Section titled “queryKeys”const queryKeys: object;Cache identity belongs to an App surface and its selected Computer.
Type Declaration
Section titled “Type Declaration”| Name | Type | Description |
|---|---|---|
of() |
(app, …parts) => readonly [string | null, string | null, unknown] |
Build a cache key scoped to this App’s surface and its currently selected Computer, followed by the given key parts. |
useFeedQuery()function
Section titled “useFeedQuery()”function useFeedQuery<T>( queryKey, watch, options?,): UseQueryResult<FeedSnapshot<T>, AppError>;Query owns sharing and teardown; Effect supplies a bounded latest-snapshot queue.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
queryKey |
readonly unknown[] |
watch |
FeedWatch<T> |
options |
{ enabled?: boolean; meta?: Record<string, unknown>; } |
options.enabled? |
boolean |
options.meta? |
Record<string, unknown> |
Returns
Section titled “Returns”UseQueryResult<FeedSnapshot<T>,
AppError>
createQueryClient()function
Section titled “createQueryClient()”function createQueryClient(): QueryClient;App defaults and grant lifetime binding, using the host’s ordinary cache.
Returns
Section titled “Returns”QueryClient
capabilityQuery()function
Section titled “capabilityQuery()”function capabilityQuery<H, T>( app, contract, queryKey, run,): OmitKeyof<UseQueryOptions<T, AppError, T, readonly unknown[]>, "queryFn"> & object & QueryKeyWithDataTag<readonly unknown[], T, AppError>;Decode capabilities through their owner; Query owns cancellation and retries.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
H |
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
app |
QueryApp | null |
contract |
CapabilityContract<H> |
queryKey |
readonly unknown[] |
run |
(handle, signal) => Promise<T> |
Returns
Section titled “Returns”OmitKeyof<UseQueryOptions<T, AppError, T,
readonly unknown[]>, "queryFn"> & object &
QueryKeyWithDataTag<readonly unknown[], T,
AppError>
optimisticMutation()function
Section titled “optimisticMutation()”function optimisticMutation<TData, TVars, TResult>( options,): WithRequired< UseMutationOptions< TResult, AppError, TVars, | { previous: TData; optimistic: TData | undefined; } | undefined >, "mutationKey">;Optimistic writes for one cache entry, followed by owner reconciliation. Apply must return new data. Concurrent writes to this key run in order; queued writes wait for reconciliation instead of stacking rollback snapshots.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
TData |
- |
TVars |
- |
TResult |
unknown |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
{ queryKey: readonly unknown[]; mutationFn: MutationFunction<TResult, TVars>; apply: (previous, variables) => TData; } |
options.queryKey |
readonly unknown[] |
options.mutationFn |
MutationFunction<TResult, TVars> |
options.apply |
(previous, variables) => TData |
Returns
Section titled “Returns”WithRequired<UseMutationOptions<TResult,
AppError, TVars, | { previous: TData;
optimistic: TData | undefined; } | undefined>, "mutationKey">
useMemberInbox()function
Section titled “useMemberInbox()”function useMemberInbox(app): object;One shared inbox watch; reloads and stream failures retain the last live rows.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
app |
QueryApp | null |
Returns
Section titled “Returns”| Name | Type | Default value | Description |
|---|---|---|---|
items |
readonly ( | { agentId: string; sessionId: string; title: string; triggerId?: string; createdAt: number; lastActivityAt: number; settledAt?: number; visitedAt?: number; state: "running" | "done" | "needs_you" | "errored"; } | { agentId: string; sessionId: string; state: "unavailable"; } | { kind: "workflow-review"; key: { runId: string; nodeId: string; iteration: string; }; installationId: string; workflowId: string | null; workflowTitle: string; reviewTitle: string; reviewers: "runner" | "owners"; show: readonly Json[]; choices?: readonly string[]; openedAt: number; expiresAt: number; state: "pending" | "answered" | "closed" | "delivered" | "timed_out"; })[] |
- | - |
status |
"error" | "loading" | "live" |
- | - |
error |
AppError | null |
query.error |
- |
refresh() |
() => void |
- | Restart the inbox watch; use after a change that the live feed would not otherwise observe. |
visit() |
(agentId, sessionId) => Promise<void> |
- | Record that the member visited one agent session, so the inbox can clear its unread state for it. |