@dxos/assistant 0.8.4-main.3a94e84 → 0.8.4-main.5acf9ea

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.
@@ -159,7 +159,7 @@ var AiSession = class {
159
159
  ...this._pending
160
160
  ]);
161
161
  const blueprints = options.blueprints ?? [];
162
- const systemPrompt = yield* pipe2(blueprints, Effect.forEach((blueprint) => DatabaseService.loadRef(blueprint.instructions)), Effect.flatMap(Effect.forEach((template) => DatabaseService.loadRef(template.source))), Effect.map(Array3.map((template) => `
162
+ const systemPrompt = yield* pipe2(blueprints, Effect.forEach((blueprint) => Effect.succeed(blueprint.instructions)), Effect.flatMap(Effect.forEach((template) => DatabaseService.loadRef(template.source))), Effect.map(Array3.map((template) => `
163
163
 
164
164
  <blueprint>${template.content}</blueprint>`)), Effect.map(Array3.reduce(options.systemPrompt ?? "", String.concat)));
165
165
  const blueprintToolkit = yield* ToolResolverService.resolveToolkit(blueprints.flatMap((bp) => bp.tools));
@@ -308,7 +308,7 @@ ${diff}` : ""}</changed-artifact>`).join("\n")}
308
308
  `
309
309
  };
310
310
  };
311
- var ArtifactDiffResolver = class extends Context.Tag("ArtifactDiffResolver")() {
311
+ var ArtifactDiffResolver = class extends Context.Tag("@dxos/assistant/ArtifactDiffResolver")() {
312
312
  };
313
313
  var runTools = Effect.fn("runTools")(function* (toolCalls, toolkit) {
314
314
  const toolkitWithHandlers = Effect.isEffect(toolkit) ? yield* toolkit : toolkit;
@@ -712,8 +712,7 @@ var extractionNerFn = defineFunction2({
712
712
  import { AiTool } from "@effect/ai";
713
713
  import { Context as Context2, Effect as Effect3, Layer, Match, Predicate, Record, Schema as Schema5 } from "effect";
714
714
  import { AiToolNotFoundError, ToolExecutionService as ToolExecutionService2, ToolResolverService as ToolResolverService2 } from "@dxos/ai";
715
- import { todo as todo2 } from "@dxos/debug";
716
- import { FunctionError } from "@dxos/functions";
715
+ import { LocalFunctionExecutionService } from "@dxos/functions";
717
716
  import { invariant as invariant2 } from "@dxos/invariant";
718
717
  var __dxlog_file6 = "/__w/dxos/dxos/packages/core/assistant/src/functions/services.ts";
719
718
  var makeToolResolverFromFunctions = (functions) => {
@@ -728,21 +727,24 @@ var makeToolResolverFromFunctions = (functions) => {
728
727
  });
729
728
  };
730
729
  var makeToolExecutionServiceFromFunctions = (functions) => {
731
- return Layer.succeed(ToolExecutionService2, {
732
- handlersFor: (toolkit) => {
733
- const makeHandler = (tool) => {
734
- return Effect3.fn("toolFunctionHandler")(function* (input) {
735
- const { functionName } = Context2.get(FunctionToolAnnotation)(tool.annotations);
736
- const fnDef = functions.find((f) => f.name === functionName);
737
- if (!fnDef) {
738
- return yield* Effect3.fail(new AiToolNotFoundError(tool.name));
739
- }
740
- return yield* invokeFunction(fnDef, input).pipe(Effect3.catchAllDefect((defect) => Effect3.fail(defect)));
741
- });
742
- };
743
- return toolkit.of(Record.map(toolkit.tools, (tool, name) => makeHandler(tool)));
744
- }
745
- });
730
+ return Layer.effect(ToolExecutionService2, Effect3.gen(function* () {
731
+ const localFunctionExecutionService = yield* LocalFunctionExecutionService;
732
+ return {
733
+ handlersFor: (toolkit) => {
734
+ const makeHandler = (tool) => {
735
+ return Effect3.fn("toolFunctionHandler")(function* (input) {
736
+ const { functionName } = Context2.get(FunctionToolAnnotation)(tool.annotations);
737
+ const fnDef = functions.find((f) => f.name === functionName);
738
+ if (!fnDef) {
739
+ return yield* Effect3.fail(new AiToolNotFoundError(tool.name));
740
+ }
741
+ return yield* localFunctionExecutionService.invokeFunction(fnDef, input).pipe(Effect3.catchAllDefect((defect) => Effect3.fail(defect)));
742
+ });
743
+ };
744
+ return toolkit.of(Record.map(toolkit.tools, (tool, name) => makeHandler(tool)));
745
+ }
746
+ };
747
+ }));
746
748
  };
747
749
  var FunctionToolAnnotation = class extends Context2.Tag("@dxos/assisatnt/FunctionToolAnnotation")() {
748
750
  };
@@ -766,7 +768,7 @@ var makeToolName = (name) => {
766
768
  const toolName = name.replace(/[^a-zA-Z0-9]/g, "");
767
769
  invariant2(toolName.match(/^[a-zA-Z_][a-zA-Z0-9-_]*$/), void 0, {
768
770
  F: __dxlog_file6,
769
- L: 80,
771
+ L: 87,
770
772
  S: void 0,
771
773
  A: [
772
774
  "toolName.match(/^[a-zA-Z_][a-zA-Z0-9-_]*$/)",
@@ -783,45 +785,6 @@ var createStructFieldsFromSchema = (schema) => {
783
785
  ]));
784
786
  }), Match.orElseAbsurd);
785
787
  };
786
- var invokeFunction = (fnDef, input) => Effect3.gen(function* () {
787
- const assertInput = fnDef.inputSchema.pipe(Schema5.asserts);
788
- assertInput(input);
789
- const context = {
790
- getService: () => todo2(),
791
- getSpace: async (_spaceId) => {
792
- throw new Error("Not available. Use the database service instead.");
793
- },
794
- space: void 0,
795
- get ai() {
796
- throw new Error("Not available. Use the ai service instead.");
797
- }
798
- };
799
- const data = yield* Effect3.gen(function* () {
800
- const result = fnDef.handler({
801
- context,
802
- data: input
803
- });
804
- if (Effect3.isEffect(result)) {
805
- return yield* result.pipe(Effect3.orDie);
806
- } else if (typeof result === "object" && result !== null && "then" in result && typeof result.then === "function") {
807
- return yield* Effect3.promise(() => result);
808
- } else {
809
- return result;
810
- }
811
- }).pipe(Effect3.orDie, Effect3.catchAllDefect((defect) => Effect3.die(new FunctionError("Error running function", {
812
- context: {
813
- name: fnDef.name
814
- },
815
- cause: defect
816
- }))));
817
- const assertOutput = fnDef.outputSchema?.pipe(Schema5.asserts);
818
- assertOutput(data);
819
- return data;
820
- }).pipe(Effect3.withSpan("invokeFunction", {
821
- attributes: {
822
- name: fnDef.name
823
- }
824
- }));
825
788
 
826
789
  // src/research/exa.ts
827
790
  import { AiTool as AiTool2, AiToolkit as AiToolkit2 } from "@effect/ai";
@@ -1492,7 +1455,7 @@ var LocalSearchHandler = LocalSearchToolkit.toLayer({
1492
1455
  `;
1493
1456
  })
1494
1457
  });
1495
- var GraphWriterSchema = class extends Context3.Tag("GraphWriterSchema")() {
1458
+ var GraphWriterSchema = class extends Context3.Tag("@dxos/assistant/GraphWriterSchema")() {
1496
1459
  };
1497
1460
  var makeGraphWriterToolkit = ({ schema }) => {
1498
1461
  return AiToolkit3.make(AiTool3.make("graph_writer", {