@taskyon/tyclient 0.4.5 → 0.4.6

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.
@@ -400,7 +400,12 @@ export declare function createTool<T, SCHEMA extends Readonly<JSONSchema>, PARAM
400
400
  parameters: SCHEMA;
401
401
  function?: (params: PARAMS, context: toolContext) => unknown;
402
402
  } & Omit<InternalTool$1, "function" | "parameters">): T;
403
- export declare function initializeTaskyon(tools: ClientTool[], configuration: partialTyConfiguration, persist?: boolean): Promise<void>;
403
+ export declare function initializeTaskyon(options: {
404
+ name?: string;
405
+ persist?: boolean;
406
+ tools: ClientTool[];
407
+ configuration: partialTyConfiguration;
408
+ }): Promise<void>;
404
409
  export declare function makeTaskResult(tasks: partialTaskDraft | partialTaskDraft[] | partialTaskDraft[][]): taskResult;
405
410
  export declare function toolCall(f: FunctionCall): partialTaskDraft & {
406
411
  content: {
@@ -11286,9 +11286,9 @@ const waitForApiChannel = (iframe) => {
11286
11286
  if (stopped) return;
11287
11287
  const channel = new MessageChannel();
11288
11288
  const targetOrigin = new URL(iframe.src, location.href).origin || "*";
11289
- console.log("establish iframe communication to", targetOrigin);
11289
+ console.log("tyclient establishing iframe communication to", targetOrigin);
11290
11290
  const handleFirst = (ev) => {
11291
- console.log("received first message from taskyon!", ev);
11291
+ console.log("tyclient received first message from taskyon!", ev);
11292
11292
  stopped = true;
11293
11293
  channel.port1.removeEventListener("message", handleFirst);
11294
11294
  clearTimeout(retryTimer);
@@ -11312,8 +11312,8 @@ const waitForApiChannel = (iframe) => {
11312
11312
  });
11313
11313
  };
11314
11314
  const handleFunctionExecutionRequest = (tools, sendTyMessage, stopSignal) => async function(event) {
11315
- console.log("received message:", event);
11316
- const tool = tools[0];
11315
+ console.log("tyclient received message:", event);
11316
+ const tool = tools[event.data.functionName];
11317
11317
  if (tool && event.data && event.data.type === "functionCall") {
11318
11318
  await handleFunctionExecution(event, tool, sendTyMessage, stopSignal);
11319
11319
  }
@@ -11323,12 +11323,12 @@ async function handleFunctionExecution(event, tool, sendTyMessage, stopSignal) {
11323
11323
  const result = await tool.function(data.arguments, {
11324
11324
  taskChain: [],
11325
11325
  getSecret: (name) => {
11326
- console.log("get secret name", name);
11326
+ console.log("tyclient get secret name", name);
11327
11327
  return Promise.resolve("N/A");
11328
11328
  },
11329
11329
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
11330
11330
  setSecret: (name, _value) => {
11331
- console.log("set secret name", name);
11331
+ console.log("tyclient set secret name", name);
11332
11332
  return Promise.resolve();
11333
11333
  },
11334
11334
  stopSignal,
@@ -11340,30 +11340,39 @@ async function handleFunctionExecution(event, tool, sendTyMessage, stopSignal) {
11340
11340
  response: result
11341
11341
  });
11342
11342
  }
11343
- async function initializeTaskyon(tools, configuration, persist) {
11344
- console.log("initialize taskyon client...");
11343
+ async function initializeTaskyon(options) {
11344
+ console.log("initialize taskyon tyclient...");
11345
+ const toolMap = options.tools.reduce((p, c) => {
11346
+ p[c.name] = c;
11347
+ return p;
11348
+ }, {});
11345
11349
  const taskyon = document.getElementById("taskyon");
11346
11350
  const controller = new AbortController();
11347
11351
  if (taskyon !== null && taskyon.tagName === "IFRAME" && taskyon.contentWindow !== null) {
11348
11352
  console.log("make sure, we can ");
11349
11353
  const tyApi = await waitForApiChannel(taskyon);
11350
- const send = (msg) => tyApi.postMessage(safeClone(msg));
11351
- console.log("send our configuration!");
11354
+ const send = (msg) => {
11355
+ console.log("tyclient sending", msg);
11356
+ tyApi.postMessage(safeClone(msg));
11357
+ };
11358
+ console.log("tyclient send our configuration!");
11352
11359
  send({
11353
11360
  type: "configurationMessage",
11354
- conf: configuration,
11355
- persist
11361
+ conf: options.configuration,
11362
+ persist: options.persist,
11363
+ origin: window.location.origin,
11364
+ peerId: options == null ? void 0 : options.name
11356
11365
  });
11357
- console.log("sending our functions!");
11358
- tools.forEach((t) => {
11366
+ console.log("tyclient sending our functions!");
11367
+ options.tools.forEach((t) => {
11359
11368
  const { function: _toolfunc, ...fdescr } = t;
11360
11369
  send({
11361
11370
  type: "functionDescription",
11362
11371
  ...fdescr
11363
11372
  });
11364
- console.log("set up function listener!");
11373
+ console.log("tyclient set up function listener!");
11365
11374
  tyApi.onmessage = (event) => {
11366
- void handleFunctionExecutionRequest(tools, send, controller.signal)(event);
11375
+ void handleFunctionExecutionRequest(toolMap, send, controller.signal)(event);
11367
11376
  };
11368
11377
  });
11369
11378
  }
@@ -11290,9 +11290,9 @@ TODO: define onwership types..`),
11290
11290
  if (stopped) return;
11291
11291
  const channel = new MessageChannel();
11292
11292
  const targetOrigin = new URL(iframe.src, location.href).origin || "*";
11293
- console.log("establish iframe communication to", targetOrigin);
11293
+ console.log("tyclient establishing iframe communication to", targetOrigin);
11294
11294
  const handleFirst = (ev) => {
11295
- console.log("received first message from taskyon!", ev);
11295
+ console.log("tyclient received first message from taskyon!", ev);
11296
11296
  stopped = true;
11297
11297
  channel.port1.removeEventListener("message", handleFirst);
11298
11298
  clearTimeout(retryTimer);
@@ -11316,8 +11316,8 @@ TODO: define onwership types..`),
11316
11316
  });
11317
11317
  };
11318
11318
  const handleFunctionExecutionRequest = (tools, sendTyMessage, stopSignal) => async function(event) {
11319
- console.log("received message:", event);
11320
- const tool = tools[0];
11319
+ console.log("tyclient received message:", event);
11320
+ const tool = tools[event.data.functionName];
11321
11321
  if (tool && event.data && event.data.type === "functionCall") {
11322
11322
  await handleFunctionExecution(event, tool, sendTyMessage, stopSignal);
11323
11323
  }
@@ -11327,12 +11327,12 @@ TODO: define onwership types..`),
11327
11327
  const result = await tool.function(data.arguments, {
11328
11328
  taskChain: [],
11329
11329
  getSecret: (name) => {
11330
- console.log("get secret name", name);
11330
+ console.log("tyclient get secret name", name);
11331
11331
  return Promise.resolve("N/A");
11332
11332
  },
11333
11333
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
11334
11334
  setSecret: (name, _value) => {
11335
- console.log("set secret name", name);
11335
+ console.log("tyclient set secret name", name);
11336
11336
  return Promise.resolve();
11337
11337
  },
11338
11338
  stopSignal,
@@ -11344,30 +11344,39 @@ TODO: define onwership types..`),
11344
11344
  response: result
11345
11345
  });
11346
11346
  }
11347
- async function initializeTaskyon(tools, configuration, persist) {
11348
- console.log("initialize taskyon client...");
11347
+ async function initializeTaskyon(options) {
11348
+ console.log("initialize taskyon tyclient...");
11349
+ const toolMap = options.tools.reduce((p, c) => {
11350
+ p[c.name] = c;
11351
+ return p;
11352
+ }, {});
11349
11353
  const taskyon = document.getElementById("taskyon");
11350
11354
  const controller = new AbortController();
11351
11355
  if (taskyon !== null && taskyon.tagName === "IFRAME" && taskyon.contentWindow !== null) {
11352
11356
  console.log("make sure, we can ");
11353
11357
  const tyApi = await waitForApiChannel(taskyon);
11354
- const send = (msg) => tyApi.postMessage(safeClone(msg));
11355
- console.log("send our configuration!");
11358
+ const send = (msg) => {
11359
+ console.log("tyclient sending", msg);
11360
+ tyApi.postMessage(safeClone(msg));
11361
+ };
11362
+ console.log("tyclient send our configuration!");
11356
11363
  send({
11357
11364
  type: "configurationMessage",
11358
- conf: configuration,
11359
- persist
11365
+ conf: options.configuration,
11366
+ persist: options.persist,
11367
+ origin: window.location.origin,
11368
+ peerId: options == null ? void 0 : options.name
11360
11369
  });
11361
- console.log("sending our functions!");
11362
- tools.forEach((t) => {
11370
+ console.log("tyclient sending our functions!");
11371
+ options.tools.forEach((t) => {
11363
11372
  const { function: _toolfunc, ...fdescr } = t;
11364
11373
  send({
11365
11374
  type: "functionDescription",
11366
11375
  ...fdescr
11367
11376
  });
11368
- console.log("set up function listener!");
11377
+ console.log("tyclient set up function listener!");
11369
11378
  tyApi.onmessage = (event) => {
11370
- void handleFunctionExecutionRequest(tools, send, controller.signal)(event);
11379
+ void handleFunctionExecutionRequest(toolMap, send, controller.signal)(event);
11371
11380
  };
11372
11381
  });
11373
11382
  }