effect-assistant 0.2.0 → 0.3.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/dist/Assistant.d.ts +74 -28
- package/dist/Assistant.d.ts.map +1 -1
- package/dist/Assistant.js +11 -4
- package/dist/Assistant.js.map +1 -1
- package/dist/AssistantActivity.d.ts +10 -16
- package/dist/AssistantActivity.d.ts.map +1 -1
- package/dist/AssistantActivity.js +11 -4
- package/dist/AssistantActivity.js.map +1 -1
- package/dist/AssistantEngine.d.ts +39 -1
- package/dist/AssistantEngine.d.ts.map +1 -1
- package/dist/AssistantEngine.js +81 -28
- package/dist/AssistantEngine.js.map +1 -1
- package/dist/AssistantEvent.d.ts +50 -5
- package/dist/AssistantEvent.d.ts.map +1 -1
- package/dist/AssistantEvent.js +28 -7
- package/dist/AssistantEvent.js.map +1 -1
- package/dist/BlockKit.d.ts +4 -4
- package/dist/BlockKit.js +1 -1
- package/dist/BlockKit.js.map +1 -1
- package/dist/ChatLog.js +1 -1
- package/dist/Compaction.d.ts +6 -2
- package/dist/Compaction.d.ts.map +1 -1
- package/dist/Compaction.js +6 -2
- package/dist/Compaction.js.map +1 -1
- package/dist/CurrentChat.d.ts +2 -1
- package/dist/CurrentChat.d.ts.map +1 -1
- package/dist/CurrentChat.js.map +1 -1
- package/dist/Instructions.js +1 -1
- package/dist/Skill.d.ts +33 -0
- package/dist/Skill.d.ts.map +1 -1
- package/dist/Skill.js +27 -1
- package/dist/Skill.js.map +1 -1
- package/dist/Specialist.d.ts +4 -1
- package/dist/Specialist.d.ts.map +1 -1
- package/dist/Specialist.js.map +1 -1
- package/dist/Timeline.d.ts +482 -0
- package/dist/Timeline.d.ts.map +1 -0
- package/dist/Timeline.js +572 -0
- package/dist/Timeline.js.map +1 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/internal/chat.js +5 -6
- package/dist/internal/chat.js.map +1 -1
- package/dist/internal/events.d.ts +15 -16
- package/dist/internal/events.d.ts.map +1 -1
- package/dist/internal/events.js +29 -28
- package/dist/internal/events.js.map +1 -1
- package/dist/internal/history.js +25 -19
- package/dist/internal/history.js.map +1 -1
- package/dist/internal/input.js +7 -0
- package/dist/internal/input.js.map +1 -0
- package/dist/internal/loop.js +1 -1
- package/dist/internal/skills.js +6 -1
- package/dist/internal/skills.js.map +1 -1
- package/dist/internal/specialists.js +5 -4
- package/dist/internal/specialists.js.map +1 -1
- package/dist/internal/tools.js +1 -1
- package/dist/internal/turns.d.ts.map +1 -1
- package/dist/internal/turns.js +23 -35
- package/dist/internal/turns.js.map +1 -1
- package/package.json +1 -1
- package/src/Assistant.ts +75 -29
- package/src/AssistantActivity.ts +11 -18
- package/src/AssistantEngine.ts +110 -43
- package/src/AssistantEvent.ts +46 -8
- package/src/BlockKit.ts +6 -6
- package/src/Compaction.ts +6 -2
- package/src/CurrentChat.ts +2 -1
- package/src/Skill.ts +34 -1
- package/src/Specialist.ts +4 -1
- package/src/Timeline.ts +861 -0
- package/src/index.ts +5 -10
- package/src/internal/chat.ts +4 -4
- package/src/internal/events.ts +43 -43
- package/src/internal/history.ts +36 -29
- package/src/internal/input.ts +3 -0
- package/src/internal/skills.ts +11 -0
- package/src/internal/specialists.ts +3 -2
- package/src/internal/turns.ts +30 -53
- package/dist/AppEvent.d.ts +0 -111
- package/dist/AppEvent.d.ts.map +0 -1
- package/dist/AppEvent.js +0 -71
- package/dist/AppEvent.js.map +0 -1
- package/dist/ChatView.d.ts +0 -408
- package/dist/ChatView.d.ts.map +0 -1
- package/dist/ChatView.js +0 -443
- package/dist/ChatView.js.map +0 -1
- package/src/AppEvent.ts +0 -134
- package/src/ChatView.ts +0 -587
package/dist/AppEvent.d.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import * as SchemaAST from "effect/SchemaAST";
|
|
2
|
-
import * as Schema from "effect/Schema";
|
|
3
|
-
declare namespace AppEvent_d_exports {
|
|
4
|
-
export { Any, AppEvent, EventSchema, Render, Type, make };
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Schema for one of the application's own events.
|
|
8
|
-
*
|
|
9
|
-
* It is a tagged struct or class (`Schema.TaggedStruct`, `Schema.TaggedClass`) that needs no
|
|
10
|
-
* services.
|
|
11
|
-
*
|
|
12
|
-
* @category models
|
|
13
|
-
* @since 0.1.0
|
|
14
|
-
*/
|
|
15
|
-
export type EventSchema = Schema.Codec<{
|
|
16
|
-
readonly _tag: string;
|
|
17
|
-
}, {
|
|
18
|
-
readonly _tag: string;
|
|
19
|
-
}> & {
|
|
20
|
-
readonly fields: {
|
|
21
|
-
readonly _tag: {
|
|
22
|
-
readonly ast: SchemaAST.AST;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Describes how the model reads an event.
|
|
28
|
-
*
|
|
29
|
-
* `"json"` shows the event's tag and fields as JSON. A function shows the text it returns for the
|
|
30
|
-
* event.
|
|
31
|
-
*
|
|
32
|
-
* @category models
|
|
33
|
-
* @since 0.1.0
|
|
34
|
-
*/
|
|
35
|
-
export type Render<A> = "json" | ((event: A) => string);
|
|
36
|
-
/**
|
|
37
|
-
* Represents one of the application's events, registered with an assistant.
|
|
38
|
-
*
|
|
39
|
-
* It holds the event's schema and tag, whether storing it wakes a turn, and how the model reads
|
|
40
|
-
* it. A `render` of `undefined` means the model doesn't read it.
|
|
41
|
-
*
|
|
42
|
-
* @category models
|
|
43
|
-
* @since 0.1.0
|
|
44
|
-
*/
|
|
45
|
-
export interface AppEvent<S extends EventSchema = EventSchema> {
|
|
46
|
-
readonly schema: S;
|
|
47
|
-
readonly tag: string;
|
|
48
|
-
readonly wakes: boolean;
|
|
49
|
-
readonly render: Render<S["Type"]> | undefined;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Represents any registered event, for generic constraints.
|
|
53
|
-
*
|
|
54
|
-
* @category utility types
|
|
55
|
-
* @since 0.1.0
|
|
56
|
-
*/
|
|
57
|
-
export type Any = AppEvent<any>;
|
|
58
|
-
/**
|
|
59
|
-
* Extracts the type of a registered event's values.
|
|
60
|
-
*
|
|
61
|
-
* @category utility types
|
|
62
|
-
* @since 0.1.0
|
|
63
|
-
*/
|
|
64
|
-
export type Type<E extends Any> = E["schema"]["Type"];
|
|
65
|
-
/**
|
|
66
|
-
* Registers one of the application's events with an assistant.
|
|
67
|
-
*
|
|
68
|
-
* **Details**
|
|
69
|
-
*
|
|
70
|
-
* Storing the event wakes a turn only when `wakes` is `true`; it defaults to `false`. `render`
|
|
71
|
-
* defaults to `"json"` for an event that wakes a turn. An event that doesn't wake a turn and has
|
|
72
|
-
* no `render` isn't read by the model.
|
|
73
|
-
*
|
|
74
|
-
* The schema must be a tagged struct or class whose `_tag` is a string literal; `make` throws
|
|
75
|
-
* otherwise.
|
|
76
|
-
*
|
|
77
|
-
* **Example** (Registering an event that wakes a turn)
|
|
78
|
-
*
|
|
79
|
-
* ```ts
|
|
80
|
-
* import { AppEvent, Assistant, InputId } from "effect-assistant"
|
|
81
|
-
* import * as Schema from "effect/Schema"
|
|
82
|
-
*
|
|
83
|
-
* class OrderShipped extends Schema.TaggedClass<OrderShipped>()("OrderShipped", {
|
|
84
|
-
* id: InputId.InputId,
|
|
85
|
-
* orderId: Schema.String,
|
|
86
|
-
* carrier: Schema.String
|
|
87
|
-
* }) {}
|
|
88
|
-
*
|
|
89
|
-
* export const MyAssistant = Assistant.make("my-assistant", {
|
|
90
|
-
* events: [
|
|
91
|
-
* AppEvent.make(OrderShipped, {
|
|
92
|
-
* wakes: true,
|
|
93
|
-
* render: (shipped) =>
|
|
94
|
-
* `Order ${shipped.orderId} shipped with ${shipped.carrier}. Tell the user if it matters.`
|
|
95
|
-
* })
|
|
96
|
-
* ]
|
|
97
|
-
* })
|
|
98
|
-
* ```
|
|
99
|
-
*
|
|
100
|
-
* @category constructors
|
|
101
|
-
* @since 0.1.0
|
|
102
|
-
*/
|
|
103
|
-
export declare const make: <S extends EventSchema>(schema: S, options?: {
|
|
104
|
-
/** Whether storing it starts a turn, like a user's message. Default false. */
|
|
105
|
-
readonly wakes?: boolean | undefined;
|
|
106
|
-
/** How the model reads it in its history. */
|
|
107
|
-
readonly render?: Render<S["Type"]> | undefined;
|
|
108
|
-
}) => AppEvent<S>;
|
|
109
|
-
//#endregion
|
|
110
|
-
export { AppEvent_d_exports };
|
|
111
|
-
//# sourceMappingURL=AppEvent.d.ts.map
|
package/dist/AppEvent.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AppEvent.d.ts","names":[],"sources":["../src/AppEvent.ts"],"mappings":";;;;;;;;;;;;;;YAuBY,cAAc,OAAO;WAAiB;;WAA2B;;WAClE;aAAmB;eAAiB,KAAK,UAAU;;;;;;;;;;;;;YAYlD,OAAO,gBAAgB,OAAO;;;;;;;;;;iBAWzB,SAAS,UAAU,cAAc;WACvC,QAAQ;WACR;WACA;WACA,QAAQ,OAAO;;;;;;;;YASd,MAAM;;;;;;;YAQN,KAAK,UAAU,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgDrB,OAAQ,UAAU,aAAW,QAChC,GAAC;;WAGE;;WAEA,SAAS,OAAO;MAE1B,SAAS"}
|
package/dist/AppEvent.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
import * as Predicate from "effect/Predicate";
|
|
3
|
-
import * as SchemaAST from "effect/SchemaAST";
|
|
4
|
-
//#region src/AppEvent.ts
|
|
5
|
-
/**
|
|
6
|
-
* Registers an application's own events with an assistant.
|
|
7
|
-
*
|
|
8
|
-
* An app event is a tagged schema for something the application reports into a chat, such as a
|
|
9
|
-
* workflow's progress, a webhook, a summary for compaction, or the draft the user opened.
|
|
10
|
-
* {@link make} registers one with two choices: whether storing it wakes a turn (`wakes`), and
|
|
11
|
-
* how the model reads it (`render`).
|
|
12
|
-
*
|
|
13
|
-
* @since 0.1.0
|
|
14
|
-
*/
|
|
15
|
-
var AppEvent_exports = /* @__PURE__ */ __exportAll({ make: () => make });
|
|
16
|
-
const tagOf = (schema) => {
|
|
17
|
-
const ast = schema.fields._tag.ast;
|
|
18
|
-
if (SchemaAST.isLiteral(ast) && Predicate.isString(ast.literal)) return ast.literal;
|
|
19
|
-
throw new Error("An app event is a tagged struct or class.");
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Registers one of the application's events with an assistant.
|
|
23
|
-
*
|
|
24
|
-
* **Details**
|
|
25
|
-
*
|
|
26
|
-
* Storing the event wakes a turn only when `wakes` is `true`; it defaults to `false`. `render`
|
|
27
|
-
* defaults to `"json"` for an event that wakes a turn. An event that doesn't wake a turn and has
|
|
28
|
-
* no `render` isn't read by the model.
|
|
29
|
-
*
|
|
30
|
-
* The schema must be a tagged struct or class whose `_tag` is a string literal; `make` throws
|
|
31
|
-
* otherwise.
|
|
32
|
-
*
|
|
33
|
-
* **Example** (Registering an event that wakes a turn)
|
|
34
|
-
*
|
|
35
|
-
* ```ts
|
|
36
|
-
* import { AppEvent, Assistant, InputId } from "effect-assistant"
|
|
37
|
-
* import * as Schema from "effect/Schema"
|
|
38
|
-
*
|
|
39
|
-
* class OrderShipped extends Schema.TaggedClass<OrderShipped>()("OrderShipped", {
|
|
40
|
-
* id: InputId.InputId,
|
|
41
|
-
* orderId: Schema.String,
|
|
42
|
-
* carrier: Schema.String
|
|
43
|
-
* }) {}
|
|
44
|
-
*
|
|
45
|
-
* export const MyAssistant = Assistant.make("my-assistant", {
|
|
46
|
-
* events: [
|
|
47
|
-
* AppEvent.make(OrderShipped, {
|
|
48
|
-
* wakes: true,
|
|
49
|
-
* render: (shipped) =>
|
|
50
|
-
* `Order ${shipped.orderId} shipped with ${shipped.carrier}. Tell the user if it matters.`
|
|
51
|
-
* })
|
|
52
|
-
* ]
|
|
53
|
-
* })
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* @category constructors
|
|
57
|
-
* @since 0.1.0
|
|
58
|
-
*/
|
|
59
|
-
const make = (schema, options) => {
|
|
60
|
-
const wakes = options?.wakes ?? false;
|
|
61
|
-
return {
|
|
62
|
-
schema,
|
|
63
|
-
tag: tagOf(schema),
|
|
64
|
-
wakes,
|
|
65
|
-
render: options?.render ?? (wakes ? "json" : void 0)
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
//#endregion
|
|
69
|
-
export { AppEvent_exports, make };
|
|
70
|
-
|
|
71
|
-
//# sourceMappingURL=AppEvent.js.map
|
package/dist/AppEvent.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AppEvent.js","names":[],"sources":["../src/AppEvent.ts"],"sourcesContent":["/**\n * Registers an application's own events with an assistant.\n *\n * An app event is a tagged schema for something the application reports into a chat, such as a\n * workflow's progress, a webhook, a summary for compaction, or the draft the user opened.\n * {@link make} registers one with two choices: whether storing it wakes a turn (`wakes`), and\n * how the model reads it (`render`).\n *\n * @since 0.1.0\n */\nimport * as Predicate from \"effect/Predicate\"\nimport type * as Schema from \"effect/Schema\"\nimport * as SchemaAST from \"effect/SchemaAST\"\n\n/**\n * Schema for one of the application's own events.\n *\n * It is a tagged struct or class (`Schema.TaggedStruct`, `Schema.TaggedClass`) that needs no\n * services.\n *\n * @category models\n * @since 0.1.0\n */\nexport type EventSchema = Schema.Codec<{ readonly _tag: string }, { readonly _tag: string }> & {\n readonly fields: { readonly _tag: { readonly ast: SchemaAST.AST } }\n}\n\n/**\n * Describes how the model reads an event.\n *\n * `\"json\"` shows the event's tag and fields as JSON. A function shows the text it returns for the\n * event.\n *\n * @category models\n * @since 0.1.0\n */\nexport type Render<A> = \"json\" | ((event: A) => string)\n\n/**\n * Represents one of the application's events, registered with an assistant.\n *\n * It holds the event's schema and tag, whether storing it wakes a turn, and how the model reads\n * it. A `render` of `undefined` means the model doesn't read it.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface AppEvent<S extends EventSchema = EventSchema> {\n readonly schema: S\n readonly tag: string\n readonly wakes: boolean\n readonly render: Render<S[\"Type\"]> | undefined\n}\n\n/**\n * Represents any registered event, for generic constraints.\n *\n * @category utility types\n * @since 0.1.0\n */\nexport type Any = AppEvent<any>\n\n/**\n * Extracts the type of a registered event's values.\n *\n * @category utility types\n * @since 0.1.0\n */\nexport type Type<E extends Any> = E[\"schema\"][\"Type\"]\n\nconst tagOf = (schema: EventSchema): string => {\n const ast = schema.fields._tag.ast\n\n if (SchemaAST.isLiteral(ast) && Predicate.isString(ast.literal)) return ast.literal\n\n throw new Error(\"An app event is a tagged struct or class.\")\n}\n\n/**\n * Registers one of the application's events with an assistant.\n *\n * **Details**\n *\n * Storing the event wakes a turn only when `wakes` is `true`; it defaults to `false`. `render`\n * defaults to `\"json\"` for an event that wakes a turn. An event that doesn't wake a turn and has\n * no `render` isn't read by the model.\n *\n * The schema must be a tagged struct or class whose `_tag` is a string literal; `make` throws\n * otherwise.\n *\n * **Example** (Registering an event that wakes a turn)\n *\n * ```ts\n * import { AppEvent, Assistant, InputId } from \"effect-assistant\"\n * import * as Schema from \"effect/Schema\"\n *\n * class OrderShipped extends Schema.TaggedClass<OrderShipped>()(\"OrderShipped\", {\n * id: InputId.InputId,\n * orderId: Schema.String,\n * carrier: Schema.String\n * }) {}\n *\n * export const MyAssistant = Assistant.make(\"my-assistant\", {\n * events: [\n * AppEvent.make(OrderShipped, {\n * wakes: true,\n * render: (shipped) =>\n * `Order ${shipped.orderId} shipped with ${shipped.carrier}. Tell the user if it matters.`\n * })\n * ]\n * })\n * ```\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = <S extends EventSchema>(\n schema: S,\n options?: {\n /** Whether storing it starts a turn, like a user's message. Default false. */\n readonly wakes?: boolean | undefined\n /** How the model reads it in its history. */\n readonly render?: Render<S[\"Type\"]> | undefined\n }\n): AppEvent<S> => {\n const wakes = options?.wakes ?? false\n\n return {\n schema,\n tag: tagOf(schema),\n wakes,\n render: options?.render ?? (wakes ? \"json\" : undefined)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsEA,MAAM,SAAS,WAAgC;CAC7C,MAAM,MAAM,OAAO,OAAO,KAAK;CAE/B,IAAI,UAAU,UAAU,GAAG,KAAK,UAAU,SAAS,IAAI,OAAO,GAAG,OAAO,IAAI;CAE5E,MAAM,IAAI,MAAM,2CAA2C;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,QACX,QACA,YAMgB;CAChB,MAAM,QAAQ,SAAS,SAAS;CAEhC,OAAO;EACL;EACA,KAAK,MAAM,MAAM;EACjB;EACA,QAAQ,SAAS,WAAW,QAAQ,SAAS,KAAA;CAC/C;AACF"}
|
package/dist/ChatView.d.ts
DELETED
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
import { AnyEntry, AssistantEvent_d_exports } from "./AssistantEvent.js";
|
|
2
|
-
import * as Schema from "effect/Schema";
|
|
3
|
-
import * as Stream from "effect/Stream";
|
|
4
|
-
declare namespace ChatView_d_exports {
|
|
5
|
-
export { Activity, AssistantMessage, Block, BlockStatus, Definition, Message, Options, SpecialistWorking, Update, UpdatesOptions, UserMessage, View, apply, empty, fromEntries, isIdle, updates };
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Schema for the status of a block. A block is `"open"` while it accepts an answer, `"answered"`
|
|
9
|
-
* once the user has used it, and `"closed"` when it closed without an answer because the user
|
|
10
|
-
* answered in words or moved on.
|
|
11
|
-
*
|
|
12
|
-
* @category schemas
|
|
13
|
-
* @since 0.1.0
|
|
14
|
-
*/
|
|
15
|
-
export declare const BlockStatus: Schema.Literals<readonly ["open", "answered", "closed"]>;
|
|
16
|
-
/**
|
|
17
|
-
* The status of a block.
|
|
18
|
-
*
|
|
19
|
-
* @category models
|
|
20
|
-
* @since 0.1.0
|
|
21
|
-
*/
|
|
22
|
-
export type BlockStatus = typeof BlockStatus.Type;
|
|
23
|
-
/**
|
|
24
|
-
* Schema for a block on an assistant's message. It holds the block's kind, its props (JSON, as
|
|
25
|
-
* the block's props schema encodes them), its status, and the user's answer (JSON, as the block's
|
|
26
|
-
* answer schema encodes it).
|
|
27
|
-
*
|
|
28
|
-
* @category schemas
|
|
29
|
-
* @since 0.1.0
|
|
30
|
-
*/
|
|
31
|
-
export declare const Block: Schema.Struct<{
|
|
32
|
-
readonly kind: Schema.String;
|
|
33
|
-
readonly props: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
34
|
-
readonly status: Schema.Literals<readonly ["open", "answered", "closed"]>;
|
|
35
|
-
readonly answer: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
36
|
-
}>;
|
|
37
|
-
/**
|
|
38
|
-
* Represents a block on an assistant's message.
|
|
39
|
-
*
|
|
40
|
-
* @category models
|
|
41
|
-
* @since 0.1.0
|
|
42
|
-
*/
|
|
43
|
-
export type Block = typeof Block.Type;
|
|
44
|
-
/**
|
|
45
|
-
* Schema for a message the user sent. `at` is when it was stored, in epoch
|
|
46
|
-
* milliseconds.
|
|
47
|
-
*
|
|
48
|
-
* @category schemas
|
|
49
|
-
* @since 0.1.0
|
|
50
|
-
*/
|
|
51
|
-
export declare const UserMessage: Schema.TaggedStruct<"UserMessage", {
|
|
52
|
-
readonly id: Schema.brand<Schema.String, "~effect-assistant/InputId">;
|
|
53
|
-
readonly text: Schema.String;
|
|
54
|
-
readonly attachments: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
55
|
-
readonly fileId: Schema.String;
|
|
56
|
-
readonly name: Schema.String;
|
|
57
|
-
readonly mediaType: Schema.String;
|
|
58
|
-
readonly size: Schema.Finite;
|
|
59
|
-
}>>>;
|
|
60
|
-
readonly at: Schema.Finite;
|
|
61
|
-
}>;
|
|
62
|
-
/**
|
|
63
|
-
* Represents a message the user sent.
|
|
64
|
-
*
|
|
65
|
-
* @category models
|
|
66
|
-
* @since 0.1.0
|
|
67
|
-
*/
|
|
68
|
-
export type UserMessage = typeof UserMessage.Type;
|
|
69
|
-
/**
|
|
70
|
-
* Schema for a message the assistant sent the user, including its block if it has one.
|
|
71
|
-
*
|
|
72
|
-
* @category schemas
|
|
73
|
-
* @since 0.1.0
|
|
74
|
-
*/
|
|
75
|
-
export declare const AssistantMessage: Schema.TaggedStruct<"AssistantMessage", {
|
|
76
|
-
readonly id: Schema.String;
|
|
77
|
-
readonly text: Schema.String;
|
|
78
|
-
readonly at: Schema.Finite;
|
|
79
|
-
readonly block: Schema.optional<Schema.Struct<{
|
|
80
|
-
readonly kind: Schema.String;
|
|
81
|
-
readonly props: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
82
|
-
readonly status: Schema.Literals<readonly ["open", "answered", "closed"]>;
|
|
83
|
-
readonly answer: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
84
|
-
}>>;
|
|
85
|
-
}>;
|
|
86
|
-
/**
|
|
87
|
-
* Represents a message the assistant sent the user.
|
|
88
|
-
*
|
|
89
|
-
* @category models
|
|
90
|
-
* @since 0.1.0
|
|
91
|
-
*/
|
|
92
|
-
export type AssistantMessage = typeof AssistantMessage.Type;
|
|
93
|
-
/**
|
|
94
|
-
* Schema for a message in the chat, sent by either the user or the assistant.
|
|
95
|
-
*
|
|
96
|
-
* @category schemas
|
|
97
|
-
* @since 0.1.0
|
|
98
|
-
*/
|
|
99
|
-
export declare const Message: Schema.Union<readonly [Schema.TaggedStruct<"UserMessage", {
|
|
100
|
-
readonly id: Schema.brand<Schema.String, "~effect-assistant/InputId">;
|
|
101
|
-
readonly text: Schema.String;
|
|
102
|
-
readonly attachments: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
103
|
-
readonly fileId: Schema.String;
|
|
104
|
-
readonly name: Schema.String;
|
|
105
|
-
readonly mediaType: Schema.String;
|
|
106
|
-
readonly size: Schema.Finite;
|
|
107
|
-
}>>>;
|
|
108
|
-
readonly at: Schema.Finite;
|
|
109
|
-
}>, Schema.TaggedStruct<"AssistantMessage", {
|
|
110
|
-
readonly id: Schema.String;
|
|
111
|
-
readonly text: Schema.String;
|
|
112
|
-
readonly at: Schema.Finite;
|
|
113
|
-
readonly block: Schema.optional<Schema.Struct<{
|
|
114
|
-
readonly kind: Schema.String;
|
|
115
|
-
readonly props: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
116
|
-
readonly status: Schema.Literals<readonly ["open", "answered", "closed"]>;
|
|
117
|
-
readonly answer: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
118
|
-
}>>;
|
|
119
|
-
}>]>;
|
|
120
|
-
/**
|
|
121
|
-
* Represents a message in the chat.
|
|
122
|
-
*
|
|
123
|
-
* @category models
|
|
124
|
-
* @since 0.1.0
|
|
125
|
-
*/
|
|
126
|
-
export type Message = typeof Message.Type;
|
|
127
|
-
/**
|
|
128
|
-
* Schema for a specialist that is working for the assistant. It holds the specialist's name and
|
|
129
|
-
* when it started, in epoch milliseconds.
|
|
130
|
-
*
|
|
131
|
-
* @category schemas
|
|
132
|
-
* @since 0.1.0
|
|
133
|
-
*/
|
|
134
|
-
export declare const SpecialistWorking: Schema.Struct<{
|
|
135
|
-
readonly specialist: Schema.String;
|
|
136
|
-
readonly since: Schema.Finite;
|
|
137
|
-
}>;
|
|
138
|
-
/**
|
|
139
|
-
* Represents a specialist that is working for the assistant.
|
|
140
|
-
*
|
|
141
|
-
* @category models
|
|
142
|
-
* @since 0.1.0
|
|
143
|
-
*/
|
|
144
|
-
export type SpecialistWorking = typeof SpecialistWorking.Type;
|
|
145
|
-
/**
|
|
146
|
-
* Schema for what is working in the chat.
|
|
147
|
-
*
|
|
148
|
-
* `working` is true while the assistant runs a turn, or when a turn is about to start for
|
|
149
|
-
* something that arrived. `specialists` lists the specialists that are working. When the chat is
|
|
150
|
-
* idle, nothing is working, even if a workflow is waiting on a timer or on the user.
|
|
151
|
-
*
|
|
152
|
-
* @category schemas
|
|
153
|
-
* @since 0.1.0
|
|
154
|
-
*/
|
|
155
|
-
export declare const Activity: Schema.Struct<{
|
|
156
|
-
readonly working: Schema.Boolean;
|
|
157
|
-
readonly specialists: Schema.$Array<Schema.Struct<{
|
|
158
|
-
readonly specialist: Schema.String;
|
|
159
|
-
readonly since: Schema.Finite;
|
|
160
|
-
}>>;
|
|
161
|
-
}>;
|
|
162
|
-
/**
|
|
163
|
-
* Represents what is working in the chat.
|
|
164
|
-
*
|
|
165
|
-
* @category models
|
|
166
|
-
* @since 0.1.0
|
|
167
|
-
*/
|
|
168
|
-
export type Activity = typeof Activity.Type;
|
|
169
|
-
/**
|
|
170
|
-
* Schema for a chat as its user sees it. It holds the chat's messages, what is working in it,
|
|
171
|
-
* whether the last turn failed, and whether the chat was deleted. `seq` is the position in the
|
|
172
|
-
* chat's log that the view is up to.
|
|
173
|
-
*
|
|
174
|
-
* @category schemas
|
|
175
|
-
* @since 0.1.0
|
|
176
|
-
*/
|
|
177
|
-
export declare const View: Schema.Struct<{
|
|
178
|
-
readonly seq: Schema.Int;
|
|
179
|
-
readonly messages: Schema.$Array<Schema.Union<readonly [Schema.TaggedStruct<"UserMessage", {
|
|
180
|
-
readonly id: Schema.brand<Schema.String, "~effect-assistant/InputId">;
|
|
181
|
-
readonly text: Schema.String;
|
|
182
|
-
readonly attachments: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
183
|
-
readonly fileId: Schema.String;
|
|
184
|
-
readonly name: Schema.String;
|
|
185
|
-
readonly mediaType: Schema.String;
|
|
186
|
-
readonly size: Schema.Finite;
|
|
187
|
-
}>>>;
|
|
188
|
-
readonly at: Schema.Finite;
|
|
189
|
-
}>, Schema.TaggedStruct<"AssistantMessage", {
|
|
190
|
-
readonly id: Schema.String;
|
|
191
|
-
readonly text: Schema.String;
|
|
192
|
-
readonly at: Schema.Finite;
|
|
193
|
-
readonly block: Schema.optional<Schema.Struct<{
|
|
194
|
-
readonly kind: Schema.String;
|
|
195
|
-
readonly props: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
196
|
-
readonly status: Schema.Literals<readonly ["open", "answered", "closed"]>;
|
|
197
|
-
readonly answer: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
198
|
-
}>>;
|
|
199
|
-
}>]>>;
|
|
200
|
-
readonly activity: Schema.Struct<{
|
|
201
|
-
readonly working: Schema.Boolean;
|
|
202
|
-
readonly specialists: Schema.$Array<Schema.Struct<{
|
|
203
|
-
readonly specialist: Schema.String;
|
|
204
|
-
readonly since: Schema.Finite;
|
|
205
|
-
}>>;
|
|
206
|
-
}>;
|
|
207
|
-
/** Whether the last turn failed with no message after it. */
|
|
208
|
-
readonly failed: Schema.Boolean;
|
|
209
|
-
/** Whether the chat was deleted. A deleted chat accepts nothing more, and its stream ends. */
|
|
210
|
-
readonly deleted: Schema.Boolean;
|
|
211
|
-
}>;
|
|
212
|
-
/**
|
|
213
|
-
* Represents a chat as its user sees it.
|
|
214
|
-
*
|
|
215
|
-
* @category models
|
|
216
|
-
* @since 0.1.0
|
|
217
|
-
*/
|
|
218
|
-
export type View = typeof View.Type;
|
|
219
|
-
/**
|
|
220
|
-
* Schema for a change to a chat's view.
|
|
221
|
-
*
|
|
222
|
-
* An update holds each message that is new or changed (for example, a block answered or
|
|
223
|
-
* closed), in full. It also holds the current activity, whether the last turn failed,
|
|
224
|
-
* and whether the chat was deleted. `seq` is the position in the chat's log that the update is up
|
|
225
|
-
* to.
|
|
226
|
-
*
|
|
227
|
-
* @category schemas
|
|
228
|
-
* @since 0.1.0
|
|
229
|
-
*/
|
|
230
|
-
export declare const Update: Schema.Struct<{
|
|
231
|
-
readonly seq: Schema.Int;
|
|
232
|
-
readonly messages: Schema.$Array<Schema.Union<readonly [Schema.TaggedStruct<"UserMessage", {
|
|
233
|
-
readonly id: Schema.brand<Schema.String, "~effect-assistant/InputId">;
|
|
234
|
-
readonly text: Schema.String;
|
|
235
|
-
readonly attachments: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
236
|
-
readonly fileId: Schema.String;
|
|
237
|
-
readonly name: Schema.String;
|
|
238
|
-
readonly mediaType: Schema.String;
|
|
239
|
-
readonly size: Schema.Finite;
|
|
240
|
-
}>>>;
|
|
241
|
-
readonly at: Schema.Finite;
|
|
242
|
-
}>, Schema.TaggedStruct<"AssistantMessage", {
|
|
243
|
-
readonly id: Schema.String;
|
|
244
|
-
readonly text: Schema.String;
|
|
245
|
-
readonly at: Schema.Finite;
|
|
246
|
-
readonly block: Schema.optional<Schema.Struct<{
|
|
247
|
-
readonly kind: Schema.String;
|
|
248
|
-
readonly props: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
249
|
-
readonly status: Schema.Literals<readonly ["open", "answered", "closed"]>;
|
|
250
|
-
readonly answer: Schema.optional<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
|
|
251
|
-
}>>;
|
|
252
|
-
}>]>>;
|
|
253
|
-
readonly activity: Schema.Struct<{
|
|
254
|
-
readonly working: Schema.Boolean;
|
|
255
|
-
readonly specialists: Schema.$Array<Schema.Struct<{
|
|
256
|
-
readonly specialist: Schema.String;
|
|
257
|
-
readonly since: Schema.Finite;
|
|
258
|
-
}>>;
|
|
259
|
-
}>;
|
|
260
|
-
readonly failed: Schema.Boolean;
|
|
261
|
-
readonly deleted: Schema.Boolean;
|
|
262
|
-
}>;
|
|
263
|
-
/**
|
|
264
|
-
* Represents a change to a chat's view.
|
|
265
|
-
*
|
|
266
|
-
* @category models
|
|
267
|
-
* @since 0.1.0
|
|
268
|
-
*/
|
|
269
|
-
export type Update = typeof Update.Type;
|
|
270
|
-
/**
|
|
271
|
-
* The view of a chat before anything has happened in it, with no messages and nothing working.
|
|
272
|
-
* Use it as the starting point when folding updates with {@link apply}.
|
|
273
|
-
*
|
|
274
|
-
* @category constructors
|
|
275
|
-
* @since 0.1.0
|
|
276
|
-
*/
|
|
277
|
-
export declare const empty: View;
|
|
278
|
-
/**
|
|
279
|
-
* Returns the view after applying an update.
|
|
280
|
-
*
|
|
281
|
-
* **Details**
|
|
282
|
-
*
|
|
283
|
-
* Each message in the update replaces the message with the same id, in place, and new messages
|
|
284
|
-
* are added after the rest. The update's activity, `failed`, and `deleted` replace the view's.
|
|
285
|
-
* Applying an update twice changes nothing, so a client that resubscribes from the start can fold
|
|
286
|
-
* again and get the same view.
|
|
287
|
-
*
|
|
288
|
-
* @category combinators
|
|
289
|
-
* @since 0.1.0
|
|
290
|
-
*/
|
|
291
|
-
export declare const apply: (view: View, update: Update) => View;
|
|
292
|
-
/**
|
|
293
|
-
* Returns whether nothing is working in the chat: no turn is running or about to start, and no
|
|
294
|
-
* specialist is working.
|
|
295
|
-
*
|
|
296
|
-
* @category guards
|
|
297
|
-
* @since 0.1.0
|
|
298
|
-
*/
|
|
299
|
-
export declare const isIdle: (view: View) => boolean;
|
|
300
|
-
/**
|
|
301
|
-
* Represents the options for building a view from a chat's log.
|
|
302
|
-
*
|
|
303
|
-
* @category models
|
|
304
|
-
* @since 0.1.0
|
|
305
|
-
*/
|
|
306
|
-
export interface Options {
|
|
307
|
-
/**
|
|
308
|
-
* The tags of the app's events that wake a turn. After such an event, the view shows a turn as
|
|
309
|
-
* about to start. Defaults to none.
|
|
310
|
-
*/
|
|
311
|
-
readonly wakes?: ReadonlySet<string> | undefined;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Returns a chat's view, built from the entries of its log.
|
|
315
|
-
*
|
|
316
|
-
* **When to use**
|
|
317
|
-
*
|
|
318
|
-
* Use it in server-side code, for example to return a whole chat at once. A client gets the view
|
|
319
|
-
* as a stream from {@link updates} instead.
|
|
320
|
-
*
|
|
321
|
-
* **Example** (Building a chat's view from its log)
|
|
322
|
-
*
|
|
323
|
-
* ```ts
|
|
324
|
-
* import { type ChatId, ChatLog, ChatView } from "effect-assistant"
|
|
325
|
-
* import * as Effect from "effect/Effect"
|
|
326
|
-
*
|
|
327
|
-
* const viewOf = (chatId: ChatId.ChatId) =>
|
|
328
|
-
* ChatLog.ChatLog.use((log) => log.read(chatId)).pipe(
|
|
329
|
-
* Effect.map((entries) => ChatView.fromEntries(entries))
|
|
330
|
-
* )
|
|
331
|
-
* ```
|
|
332
|
-
*
|
|
333
|
-
* @see {@link updates} for a stream of changes instead of a whole view
|
|
334
|
-
*
|
|
335
|
-
* @category constructors
|
|
336
|
-
* @since 0.1.0
|
|
337
|
-
*/
|
|
338
|
-
export declare const fromEntries: (entries: ReadonlyArray<AnyEntry>, options?: Options) => View;
|
|
339
|
-
/**
|
|
340
|
-
* Represents an assistant's definition as {@link updates} reads it: the app's events it
|
|
341
|
-
* registered, and whether each one wakes a turn. An assistant made with `Assistant.make` fits it.
|
|
342
|
-
*
|
|
343
|
-
* @category models
|
|
344
|
-
* @since 0.1.0
|
|
345
|
-
*/
|
|
346
|
-
export interface Definition {
|
|
347
|
-
readonly events: ReadonlyArray<{
|
|
348
|
-
readonly tag: string;
|
|
349
|
-
readonly wakes: boolean;
|
|
350
|
-
}>;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Represents the options accepted by {@link updates}.
|
|
354
|
-
*
|
|
355
|
-
* @category models
|
|
356
|
-
* @since 0.1.0
|
|
357
|
-
*/
|
|
358
|
-
export interface UpdatesOptions {
|
|
359
|
-
/**
|
|
360
|
-
* The `seq` up to which the client already has the view. The result contains only the updates
|
|
361
|
-
* after it. Defaults to `0`, every update.
|
|
362
|
-
*/
|
|
363
|
-
readonly after?: number | undefined;
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* Returns the stream of view updates that a chat's entries produce, for a chat client.
|
|
367
|
-
*
|
|
368
|
-
* **Details**
|
|
369
|
-
*
|
|
370
|
-
* The entries must stream from the start of the chat's log, as `assistant.subscribe(chatId)` does
|
|
371
|
-
* without `after`. The fold reads every entry, because a message's view depends on earlier
|
|
372
|
-
* entries: a block is answered or closed later. `after` only skips
|
|
373
|
-
* emitting the updates up to that `seq`, so a client that has the view up to a `seq` receives only
|
|
374
|
-
* what changed since. Pass `after` here, not to `subscribe`: a subscription that starts after a
|
|
375
|
-
* `seq` gives the fold an incomplete log, and the updates it produces are wrong.
|
|
376
|
-
*
|
|
377
|
-
* The definition tells the fold which of the app's events wake a turn, so the view shows a turn as
|
|
378
|
-
* about to start after one. Each chunk of entries becomes one update; the stored entries, for
|
|
379
|
-
* example, arrive as one chunk.
|
|
380
|
-
*
|
|
381
|
-
* **Example** (Streaming a chat's view to a client)
|
|
382
|
-
*
|
|
383
|
-
* ```ts
|
|
384
|
-
* import { Assistant, type ChatId, ChatView } from "effect-assistant"
|
|
385
|
-
* import * as Stream from "effect/Stream"
|
|
386
|
-
*
|
|
387
|
-
* const MyAssistant = Assistant.make("my-assistant")
|
|
388
|
-
*
|
|
389
|
-
* const watch = (chatId: ChatId.ChatId, after: number) =>
|
|
390
|
-
* Stream.unwrap(
|
|
391
|
-
* MyAssistant.useSync((assistant) =>
|
|
392
|
-
* assistant.subscribe(chatId).pipe(ChatView.updates(MyAssistant, { after }))
|
|
393
|
-
* )
|
|
394
|
-
* )
|
|
395
|
-
* ```
|
|
396
|
-
*
|
|
397
|
-
* @see {@link apply} for folding the updates into a view on the client
|
|
398
|
-
*
|
|
399
|
-
* @category utils
|
|
400
|
-
* @since 0.1.0
|
|
401
|
-
*/
|
|
402
|
-
export declare const updates: {
|
|
403
|
-
(definition: Definition, options?: UpdatesOptions): <E, R>(entries: Stream.Stream<AnyEntry, E, R>) => Stream.Stream<Update, E, R>;
|
|
404
|
-
<E, R>(entries: Stream.Stream<AnyEntry, E, R>, definition: Definition, options?: UpdatesOptions): Stream.Stream<Update, E, R>;
|
|
405
|
-
};
|
|
406
|
-
//#endregion
|
|
407
|
-
export { ChatView_d_exports };
|
|
408
|
-
//# sourceMappingURL=ChatView.d.ts.map
|
package/dist/ChatView.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChatView.d.ts","names":[],"sources":["../src/ChatView.ts"],"mappings":";;;;;;;;;;;;;;qBA+Ba,aAAW,OAAA;;;;;;;YAQZ,qBAAqB,YAAY;;;;;;;;;qBAUhC,OAAK,OAAA;;;;;;;;;;;;YAaN,eAAe,MAAM;;;;;;;;qBASpB,aAAW,OAAA;;;;;;;;;;;;;;;;;YAaZ,qBAAqB,YAAY;;;;;;;qBAQhC,kBAAgB,OAAA;;;;;;;;;;;;;;;;;YAajB,0BAA0B,iBAAiB;;;;;;;qBAQ1C,SAAO,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;YAQR,iBAAiB,QAAQ;;;;;;;;qBASxB,mBAAiB,OAAA;;;;;;;;;;YAWlB,2BAA2B,kBAAkB;;;;;;;;;;;qBAY5C,UAAQ,OAAA;;;;;;;;;;;;;YAWT,kBAAkB,SAAS;;;;;;;;;qBAU1B,MAAI,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAgBL,cAAc,KAAK;;;;;;;;;;;;qBAalB,QAAM,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAcP,gBAAgB,OAAO;;;;;;;;qBAStB,OAAO;;;;;;;;;;;;;;qBAqBP,QAAK,MAAU,MAAI,QAAU,WAAS;;;;;;;;qBAuBtC,SAAM,MAAU;;;;;;;iBAQZ;;;;;WAKN,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA4BN,cAAW,SAAa,cAAc,WAAwB,UAAY,YAAU;;;;;;;;iBAoLhF;WACN,QAAQ;aAAyB;aAAsB;;;;;;;;;iBASjD;;;;;WAKN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA2CE;GAET,YAAY,YACZ,UAAU,kBACR,GAAG,GAAG,SAAS,OAAO,OAAO,UAAyB,GAAG,OAAO,OAAO,OAAO,QAAQ,GAAG;GAC5F,GAAG,GACF,SAAS,OAAO,OAAO,UAAyB,GAAG,IACnD,YAAY,YACZ,UAAU,iBACT,OAAO,OAAO,QAAQ,GAAG"}
|