@unoverse-platform/studio 0.1.102 → 0.1.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/vendor/sdk/appEngine.tsx
CHANGED
|
@@ -297,10 +297,12 @@ export function AppEngine(cfg: AppConfig) {
|
|
|
297
297
|
});
|
|
298
298
|
};
|
|
299
299
|
|
|
300
|
-
// A PAGE TEMPLATE'S TASK,
|
|
301
|
-
//
|
|
302
|
-
//
|
|
303
|
-
|
|
300
|
+
// A PAGE TEMPLATE'S TASK, called at its own workflow's trigger over REST with the user's
|
|
301
|
+
// token, as any request to a workflow (§5a). `metadata.task` names the task its Task Runner
|
|
302
|
+
// loads. The avatar's press is the first call; the task's submit is the last, carrying the
|
|
303
|
+
// answers as `metadata.submit`, and nothing waits for it (design/tasks.md, "The submit").
|
|
304
|
+
// From the first call the page is in the task.
|
|
305
|
+
const startTask = async (b: Binding, task: string, submit?: Record<string, unknown>) => {
|
|
304
306
|
if (!b.workflow) return;
|
|
305
307
|
setInTask(true);
|
|
306
308
|
const token = getAccessToken ? await getAccessToken() : null;
|
|
@@ -309,12 +311,12 @@ export function AppEngine(cfg: AppConfig) {
|
|
|
309
311
|
headers: { "Content-Type": "application/json", ...(token ? { Authorization: `Bearer ${token}` } : {}) },
|
|
310
312
|
body: JSON.stringify({
|
|
311
313
|
input: {
|
|
312
|
-
message: "Start",
|
|
314
|
+
message: submit ? "Submit" : "Start",
|
|
313
315
|
chatId: conversationId,
|
|
314
316
|
conversationId,
|
|
315
317
|
userId,
|
|
316
318
|
providerId: "gravity-ds",
|
|
317
|
-
metadata: { targetTriggerNode: b.trigger, workflowId: b.workflow, task },
|
|
319
|
+
metadata: { targetTriggerNode: b.trigger, workflowId: b.workflow, task, ...(submit ? { submit } : {}) },
|
|
318
320
|
},
|
|
319
321
|
conversationId,
|
|
320
322
|
}),
|
|
@@ -289,7 +289,7 @@ function PageTemplate({ client, uri, el, voice, waiting, onBinding, onCall, appS
|
|
|
289
289
|
* all of them read and write the app's state in `appStore`, the store the call and the
|
|
290
290
|
* workflow write to. A name one template saves is a name every other template can show.
|
|
291
291
|
*/
|
|
292
|
-
export function PageInterfaces({ org, client, voice, appStore, toServer, startTask }: { org: string; client: UnoverseClient; voice: VoiceService; appStore: ComponentStore; toServer: (t: string, data: Record<string, unknown>, meta?: ActionMeta) => void; startTask: (binding: Binding, task: string) => void }) {
|
|
292
|
+
export function PageInterfaces({ org, client, voice, appStore, toServer, startTask }: { org: string; client: UnoverseClient; voice: VoiceService; appStore: ComponentStore; toServer: (t: string, data: Record<string, unknown>, meta?: ActionMeta) => void; startTask: (binding: Binding, task: string, submit?: Record<string, unknown>) => void }) {
|
|
293
293
|
const [targets, setTargets] = useState<HTMLElement[]>([]);
|
|
294
294
|
// The task in view, by its URI, measured again as the page scrolls or resizes.
|
|
295
295
|
const [inView, setInView] = useState<string | null>(null);
|
|
@@ -307,12 +307,17 @@ export function PageInterfaces({ org, client, voice, appStore, toServer, startTa
|
|
|
307
307
|
// in that workflow is the workflow's own. Nothing in view, or nothing bound: nothing.
|
|
308
308
|
const target = inView && bindings[inView]?.workflow ? inView : null;
|
|
309
309
|
const waiting = !!target && !started.current.has(target);
|
|
310
|
-
// A TEMPLATE'S OWN ACTIONS go where the app's go: its `submit` answers the task
|
|
311
|
-
//
|
|
312
|
-
|
|
310
|
+
// A TEMPLATE'S OWN ACTIONS go where the app's go: its `submit` answers whoever opened the task,
|
|
311
|
+
// exactly as in the app (appEngine `toServer`). A template with its own workflow also has
|
|
312
|
+
// that workflow called with the answers: the submit is the task's last call, and its Task
|
|
313
|
+
// Runner finishes it (design/tasks.md, "The submit"). The call's three are the page's.
|
|
314
|
+
const onCallFor = (uri: string): ActionHandler => (spec, data, meta) => {
|
|
313
315
|
const action = typeof spec === "string" ? spec : spec?.type;
|
|
314
|
-
if (action === "submit" || action === "cancel")
|
|
315
|
-
|
|
316
|
+
if (action === "submit" || action === "cancel") {
|
|
317
|
+
toServer(action, data, meta);
|
|
318
|
+
const state = (meta?.state ?? data) as Record<string, unknown> | undefined;
|
|
319
|
+
if (action === "submit" && bindings[uri]?.workflow && state && typeof state === "object") startTask(bindings[uri], uri, state);
|
|
320
|
+
} else if (action === "startCall") {
|
|
316
321
|
if (!target || started.current.has(target)) return;
|
|
317
322
|
started.current.add(target);
|
|
318
323
|
setStarted((n) => n + 1);
|
|
@@ -376,7 +381,7 @@ export function PageInterfaces({ org, client, voice, appStore, toServer, startTa
|
|
|
376
381
|
{targets.map((el) => {
|
|
377
382
|
const name = el.getAttribute(MARK) ?? "";
|
|
378
383
|
if (!name) return null;
|
|
379
|
-
return createPortal(<PageTemplate client={client} uri={uriOf(name)} el={el} voice={voice} waiting={waiting} onBinding={onBinding} onCall={
|
|
384
|
+
return createPortal(<PageTemplate client={client} uri={uriOf(name)} el={el} voice={voice} waiting={waiting} onBinding={onBinding} onCall={onCallFor(uriOf(name))} appStore={appStore} />, el, name);
|
|
380
385
|
})}
|
|
381
386
|
</>
|
|
382
387
|
);
|