@taskyon/tyclient 0.5.0 → 0.5.2
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/dist/tyclient.d.mts +479 -372
- package/dist/tyclient.d.ts +479 -372
- package/dist/tyclient.js +75 -62
- package/dist/tyclient.js.map +1 -1
- package/dist/tyclient.mjs +75 -62
- package/dist/tyclient.mjs.map +1 -1
- package/package.json +1 -1
package/dist/tyclient.js
CHANGED
|
@@ -135,22 +135,19 @@ with the function name.`
|
|
|
135
135
|
// ../taskyon/src/types/node.ts
|
|
136
136
|
var Annotation = z3__default.default.union([
|
|
137
137
|
z3__default.default.object({
|
|
138
|
-
type: z3__default.default.literal("
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}),
|
|
138
|
+
type: z3__default.default.literal("url"),
|
|
139
|
+
id: z3__default.default.string(),
|
|
140
|
+
end_index: z3__default.default.number(),
|
|
141
|
+
start_index: z3__default.default.number(),
|
|
142
|
+
title: z3__default.default.string(),
|
|
143
|
+
url: z3__default.default.string(),
|
|
144
|
+
content: z3__default.default.string()
|
|
145
|
+
}).partial().required({ type: true }),
|
|
147
146
|
z3__default.default.object({
|
|
148
|
-
type: z3__default.default.literal("
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}).array().optional()
|
|
153
|
-
})
|
|
147
|
+
type: z3__default.default.literal("document"),
|
|
148
|
+
text: z3__default.default.string().optional(),
|
|
149
|
+
content: z3__default.default.string().optional()
|
|
150
|
+
}).partial().required({ type: true })
|
|
154
151
|
]);
|
|
155
152
|
var MessageContent = z3__default.default.object({
|
|
156
153
|
type: z3__default.default.literal("message"),
|
|
@@ -601,19 +598,19 @@ function MessageChannelBridge(dport, mport) {
|
|
|
601
598
|
|
|
602
599
|
// ../taskyon/src/api/index.ts
|
|
603
600
|
var createChatCompletionTask = (args) => toolCall({ name: "chatCompletion", arguments: args });
|
|
604
|
-
var
|
|
601
|
+
var sendTasks = (tyPort) => async (taskList, opts) => {
|
|
605
602
|
const tasks = await forgeTaskChain(taskList);
|
|
606
603
|
tyPort.send({
|
|
607
604
|
type: "tasks",
|
|
608
605
|
tasks,
|
|
609
606
|
execute: true,
|
|
610
|
-
show: true,
|
|
607
|
+
show: opts.show ?? true,
|
|
611
608
|
// we want to show this task in our GUI as a succesful test
|
|
612
|
-
origin:
|
|
609
|
+
origin: window.origin
|
|
613
610
|
});
|
|
614
611
|
const initialIds = tasks.map((t) => t.id);
|
|
615
612
|
const subTasks = new Set(initialIds);
|
|
616
|
-
const
|
|
613
|
+
const subTaskStream = tyPort.receive.narrow((m) => {
|
|
617
614
|
console.log("api received", m);
|
|
618
615
|
if (m.type === "taskCreated" && "task" in m && !!m.task?.id && !!m.task?.parentID && subTasks.has(m.task?.parentID)) {
|
|
619
616
|
subTasks.add(m.task?.id);
|
|
@@ -621,12 +618,19 @@ var processTasks = (tyPort) => async (taskList, opts) => {
|
|
|
621
618
|
}
|
|
622
619
|
return false;
|
|
623
620
|
}).map((msg) => msg.task);
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
621
|
+
return { initialIds, subTaskStream };
|
|
622
|
+
};
|
|
623
|
+
var processTasks = (tyPort) => {
|
|
624
|
+
const send = sendTasks(tyPort);
|
|
625
|
+
return async (taskList, quitCondition, opts) => {
|
|
626
|
+
const { subTaskStream } = await send(taskList, opts);
|
|
627
|
+
const condition = typeof quitCondition === "string" ? subTaskStream.filter((t) => t.content.type === quitCondition) : typeof quitCondition === "object" && Array.isArray(quitCondition) ? subTaskStream.filter((t) => quitCondition.includes(t.content.type)) : subTaskStream.filter(quitCondition);
|
|
628
|
+
const unsub = condition((m) => console.log("received matching message on port:", m));
|
|
629
|
+
const lastMsg = await condition.wait(opts);
|
|
630
|
+
console.log("finished processin all tasks!");
|
|
631
|
+
unsub();
|
|
632
|
+
return lastMsg;
|
|
633
|
+
};
|
|
630
634
|
};
|
|
631
635
|
|
|
632
636
|
// src/index.ts
|
|
@@ -644,7 +648,6 @@ var waitForApiChannel = (iframe) => {
|
|
|
644
648
|
if (stopped) return;
|
|
645
649
|
const channel = new MessageChannel();
|
|
646
650
|
const targetOrigin = new URL(iframe.src, location.href).origin || "*";
|
|
647
|
-
console.log("tyclient establishing iframe communication to", targetOrigin);
|
|
648
651
|
const handleFirst = (ev) => {
|
|
649
652
|
console.log("tyclient received first message from taskyon!", ev);
|
|
650
653
|
stopped = true;
|
|
@@ -692,48 +695,58 @@ async function initializeTaskyon(options) {
|
|
|
692
695
|
p[c.name] = c;
|
|
693
696
|
return p;
|
|
694
697
|
}, {});
|
|
695
|
-
const taskyon = document.getElementById("taskyon");
|
|
698
|
+
const taskyon = document.getElementById(options.iframeId ?? "taskyon");
|
|
696
699
|
const controller = new AbortController();
|
|
697
700
|
const { x: clientSidePort, y: towardsIframe } = createDuplexChannel();
|
|
698
|
-
if (taskyon
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
701
|
+
if (!taskyon || taskyon.tagName !== "IFRAME" || taskyon.contentWindow === null)
|
|
702
|
+
throw new Error(`we could not find the taskyon iframe with id: ${options.iframeId}`);
|
|
703
|
+
console.log("make sure, we can ");
|
|
704
|
+
const iframeMessagePort = await waitForApiChannel(taskyon);
|
|
705
|
+
MessageChannelBridge(towardsIframe, iframeMessagePort);
|
|
706
|
+
const send = (msg) => {
|
|
707
|
+
console.log("tyclient sending", msg);
|
|
708
|
+
clientSidePort.send(safeClone(msg));
|
|
709
|
+
};
|
|
710
|
+
console.log("tyclient send our configuration!");
|
|
711
|
+
send({
|
|
712
|
+
type: "configurationMessage",
|
|
713
|
+
conf: options.configuration,
|
|
714
|
+
persist: options.persist,
|
|
715
|
+
origin: window.location.origin,
|
|
716
|
+
peerId: options?.name
|
|
717
|
+
});
|
|
718
|
+
console.log("tyclient sending our functions!");
|
|
719
|
+
options.tools.forEach((t) => {
|
|
720
|
+
const { function: _toolfunc, ...fdescr } = t;
|
|
707
721
|
send({
|
|
708
|
-
type: "
|
|
709
|
-
|
|
710
|
-
persist: options.persist,
|
|
711
|
-
origin: window.location.origin,
|
|
712
|
-
peerId: options?.name
|
|
722
|
+
type: "functionDescription",
|
|
723
|
+
...fdescr
|
|
713
724
|
});
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
});
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
const tool = toolMap[msg.functionName];
|
|
726
|
-
if (tool) {
|
|
727
|
-
const res = await handleFunctionExecution(msg.arguments ?? {}, tool, controller.signal);
|
|
728
|
-
send({ type: "functionResponse", functionName: tool.name, response: res });
|
|
729
|
-
console.log("tyclient tool send functionResponse to iframe", res, tool);
|
|
730
|
-
}
|
|
731
|
-
});
|
|
732
|
-
}
|
|
725
|
+
});
|
|
726
|
+
console.log("tyclient set up function listener!");
|
|
727
|
+
clientSidePort.receive((msg) => console.log("tyclient received message", msg));
|
|
728
|
+
clientSidePort.receive.narrow((msg) => msg.type === "functionCall")(async (msg) => {
|
|
729
|
+
const tool = toolMap[msg.functionName];
|
|
730
|
+
if (tool) {
|
|
731
|
+
const res = await handleFunctionExecution(msg.arguments ?? {}, tool, controller.signal);
|
|
732
|
+
send({ type: "functionResponse", functionName: tool.name, response: res });
|
|
733
|
+
console.log("tyclient tool send functionResponse to iframe", res, tool);
|
|
734
|
+
}
|
|
735
|
+
});
|
|
733
736
|
return {
|
|
734
|
-
|
|
737
|
+
sendTasks: sendTasks(clientSidePort),
|
|
738
|
+
waitForTaskResult: processTasks(clientSidePort),
|
|
735
739
|
port: clientSidePort,
|
|
736
|
-
sendFile: (file) => sendFile(clientSidePort.send)(file)
|
|
740
|
+
sendFile: (file) => sendFile(clientSidePort.send)(file),
|
|
741
|
+
reconfigure: (options2) => {
|
|
742
|
+
send({
|
|
743
|
+
type: "configurationMessage",
|
|
744
|
+
conf: options2.configuration,
|
|
745
|
+
persist: options2.persist,
|
|
746
|
+
origin: window.location.origin,
|
|
747
|
+
peerId: options2?.name
|
|
748
|
+
});
|
|
749
|
+
}
|
|
737
750
|
};
|
|
738
751
|
}
|
|
739
752
|
|