effect-assistant 0.12.0 → 0.13.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.
Files changed (76) hide show
  1. package/dist/Assistant.d.ts +26 -5
  2. package/dist/Assistant.d.ts.map +1 -1
  3. package/dist/Assistant.js +7 -1
  4. package/dist/Assistant.js.map +1 -1
  5. package/dist/AssistantEngine.d.ts +6 -2
  6. package/dist/AssistantEngine.d.ts.map +1 -1
  7. package/dist/AssistantEngine.js +18 -10
  8. package/dist/AssistantEngine.js.map +1 -1
  9. package/dist/AssistantLoop.js +1 -1
  10. package/dist/AssistantTest.js +1 -1
  11. package/dist/BlockKit.js +1 -1
  12. package/dist/ChatSignal.d.ts +58 -0
  13. package/dist/ChatSignal.d.ts.map +1 -0
  14. package/dist/ChatSignal.js +73 -0
  15. package/dist/ChatSignal.js.map +1 -0
  16. package/dist/Compaction.js +1 -1
  17. package/dist/Memory.js +1 -1
  18. package/dist/StatusSummary.d.ts +70 -0
  19. package/dist/StatusSummary.d.ts.map +1 -0
  20. package/dist/StatusSummary.js +84 -0
  21. package/dist/StatusSummary.js.map +1 -0
  22. package/dist/Timeline.d.ts +10 -2
  23. package/dist/Timeline.d.ts.map +1 -1
  24. package/dist/Timeline.js +72 -18
  25. package/dist/Timeline.js.map +1 -1
  26. package/dist/ToolStatus.d.ts +72 -0
  27. package/dist/ToolStatus.d.ts.map +1 -0
  28. package/dist/ToolStatus.js +71 -0
  29. package/dist/ToolStatus.js.map +1 -0
  30. package/dist/index.d.ts +4 -1
  31. package/dist/index.js +4 -1
  32. package/dist/internal/chat.js +18 -10
  33. package/dist/internal/chat.js.map +1 -1
  34. package/dist/internal/events.d.ts +1 -1
  35. package/dist/internal/events.js +1 -1
  36. package/dist/internal/history.js +1 -1
  37. package/dist/internal/live.js +87 -0
  38. package/dist/internal/live.js.map +1 -0
  39. package/dist/internal/loop.d.ts +1 -1
  40. package/dist/internal/loop.d.ts.map +1 -1
  41. package/dist/internal/loop.js +42 -11
  42. package/dist/internal/loop.js.map +1 -1
  43. package/dist/internal/schema.js +1 -1
  44. package/dist/internal/specialists.js +3 -2
  45. package/dist/internal/specialists.js.map +1 -1
  46. package/dist/internal/stream.js +72 -0
  47. package/dist/internal/stream.js.map +1 -0
  48. package/dist/internal/summary.js +65 -0
  49. package/dist/internal/summary.js.map +1 -0
  50. package/dist/internal/telemetry.js +3 -2
  51. package/dist/internal/telemetry.js.map +1 -1
  52. package/dist/internal/toolkit.js +1 -1
  53. package/dist/internal/tools.js +1 -1
  54. package/dist/internal/turns.d.ts +3 -1
  55. package/dist/internal/turns.d.ts.map +1 -1
  56. package/dist/internal/turns.js +12 -3
  57. package/dist/internal/turns.js.map +1 -1
  58. package/dist/internal/writer.d.ts +2 -0
  59. package/dist/internal/writer.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/Assistant.ts +48 -13
  62. package/src/AssistantEngine.ts +25 -11
  63. package/src/ChatSignal.ts +71 -0
  64. package/src/StatusSummary.ts +126 -0
  65. package/src/Timeline.ts +82 -20
  66. package/src/ToolStatus.ts +90 -0
  67. package/src/index.ts +15 -0
  68. package/src/internal/chat.ts +40 -21
  69. package/src/internal/live.ts +133 -0
  70. package/src/internal/loop.ts +104 -25
  71. package/src/internal/specialists.ts +3 -0
  72. package/src/internal/stream.ts +98 -0
  73. package/src/internal/summary.ts +123 -0
  74. package/src/internal/telemetry.ts +5 -1
  75. package/src/internal/turns.ts +20 -1
  76. package/src/internal/writer.ts +3 -0
@@ -0,0 +1,73 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import * as Schema from "effect/Schema";
3
+ //#region src/ChatSignal.ts
4
+ /**
5
+ * This module provides the signals a chat sends its live subscribers while a turn works: a short
6
+ * status of what the assistant is doing, and whether it is writing a message to the user.
7
+ *
8
+ * Signals are never stored. They reach only the subscribers that are listening when they are sent
9
+ * (`assistant.subscribe(chatId, { live: true })`), between the chat's entries and in order with
10
+ * them. A turn's model never reads them, compaction never sees them, and a client that loads the
11
+ * chat again starts without them. The turn itself shows in the log, from its `TurnStarted` to its
12
+ * `TurnCompleted` or `TurnFailed`.
13
+ *
14
+ * There is no signal that clears a status: the next one replaces it, typing hides it, and the
15
+ * turn's end clears it. Typing stops before the turn ends, also when it fails, so neither
16
+ * outlives its turn.
17
+ *
18
+ * @since 0.13.0
19
+ */
20
+ var ChatSignal_exports = /* @__PURE__ */ __exportAll({
21
+ ChatSignal: () => ChatSignal,
22
+ Status: () => Status,
23
+ TypingStarted: () => TypingStarted,
24
+ TypingStopped: () => TypingStopped,
25
+ isChatSignal: () => isChatSignal
26
+ });
27
+ /**
28
+ * Represents the line the chat shows next to the assistant while a turn works, like "Checking
29
+ * last summer's campaign budget". The latest one shows until the next, until the model starts
30
+ * writing to the user, or until the turn ends.
31
+ *
32
+ * @category schemas
33
+ * @since 0.13.0
34
+ */
35
+ var Status = class extends Schema.TaggedClass()("Status", { text: Schema.String }) {};
36
+ /**
37
+ * Represents the model starting to write a message to the user. The status line goes: the user
38
+ * sees the message coming instead.
39
+ *
40
+ * @category schemas
41
+ * @since 0.13.0
42
+ */
43
+ var TypingStarted = class extends Schema.TaggedClass()("TypingStarted", {}) {};
44
+ /**
45
+ * Represents the end of the typing: the message is in the chat's log, or the model wrote none.
46
+ *
47
+ * @category schemas
48
+ * @since 0.13.0
49
+ */
50
+ var TypingStopped = class extends Schema.TaggedClass()("TypingStopped", {}) {};
51
+ /**
52
+ * Schema for any of a chat's signals.
53
+ *
54
+ * @category schemas
55
+ * @since 0.13.0
56
+ */
57
+ const ChatSignal = Schema.Union([
58
+ Status,
59
+ TypingStarted,
60
+ TypingStopped
61
+ ]);
62
+ /**
63
+ * Returns whether a value is one of a chat's signals, such as an item of a live subscription that
64
+ * isn't an entry.
65
+ *
66
+ * @category guards
67
+ * @since 0.13.0
68
+ */
69
+ const isChatSignal = Schema.is(ChatSignal);
70
+ //#endregion
71
+ export { ChatSignal, ChatSignal_exports, Status, TypingStarted, TypingStopped, isChatSignal };
72
+
73
+ //# sourceMappingURL=ChatSignal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatSignal.js","names":[],"sources":["../src/ChatSignal.ts"],"sourcesContent":["/**\n * This module provides the signals a chat sends its live subscribers while a turn works: a short\n * status of what the assistant is doing, and whether it is writing a message to the user.\n *\n * Signals are never stored. They reach only the subscribers that are listening when they are sent\n * (`assistant.subscribe(chatId, { live: true })`), between the chat's entries and in order with\n * them. A turn's model never reads them, compaction never sees them, and a client that loads the\n * chat again starts without them. The turn itself shows in the log, from its `TurnStarted` to its\n * `TurnCompleted` or `TurnFailed`.\n *\n * There is no signal that clears a status: the next one replaces it, typing hides it, and the\n * turn's end clears it. Typing stops before the turn ends, also when it fails, so neither\n * outlives its turn.\n *\n * @since 0.13.0\n */\nimport * as Schema from \"effect/Schema\"\n\n/**\n * Represents the line the chat shows next to the assistant while a turn works, like \"Checking\n * last summer's campaign budget\". The latest one shows until the next, until the model starts\n * writing to the user, or until the turn ends.\n *\n * @category schemas\n * @since 0.13.0\n */\nexport class Status extends Schema.TaggedClass<Status>()(\"Status\", {\n text: Schema.String\n}) {}\n\n/**\n * Represents the model starting to write a message to the user. The status line goes: the user\n * sees the message coming instead.\n *\n * @category schemas\n * @since 0.13.0\n */\nexport class TypingStarted extends Schema.TaggedClass<TypingStarted>()(\"TypingStarted\", {}) {}\n\n/**\n * Represents the end of the typing: the message is in the chat's log, or the model wrote none.\n *\n * @category schemas\n * @since 0.13.0\n */\nexport class TypingStopped extends Schema.TaggedClass<TypingStopped>()(\"TypingStopped\", {}) {}\n\n/**\n * Schema for any of a chat's signals.\n *\n * @category schemas\n * @since 0.13.0\n */\nexport const ChatSignal = Schema.Union([Status, TypingStarted, TypingStopped])\n\n/**\n * Represents any of a chat's signals.\n *\n * @category models\n * @since 0.13.0\n */\nexport type ChatSignal = typeof ChatSignal.Type\n\n/**\n * Returns whether a value is one of a chat's signals, such as an item of a live subscription that\n * isn't an entry.\n *\n * @category guards\n * @since 0.13.0\n */\nexport const isChatSignal: (u: unknown) => u is ChatSignal = Schema.is(ChatSignal)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,SAAb,cAA4B,OAAO,YAAoB,CAAC,CAAC,UAAU,EACjE,MAAM,OAAO,OACf,CAAC,CAAC,CAAC,CAAC;;;;;;;;AASJ,IAAa,gBAAb,cAAmC,OAAO,YAA2B,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;;;AAQ7F,IAAa,gBAAb,cAAmC,OAAO,YAA2B,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;;;;;;;AAQ7F,MAAa,aAAa,OAAO,MAAM;CAAC;CAAQ;CAAe;AAAa,CAAC;;;;;;;;AAiB7E,MAAa,eAAgD,OAAO,GAAG,UAAU"}
@@ -5,8 +5,8 @@ import { fromEntries } from "./ToolApproval.js";
5
5
  import { userText } from "./internal/history.js";
6
6
  import { fromEntries as fromEntries$1 } from "./BlockKit.js";
7
7
  import { fromEntries as fromEntries$2 } from "./AssistantActivity.js";
8
- import * as Predicate from "effect/Predicate";
9
8
  import * as Option from "effect/Option";
9
+ import * as Predicate from "effect/Predicate";
10
10
  //#region src/Compaction.ts
11
11
  var Compaction_exports = /* @__PURE__ */ __exportAll({
12
12
  attachedFiles: () => attachedFiles,
package/dist/Memory.js CHANGED
@@ -5,8 +5,8 @@ import { ToolFailure, fail } from "./ToolFailure.js";
5
5
  import * as Context from "effect/Context";
6
6
  import * as Effect from "effect/Effect";
7
7
  import * as Layer from "effect/Layer";
8
- import * as Schema from "effect/Schema";
9
8
  import * as Option from "effect/Option";
9
+ import * as Schema from "effect/Schema";
10
10
  import * as Clock from "effect/Clock";
11
11
  import * as Ref from "effect/Ref";
12
12
  import * as Tool from "effect/ai/Tool";
@@ -0,0 +1,70 @@
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as Option from "effect/Option";
5
+ import * as LanguageModel from "effect/ai/LanguageModel";
6
+ import * as Duration from "effect/Duration";
7
+ declare namespace StatusSummary_d_exports {
8
+ export { Options, StatusSummary, defaultInstructions, layer };
9
+ }
10
+ /**
11
+ * The instructions the summary's model gets by default.
12
+ *
13
+ * @category constants
14
+ * @since 0.13.0
15
+ */
16
+ export declare const defaultInstructions = "You write the status line a chat shows while an assistant works for its user. Read what the assistant did so far in this turn and say what it is doing now, in 3 to 5 plain words, in the language the user writes in, like \"Comparing last year's budgets\". No tool names, ids, code, quotes or final period. Answer with the status only.";
17
+ /**
18
+ * Represents the options accepted by {@link layer}.
19
+ *
20
+ * @category models
21
+ * @since 0.13.0
22
+ */
23
+ export interface Options {
24
+ /** How long the line may stay empty before a summary fills it. Defaults to 2 seconds. */
25
+ readonly after?: Duration.Input | undefined;
26
+ /** How long a line may stay unchanged before a summary refreshes it. Defaults to 5 seconds. */
27
+ readonly staleAfter?: Duration.Input | undefined;
28
+ /** The summary model's instructions. Defaults to {@link defaultInstructions}. */
29
+ readonly instructions?: string | undefined;
30
+ }
31
+ declare const StatusSummary_base: Context.ServiceClass<StatusSummary, "effect-assistant/StatusSummary", {
32
+ readonly after: Duration.Duration;
33
+ readonly staleAfter: Duration.Duration;
34
+ /**
35
+ * Returns the status for a turn, from its transcript: the user's input and what the assistant
36
+ * did since. `None` when the model wrote nothing usable or its call failed.
37
+ */
38
+ readonly summarize: (transcript: string) => Effect.Effect<Option.Option<string>>;
39
+ }>;
40
+ /**
41
+ * Service that writes a turn's status from what the turn did so far.
42
+ *
43
+ * @category services
44
+ * @since 0.13.0
45
+ */
46
+ export declare class StatusSummary extends StatusSummary_base {}
47
+ /**
48
+ * Creates the summary on the model it is given: provide a small, fast one.
49
+ *
50
+ * **Example** (A cheap model for statuses)
51
+ *
52
+ * ```ts
53
+ * import { StatusSummary } from "effect-assistant"
54
+ * import * as Layer from "effect/Layer"
55
+ *
56
+ * declare const MyAssistantLive: Layer.Layer<never>
57
+ * declare const FastModel: Layer.Layer<import("effect/ai/LanguageModel").LanguageModel>
58
+ *
59
+ * export const Live = MyAssistantLive.pipe(
60
+ * Layer.provide(StatusSummary.layer({ after: "2 seconds" }).pipe(Layer.provide(FastModel)))
61
+ * )
62
+ * ```
63
+ *
64
+ * @category layers
65
+ * @since 0.13.0
66
+ */
67
+ export declare const layer: (options?: Options) => Layer.Layer<StatusSummary, never, LanguageModel.LanguageModel>;
68
+ //#endregion
69
+ export { StatusSummary_d_exports };
70
+ //# sourceMappingURL=StatusSummary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatusSummary.d.ts","names":[],"sources":["../src/StatusSummary.ts"],"mappings":";;;;;;;;;;;;;;;qBA4Ba;;;;;;;iBASI;;WAEN,QAAQ,SAAS;;WAEjB,aAAa,SAAS;;WAEtB;;;WAYS,OAAA,SAAS;WACJ,YAAA,SAAS;;;;;WAKV,YAAC,uBAAuB,OAAO,OAAO,OAAO;;;;;;;;qBATxD,sBAAsB;;;;;;;;;;;;;;;;;;;;;qBA4CtB,QAAK,UAAc,YAAU,MAAM,MAAM,sBAAsB,cAAc"}
@@ -0,0 +1,84 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import * as Context from "effect/Context";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Option from "effect/Option";
6
+ import * as Prompt from "effect/ai/Prompt";
7
+ import * as LanguageModel from "effect/ai/LanguageModel";
8
+ import * as Duration from "effect/Duration";
9
+ //#region src/StatusSummary.ts
10
+ /**
11
+ * This module provides the status a turn shows when nothing else says what it is doing: when the
12
+ * line stays empty for a while, or a call's status still shows after that call ended, a model reads
13
+ * the turn so far and writes a few words about it, like "Comparing last year's budgets".
14
+ *
15
+ * Provide {@link layer} next to the assistant's `toLayer`, with a small, fast model of its own.
16
+ * Without it, a turn shows only the statuses its tool calls write (see `ToolStatus`). The summary
17
+ * is a `ChatSignal.Status` like any other: it is never stored and the turn's model never reads it.
18
+ * It never replaces the status of a described call that still runs, never shows while the model
19
+ * writes to the user, and never after the turn's message unless the model starts new work. A
20
+ * summary that says what the line says already isn't sent.
21
+ *
22
+ * @since 0.13.0
23
+ */
24
+ var StatusSummary_exports = /* @__PURE__ */ __exportAll({
25
+ StatusSummary: () => StatusSummary,
26
+ defaultInstructions: () => defaultInstructions,
27
+ layer: () => layer
28
+ });
29
+ /**
30
+ * The instructions the summary's model gets by default.
31
+ *
32
+ * @category constants
33
+ * @since 0.13.0
34
+ */
35
+ const defaultInstructions = "You write the status line a chat shows while an assistant works for its user. Read what the assistant did so far in this turn and say what it is doing now, in 3 to 5 plain words, in the language the user writes in, like \"Comparing last year's budgets\". No tool names, ids, code, quotes or final period. Answer with the status only.";
36
+ /**
37
+ * Service that writes a turn's status from what the turn did so far.
38
+ *
39
+ * @category services
40
+ * @since 0.13.0
41
+ */
42
+ var StatusSummary = class extends Context.Service()("effect-assistant/StatusSummary") {};
43
+ const MAX_LENGTH = 60;
44
+ const clean = (text) => {
45
+ const line = (text.trim().split("\n")[0] ?? "").replace(/^["'“”‘’]+|["'“”‘’]+$/g, "").replace(/[.…]+$/, "").trim();
46
+ return line === "" || line.length > MAX_LENGTH ? Option.none() : Option.some(line);
47
+ };
48
+ /**
49
+ * Creates the summary on the model it is given: provide a small, fast one.
50
+ *
51
+ * **Example** (A cheap model for statuses)
52
+ *
53
+ * ```ts
54
+ * import { StatusSummary } from "effect-assistant"
55
+ * import * as Layer from "effect/Layer"
56
+ *
57
+ * declare const MyAssistantLive: Layer.Layer<never>
58
+ * declare const FastModel: Layer.Layer<import("effect/ai/LanguageModel").LanguageModel>
59
+ *
60
+ * export const Live = MyAssistantLive.pipe(
61
+ * Layer.provide(StatusSummary.layer({ after: "2 seconds" }).pipe(Layer.provide(FastModel)))
62
+ * )
63
+ * ```
64
+ *
65
+ * @category layers
66
+ * @since 0.13.0
67
+ */
68
+ const layer = (options) => Layer.effect(StatusSummary, Effect.gen(function* () {
69
+ const model = yield* LanguageModel.LanguageModel;
70
+ const instructions = options?.instructions ?? "You write the status line a chat shows while an assistant works for its user. Read what the assistant did so far in this turn and say what it is doing now, in 3 to 5 plain words, in the language the user writes in, like \"Comparing last year's budgets\". No tool names, ids, code, quotes or final period. Answer with the status only.";
71
+ const summarize = Effect.fn("StatusSummary.summarize")(function* (transcript) {
72
+ const response = yield* model.generateText({ prompt: Prompt.fromMessages([Prompt.systemMessage({ content: instructions }), Prompt.userMessage({ content: [Prompt.textPart({ text: transcript })] })]) });
73
+ return clean(response.text);
74
+ });
75
+ return StatusSummary.of({
76
+ after: Duration.fromInputUnsafe(options?.after ?? "2 seconds"),
77
+ staleAfter: Duration.fromInputUnsafe(options?.staleAfter ?? "5 seconds"),
78
+ summarize: (transcript) => summarize(transcript).pipe(Effect.catchCause((cause) => Effect.as(Effect.logDebug("assistant status summary failed", cause), Option.none())))
79
+ });
80
+ }));
81
+ //#endregion
82
+ export { StatusSummary, StatusSummary_exports, defaultInstructions, layer };
83
+
84
+ //# sourceMappingURL=StatusSummary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatusSummary.js","names":[],"sources":["../src/StatusSummary.ts"],"sourcesContent":["/**\n * This module provides the status a turn shows when nothing else says what it is doing: when the\n * line stays empty for a while, or a call's status still shows after that call ended, a model reads\n * the turn so far and writes a few words about it, like \"Comparing last year's budgets\".\n *\n * Provide {@link layer} next to the assistant's `toLayer`, with a small, fast model of its own.\n * Without it, a turn shows only the statuses its tool calls write (see `ToolStatus`). The summary\n * is a `ChatSignal.Status` like any other: it is never stored and the turn's model never reads it.\n * It never replaces the status of a described call that still runs, never shows while the model\n * writes to the user, and never after the turn's message unless the model starts new work. A\n * summary that says what the line says already isn't sent.\n *\n * @since 0.13.0\n */\nimport * as LanguageModel from \"effect/ai/LanguageModel\"\nimport * as Prompt from \"effect/ai/Prompt\"\nimport * as Context from \"effect/Context\"\nimport * as Duration from \"effect/Duration\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport * as Option from \"effect/Option\"\n\n/**\n * The instructions the summary's model gets by default.\n *\n * @category constants\n * @since 0.13.0\n */\nexport const defaultInstructions =\n 'You write the status line a chat shows while an assistant works for its user. Read what the assistant did so far in this turn and say what it is doing now, in 3 to 5 plain words, in the language the user writes in, like \"Comparing last year\\'s budgets\". No tool names, ids, code, quotes or final period. Answer with the status only.'\n\n/**\n * Represents the options accepted by {@link layer}.\n *\n * @category models\n * @since 0.13.0\n */\nexport interface Options {\n /** How long the line may stay empty before a summary fills it. Defaults to 2 seconds. */\n readonly after?: Duration.Input | undefined\n /** How long a line may stay unchanged before a summary refreshes it. Defaults to 5 seconds. */\n readonly staleAfter?: Duration.Input | undefined\n /** The summary model's instructions. Defaults to {@link defaultInstructions}. */\n readonly instructions?: string | undefined\n}\n\n/**\n * Service that writes a turn's status from what the turn did so far.\n *\n * @category services\n * @since 0.13.0\n */\nexport class StatusSummary extends Context.Service<\n StatusSummary,\n {\n readonly after: Duration.Duration\n readonly staleAfter: Duration.Duration\n /**\n * Returns the status for a turn, from its transcript: the user's input and what the assistant\n * did since. `None` when the model wrote nothing usable or its call failed.\n */\n readonly summarize: (transcript: string) => Effect.Effect<Option.Option<string>>\n }\n>()(\"effect-assistant/StatusSummary\") {}\n\nconst MAX_LENGTH = 60\n\nconst clean = (text: string): Option.Option<string> => {\n const line = (text.trim().split(\"\\n\")[0] ?? \"\")\n .replace(/^[\"'“”‘’]+|[\"'“”‘’]+$/g, \"\")\n .replace(/[.…]+$/, \"\")\n .trim()\n\n return line === \"\" || line.length > MAX_LENGTH ? Option.none() : Option.some(line)\n}\n\n/**\n * Creates the summary on the model it is given: provide a small, fast one.\n *\n * **Example** (A cheap model for statuses)\n *\n * ```ts\n * import { StatusSummary } from \"effect-assistant\"\n * import * as Layer from \"effect/Layer\"\n *\n * declare const MyAssistantLive: Layer.Layer<never>\n * declare const FastModel: Layer.Layer<import(\"effect/ai/LanguageModel\").LanguageModel>\n *\n * export const Live = MyAssistantLive.pipe(\n * Layer.provide(StatusSummary.layer({ after: \"2 seconds\" }).pipe(Layer.provide(FastModel)))\n * )\n * ```\n *\n * @category layers\n * @since 0.13.0\n */\nexport const layer = (options?: Options): Layer.Layer<StatusSummary, never, LanguageModel.LanguageModel> =>\n Layer.effect(\n StatusSummary,\n Effect.gen(function* () {\n const model = yield* LanguageModel.LanguageModel\n const instructions = options?.instructions ?? defaultInstructions\n\n const summarize = Effect.fn(\"StatusSummary.summarize\")(function* (transcript: string) {\n const response = yield* model.generateText({\n prompt: Prompt.fromMessages([\n Prompt.systemMessage({ content: instructions }),\n Prompt.userMessage({ content: [Prompt.textPart({ text: transcript })] })\n ])\n })\n\n return clean(response.text)\n })\n\n return StatusSummary.of({\n after: Duration.fromInputUnsafe(options?.after ?? \"2 seconds\"),\n staleAfter: Duration.fromInputUnsafe(options?.staleAfter ?? \"5 seconds\"),\n summarize: (transcript) =>\n summarize(transcript).pipe(\n Effect.catchCause((cause) =>\n Effect.as(Effect.logDebug(\"assistant status summary failed\", cause), Option.none())\n )\n )\n })\n })\n )\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,sBACX;;;;;;;AAuBF,IAAa,gBAAb,cAAmC,QAAQ,QAWzC,CAAC,CAAC,gCAAgC,CAAC,CAAC,CAAC;AAEvC,MAAM,aAAa;AAEnB,MAAM,SAAS,SAAwC;CACrD,MAAM,QAAQ,KAAK,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,GAAA,CACzC,QAAQ,0BAA0B,EAAE,CAAC,CACrC,QAAQ,UAAU,EAAE,CAAC,CACrB,KAAK;CAER,OAAO,SAAS,MAAM,KAAK,SAAS,aAAa,OAAO,KAAK,IAAI,OAAO,KAAK,IAAI;AACnF;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,SAAS,YACpB,MAAM,OACJ,eACA,OAAO,IAAI,aAAa;CACtB,MAAM,QAAQ,OAAO,cAAc;CACnC,MAAM,eAAe,SAAS,gBAAA;CAE9B,MAAM,YAAY,OAAO,GAAG,yBAAyB,CAAC,CAAC,WAAW,YAAoB;EACpF,MAAM,WAAW,OAAO,MAAM,aAAa,EACzC,QAAQ,OAAO,aAAa,CAC1B,OAAO,cAAc,EAAE,SAAS,aAAa,CAAC,GAC9C,OAAO,YAAY,EAAE,SAAS,CAAC,OAAO,SAAS,EAAE,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,CACzE,CAAC,EACH,CAAC;EAED,OAAO,MAAM,SAAS,IAAI;CAC5B,CAAC;CAED,OAAO,cAAc,GAAG;EACtB,OAAO,SAAS,gBAAgB,SAAS,SAAS,WAAW;EAC7D,YAAY,SAAS,gBAAgB,SAAS,cAAc,WAAW;EACvE,YAAY,eACV,UAAU,UAAU,CAAC,CAAC,KACpB,OAAO,YAAY,UACjB,OAAO,GAAG,OAAO,SAAS,mCAAmC,KAAK,GAAG,OAAO,KAAK,CAAC,CACpF,CACF;CACJ,CAAC;AACH,CAAC,CACH"}
@@ -1,4 +1,5 @@
1
1
  import { AnyEntry, AppEventSchema, AssistantEvent_d_exports } from "./AssistantEvent.js";
2
+ import { ChatSignal, ChatSignal_d_exports } from "./ChatSignal.js";
2
3
  import { Assistant_d_exports, Entry } from "./Assistant.js";
3
4
  import * as Schema from "effect/Schema";
4
5
  import * as Stream from "effect/Stream";
@@ -201,6 +202,11 @@ export type SpecialistWorking = typeof SpecialistWorking.Type;
201
202
  * something that arrived. `specialists` lists the specialists that are working. When the chat is
202
203
  * idle, nothing is working, even if a workflow is waiting on a timer or on the user.
203
204
  *
205
+ * On a live subscription (`subscribe(chatId, { live: true })`), `status` is a short line about what
206
+ * the running turn is doing, and `typing` is true while the model writes a message to the user. Both
207
+ * come from the chat's signals (see `ChatSignal`): they go when the turn ends, and a timeline
208
+ * folded from the log alone has neither.
209
+ *
204
210
  * @category schemas
205
211
  * @since 0.1.0
206
212
  */
@@ -210,6 +216,8 @@ export declare const Activity: Schema.Struct<{
210
216
  readonly specialist: Schema.String;
211
217
  readonly since: Schema.Finite;
212
218
  }>>;
219
+ readonly status: Schema.optional<Schema.String>;
220
+ readonly typing: Schema.Boolean;
213
221
  }>;
214
222
  /**
215
223
  * Represents what is working in the chat.
@@ -512,8 +520,8 @@ export interface ChangesOptions<Show extends ReadonlyArray<AppEventSchema> = rea
512
520
  * @since 0.3.0
513
521
  */
514
522
  export declare const changes: {
515
- <Events, const Show extends Shown<Events> = readonly []>(definition: Definition<Events>, options?: ChangesOptions<Show>): <E, R>(entries: Stream.Stream<AnyEntry, E, R>) => Stream.Stream<Change<Show[number]["Type"]>, E, R>;
516
- <E, R, Events, const Show extends Shown<Events> = readonly []>(entries: Stream.Stream<AnyEntry, E, R>, definition: Definition<Events>, options?: ChangesOptions<Show>): Stream.Stream<Change<Show[number]["Type"]>, E, R>;
523
+ <Events, const Show extends Shown<Events> = readonly []>(definition: Definition<Events>, options?: ChangesOptions<Show>): <E, R>(entries: Stream.Stream<AnyEntry | ChatSignal, E, R>) => Stream.Stream<Change<Show[number]["Type"]>, E, R>;
524
+ <E, R, Events, const Show extends Shown<Events> = readonly []>(entries: Stream.Stream<AnyEntry | ChatSignal, E, R>, definition: Definition<Events>, options?: ChangesOptions<Show>): Stream.Stream<Change<Show[number]["Type"]>, E, R>;
517
525
  };
518
526
  //#endregion
519
527
  export { Timeline_d_exports };
@@ -1 +1 @@
1
- {"version":3,"file":"Timeline.d.ts","names":[],"sources":["../src/Timeline.ts"],"mappings":";;;;;;;;;;;;;;;qBA4Ca,aAAW,OAAA;;;;;;;YAQZ,qBAAqB,YAAY;;;;;;;;;qBAUhC,OAAK,OAAA;;;;;;;;;;;;;;YAeN,eAAe,MAAM;;;;;;;;qBASpB,aAAW,OAAA;;;;;;;;;;;;;;;;;YAaZ,qBAAqB,YAAY;;;;;;;qBAQhC,kBAAgB,OAAA;;;;;;;;;;;;;;;;;;;YAajB,0BAA0B,iBAAiB;;;;;;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iBAS9C,eACf,aAAa,cAAc,uCACnB,YAAY;;;;;WAKX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkFE;GACV,cAAc,aAAa,MAAM,uBAChC,YAAY,WAAW,SACvB,UAAU,eAAe,SACvB,GAAG,GACL,SAAS,OAAO,OAAO,WAA0B,YAAuB,GAAG,OACxE,OAAO,OAAO,OAAO,uBAAuB,GAAG;GACnD,GAAG,GAAG,cAAc,aAAa,MAAM,uBACtC,SAAS,OAAO,OAAO,WAA0B,YAAuB,GAAG,IAC3E,YAAY,WAAW,SACvB,UAAU,eAAe,QACxB,OAAO,OAAO,OAAO,uBAAuB,GAAG"}
package/dist/Timeline.js CHANGED
@@ -1,15 +1,16 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { InputId } from "./InputId.js";
3
3
  import { Attachment, ToolOutcome, isLibraryEvent } from "./AssistantEvent.js";
4
+ import { isChatSignal } from "./ChatSignal.js";
4
5
  import { toJson } from "./internal/schema.js";
5
6
  import { apply as apply$1 } from "./ToolApproval.js";
6
7
  import { decodeWith, tagOf } from "./internal/events.js";
7
8
  import { apply as apply$2 } from "./BlockKit.js";
8
9
  import { apply as apply$3, empty as empty$1 } from "./AssistantActivity.js";
10
+ import * as Option from "effect/Option";
9
11
  import * as Predicate from "effect/Predicate";
10
12
  import * as Schema from "effect/Schema";
11
13
  import * as Stream from "effect/Stream";
12
- import * as Option from "effect/Option";
13
14
  import { dual } from "effect/Function";
14
15
  import * as Match from "effect/Match";
15
16
  import * as SchemaTransformation from "effect/SchemaTransformation";
@@ -152,12 +153,19 @@ const SpecialistWorking = Schema.Struct({
152
153
  * something that arrived. `specialists` lists the specialists that are working. When the chat is
153
154
  * idle, nothing is working, even if a workflow is waiting on a timer or on the user.
154
155
  *
156
+ * On a live subscription (`subscribe(chatId, { live: true })`), `status` is a short line about what
157
+ * the running turn is doing, and `typing` is true while the model writes a message to the user. Both
158
+ * come from the chat's signals (see `ChatSignal`): they go when the turn ends, and a timeline
159
+ * folded from the log alone has neither.
160
+ *
155
161
  * @category schemas
156
162
  * @since 0.1.0
157
163
  */
158
164
  const Activity = Schema.Struct({
159
165
  working: Schema.Boolean,
160
- specialists: Schema.Array(SpecialistWorking)
166
+ specialists: Schema.Array(SpecialistWorking),
167
+ status: Schema.optional(Schema.String),
168
+ typing: Schema.Boolean
161
169
  });
162
170
  const eventItem = (schema) => Schema.Struct({
163
171
  _tag: Schema.Literal(tagOf(schema)),
@@ -231,7 +239,8 @@ const empty = {
231
239
  items: [],
232
240
  activity: {
233
241
  working: false,
234
- specialists: []
242
+ specialists: [],
243
+ typing: false
235
244
  },
236
245
  failed: false,
237
246
  deleted: false
@@ -369,14 +378,40 @@ function fromEntriesWith(entries, _definition, options) {
369
378
  * @since 0.1.0
370
379
  */
371
380
  const fromEntries = fromEntriesWith;
372
- const activityOf = (activity) => ({
373
- working: activity.turnSince !== void 0 || activity.queued,
374
- specialists: [...activity.specialists.values()].map((run) => ({
375
- specialist: run.specialist,
376
- since: run.since
377
- }))
378
- });
379
- const sameActivity = (a, b) => a.working === b.working && a.specialists.length === b.specialists.length && a.specialists.every((run, i) => {
381
+ const noLive = {
382
+ status: void 0,
383
+ typing: false
384
+ };
385
+ const applySignal = (live, signal) => Match.value(signal).pipe(Match.tagsExhaustive({
386
+ Status: ({ text }) => ({
387
+ ...live,
388
+ status: text
389
+ }),
390
+ TypingStarted: () => ({
391
+ status: void 0,
392
+ typing: true
393
+ }),
394
+ TypingStopped: () => ({
395
+ ...live,
396
+ typing: false
397
+ })
398
+ }));
399
+ const activityOf = (activity, live) => {
400
+ const { status } = live;
401
+ const shown = {
402
+ working: activity.turnSince !== void 0 || activity.queued,
403
+ specialists: [...activity.specialists.values()].map((run) => ({
404
+ specialist: run.specialist,
405
+ since: run.since
406
+ })),
407
+ typing: live.typing
408
+ };
409
+ return status === void 0 ? shown : {
410
+ ...shown,
411
+ status
412
+ };
413
+ };
414
+ const sameActivity = (a, b) => a.working === b.working && a.status === b.status && a.typing === b.typing && a.specialists.length === b.specialists.length && a.specialists.every((run, i) => {
380
415
  const other = b.specialists[i];
381
416
  return other !== void 0 && run.specialist === other.specialist && run.since === other.since;
382
417
  });
@@ -387,6 +422,7 @@ const folding = (show) => {
387
422
  let failed = false;
388
423
  let deleted = false;
389
424
  let activity = empty$1;
425
+ let live = noLive;
390
426
  let blocks = /* @__PURE__ */ new Map();
391
427
  const items = /* @__PURE__ */ new Map();
392
428
  const sent = /* @__PURE__ */ new Map();
@@ -501,17 +537,33 @@ const folding = (show) => {
501
537
  items.set(callId, item);
502
538
  return [item];
503
539
  });
540
+ const settle = (event) => {
541
+ if (Predicate.isTagged(event, "TurnCompleted") || Predicate.isTagged(event, "TurnFailed") || Predicate.isTagged(event, "ChatDeleted")) live = noLive;
542
+ };
543
+ const signal = (received) => {
544
+ const previous = activityOf(activity, live);
545
+ live = applySignal(live, received);
546
+ const now = activityOf(activity, live);
547
+ return sameActivity(previous, now) ? void 0 : {
548
+ sequence,
549
+ items: [],
550
+ activity: now,
551
+ failed,
552
+ deleted
553
+ };
554
+ };
504
555
  const step = (entry) => {
505
556
  const previous = {
506
- activity: activityOf(activity),
557
+ activity: activityOf(activity, live),
507
558
  failed,
508
559
  deleted
509
560
  };
510
561
  const { event } = entry;
511
562
  sequence = entry.sequence;
512
563
  activity = apply$3(activity, entry);
564
+ settle(event);
513
565
  if (!isLibraryEvent(event)) {
514
- const now = activityOf(activity);
566
+ const now = activityOf(activity, live);
515
567
  return Option.match(eventItemOf(entry), {
516
568
  onNone: () => sameActivity(previous.activity, now) ? void 0 : {
517
569
  sequence,
@@ -543,7 +595,7 @@ const folding = (show) => {
543
595
  items.set(id, next);
544
596
  return [next];
545
597
  }), ...approvalItems(event, decidedBefore)];
546
- const now = activityOf(activity);
598
+ const now = activityOf(activity, live);
547
599
  return all.length === 0 && failed === previous.failed && deleted === previous.deleted && sameActivity(previous.activity, now) ? void 0 : {
548
600
  sequence,
549
601
  items: all,
@@ -554,11 +606,12 @@ const folding = (show) => {
554
606
  };
555
607
  return {
556
608
  step,
609
+ signal,
557
610
  get snapshot() {
558
611
  return {
559
612
  sequence,
560
613
  items: [...items.values()],
561
- activity: activityOf(activity),
614
+ activity: activityOf(activity, live),
562
615
  failed,
563
616
  deleted
564
617
  };
@@ -581,9 +634,10 @@ const merge = (changes) => {
581
634
  function changesWith(entries, _definition, options) {
582
635
  const after = options?.after ?? 0;
583
636
  return entries.pipe(Stream.mapAccumArray(() => folding(options?.show ?? []), (timeline, chunk) => {
584
- const changed = chunk.flatMap((entry) => {
585
- const change = timeline.step(entry);
586
- return change === void 0 || entry.sequence <= after ? [] : [change];
637
+ const changed = chunk.flatMap((item) => {
638
+ if (isChatSignal(item)) return Option.toArray(Option.fromUndefinedOr(timeline.signal(item)));
639
+ const change = timeline.step(item);
640
+ return change === void 0 || item.sequence <= after ? [] : [change];
587
641
  });
588
642
  const merged = merge(changed);
589
643
  return [timeline, merged === void 0 ? [] : [merged]];