effect-assistant 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +22 -2
- package/dist/AppEvent.d.ts +111 -0
- package/dist/AppEvent.d.ts.map +1 -0
- package/dist/AppEvent.js +71 -0
- package/dist/AppEvent.js.map +1 -0
- package/dist/Assistant.d.ts +403 -0
- package/dist/Assistant.d.ts.map +1 -0
- package/dist/Assistant.js +126 -0
- package/dist/Assistant.js.map +1 -0
- package/dist/AssistantActivity.d.ts +85 -0
- package/dist/AssistantActivity.d.ts.map +1 -0
- package/dist/AssistantActivity.js +105 -0
- package/dist/AssistantActivity.js.map +1 -0
- package/dist/AssistantEngine.d.ts +116 -0
- package/dist/AssistantEngine.d.ts.map +1 -0
- package/dist/AssistantEngine.js +255 -0
- package/dist/AssistantEngine.js.map +1 -0
- package/dist/AssistantEvent.d.ts +551 -0
- package/dist/AssistantEvent.d.ts.map +1 -0
- package/dist/AssistantEvent.js +473 -0
- package/dist/AssistantEvent.js.map +1 -0
- package/dist/AssistantLoop.d.ts +173 -0
- package/dist/AssistantLoop.d.ts.map +1 -0
- package/dist/AssistantLoop.js +111 -0
- package/dist/AssistantLoop.js.map +1 -0
- package/dist/AssistantToolCall.d.ts +32 -0
- package/dist/AssistantToolCall.d.ts.map +1 -0
- package/dist/AssistantToolCall.js +37 -0
- package/dist/AssistantToolCall.js.map +1 -0
- package/dist/Block.d.ts +69 -0
- package/dist/Block.d.ts.map +1 -0
- package/dist/Block.js +39 -0
- package/dist/Block.js.map +1 -0
- package/dist/BlockKit.d.ts +180 -0
- package/dist/BlockKit.d.ts.map +1 -0
- package/dist/BlockKit.js +148 -0
- package/dist/BlockKit.js.map +1 -0
- package/dist/ChatId.d.ts +31 -0
- package/dist/ChatId.d.ts.map +1 -0
- package/dist/ChatId.js +36 -0
- package/dist/ChatId.js.map +1 -0
- package/dist/ChatLog.d.ts +109 -0
- package/dist/ChatLog.d.ts.map +1 -0
- package/dist/ChatLog.js +177 -0
- package/dist/ChatLog.js.map +1 -0
- package/dist/ChatView.d.ts +408 -0
- package/dist/ChatView.d.ts.map +1 -0
- package/dist/ChatView.js +443 -0
- package/dist/ChatView.js.map +1 -0
- package/dist/Chats.d.ts +110 -0
- package/dist/Chats.d.ts.map +1 -0
- package/dist/Chats.js +98 -0
- package/dist/Chats.js.map +1 -0
- package/dist/Compaction.d.ts +105 -0
- package/dist/Compaction.d.ts.map +1 -0
- package/dist/Compaction.js +126 -0
- package/dist/Compaction.js.map +1 -0
- package/dist/CurrentChat.d.ts +40 -0
- package/dist/CurrentChat.d.ts.map +1 -0
- package/dist/CurrentChat.js +33 -0
- package/dist/CurrentChat.js.map +1 -0
- package/dist/InputId.d.ts +38 -0
- package/dist/InputId.d.ts.map +1 -0
- package/dist/InputId.js +43 -0
- package/dist/InputId.js.map +1 -0
- package/dist/Instructions.d.ts +56 -0
- package/dist/Instructions.d.ts.map +1 -0
- package/dist/Instructions.js +50 -0
- package/dist/Instructions.js.map +1 -0
- package/dist/Memory.d.ts +190 -0
- package/dist/Memory.d.ts.map +1 -0
- package/dist/Memory.js +216 -0
- package/dist/Memory.js.map +1 -0
- package/dist/RunId.d.ts +41 -0
- package/dist/RunId.d.ts.map +1 -0
- package/dist/RunId.js +46 -0
- package/dist/RunId.js.map +1 -0
- package/dist/Skill.d.ts +72 -0
- package/dist/Skill.d.ts.map +1 -0
- package/dist/Skill.js +58 -0
- package/dist/Skill.js.map +1 -0
- package/dist/Specialist.d.ts +267 -0
- package/dist/Specialist.d.ts.map +1 -0
- package/dist/Specialist.js +119 -0
- package/dist/Specialist.js.map +1 -0
- package/dist/ToolDiscovery.d.ts +107 -0
- package/dist/ToolDiscovery.d.ts.map +1 -0
- package/dist/ToolDiscovery.js +140 -0
- package/dist/ToolDiscovery.js.map +1 -0
- package/dist/ToolFailure.d.ts +66 -0
- package/dist/ToolFailure.d.ts.map +1 -0
- package/dist/ToolFailure.js +79 -0
- package/dist/ToolFailure.js.map +1 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +24 -0
- package/dist/internal/chat.js +177 -0
- package/dist/internal/chat.js.map +1 -0
- package/dist/internal/events.d.ts +46 -0
- package/dist/internal/events.d.ts.map +1 -0
- package/dist/internal/events.js +65 -0
- package/dist/internal/events.js.map +1 -0
- package/dist/internal/history.js +147 -0
- package/dist/internal/history.js.map +1 -0
- package/dist/internal/instructions.js +11 -0
- package/dist/internal/instructions.js.map +1 -0
- package/dist/internal/loop.d.ts +73 -0
- package/dist/internal/loop.d.ts.map +1 -0
- package/dist/internal/loop.js +131 -0
- package/dist/internal/loop.js.map +1 -0
- package/dist/internal/schema.js +14 -0
- package/dist/internal/schema.js.map +1 -0
- package/dist/internal/skills.js +28 -0
- package/dist/internal/skills.js.map +1 -0
- package/dist/internal/specialists.js +272 -0
- package/dist/internal/specialists.js.map +1 -0
- package/dist/internal/telemetry.js +85 -0
- package/dist/internal/telemetry.js.map +1 -0
- package/dist/internal/toolkit.d.ts +62 -0
- package/dist/internal/toolkit.d.ts.map +1 -0
- package/dist/internal/toolkit.js +108 -0
- package/dist/internal/toolkit.js.map +1 -0
- package/dist/internal/tools.js +113 -0
- package/dist/internal/tools.js.map +1 -0
- package/dist/internal/turns.d.ts +64 -0
- package/dist/internal/turns.d.ts.map +1 -0
- package/dist/internal/turns.js +214 -0
- package/dist/internal/turns.js.map +1 -0
- package/dist/internal/uuid.js +45 -0
- package/dist/internal/uuid.js.map +1 -0
- package/dist/internal/writer.d.ts +12 -0
- package/dist/internal/writer.d.ts.map +1 -0
- package/package.json +52 -3
- package/src/AppEvent.ts +134 -0
- package/src/Assistant.ts +589 -0
- package/src/AssistantActivity.ts +150 -0
- package/src/AssistantEngine.ts +343 -0
- package/src/AssistantEvent.ts +569 -0
- package/src/AssistantLoop.ts +209 -0
- package/src/AssistantToolCall.ts +40 -0
- package/src/Block.ts +84 -0
- package/src/BlockKit.ts +298 -0
- package/src/ChatId.ts +36 -0
- package/src/ChatLog.ts +247 -0
- package/src/ChatView.ts +587 -0
- package/src/Chats.ts +122 -0
- package/src/Compaction.ts +207 -0
- package/src/CurrentChat.ts +47 -0
- package/src/InputId.ts +43 -0
- package/src/Instructions.ts +72 -0
- package/src/Memory.ts +276 -0
- package/src/RunId.ts +46 -0
- package/src/Skill.ts +91 -0
- package/src/Specialist.ts +355 -0
- package/src/ToolDiscovery.ts +179 -0
- package/src/ToolFailure.ts +74 -0
- package/src/index.ts +120 -0
- package/src/internal/chat.ts +323 -0
- package/src/internal/events.ts +100 -0
- package/src/internal/history.ts +294 -0
- package/src/internal/instructions.ts +9 -0
- package/src/internal/loop.ts +274 -0
- package/src/internal/schema.ts +25 -0
- package/src/internal/skills.ts +37 -0
- package/src/internal/specialists.ts +410 -0
- package/src/internal/telemetry.ts +125 -0
- package/src/internal/toolkit.ts +188 -0
- package/src/internal/tools.ts +159 -0
- package/src/internal/turns.ts +410 -0
- package/src/internal/uuid.ts +50 -0
- package/src/internal/writer.ts +12 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { toJson } from "./internal/schema.js";
|
|
3
|
+
import { AssistantToolCall } from "./AssistantToolCall.js";
|
|
4
|
+
import { needingApproval, needsApprovalMessage, runNative } from "./internal/toolkit.js";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
import * as Response from "effect/ai/Response";
|
|
8
|
+
import * as Tool from "effect/ai/Tool";
|
|
9
|
+
import * as Toolkit from "effect/ai/Toolkit";
|
|
10
|
+
//#region src/ToolDiscovery.ts
|
|
11
|
+
/**
|
|
12
|
+
* Turns a catalog toolkit into two tools, so the prompt doesn't carry every tool definition.
|
|
13
|
+
*
|
|
14
|
+
* `search_tools` finds tools by what the model needs to do and returns their names, descriptions,
|
|
15
|
+
* and input schemas. `execute_tool` validates an input and runs one of them. {@link make} returns
|
|
16
|
+
* the two tools as a native toolkit, and {@link layer} their handlers.
|
|
17
|
+
*
|
|
18
|
+
* @since 0.1.0
|
|
19
|
+
*/
|
|
20
|
+
var ToolDiscovery_exports = /* @__PURE__ */ __exportAll({
|
|
21
|
+
layer: () => layer,
|
|
22
|
+
make: () => make
|
|
23
|
+
});
|
|
24
|
+
const words = (text) => new Set(text.toLowerCase().split(/[^a-z0-9]+/).filter((word) => word.length >= 3));
|
|
25
|
+
const score = (query, text) => {
|
|
26
|
+
const target = [...words(text)];
|
|
27
|
+
const matches = (word) => target.some((t) => t === word || word.length >= 4 && (t.startsWith(word) || word.startsWith(t)));
|
|
28
|
+
return [...query].filter(matches).length;
|
|
29
|
+
};
|
|
30
|
+
const search = (tools, query, limit) => {
|
|
31
|
+
const queryWords = words(query);
|
|
32
|
+
const ranked = tools.flatMap((tool) => {
|
|
33
|
+
const hits = score(queryWords, `${tool.name} ${Tool.getDescription(tool) ?? ""}`);
|
|
34
|
+
return hits > 0 ? [{
|
|
35
|
+
tool,
|
|
36
|
+
score: hits
|
|
37
|
+
}] : [];
|
|
38
|
+
}).sort((a, b) => b.score - a.score);
|
|
39
|
+
return (ranked.length > 0 ? ranked.map((hit) => hit.tool) : tools).slice(0, limit);
|
|
40
|
+
};
|
|
41
|
+
const SearchTools = Tool.make("search_tools", {
|
|
42
|
+
description: "Search for more tools by what you need to do. Returns their names, descriptions, and input schemas; call one with execute_tool.",
|
|
43
|
+
parameters: Schema.Struct({ query: Schema.String.annotate({ description: "What you need to do, in a few words." }) }),
|
|
44
|
+
success: Schema.Array(Schema.Struct({
|
|
45
|
+
name: Schema.String,
|
|
46
|
+
description: Schema.optional(Schema.String),
|
|
47
|
+
inputSchema: Schema.Json
|
|
48
|
+
}))
|
|
49
|
+
});
|
|
50
|
+
const ExecuteTool = Tool.make("execute_tool", {
|
|
51
|
+
description: "Run a tool found with search_tools. Pass its name and an input matching its input schema.",
|
|
52
|
+
parameters: Schema.Struct({
|
|
53
|
+
name: Schema.String,
|
|
54
|
+
input: Schema.Record(Schema.String, Schema.Json)
|
|
55
|
+
}),
|
|
56
|
+
success: Schema.Json,
|
|
57
|
+
failure: Schema.Json,
|
|
58
|
+
dependencies: [AssistantToolCall]
|
|
59
|
+
});
|
|
60
|
+
const requiring = () => (tool) => tool;
|
|
61
|
+
/**
|
|
62
|
+
* Creates the `search_tools` and `execute_tool` tools over a catalog toolkit, as a native toolkit.
|
|
63
|
+
*
|
|
64
|
+
* **Details**
|
|
65
|
+
*
|
|
66
|
+
* Merge the toolkit into the loop's, and provide {@link layer} for the same catalog, which has
|
|
67
|
+
* the tools' handlers. A catalog tool's services are `execute_tool`'s, so the turn provides them
|
|
68
|
+
* as it does for any tool.
|
|
69
|
+
*
|
|
70
|
+
* A catalog tool with Effect's `needsApproval` set fails the layer when it is built, as it would
|
|
71
|
+
* fail a loop: the library doesn't run calls that wait for approval.
|
|
72
|
+
*
|
|
73
|
+
* **Example** (Finding rarely used tools when needed)
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { ToolDiscovery } from "effect-assistant"
|
|
77
|
+
* import * as Toolkit from "effect/ai/Toolkit"
|
|
78
|
+
* import * as Layer from "effect/Layer"
|
|
79
|
+
*
|
|
80
|
+
* // OfficeTools is a big toolkit, found when needed. CommonTools stays in the prompt.
|
|
81
|
+
* const OfficeDiscovery = ToolDiscovery.make(OfficeTools)
|
|
82
|
+
* const OfficeDiscoveryLive = ToolDiscovery.layer(OfficeTools).pipe(Layer.provide(OfficeToolsLive))
|
|
83
|
+
*
|
|
84
|
+
* const MyAssistantLive = MyAssistant.toLayer((turn) =>
|
|
85
|
+
* turn.loop({
|
|
86
|
+
* instructions,
|
|
87
|
+
* toolkit: Toolkit.merge(CommonTools, OfficeDiscovery)
|
|
88
|
+
* })
|
|
89
|
+
* ).pipe(Layer.provide([CommonToolsLive, OfficeDiscoveryLive]))
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @see {@link layer} for the tools' handlers
|
|
93
|
+
*
|
|
94
|
+
* @category constructors
|
|
95
|
+
* @since 0.1.0
|
|
96
|
+
*/
|
|
97
|
+
const make = (_catalog) => Toolkit.make(SearchTools, requiring()(ExecuteTool));
|
|
98
|
+
/**
|
|
99
|
+
* Creates the layer with the handlers of the `search_tools` and `execute_tool` tools over a
|
|
100
|
+
* catalog toolkit.
|
|
101
|
+
*
|
|
102
|
+
* **Details**
|
|
103
|
+
*
|
|
104
|
+
* The layer needs the catalog's handlers. It provides the handlers of the toolkit that
|
|
105
|
+
* {@link make} returns for the same catalog: handlers are keyed by tool name, so the two calls
|
|
106
|
+
* don't need to share a value. Give both the same catalog.
|
|
107
|
+
*
|
|
108
|
+
* @see {@link make} for the toolkit and an example
|
|
109
|
+
*
|
|
110
|
+
* @category layers
|
|
111
|
+
* @since 0.1.0
|
|
112
|
+
*/
|
|
113
|
+
const layer = (catalog) => make(catalog).toLayer(Effect.gen(function* () {
|
|
114
|
+
const resolved = yield* catalog;
|
|
115
|
+
const definitions = Object.values(resolved.tools);
|
|
116
|
+
const needingApproval$1 = needingApproval(definitions);
|
|
117
|
+
if (needingApproval$1.length > 0) return yield* Effect.die(needsApprovalMessage(needingApproval$1));
|
|
118
|
+
return {
|
|
119
|
+
search_tools: ({ query }) => Effect.sync(() => search(definitions, query, 5).map((tool) => ({
|
|
120
|
+
name: tool.name,
|
|
121
|
+
description: Tool.getDescription(tool),
|
|
122
|
+
inputSchema: toJson(Tool.getJsonSchema(tool))
|
|
123
|
+
}))),
|
|
124
|
+
execute_tool: Effect.fnUntraced(function* ({ name, input }) {
|
|
125
|
+
const outer = yield* AssistantToolCall;
|
|
126
|
+
const call = Response.makePart("tool-call", {
|
|
127
|
+
id: `${outer.callId}:${name}`,
|
|
128
|
+
name,
|
|
129
|
+
params: input,
|
|
130
|
+
providerExecuted: false
|
|
131
|
+
});
|
|
132
|
+
const { outcome, result } = yield* runNative(resolved, call);
|
|
133
|
+
return outcome === "failure" ? yield* Effect.fail(result) : result;
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
}));
|
|
137
|
+
//#endregion
|
|
138
|
+
export { ToolDiscovery_exports, layer, make };
|
|
139
|
+
|
|
140
|
+
//# sourceMappingURL=ToolDiscovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolDiscovery.js","names":["needingApproval","Toolkits.needingApproval","Toolkits.needsApprovalMessage","Toolkits.runNative"],"sources":["../src/ToolDiscovery.ts"],"sourcesContent":["/**\n * Turns a catalog toolkit into two tools, so the prompt doesn't carry every tool definition.\n *\n * `search_tools` finds tools by what the model needs to do and returns their names, descriptions,\n * and input schemas. `execute_tool` validates an input and runs one of them. {@link make} returns\n * the two tools as a native toolkit, and {@link layer} their handlers.\n *\n * @since 0.1.0\n */\nimport * as Response from \"effect/ai/Response\"\nimport * as Tool from \"effect/ai/Tool\"\nimport * as Toolkit from \"effect/ai/Toolkit\"\nimport * as Effect from \"effect/Effect\"\nimport * as Schema from \"effect/Schema\"\nimport { AssistantToolCall } from \"./AssistantToolCall.ts\"\nimport { toJson } from \"./internal/schema.ts\"\nimport * as Toolkits from \"./internal/toolkit.ts\"\n\nconst words = (text: string): ReadonlySet<string> =>\n new Set(\n text\n .toLowerCase()\n .split(/[^a-z0-9]+/)\n .filter((word) => word.length >= 3)\n )\n\nconst score = (query: ReadonlySet<string>, text: string): number => {\n const target = [...words(text)]\n\n const matches = (word: string) =>\n target.some((t) => t === word || (word.length >= 4 && (t.startsWith(word) || word.startsWith(t))))\n\n return [...query].filter(matches).length\n}\n\n// Everything when nothing matches, so the model can pick or search again.\nconst search = (tools: ReadonlyArray<Tool.Any>, query: string, limit: number): ReadonlyArray<Tool.Any> => {\n const queryWords = words(query)\n\n const ranked = tools\n .flatMap((tool) => {\n const hits = score(queryWords, `${tool.name} ${Tool.getDescription(tool) ?? \"\"}`)\n\n return hits > 0 ? [{ tool, score: hits }] : []\n })\n .sort((a, b) => b.score - a.score)\n\n return (ranked.length > 0 ? ranked.map((hit) => hit.tool) : tools).slice(0, limit)\n}\n\nconst SearchTools = Tool.make(\"search_tools\", {\n description:\n \"Search for more tools by what you need to do. Returns their names, descriptions, and input schemas; call one with execute_tool.\",\n parameters: Schema.Struct({\n query: Schema.String.annotate({ description: \"What you need to do, in a few words.\" })\n }),\n success: Schema.Array(\n Schema.Struct({\n name: Schema.String,\n description: Schema.optional(Schema.String),\n inputSchema: Schema.Json\n })\n )\n})\n\nconst ExecuteTool = Tool.make(\"execute_tool\", {\n description: \"Run a tool found with search_tools. Pass its name and an input matching its input schema.\",\n parameters: Schema.Struct({\n name: Schema.String,\n input: Schema.Record(Schema.String, Schema.Json)\n }),\n success: Schema.Json,\n // The tool's failure is this call's, so the loop sees it failed (a `wait: true` message doesn't\n // end the turn).\n failure: Schema.Json,\n dependencies: [AssistantToolCall]\n})\n\n// A tool's requirements are a covariant phantom type, so one that needs nothing is one that needs\n// any.\nconst requiring =\n <R>() =>\n <N extends string, C extends (Tool.Any extends Tool.Tool<string, infer K, unknown> ? K : never), R0>(\n tool: Tool.Tool<N, C, R0>\n ): Tool.Tool<N, C, R0 | R> =>\n tool\n\n/**\n * Creates the `search_tools` and `execute_tool` tools over a catalog toolkit, as a native toolkit.\n *\n * **Details**\n *\n * Merge the toolkit into the loop's, and provide {@link layer} for the same catalog, which has\n * the tools' handlers. A catalog tool's services are `execute_tool`'s, so the turn provides them\n * as it does for any tool.\n *\n * A catalog tool with Effect's `needsApproval` set fails the layer when it is built, as it would\n * fail a loop: the library doesn't run calls that wait for approval.\n *\n * **Example** (Finding rarely used tools when needed)\n *\n * ```ts\n * import { ToolDiscovery } from \"effect-assistant\"\n * import * as Toolkit from \"effect/ai/Toolkit\"\n * import * as Layer from \"effect/Layer\"\n *\n * // OfficeTools is a big toolkit, found when needed. CommonTools stays in the prompt.\n * const OfficeDiscovery = ToolDiscovery.make(OfficeTools)\n * const OfficeDiscoveryLive = ToolDiscovery.layer(OfficeTools).pipe(Layer.provide(OfficeToolsLive))\n *\n * const MyAssistantLive = MyAssistant.toLayer((turn) =>\n * turn.loop({\n * instructions,\n * toolkit: Toolkit.merge(CommonTools, OfficeDiscovery)\n * })\n * ).pipe(Layer.provide([CommonToolsLive, OfficeDiscoveryLive]))\n * ```\n *\n * @see {@link layer} for the tools' handlers\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = <T extends Record<string, Tool.Any>>(\n // Only its type is used here, for `execute_tool`'s services: `layer` runs its tools.\n _catalog: Toolkit.Toolkit<T>\n) => Toolkit.make(SearchTools, requiring<Toolkits.ToolServices<T>>()(ExecuteTool))\n\n/**\n * Creates the layer with the handlers of the `search_tools` and `execute_tool` tools over a\n * catalog toolkit.\n *\n * **Details**\n *\n * The layer needs the catalog's handlers. It provides the handlers of the toolkit that\n * {@link make} returns for the same catalog: handlers are keyed by tool name, so the two calls\n * don't need to share a value. Give both the same catalog.\n *\n * @see {@link make} for the toolkit and an example\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer = <T extends Record<string, Tool.Any>>(catalog: Toolkit.Toolkit<T>) =>\n make(catalog).toLayer(\n Effect.gen(function* () {\n const resolved = yield* catalog\n const definitions = Object.values(resolved.tools)\n const needingApproval = Toolkits.needingApproval(definitions)\n\n if (needingApproval.length > 0) return yield* Effect.die(Toolkits.needsApprovalMessage(needingApproval))\n\n return {\n search_tools: ({ query }) =>\n Effect.sync(() =>\n search(definitions, query, 5).map((tool) => ({\n name: tool.name,\n description: Tool.getDescription(tool),\n inputSchema: toJson(Tool.getJsonSchema(tool))\n }))\n ),\n execute_tool: Effect.fnUntraced(function* ({ name, input }) {\n // Named after the call that runs it: the same id when a crash runs that call again.\n const outer = yield* AssistantToolCall\n\n const call = Response.makePart(\"tool-call\", {\n id: `${outer.callId}:${name}`,\n name,\n params: input,\n providerExecuted: false\n })\n\n const { outcome, result } = yield* Toolkits.runNative(resolved, call)\n\n return outcome === \"failure\" ? yield* Effect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ToolFailure_d_exports {
|
|
4
|
+
export { ToolFailure, fail };
|
|
5
|
+
}
|
|
6
|
+
declare const ToolFailure_base: Schema.Class<ToolFailure, Schema.Struct<{
|
|
7
|
+
readonly _tag: Schema.tag<"ToolFailure">;
|
|
8
|
+
readonly message: Schema.String;
|
|
9
|
+
readonly reason: Schema.optional<Schema.String>;
|
|
10
|
+
}>, import("effect/Cause").YieldableError>;
|
|
11
|
+
/**
|
|
12
|
+
* Represents a tool's failure, written for the model.
|
|
13
|
+
*
|
|
14
|
+
* It holds a message that says what went wrong and, optionally, a `reason` the model can tell
|
|
15
|
+
* apart, such as `"NotFound"` or `"OverBudget"`. The library's own reasons are PascalCase, like
|
|
16
|
+
* `"ToolNotFoundError"`.
|
|
17
|
+
*
|
|
18
|
+
* @category errors
|
|
19
|
+
* @since 0.1.0
|
|
20
|
+
*/
|
|
21
|
+
export declare class ToolFailure extends ToolFailure_base {}
|
|
22
|
+
/**
|
|
23
|
+
* Fails a tool's handler with a message for the model.
|
|
24
|
+
*
|
|
25
|
+
* **Details**
|
|
26
|
+
*
|
|
27
|
+
* The tool must declare `failure: ToolFailure.ToolFailure`. The model reads the failure as the
|
|
28
|
+
* call's result, with its `reason` when one is given.
|
|
29
|
+
*
|
|
30
|
+
* **Example** (Failing a tool call the model can correct)
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { ToolFailure } from "effect-assistant"
|
|
34
|
+
* import * as Tool from "effect/ai/Tool"
|
|
35
|
+
* import * as Toolkit from "effect/ai/Toolkit"
|
|
36
|
+
* import * as Effect from "effect/Effect"
|
|
37
|
+
* import * as Schema from "effect/Schema"
|
|
38
|
+
*
|
|
39
|
+
* const budgets = new Map([["Oslo", 1200]])
|
|
40
|
+
*
|
|
41
|
+
* const BudgetTools = Toolkit.make(
|
|
42
|
+
* Tool.make("office_budget", {
|
|
43
|
+
* description: "The budget left for an office.",
|
|
44
|
+
* parameters: Schema.Struct({ office: Schema.String }),
|
|
45
|
+
* success: Schema.Number,
|
|
46
|
+
* failure: ToolFailure.ToolFailure
|
|
47
|
+
* })
|
|
48
|
+
* )
|
|
49
|
+
*
|
|
50
|
+
* const BudgetToolsLive = BudgetTools.toLayer({
|
|
51
|
+
* office_budget: ({ office }) =>
|
|
52
|
+
* Effect.fromNullishOr(budgets.get(office)).pipe(
|
|
53
|
+
* Effect.catch(() => ToolFailure.fail(`No office named ${office}.`, { reason: "NotFound" }))
|
|
54
|
+
* )
|
|
55
|
+
* })
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @category constructors
|
|
59
|
+
* @since 0.1.0
|
|
60
|
+
*/
|
|
61
|
+
export declare const fail: (message: string, options?: {
|
|
62
|
+
readonly reason?: string | undefined;
|
|
63
|
+
}) => Effect.Effect<never, ToolFailure>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { ToolFailure_d_exports };
|
|
66
|
+
//# sourceMappingURL=ToolFailure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolFailure.d.ts","names":[],"sources":["../src/ToolFailure.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;qBAsBa,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA6CpB,OAAI,iBACA;WACM;MACpB,OAAO,cAAc"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
//#region src/ToolFailure.ts
|
|
5
|
+
/**
|
|
6
|
+
* Defines the failure a tool returns to the model.
|
|
7
|
+
*
|
|
8
|
+
* A {@link ToolFailure} carries a message the model reads and adapts to, such as "No office named
|
|
9
|
+
* Paris", instead of failing the turn. Tools declare it as their `failure` schema and fail with
|
|
10
|
+
* {@link fail}.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.1.0
|
|
13
|
+
*/
|
|
14
|
+
var ToolFailure_exports = /* @__PURE__ */ __exportAll({
|
|
15
|
+
ToolFailure: () => ToolFailure,
|
|
16
|
+
fail: () => fail
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Represents a tool's failure, written for the model.
|
|
20
|
+
*
|
|
21
|
+
* It holds a message that says what went wrong and, optionally, a `reason` the model can tell
|
|
22
|
+
* apart, such as `"NotFound"` or `"OverBudget"`. The library's own reasons are PascalCase, like
|
|
23
|
+
* `"ToolNotFoundError"`.
|
|
24
|
+
*
|
|
25
|
+
* @category errors
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
*/
|
|
28
|
+
var ToolFailure = class extends Schema.Error("effect-assistant/ToolFailure/ToolFailure")({
|
|
29
|
+
_tag: Schema.tag("ToolFailure"),
|
|
30
|
+
message: Schema.String,
|
|
31
|
+
reason: Schema.optional(Schema.String)
|
|
32
|
+
}) {};
|
|
33
|
+
/**
|
|
34
|
+
* Fails a tool's handler with a message for the model.
|
|
35
|
+
*
|
|
36
|
+
* **Details**
|
|
37
|
+
*
|
|
38
|
+
* The tool must declare `failure: ToolFailure.ToolFailure`. The model reads the failure as the
|
|
39
|
+
* call's result, with its `reason` when one is given.
|
|
40
|
+
*
|
|
41
|
+
* **Example** (Failing a tool call the model can correct)
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { ToolFailure } from "effect-assistant"
|
|
45
|
+
* import * as Tool from "effect/ai/Tool"
|
|
46
|
+
* import * as Toolkit from "effect/ai/Toolkit"
|
|
47
|
+
* import * as Effect from "effect/Effect"
|
|
48
|
+
* import * as Schema from "effect/Schema"
|
|
49
|
+
*
|
|
50
|
+
* const budgets = new Map([["Oslo", 1200]])
|
|
51
|
+
*
|
|
52
|
+
* const BudgetTools = Toolkit.make(
|
|
53
|
+
* Tool.make("office_budget", {
|
|
54
|
+
* description: "The budget left for an office.",
|
|
55
|
+
* parameters: Schema.Struct({ office: Schema.String }),
|
|
56
|
+
* success: Schema.Number,
|
|
57
|
+
* failure: ToolFailure.ToolFailure
|
|
58
|
+
* })
|
|
59
|
+
* )
|
|
60
|
+
*
|
|
61
|
+
* const BudgetToolsLive = BudgetTools.toLayer({
|
|
62
|
+
* office_budget: ({ office }) =>
|
|
63
|
+
* Effect.fromNullishOr(budgets.get(office)).pipe(
|
|
64
|
+
* Effect.catch(() => ToolFailure.fail(`No office named ${office}.`, { reason: "NotFound" }))
|
|
65
|
+
* )
|
|
66
|
+
* })
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @category constructors
|
|
70
|
+
* @since 0.1.0
|
|
71
|
+
*/
|
|
72
|
+
const fail = (message, options) => Effect.fail(options?.reason === void 0 ? new ToolFailure({ message }) : new ToolFailure({
|
|
73
|
+
message,
|
|
74
|
+
reason: options.reason
|
|
75
|
+
}));
|
|
76
|
+
//#endregion
|
|
77
|
+
export { ToolFailure, ToolFailure_exports, fail };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=ToolFailure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolFailure.js","names":[],"sources":["../src/ToolFailure.ts"],"sourcesContent":["/**\n * Defines the failure a tool returns to the model.\n *\n * A {@link ToolFailure} carries a message the model reads and adapts to, such as \"No office named\n * Paris\", instead of failing the turn. Tools declare it as their `failure` schema and fail with\n * {@link fail}.\n *\n * @since 0.1.0\n */\nimport * as Effect from \"effect/Effect\"\nimport * as Schema from \"effect/Schema\"\n\n/**\n * Represents a tool's failure, written for the model.\n *\n * It holds a message that says what went wrong and, optionally, a `reason` the model can tell\n * apart, such as `\"NotFound\"` or `\"OverBudget\"`. The library's own reasons are PascalCase, like\n * `\"ToolNotFoundError\"`.\n *\n * @category errors\n * @since 0.1.0\n */\nexport class ToolFailure extends Schema.Error<ToolFailure>(\"effect-assistant/ToolFailure/ToolFailure\")({\n _tag: Schema.tag(\"ToolFailure\"),\n message: Schema.String,\n reason: Schema.optional(Schema.String)\n}) {}\n\n/**\n * Fails a tool's handler with a message for the model.\n *\n * **Details**\n *\n * The tool must declare `failure: ToolFailure.ToolFailure`. The model reads the failure as the\n * call's result, with its `reason` when one is given.\n *\n * **Example** (Failing a tool call the model can correct)\n *\n * ```ts\n * import { ToolFailure } from \"effect-assistant\"\n * import * as Tool from \"effect/ai/Tool\"\n * import * as Toolkit from \"effect/ai/Toolkit\"\n * import * as Effect from \"effect/Effect\"\n * import * as Schema from \"effect/Schema\"\n *\n * const budgets = new Map([[\"Oslo\", 1200]])\n *\n * const BudgetTools = Toolkit.make(\n * Tool.make(\"office_budget\", {\n * description: \"The budget left for an office.\",\n * parameters: Schema.Struct({ office: Schema.String }),\n * success: Schema.Number,\n * failure: ToolFailure.ToolFailure\n * })\n * )\n *\n * const BudgetToolsLive = BudgetTools.toLayer({\n * office_budget: ({ office }) =>\n * Effect.fromNullishOr(budgets.get(office)).pipe(\n * Effect.catch(() => ToolFailure.fail(`No office named ${office}.`, { reason: \"NotFound\" }))\n * )\n * })\n * ```\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const fail = (\n message: string,\n options?: { readonly reason?: string | undefined }\n): Effect.Effect<never, ToolFailure> =>\n Effect.fail(\n options?.reason === undefined ? new ToolFailure({ message }) : new ToolFailure({ message, reason: options.reason })\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,cAAb,cAAiC,OAAO,MAAmB,0CAA0C,CAAC,CAAC;CACrG,MAAM,OAAO,IAAI,aAAa;CAC9B,SAAS,OAAO;CAChB,QAAQ,OAAO,SAAS,OAAO,MAAM;AACvC,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCJ,MAAa,QACX,SACA,YAEA,OAAO,KACL,SAAS,WAAW,KAAA,IAAY,IAAI,YAAY,EAAE,QAAQ,CAAC,IAAI,IAAI,YAAY;CAAE;CAAS,QAAQ,QAAQ;AAAO,CAAC,CACpH"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AppEvent_d_exports } from "./AppEvent.js";
|
|
2
|
+
import { ChatId_d_exports } from "./ChatId.js";
|
|
3
|
+
import { AssistantEvent_d_exports } from "./AssistantEvent.js";
|
|
4
|
+
import { ChatLog_d_exports } from "./ChatLog.js";
|
|
5
|
+
import { Instructions_d_exports } from "./Instructions.js";
|
|
6
|
+
import { AssistantToolCall_d_exports } from "./AssistantToolCall.js";
|
|
7
|
+
import { AssistantLoop_d_exports } from "./AssistantLoop.js";
|
|
8
|
+
import { Block_d_exports } from "./Block.js";
|
|
9
|
+
import { ChatView_d_exports } from "./ChatView.js";
|
|
10
|
+
import { CurrentChat_d_exports } from "./CurrentChat.js";
|
|
11
|
+
import { BlockKit_d_exports } from "./BlockKit.js";
|
|
12
|
+
import { RunId_d_exports } from "./RunId.js";
|
|
13
|
+
import { Skill_d_exports } from "./Skill.js";
|
|
14
|
+
import { Specialist_d_exports } from "./Specialist.js";
|
|
15
|
+
import { AssistantEngine_d_exports } from "./AssistantEngine.js";
|
|
16
|
+
import { Chats_d_exports } from "./Chats.js";
|
|
17
|
+
import { Assistant_d_exports } from "./Assistant.js";
|
|
18
|
+
import { AssistantActivity_d_exports } from "./AssistantActivity.js";
|
|
19
|
+
import { Compaction_d_exports } from "./Compaction.js";
|
|
20
|
+
import { InputId_d_exports } from "./InputId.js";
|
|
21
|
+
import { ToolFailure_d_exports } from "./ToolFailure.js";
|
|
22
|
+
import { Memory_d_exports } from "./Memory.js";
|
|
23
|
+
import { ToolDiscovery_d_exports } from "./ToolDiscovery.js";
|
|
24
|
+
export { AppEvent_d_exports as AppEvent, Assistant_d_exports as Assistant, AssistantActivity_d_exports as AssistantActivity, AssistantEngine_d_exports as AssistantEngine, AssistantEvent_d_exports as AssistantEvent, AssistantLoop_d_exports as AssistantLoop, AssistantToolCall_d_exports as AssistantToolCall, Block_d_exports as Block, BlockKit_d_exports as BlockKit, ChatId_d_exports as ChatId, ChatLog_d_exports as ChatLog, ChatView_d_exports as ChatView, Chats_d_exports as Chats, Compaction_d_exports as Compaction, CurrentChat_d_exports as CurrentChat, InputId_d_exports as InputId, Instructions_d_exports as Instructions, Memory_d_exports as Memory, RunId_d_exports as RunId, Skill_d_exports as Skill, Specialist_d_exports as Specialist, ToolDiscovery_d_exports as ToolDiscovery, ToolFailure_d_exports as ToolFailure };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AppEvent_exports } from "./AppEvent.js";
|
|
2
|
+
import { ChatId_exports } from "./ChatId.js";
|
|
3
|
+
import { InputId_exports } from "./InputId.js";
|
|
4
|
+
import { RunId_exports } from "./RunId.js";
|
|
5
|
+
import { AssistantEvent_exports } from "./AssistantEvent.js";
|
|
6
|
+
import { ChatLog_exports } from "./ChatLog.js";
|
|
7
|
+
import { CurrentChat_exports } from "./CurrentChat.js";
|
|
8
|
+
import { Chats_exports } from "./Chats.js";
|
|
9
|
+
import { Specialist_exports } from "./Specialist.js";
|
|
10
|
+
import { AssistantToolCall_exports } from "./AssistantToolCall.js";
|
|
11
|
+
import { ToolFailure_exports } from "./ToolFailure.js";
|
|
12
|
+
import { Skill_exports } from "./Skill.js";
|
|
13
|
+
import { Instructions_exports } from "./Instructions.js";
|
|
14
|
+
import { AssistantEngine_exports } from "./AssistantEngine.js";
|
|
15
|
+
import { Assistant_exports } from "./Assistant.js";
|
|
16
|
+
import { AssistantActivity_exports } from "./AssistantActivity.js";
|
|
17
|
+
import { AssistantLoop_exports } from "./AssistantLoop.js";
|
|
18
|
+
import { Block_exports } from "./Block.js";
|
|
19
|
+
import { BlockKit_exports } from "./BlockKit.js";
|
|
20
|
+
import { ChatView_exports } from "./ChatView.js";
|
|
21
|
+
import { Compaction_exports } from "./Compaction.js";
|
|
22
|
+
import { Memory_exports } from "./Memory.js";
|
|
23
|
+
import { ToolDiscovery_exports } from "./ToolDiscovery.js";
|
|
24
|
+
export { AppEvent_exports as AppEvent, Assistant_exports as Assistant, AssistantActivity_exports as AssistantActivity, AssistantEngine_exports as AssistantEngine, AssistantEvent_exports as AssistantEvent, AssistantLoop_exports as AssistantLoop, AssistantToolCall_exports as AssistantToolCall, Block_exports as Block, BlockKit_exports as BlockKit, ChatId_exports as ChatId, ChatLog_exports as ChatLog, ChatView_exports as ChatView, Chats_exports as Chats, Compaction_exports as Compaction, CurrentChat_exports as CurrentChat, InputId_exports as InputId, Instructions_exports as Instructions, Memory_exports as Memory, RunId_exports as RunId, Skill_exports as Skill, Specialist_exports as Specialist, ToolDiscovery_exports as ToolDiscovery, ToolFailure_exports as ToolFailure };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { ChatDeleted, isInput, isLibraryEvent } from "../AssistantEvent.js";
|
|
2
|
+
import { ChatLog } from "../ChatLog.js";
|
|
3
|
+
import { CurrentChat } from "../CurrentChat.js";
|
|
4
|
+
import { Chats } from "../Chats.js";
|
|
5
|
+
import { Runner } from "../Specialist.js";
|
|
6
|
+
import { decodeEntries, encode, isRegistered } from "./events.js";
|
|
7
|
+
import { needsTurn } from "./history.js";
|
|
8
|
+
import { makeRunner } from "./specialists.js";
|
|
9
|
+
import { run } from "./turns.js";
|
|
10
|
+
import * as Predicate from "effect/Predicate";
|
|
11
|
+
import * as Context from "effect/Context";
|
|
12
|
+
import * as Effect from "effect/Effect";
|
|
13
|
+
import * as Stream from "effect/Stream";
|
|
14
|
+
import * as Exit from "effect/Exit";
|
|
15
|
+
import * as Scope from "effect/Scope";
|
|
16
|
+
import * as Ref from "effect/Ref";
|
|
17
|
+
import * as Cause from "effect/Cause";
|
|
18
|
+
import * as Deferred from "effect/Deferred";
|
|
19
|
+
import * as Fiber from "effect/Fiber";
|
|
20
|
+
import * as FiberSet from "effect/FiberSet";
|
|
21
|
+
import * as PubSub from "effect/PubSub";
|
|
22
|
+
import * as Semaphore from "effect/Semaphore";
|
|
23
|
+
import * as SynchronizedRef from "effect/SynchronizedRef";
|
|
24
|
+
//#region src/internal/chat.ts
|
|
25
|
+
const idOf = (event) => isLibraryEvent(event) ? isInput(event) ? event.id : void 0 : Predicate.hasProperty(event, "id") && Predicate.isString(event.id) ? event.id : void 0;
|
|
26
|
+
const makeChannelPubSub = Effect.acquireRelease(PubSub.unbounded(), PubSub.shutdown);
|
|
27
|
+
const makeHolding = Effect.fnUntraced(function* (keepAlive) {
|
|
28
|
+
const holds = yield* SynchronizedRef.make(0);
|
|
29
|
+
const acquire = SynchronizedRef.updateEffect(holds, Effect.fnUntraced(function* (n) {
|
|
30
|
+
if (n !== 0) return n + 1;
|
|
31
|
+
yield* keepAlive(true);
|
|
32
|
+
return 1;
|
|
33
|
+
}));
|
|
34
|
+
const release = SynchronizedRef.updateEffect(holds, Effect.fnUntraced(function* (n) {
|
|
35
|
+
if (n !== 1) return n - 1;
|
|
36
|
+
yield* keepAlive(false);
|
|
37
|
+
return 0;
|
|
38
|
+
}));
|
|
39
|
+
return (effect) => Effect.acquireUseRelease(acquire, () => effect, (_, exit) => Exit.hasInterrupts(exit) ? Effect.void : release);
|
|
40
|
+
});
|
|
41
|
+
const isChatDeleted = (entry) => Predicate.isTagged(entry.event, "ChatDeleted");
|
|
42
|
+
const deletedChat = (entries) => ({
|
|
43
|
+
submit: () => Effect.void,
|
|
44
|
+
submitInBackground: () => Effect.void,
|
|
45
|
+
resume: Effect.void,
|
|
46
|
+
stream: (after) => Stream.fromIterable(entries.filter((entry) => entry.seq > after)),
|
|
47
|
+
delete: Effect.void
|
|
48
|
+
});
|
|
49
|
+
const refused = (input, why) => Effect.logDebug(`assistant chat ${why}: ${input._tag} not stored`);
|
|
50
|
+
/** @internal */
|
|
51
|
+
const make = Effect.fnUntraced(function* (options) {
|
|
52
|
+
const { registration, chatId } = options;
|
|
53
|
+
const { app } = registration.definition;
|
|
54
|
+
const { wakes } = app;
|
|
55
|
+
const storage = yield* ChatLog;
|
|
56
|
+
const chats = yield* Chats;
|
|
57
|
+
const initial = yield* storage.read(chatId);
|
|
58
|
+
if (initial.some(isChatDeleted)) return deletedChat(initial);
|
|
59
|
+
const channel = yield* makeChannelPubSub;
|
|
60
|
+
const writes = yield* Semaphore.make(1);
|
|
61
|
+
const turnsLock = yield* Semaphore.make(1);
|
|
62
|
+
const holding = yield* makeHolding(options.keepAlive);
|
|
63
|
+
const deleted = yield* Deferred.make();
|
|
64
|
+
const working = yield* Scope.fork(yield* Effect.scope);
|
|
65
|
+
const inWorking = Effect.provideService(Scope.Scope, working);
|
|
66
|
+
const background = yield* inWorking(FiberSet.make());
|
|
67
|
+
const requests = yield* inWorking(FiberSet.make());
|
|
68
|
+
const isDeleted = Deferred.isDone(deleted);
|
|
69
|
+
const entries = yield* Ref.make(initial);
|
|
70
|
+
const write = Effect.fnUntraced(function* (events) {
|
|
71
|
+
const unknown = events.find((event) => !isLibraryEvent(event) && !isRegistered(app, event));
|
|
72
|
+
if (unknown !== void 0) return yield* Effect.die(`${unknown._tag} isn't one of the ${registration.definition.name} assistant's events.`);
|
|
73
|
+
if (yield* isDeleted) return [];
|
|
74
|
+
return yield* stored(events);
|
|
75
|
+
});
|
|
76
|
+
const stored = Effect.fnUntraced(function* (events) {
|
|
77
|
+
const stored = yield* storage.append(chatId, events);
|
|
78
|
+
yield* Ref.update(entries, (all) => [...all, ...stored]);
|
|
79
|
+
yield* PubSub.publishAll(channel, stored);
|
|
80
|
+
return stored;
|
|
81
|
+
}, Effect.uninterruptible);
|
|
82
|
+
const chat = {
|
|
83
|
+
chatId,
|
|
84
|
+
entries: Ref.get(entries),
|
|
85
|
+
append: (events) => Semaphore.withPermit(writes)(write(events))
|
|
86
|
+
};
|
|
87
|
+
const toStored = (event) => isLibraryEvent(event) ? Effect.succeed(event) : isRegistered(app, event) ? encode(app, event) : Effect.die(`${event._tag} isn't one of the ${registration.definition.name} assistant's events.`);
|
|
88
|
+
const handle = {
|
|
89
|
+
chatId,
|
|
90
|
+
entries: Effect.map(chat.entries, (all) => decodeEntries(app, all)),
|
|
91
|
+
append: (...events) => Effect.asVoid(Effect.flatMap(Effect.forEach(events, toStored), chat.append))
|
|
92
|
+
};
|
|
93
|
+
const checkAvailable = chats.get(chatId).pipe(Effect.as(true), Effect.catchTag("GetChatError", (unavailable) => unavailable.reason === "Deleted" ? Effect.as(Effect.suspend(() => remove), false) : Effect.succeed(false)));
|
|
94
|
+
const store = Effect.fnUntraced(function* (input) {
|
|
95
|
+
if (yield* isDeleted) return yield* refused(input, "is deleted");
|
|
96
|
+
if (!(yield* checkAvailable)) return yield* refused(input, "is unavailable");
|
|
97
|
+
yield* Semaphore.withPermit(writes)(Effect.gen(function* () {
|
|
98
|
+
if (yield* isDeleted) return yield* refused(input, "is deleted");
|
|
99
|
+
const id = idOf(input);
|
|
100
|
+
if (id !== void 0 && (yield* Ref.get(entries)).some(({ event }) => idOf(event) === id)) return;
|
|
101
|
+
yield* write([input]);
|
|
102
|
+
}));
|
|
103
|
+
});
|
|
104
|
+
const handler = yield* inWorking(Effect.provideService(registration.open(handle), CurrentChat, handle));
|
|
105
|
+
const specialists = yield* Effect.forEach(registration.specialists, Effect.fnUntraced(function* ({ specialist, built }) {
|
|
106
|
+
return {
|
|
107
|
+
specialist,
|
|
108
|
+
handler: yield* inWorking(Effect.provideService(built.open, CurrentChat, handle))
|
|
109
|
+
};
|
|
110
|
+
}));
|
|
111
|
+
const inBackground = (effect) => FiberSet.run(background, holding(effect)).pipe(Effect.asVoid);
|
|
112
|
+
const inRequest = Effect.fnUntraced(function* (effect) {
|
|
113
|
+
const fiber = yield* FiberSet.run(requests, effect);
|
|
114
|
+
const exit = yield* Fiber.await(fiber).pipe(Effect.onInterrupt(() => Fiber.interrupt(fiber)));
|
|
115
|
+
if (Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause)) return yield* Effect.failCause(exit.cause);
|
|
116
|
+
}, Effect.orDie);
|
|
117
|
+
const drain = Semaphore.withPermit(turnsLock)(Effect.gen(function* () {
|
|
118
|
+
while (!(yield* isDeleted) && needsTurn(yield* chat.entries, wakes)) yield* run({
|
|
119
|
+
registration,
|
|
120
|
+
handler,
|
|
121
|
+
chat,
|
|
122
|
+
services,
|
|
123
|
+
checkOpen: Effect.asVoid(checkAvailable)
|
|
124
|
+
});
|
|
125
|
+
}));
|
|
126
|
+
const runner = yield* inWorking(makeRunner({
|
|
127
|
+
chat,
|
|
128
|
+
handle,
|
|
129
|
+
specialists,
|
|
130
|
+
model: registration.model,
|
|
131
|
+
holding,
|
|
132
|
+
report: Effect.fnUntraced(function* (finished) {
|
|
133
|
+
yield* store(finished);
|
|
134
|
+
yield* inBackground(drain);
|
|
135
|
+
})
|
|
136
|
+
}));
|
|
137
|
+
const services = Context.make(CurrentChat, handle).pipe(Context.add(Runner, runner), Context.merge(registration.model));
|
|
138
|
+
const remove = Effect.gen(function* () {
|
|
139
|
+
if (!(yield* Semaphore.withPermit(writes)(Effect.gen(function* () {
|
|
140
|
+
if (yield* isDeleted) return false;
|
|
141
|
+
yield* stored([ChatDeleted.make({})]);
|
|
142
|
+
return yield* Deferred.succeed(deleted, void 0);
|
|
143
|
+
})).pipe(Effect.uninterruptible))) return;
|
|
144
|
+
const closing = yield* Effect.forkDetach(Effect.gen(function* () {
|
|
145
|
+
yield* Scope.close(working, Exit.void);
|
|
146
|
+
yield* options.keepAlive(false);
|
|
147
|
+
}));
|
|
148
|
+
yield* Fiber.await(closing);
|
|
149
|
+
});
|
|
150
|
+
yield* checkAvailable;
|
|
151
|
+
return {
|
|
152
|
+
submit: Effect.fnUntraced(function* (input) {
|
|
153
|
+
yield* store(input);
|
|
154
|
+
yield* inRequest(drain);
|
|
155
|
+
}),
|
|
156
|
+
submitInBackground: Effect.fnUntraced(function* (input) {
|
|
157
|
+
yield* store(input);
|
|
158
|
+
yield* inBackground(drain);
|
|
159
|
+
}),
|
|
160
|
+
resume: Effect.gen(function* () {
|
|
161
|
+
if (needsTurn(yield* chat.entries, wakes)) yield* inBackground(drain);
|
|
162
|
+
}),
|
|
163
|
+
stream: (after) => Stream.unwrap(Effect.gen(function* () {
|
|
164
|
+
const subscription = yield* PubSub.subscribe(channel);
|
|
165
|
+
const all = yield* chat.entries;
|
|
166
|
+
const stored = all.filter((entry) => entry.seq > after);
|
|
167
|
+
const last = stored.at(-1)?.seq ?? after;
|
|
168
|
+
if (all.some(isChatDeleted)) return Stream.fromIterable(stored);
|
|
169
|
+
return Stream.concat(Stream.fromIterable(stored), Stream.fromSubscription(subscription).pipe(Stream.filter((entry) => entry.seq > last))).pipe(Stream.takeUntil(isChatDeleted));
|
|
170
|
+
})),
|
|
171
|
+
delete: remove
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
//#endregion
|
|
175
|
+
export { make };
|
|
176
|
+
|
|
177
|
+
//# sourceMappingURL=chat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.js","names":["AssistantEvent.isLibraryEvent","AssistantEvent.isInput","Chats.Chats","AppEvents.isRegistered","AppEvents.encode","AppEvents.decodeEntries","History.needsTurn","Turns.run","Specialists.makeRunner","SpecialistService.Runner"],"sources":["../../src/internal/chat.ts"],"sourcesContent":["import * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport * as Deferred from \"effect/Deferred\"\nimport * as Effect from \"effect/Effect\"\nimport * as Exit from \"effect/Exit\"\nimport * as Fiber from \"effect/Fiber\"\nimport * as FiberSet from \"effect/FiberSet\"\nimport * as Predicate from \"effect/Predicate\"\nimport * as PubSub from \"effect/PubSub\"\nimport * as Ref from \"effect/Ref\"\nimport * as Scope from \"effect/Scope\"\nimport * as Semaphore from \"effect/Semaphore\"\nimport * as Stream from \"effect/Stream\"\nimport * as SynchronizedRef from \"effect/SynchronizedRef\"\nimport * as AssistantEvent from \"../AssistantEvent.ts\"\nimport type { ChatId } from \"../ChatId.ts\"\nimport { ChatLog } from \"../ChatLog.ts\"\nimport { CurrentChat } from \"../CurrentChat.ts\"\nimport * as Chats from \"../Chats.ts\"\nimport * as SpecialistService from \"../Specialist.ts\"\nimport * as AppEvents from \"./events.ts\"\nimport * as History from \"./history.ts\"\nimport * as Specialists from \"./specialists.ts\"\nimport * as Turns from \"./turns.ts\"\nimport type { Writer } from \"./writer.ts\"\n\nconst idOf = (event: { readonly _tag: string }): string | undefined =>\n AssistantEvent.isLibraryEvent(event)\n ? AssistantEvent.isInput(event)\n ? event.id\n : undefined\n : Predicate.hasProperty(event, \"id\") && Predicate.isString(event.id)\n ? event.id\n : undefined\n\nconst makeChannelPubSub = Effect.acquireRelease(PubSub.unbounded<AssistantEvent.Entry>(), PubSub.shutdown)\n\nconst makeHolding = Effect.fnUntraced(function* (keepAlive: (enabled: boolean) => Effect.Effect<void>) {\n const holds = yield* SynchronizedRef.make(0)\n\n const acquire = SynchronizedRef.updateEffect(\n holds,\n Effect.fnUntraced(function* (n: number) {\n if (n !== 0) return n + 1\n\n yield* keepAlive(true)\n\n return 1\n })\n )\n\n const release = SynchronizedRef.updateEffect(\n holds,\n Effect.fnUntraced(function* (n: number) {\n if (n !== 1) return n - 1\n\n yield* keepAlive(false)\n\n return 0\n })\n )\n\n return (effect: Effect.Effect<void>) =>\n Effect.acquireUseRelease(\n acquire,\n () => effect,\n // An interrupted effect (a shutdown) keeps its hold, so the chat starts again and picks up where it was cut off.\n (_, exit) => (Exit.hasInterrupts(exit) ? Effect.void : release)\n )\n})\n\n/** @internal */\nexport interface Chat {\n readonly submit: (input: AssistantEvent.Input | AssistantEvent.StoredAppEvent) => Effect.Effect<void>\n readonly submitInBackground: (input: AssistantEvent.Input | AssistantEvent.StoredAppEvent) => Effect.Effect<void>\n // For inputs no turn has read, like a report stored during a shutdown.\n readonly resume: Effect.Effect<void>\n readonly stream: (after: number) => Stream.Stream<AssistantEvent.Entry>\n // Stops what works in the chat and ends its subscribers' streams; its log stays.\n readonly delete: Effect.Effect<void>\n}\n\nconst isChatDeleted = (entry: AssistantEvent.Entry) => Predicate.isTagged(entry.event, \"ChatDeleted\")\n\nconst deletedChat = (entries: ReadonlyArray<AssistantEvent.Entry>): Chat => ({\n submit: () => Effect.void,\n submitInBackground: () => Effect.void,\n resume: Effect.void,\n stream: (after) => Stream.fromIterable(entries.filter((entry) => entry.seq > after)),\n delete: Effect.void\n})\n\nconst refused = (input: { readonly _tag: string }, why: string) =>\n Effect.logDebug(`assistant chat ${why}: ${input._tag} not stored`)\n\n/** @internal */\nexport const make = Effect.fnUntraced(function* (options: {\n readonly registration: Turns.Registration\n readonly chatId: ChatId\n readonly keepAlive: (enabled: boolean) => Effect.Effect<void>\n}) {\n const { registration, chatId } = options\n const { app } = registration.definition\n const { wakes } = app\n const storage = yield* ChatLog\n const chats = yield* Chats.Chats\n const initial = yield* storage.read(chatId)\n\n if (initial.some(isChatDeleted)) return deletedChat(initial)\n\n const channel = yield* makeChannelPubSub\n const writes = yield* Semaphore.make(1)\n const turnsLock = yield* Semaphore.make(1)\n const holding = yield* makeHolding(options.keepAlive)\n const deleted = yield* Deferred.make<undefined>()\n // So deleting the chat stops all its work: its turns, runs, and the builds' resources.\n const working = yield* Scope.fork(yield* Effect.scope)\n const inWorking = Effect.provideService(Scope.Scope, working)\n const background = yield* inWorking(FiberSet.make())\n const requests = yield* inWorking(FiberSet.make())\n\n const isDeleted = Deferred.isDone(deleted)\n\n // The chat is its log's only writer, so it reads the log once and turns read memory.\n const entries = yield* Ref.make(initial)\n\n // Every writer goes through here, one at a time, so each append is numbered after the last. After a delete it\n // stores nothing.\n const write = Effect.fnUntraced(function* (\n events: ReadonlyArray<AssistantEvent.AssistantEvent | AssistantEvent.StoredAppEvent>\n ) {\n const unknown = events.find((event) => !AssistantEvent.isLibraryEvent(event) && !AppEvents.isRegistered(app, event))\n\n if (unknown !== undefined) {\n return yield* Effect.die(`${unknown._tag} isn't one of the ${registration.definition.name} assistant's events.`)\n }\n\n if (yield* isDeleted) return []\n\n return yield* stored(events)\n })\n\n // Uninterruptible: a stored append must reach memory and the subscribers too, or a turn misses it and replies twice.\n const stored = Effect.fnUntraced(function* (\n events: ReadonlyArray<AssistantEvent.AssistantEvent | AssistantEvent.StoredAppEvent>\n ) {\n const stored = yield* storage.append(chatId, events)\n\n yield* Ref.update(entries, (all) => [...all, ...stored])\n yield* PubSub.publishAll(channel, stored)\n\n return stored\n }, Effect.uninterruptible)\n\n const chat: Writer = {\n chatId,\n entries: Ref.get(entries),\n append: (events) => Semaphore.withPermit(writes)(write(events))\n }\n\n const toStored = (event: {\n readonly _tag: string\n }): Effect.Effect<AssistantEvent.AssistantEvent | AssistantEvent.StoredAppEvent> =>\n AssistantEvent.isLibraryEvent(event)\n ? Effect.succeed(event)\n : AppEvents.isRegistered(app, event)\n ? AppEvents.encode(app, event)\n : Effect.die(`${event._tag} isn't one of the ${registration.definition.name} assistant's events.`)\n\n // What handlers, tools, and runs see: the assistant's own events decoded, and encoded when appended.\n const handle: Turns.TypedChat = {\n chatId,\n entries: Effect.map(chat.entries, (all) => AppEvents.decodeEntries(app, all)),\n append: (...events) => Effect.asVoid(Effect.flatMap(Effect.forEach(events, toStored), chat.append))\n }\n\n // A chat the app deleted is deleted here too, which stops what works in it: a turn that checks stops there.\n const checkAvailable: Effect.Effect<boolean> = chats.get(chatId).pipe(\n Effect.as(true),\n Effect.catchTag(\"GetChatError\", (unavailable) =>\n unavailable.reason === \"Deleted\"\n ? Effect.as(\n Effect.suspend(() => remove),\n false\n )\n : Effect.succeed(false)\n )\n )\n\n const store = Effect.fnUntraced(function* (input: AssistantEvent.Input | AssistantEvent.StoredAppEvent) {\n if (yield* isDeleted) return yield* refused(input, \"is deleted\")\n\n if (!(yield* checkAvailable)) return yield* refused(input, \"is unavailable\")\n\n // Checked under the write lock: a retry that arrives while the first submit is storing is stored once.\n yield* Semaphore.withPermit(writes)(\n Effect.gen(function* () {\n if (yield* isDeleted) return yield* refused(input, \"is deleted\")\n\n const id = idOf(input)\n\n if (id !== undefined && (yield* Ref.get(entries)).some(({ event }) => idOf(event) === id)) return\n\n yield* write([input])\n })\n )\n })\n\n // The handlers' builds run in the chat's working scope: what they set up lives until the chat closes or is deleted.\n const handler = yield* inWorking(Effect.provideService(registration.open(handle), CurrentChat, handle))\n\n const specialists = yield* Effect.forEach(\n registration.specialists,\n Effect.fnUntraced(function* ({ specialist, built }) {\n const handler = yield* inWorking(Effect.provideService(built.open, CurrentChat, handle))\n\n return { specialist, handler }\n })\n )\n\n const inBackground = (effect: Effect.Effect<void>) => FiberSet.run(background, holding(effect)).pipe(Effect.asVoid)\n\n // A request's turns run in the working scope too, so a delete stops them; the request ends quietly then.\n const inRequest = Effect.fnUntraced(function* (effect: Effect.Effect<void>) {\n const fiber = yield* FiberSet.run(requests, effect)\n const exit = yield* Fiber.await(fiber).pipe(Effect.onInterrupt(() => Fiber.interrupt(fiber)))\n\n if (Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause)) {\n return yield* Effect.failCause(exit.cause)\n }\n }, Effect.orDie)\n\n const drain: Effect.Effect<void> = Semaphore.withPermit(turnsLock)(\n Effect.gen(function* () {\n while (!(yield* isDeleted) && History.needsTurn(yield* chat.entries, wakes)) {\n yield* Turns.run({ registration, handler, chat, services, checkOpen: Effect.asVoid(checkAvailable) })\n }\n })\n )\n\n const runner = yield* inWorking(\n Specialists.makeRunner({\n chat,\n handle,\n specialists,\n model: registration.model,\n holding,\n report: Effect.fnUntraced(function* (finished) {\n yield* store(finished)\n yield* inBackground(drain)\n })\n })\n )\n\n const services = Context.make(CurrentChat, handle).pipe(\n Context.add(SpecialistService.Runner, runner),\n Context.merge(registration.model)\n )\n\n const remove = Effect.gen(function* () {\n // Under the write lock: an append in flight is stored before the `ChatDeleted`; none comes after.\n const first = yield* Semaphore.withPermit(writes)(\n Effect.gen(function* () {\n if (yield* isDeleted) return false\n\n yield* stored([AssistantEvent.ChatDeleted.make({})])\n\n return yield* Deferred.succeed(deleted, undefined)\n })\n ).pipe(Effect.uninterruptible)\n\n if (!first) return\n\n // Its own fiber: a tool that deletes its own chat is in the working scope, and closing it interrupts that tool.\n // Interrupted work keeps its hold (see `makeHolding`), so the chat lets go of it here.\n const closing = yield* Effect.forkDetach(\n Effect.gen(function* () {\n yield* Scope.close(working, Exit.void)\n yield* options.keepAlive(false)\n })\n )\n\n yield* Fiber.await(closing)\n })\n\n // A chat the app deleted while it was closed is deleted now, so its subscribers hear it.\n yield* checkAvailable\n\n const chatApi: Chat = {\n submit: Effect.fnUntraced(function* (input) {\n yield* store(input)\n yield* inRequest(drain)\n }),\n submitInBackground: Effect.fnUntraced(function* (input) {\n yield* store(input)\n yield* inBackground(drain)\n }),\n resume: Effect.gen(function* () {\n if (History.needsTurn(yield* chat.entries, wakes)) yield* inBackground(drain)\n }),\n stream: (after) =>\n Stream.unwrap(\n Effect.gen(function* () {\n // Subscribes before it reads, so nothing appended in between is missed.\n const subscription = yield* PubSub.subscribe(channel)\n const all = yield* chat.entries\n const stored = all.filter((entry) => entry.seq > after)\n const last = stored.at(-1)?.seq ?? after\n\n // Deleted: what the reader hasn't seen, then the end. Otherwise the stream ends with the `ChatDeleted`.\n if (all.some(isChatDeleted)) return Stream.fromIterable(stored)\n\n return Stream.concat(\n Stream.fromIterable(stored),\n Stream.fromSubscription(subscription).pipe(Stream.filter((entry) => entry.seq > last))\n ).pipe(Stream.takeUntil(isChatDeleted))\n })\n ),\n delete: remove\n }\n\n return chatApi\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,QAAQ,UACZA,eAA8B,KAAK,IAC/BC,QAAuB,KAAK,IAC1B,MA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 @@
|
|
|
1
|
+
import { Any, AppEvent_d_exports, EventSchema, Render } from "../AppEvent.js";
|
|
2
|
+
import { AnyEntry, AssistantEvent_d_exports } from "../AssistantEvent.js";
|
|
3
|
+
import { Assistant_d_exports, Entry } from "../Assistant.js";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as Option from "effect/Option";
|
|
7
|
+
declare namespace events_d_exports {
|
|
8
|
+
export { AppEvents, DecodedEntries, decodeEntries, decodeEntry, encode, isRegistered, make, read };
|
|
9
|
+
}
|
|
10
|
+
/** @internal */
|
|
11
|
+
export interface AppEvents {
|
|
12
|
+
readonly byTag: ReadonlyMap<string, Registered>;
|
|
13
|
+
readonly wakes: ReadonlySet<string>;
|
|
14
|
+
}
|
|
15
|
+
interface Registered {
|
|
16
|
+
readonly schema: EventSchema;
|
|
17
|
+
readonly render: Render<{
|
|
18
|
+
readonly _tag: string;
|
|
19
|
+
}> | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** @internal */
|
|
22
|
+
export declare const make: (events: ReadonlyArray<Any>) => AppEvents;
|
|
23
|
+
/** @internal */
|
|
24
|
+
export declare const encode: (app: AppEvents, event: {
|
|
25
|
+
readonly _tag: string;
|
|
26
|
+
}) => Effect.Effect<{
|
|
27
|
+
readonly [x: string]: Schema.Json;
|
|
28
|
+
readonly _tag: string & import("effect/Brand").Brand<"~effect-assistant/AppTag">;
|
|
29
|
+
}, never, never>;
|
|
30
|
+
/** @internal */
|
|
31
|
+
export declare const isRegistered: (app: AppEvents, event: {
|
|
32
|
+
readonly _tag: string;
|
|
33
|
+
}) => boolean;
|
|
34
|
+
/** @internal */
|
|
35
|
+
export declare const decodeEntry: (app: AppEvents, entry: AnyEntry) => Option.Option<Entry<any>>;
|
|
36
|
+
/** @internal */
|
|
37
|
+
export declare const decodeEntries: (app: AppEvents, entries: ReadonlyArray<AnyEntry>) => ReadonlyArray<Entry<any>>;
|
|
38
|
+
/** @internal */
|
|
39
|
+
export type DecodedEntries = ReturnType<typeof decodeEntries>;
|
|
40
|
+
/** @internal */
|
|
41
|
+
export declare const read: (app: AppEvents, event: {
|
|
42
|
+
readonly _tag: string;
|
|
43
|
+
}) => string | undefined;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { events_d_exports };
|
|
46
|
+
//# sourceMappingURL=events.d.ts.map
|