UNPKG

trellis

Version:

Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications

65 lines (63 loc) 1.56 kB
import { entityMutations } from "../chunk-USEINYUL.js"; import { liveEntities, liveEntity } from "../chunk-J3WYZO3Q.js"; import "../chunk-JUEMDWLU.js"; import "../chunk-UBGUDMUV.js"; import "../chunk-2ESYSVXG.js"; // src/vue/schema-hooks.ts import { computed, onScopeDispose, shallowRef } from "vue"; function parseReadOptions(opts) { if (!opts) return {}; if ("resolve" in opts || "where" in opts) return opts; return { where: opts }; } function useLive(client, schema, opts) { const res = liveEntities(client, schema, opts); const state = shallowRef(res.signal.peek()); const off = res.signal.subscribe((v) => { state.value = v; }); const stop = res.start(); onScopeDispose(() => { off(); stop(); }); return state; } function useEntities(client, schema, opts) { const state = useLive(client, schema, parseReadOptions(opts)); return computed(() => ({ data: state.value.data, loading: state.value.loading, error: state.value.error })); } function useEntity(client, schema, id, opts) { const res = liveEntity(client, schema, id, opts); const state = shallowRef(res.signal.peek()); const off = res.signal.subscribe((v) => { state.value = v; }); const stop = res.start(); onScopeDispose(() => { off(); stop(); }); return computed(() => ({ data: state.value.data, loading: state.value.loading, error: state.value.error })); } function useMutation(client, schema) { return entityMutations(client, schema); } export { useEntities, useEntity, useMutation };