effect-assistant 0.13.2 → 0.15.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 +5 -4
- package/dist/Assistant.d.ts.map +1 -1
- package/dist/Assistant.js +2 -2
- package/dist/Assistant.js.map +1 -1
- package/dist/AssistantActivity.d.ts +5 -4
- package/dist/AssistantActivity.d.ts.map +1 -1
- package/dist/AssistantActivity.js +0 -11
- package/dist/AssistantActivity.js.map +1 -1
- package/dist/AssistantEngine.d.ts +2 -2
- package/dist/AssistantEngine.d.ts.map +1 -1
- package/dist/AssistantEngine.js +8 -8
- package/dist/AssistantEngine.js.map +1 -1
- package/dist/AssistantEvent.d.ts +5 -4
- package/dist/AssistantEvent.d.ts.map +1 -1
- package/dist/AssistantEvent.js +3 -3
- package/dist/AssistantEvent.js.map +1 -1
- package/dist/ChatLog.js +4 -4
- package/dist/ChatLog.js.map +1 -1
- package/dist/ChatSignal.js +1 -1
- package/dist/ChatSignal.js.map +1 -1
- package/dist/Memory.d.ts +1 -1
- package/dist/Memory.js +2 -2
- package/dist/StatusSummary.d.ts +1 -1
- package/dist/StatusSummary.js +1 -1
- package/dist/Timeline.d.ts +21 -18
- package/dist/Timeline.d.ts.map +1 -1
- package/dist/Timeline.js +17 -15
- package/dist/Timeline.js.map +1 -1
- package/dist/ToolApproval.d.ts +3 -2
- package/dist/ToolApproval.d.ts.map +1 -1
- package/dist/ToolApproval.js +0 -13
- package/dist/ToolApproval.js.map +1 -1
- package/dist/internal/history.js +5 -3
- package/dist/internal/history.js.map +1 -1
- package/dist/internal/live.js +1 -1
- package/dist/internal/loop.js +1 -1
- package/dist/internal/summary.js +1 -1
- package/package.json +1 -1
- package/src/Assistant.ts +13 -9
- package/src/AssistantActivity.ts +5 -4
- package/src/AssistantEngine.ts +10 -10
- package/src/AssistantEvent.ts +5 -4
- package/src/ChatLog.ts +4 -4
- package/src/ChatSignal.ts +1 -1
- package/src/Timeline.ts +29 -21
- package/src/ToolApproval.ts +3 -2
- package/src/internal/history.ts +5 -3
package/src/AssistantActivity.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @since 0.1.0
|
|
11
11
|
*/
|
|
12
|
+
import type * as DateTime from "effect/DateTime"
|
|
12
13
|
import * as Match from "effect/Match"
|
|
13
14
|
import * as Predicate from "effect/Predicate"
|
|
14
15
|
import * as AssistantEvent from "./AssistantEvent.ts"
|
|
@@ -25,8 +26,8 @@ export interface SpecialistRun {
|
|
|
25
26
|
readonly specialist: string
|
|
26
27
|
/** The goal the run is working on. */
|
|
27
28
|
readonly goal: string
|
|
28
|
-
/** When the run started
|
|
29
|
-
readonly since:
|
|
29
|
+
/** When the run started. */
|
|
30
|
+
readonly since: DateTime.Utc
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -36,8 +37,8 @@ export interface SpecialistRun {
|
|
|
36
37
|
* @since 0.1.0
|
|
37
38
|
*/
|
|
38
39
|
export interface State {
|
|
39
|
-
/** When the running turn started,
|
|
40
|
-
readonly turnSince:
|
|
40
|
+
/** When the running turn started, or `undefined` when no turn runs. */
|
|
41
|
+
readonly turnSince: DateTime.Utc | undefined
|
|
41
42
|
/**
|
|
42
43
|
* Whether an input arrived that no finished turn has read. When this is true, a turn is about
|
|
43
44
|
* to start.
|
package/src/AssistantEngine.ts
CHANGED
|
@@ -56,14 +56,14 @@ export class AssistantEngine extends Context.Service<
|
|
|
56
56
|
input: AssistantEvent.Input | AssistantEvent.StoredAppEvent
|
|
57
57
|
) => Effect.Effect<void>
|
|
58
58
|
/**
|
|
59
|
-
* Streams the chat's stored entries after the `after` sequence, then live ones. With `
|
|
59
|
+
* Streams the chat's stored entries after the `after` sequence, then live ones. With `signals`,
|
|
60
60
|
* the chat's signals too, in order with the entries.
|
|
61
61
|
*/
|
|
62
62
|
readonly subscribe: (
|
|
63
63
|
assistant: string,
|
|
64
64
|
chatId: ChatId,
|
|
65
65
|
after: number,
|
|
66
|
-
|
|
66
|
+
signals: boolean
|
|
67
67
|
) => Stream.Stream<AssistantEvent.Entry | ChatSignal.ChatSignal>
|
|
68
68
|
/**
|
|
69
69
|
* Deletes one of the assistant's chats. The chat's log records the deletion, and everything
|
|
@@ -191,12 +191,12 @@ export const layerMemory: Layer.Layer<AssistantEngine, never, ChatLog> = Layer.e
|
|
|
191
191
|
yield* RcMap.invalidate(chats, new ChatKey({ assistant, chatId }))
|
|
192
192
|
}),
|
|
193
193
|
// The subscriber holds the chat open while it streams.
|
|
194
|
-
subscribe: (assistant, chatId, after,
|
|
194
|
+
subscribe: (assistant, chatId, after, signals) =>
|
|
195
195
|
Stream.unwrap(
|
|
196
196
|
Effect.gen(function* () {
|
|
197
197
|
const chat = yield* RcMap.get(chats, new ChatKey({ assistant, chatId }))
|
|
198
198
|
|
|
199
|
-
return
|
|
199
|
+
return signals ? chat.live(after) : chat.stream(after)
|
|
200
200
|
})
|
|
201
201
|
)
|
|
202
202
|
})
|
|
@@ -208,7 +208,7 @@ interface EntityClient {
|
|
|
208
208
|
readonly subscribe: (
|
|
209
209
|
chatId: ChatId,
|
|
210
210
|
after: number,
|
|
211
|
-
|
|
211
|
+
signals: boolean
|
|
212
212
|
) => Stream.Stream<AssistantEvent.Entry | ChatSignal.ChatSignal>
|
|
213
213
|
readonly delete: (chatId: ChatId) => Effect.Effect<void>
|
|
214
214
|
}
|
|
@@ -218,7 +218,7 @@ const Submit = Rpc.make("Submit", {
|
|
|
218
218
|
}).annotate(ClusterSchema.Persisted, true)
|
|
219
219
|
|
|
220
220
|
const Subscribe = Rpc.make("Subscribe", {
|
|
221
|
-
payload: { after: Schema.Int,
|
|
221
|
+
payload: { after: Schema.Int, signals: Schema.optionalKey(Schema.Boolean) },
|
|
222
222
|
success: Schema.Union([AssistantEvent.Entry, ChatSignal.ChatSignal]),
|
|
223
223
|
stream: true
|
|
224
224
|
})
|
|
@@ -243,7 +243,7 @@ const makeClusterClient = Effect.gen(function* () {
|
|
|
243
243
|
|
|
244
244
|
const client: EntityClient = {
|
|
245
245
|
submit: (chatId, input) => makeClient(chatId).Submit({ input }, { discard: true }).pipe(Effect.orDie),
|
|
246
|
-
subscribe: (chatId, after,
|
|
246
|
+
subscribe: (chatId, after, signals) => makeClient(chatId).Subscribe({ after, signals }).pipe(Stream.orDie),
|
|
247
247
|
delete: (chatId) => makeClient(chatId).Delete().pipe(Effect.orDie)
|
|
248
248
|
}
|
|
249
249
|
|
|
@@ -262,12 +262,12 @@ const makeClusterClient = Effect.gen(function* () {
|
|
|
262
262
|
|
|
263
263
|
yield* client.submit(chatId, input)
|
|
264
264
|
}),
|
|
265
|
-
subscribe: (assistant, chatId, after,
|
|
265
|
+
subscribe: (assistant, chatId, after, signals) =>
|
|
266
266
|
Stream.unwrap(
|
|
267
267
|
Effect.gen(function* () {
|
|
268
268
|
const client = yield* clientOf(assistant)
|
|
269
269
|
|
|
270
|
-
return client.subscribe(chatId, after,
|
|
270
|
+
return client.subscribe(chatId, after, signals)
|
|
271
271
|
})
|
|
272
272
|
),
|
|
273
273
|
delete: Effect.fn("AssistantEngine.delete")(function* (assistant: string, chatId: ChatId) {
|
|
@@ -354,7 +354,7 @@ export const layerCluster: Layer.Layer<AssistantEngine, never, ChatLog | Shardin
|
|
|
354
354
|
// The turns run inside the request, so a crash leaves it unprocessed and the cluster redelivers it.
|
|
355
355
|
Submit: (request) => chat.submit(request.payload.input),
|
|
356
356
|
Subscribe: (request) =>
|
|
357
|
-
request.payload.
|
|
357
|
+
request.payload.signals === true ? chat.live(request.payload.after) : chat.stream(request.payload.after),
|
|
358
358
|
Delete: () => chat.delete
|
|
359
359
|
})
|
|
360
360
|
})
|
package/src/AssistantEvent.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @since 0.1.0
|
|
10
10
|
*/
|
|
11
11
|
import * as Response from "effect/ai/Response"
|
|
12
|
+
import type * as DateTime from "effect/DateTime"
|
|
12
13
|
import * as Predicate from "effect/Predicate"
|
|
13
14
|
import * as Schema from "effect/Schema"
|
|
14
15
|
import type * as SchemaAST from "effect/SchemaAST"
|
|
@@ -586,15 +587,15 @@ export const isAppInput = (event: { readonly _tag: string }): boolean =>
|
|
|
586
587
|
export interface AnyEntry {
|
|
587
588
|
readonly chatId: ChatId
|
|
588
589
|
readonly sequence: number
|
|
589
|
-
readonly at:
|
|
590
|
+
readonly at: DateTime.Utc
|
|
590
591
|
readonly event: { readonly _tag: string }
|
|
591
592
|
}
|
|
592
593
|
|
|
593
594
|
/**
|
|
594
595
|
* Schema for a stored event with its position in the chat.
|
|
595
596
|
*
|
|
596
|
-
* `sequence` starts at 1 and has no gaps. `at` is the time the event was stored,
|
|
597
|
-
* milliseconds.
|
|
597
|
+
* `sequence` starts at 1 and has no gaps. `at` is the time the event was stored, a UTC
|
|
598
|
+
* `DateTime` that encodes as epoch milliseconds.
|
|
598
599
|
*
|
|
599
600
|
* @category schemas
|
|
600
601
|
* @since 0.1.0
|
|
@@ -602,7 +603,7 @@ export interface AnyEntry {
|
|
|
602
603
|
export const Entry = Schema.Struct({
|
|
603
604
|
chatId: ChatId,
|
|
604
605
|
sequence: Schema.Int,
|
|
605
|
-
at: Schema.
|
|
606
|
+
at: Schema.DateTimeUtcFromMillis,
|
|
606
607
|
event: Schema.Union([AssistantEvent, StoredAppEvent])
|
|
607
608
|
})
|
|
608
609
|
|
package/src/ChatLog.ts
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @since 0.1.0
|
|
10
10
|
*/
|
|
11
|
-
import * as Clock from "effect/Clock"
|
|
12
11
|
import * as Context from "effect/Context"
|
|
12
|
+
import * as DateTime from "effect/DateTime"
|
|
13
13
|
import * as Effect from "effect/Effect"
|
|
14
14
|
import * as Layer from "effect/Layer"
|
|
15
15
|
import * as Predicate from "effect/Predicate"
|
|
@@ -89,7 +89,7 @@ export const make = (storage: Storage): ChatLog["Service"] =>
|
|
|
89
89
|
if (events.length === 0) return []
|
|
90
90
|
|
|
91
91
|
const sequence = yield* storage.lastSequence(chatId)
|
|
92
|
-
const at = yield*
|
|
92
|
+
const at = yield* DateTime.now
|
|
93
93
|
|
|
94
94
|
const entries = events.map((event, n) =>
|
|
95
95
|
AssistantEvent.Entry.make({ chatId, sequence: sequence + n + 1, at, event })
|
|
@@ -228,7 +228,7 @@ export const layerSql = (options?: SqlOptions): Layer.Layer<ChatLog, never, SqlC
|
|
|
228
228
|
AssistantEvent.Entry.make({
|
|
229
229
|
chatId: row.chat_id,
|
|
230
230
|
sequence: row.sequence,
|
|
231
|
-
at: row.at,
|
|
231
|
+
at: DateTime.makeUnsafe(row.at),
|
|
232
232
|
event: row.event
|
|
233
233
|
})
|
|
234
234
|
)
|
|
@@ -259,7 +259,7 @@ export const layerSql = (options?: SqlOptions): Layer.Layer<ChatLog, never, SqlC
|
|
|
259
259
|
Effect.fnUntraced(function* (entry: AssistantEvent.Entry) {
|
|
260
260
|
const event = yield* encodeEvent(entry.event)
|
|
261
261
|
|
|
262
|
-
return { chat_id: chatId, sequence: entry.sequence, at: entry.at, event }
|
|
262
|
+
return { chat_id: chatId, sequence: entry.sequence, at: DateTime.toEpochMillis(entry.at), event }
|
|
263
263
|
})
|
|
264
264
|
)
|
|
265
265
|
|
package/src/ChatSignal.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* status of what the assistant is doing, and whether it is writing a message to the user.
|
|
4
4
|
*
|
|
5
5
|
* Signals are never stored. They reach only the subscribers that are listening when they are sent
|
|
6
|
-
* (`assistant.subscribe(chatId, {
|
|
6
|
+
* (`assistant.subscribe(chatId, { signals: true })`), between the chat's entries and in order with
|
|
7
7
|
* them. A turn's model never reads them, compaction never sees them, and a client that loads the
|
|
8
8
|
* chat again starts without them. The turn itself shows in the log, from its `TurnStarted` to its
|
|
9
9
|
* `TurnCompleted` or `TurnFailed`.
|
package/src/Timeline.ts
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* @since 0.3.0
|
|
20
20
|
*/
|
|
21
|
+
import * as DateTime from "effect/DateTime"
|
|
21
22
|
import { dual } from "effect/Function"
|
|
22
23
|
import * as Match from "effect/Match"
|
|
23
24
|
import * as Option from "effect/Option"
|
|
@@ -66,8 +67,8 @@ export const Block = Schema.Struct({
|
|
|
66
67
|
props: Schema.Json,
|
|
67
68
|
status: BlockStatus,
|
|
68
69
|
answer: Schema.optional(Schema.Json),
|
|
69
|
-
/** When the user answered,
|
|
70
|
-
answeredAt: Schema.optional(Schema.
|
|
70
|
+
/** When the user answered, once the block is answered. Encodes as epoch milliseconds. */
|
|
71
|
+
answeredAt: Schema.optional(Schema.DateTimeUtcFromMillis),
|
|
71
72
|
/** For a block that shows a tool's result (`Block.fromToolResult`): the result, as the tool's success schema encodes it. */
|
|
72
73
|
result: Schema.optional(Schema.Json)
|
|
73
74
|
})
|
|
@@ -81,8 +82,8 @@ export const Block = Schema.Struct({
|
|
|
81
82
|
export type Block = typeof Block.Type
|
|
82
83
|
|
|
83
84
|
/**
|
|
84
|
-
* Schema for a message the user sent. `at` is when it was stored,
|
|
85
|
-
* milliseconds.
|
|
85
|
+
* Schema for a message the user sent. `at` is when it was stored, a UTC `DateTime` that encodes
|
|
86
|
+
* as epoch milliseconds.
|
|
86
87
|
*
|
|
87
88
|
* @category schemas
|
|
88
89
|
* @since 0.1.0
|
|
@@ -91,7 +92,7 @@ export const UserMessage = Schema.TaggedStruct("UserMessage", {
|
|
|
91
92
|
id: InputId,
|
|
92
93
|
text: Schema.String,
|
|
93
94
|
attachments: Schema.optional(Schema.Array(AssistantEvent.Attachment)),
|
|
94
|
-
at: Schema.
|
|
95
|
+
at: Schema.DateTimeUtcFromMillis
|
|
95
96
|
})
|
|
96
97
|
|
|
97
98
|
/**
|
|
@@ -103,7 +104,8 @@ export const UserMessage = Schema.TaggedStruct("UserMessage", {
|
|
|
103
104
|
export type UserMessage = typeof UserMessage.Type
|
|
104
105
|
|
|
105
106
|
/**
|
|
106
|
-
* Schema for a message the assistant sent the user, including its block if it has one.
|
|
107
|
+
* Schema for a message the assistant sent the user, including its block if it has one. `at` is
|
|
108
|
+
* when it was stored, a UTC `DateTime` that encodes as epoch milliseconds.
|
|
107
109
|
*
|
|
108
110
|
* @category schemas
|
|
109
111
|
* @since 0.1.0
|
|
@@ -111,7 +113,7 @@ export type UserMessage = typeof UserMessage.Type
|
|
|
111
113
|
export const AssistantMessage = Schema.TaggedStruct("AssistantMessage", {
|
|
112
114
|
id: Schema.String,
|
|
113
115
|
text: Schema.String,
|
|
114
|
-
at: Schema.
|
|
116
|
+
at: Schema.DateTimeUtcFromMillis,
|
|
115
117
|
block: Schema.optional(Block)
|
|
116
118
|
})
|
|
117
119
|
|
|
@@ -133,13 +135,14 @@ export type AssistantMessage = typeof AssistantMessage.Type
|
|
|
133
135
|
* beside `UserMessage` and `AssistantMessage`. The event, decoded with its schema, is in `event`,
|
|
134
136
|
* and the item's own fields sit beside it rather than spread into it: an event may have an `id` or
|
|
135
137
|
* an `at` of its own, and a class instance keeps its prototype. `id` is fixed per entry of the
|
|
136
|
-
* chat's log, and `at` is when the event was stored,
|
|
138
|
+
* chat's log, and `at` is when the event was stored, a UTC `DateTime` that encodes as epoch
|
|
139
|
+
* milliseconds.
|
|
137
140
|
*
|
|
138
141
|
* @category models
|
|
139
142
|
* @since 0.3.0
|
|
140
143
|
*/
|
|
141
144
|
export type EventItem<E> = E extends { readonly _tag: infer Tag extends string }
|
|
142
|
-
? { readonly _tag: Tag; readonly id: string; readonly at:
|
|
145
|
+
? { readonly _tag: Tag; readonly id: string; readonly at: DateTime.Utc; readonly event: E }
|
|
143
146
|
: never
|
|
144
147
|
|
|
145
148
|
/**
|
|
@@ -152,8 +155,8 @@ export type EventItem<E> = E extends { readonly _tag: infer Tag extends string }
|
|
|
152
155
|
* approve, so the item carries no params. `id` is the call's id, which the decision is for (see
|
|
153
156
|
* `ToolApproval.approve`), and `tool` the tool's name, for a label. `status` is where the call stands
|
|
154
157
|
* (`ToolApproval.Status`); `reason` is the user's, when they rejected it with one; `outcome` is how
|
|
155
|
-
* the approved call went, once it ran. `at` is when the call started waiting,
|
|
156
|
-
* milliseconds. A change updates the item in place as the call is decided and run.
|
|
158
|
+
* the approved call went, once it ran. `at` is when the call started waiting, a UTC `DateTime` that
|
|
159
|
+
* encodes as epoch milliseconds. A change updates the item in place as the call is decided and run.
|
|
157
160
|
*
|
|
158
161
|
* @category schemas
|
|
159
162
|
* @since 0.4.0
|
|
@@ -164,7 +167,7 @@ export const ApprovalItem = Schema.TaggedStruct("ToolApproval", {
|
|
|
164
167
|
status: Schema.Literals(["pending", "approved", "rejected", "expired"]),
|
|
165
168
|
reason: Schema.optional(Schema.String),
|
|
166
169
|
outcome: Schema.optional(AssistantEvent.ToolOutcome),
|
|
167
|
-
at: Schema.
|
|
170
|
+
at: Schema.DateTimeUtcFromMillis
|
|
168
171
|
})
|
|
169
172
|
|
|
170
173
|
/**
|
|
@@ -205,14 +208,14 @@ export type Item<Events = never> = UserMessage | AssistantMessage | EventItem<Ev
|
|
|
205
208
|
|
|
206
209
|
/**
|
|
207
210
|
* Schema for a specialist that is working for the assistant. It holds the specialist's name and
|
|
208
|
-
* when it started,
|
|
211
|
+
* when it started, a UTC `DateTime` that encodes as epoch milliseconds.
|
|
209
212
|
*
|
|
210
213
|
* @category schemas
|
|
211
214
|
* @since 0.1.0
|
|
212
215
|
*/
|
|
213
216
|
export const SpecialistWorking = Schema.Struct({
|
|
214
217
|
specialist: Schema.String,
|
|
215
|
-
since: Schema.
|
|
218
|
+
since: Schema.DateTimeUtcFromMillis
|
|
216
219
|
})
|
|
217
220
|
|
|
218
221
|
/**
|
|
@@ -230,7 +233,7 @@ export type SpecialistWorking = typeof SpecialistWorking.Type
|
|
|
230
233
|
* something that arrived. `specialists` lists the specialists that are working. When the chat is
|
|
231
234
|
* idle, nothing is working, even if a workflow is waiting on a timer or on the user.
|
|
232
235
|
*
|
|
233
|
-
* On a live subscription (`subscribe(chatId, {
|
|
236
|
+
* On a live subscription (`subscribe(chatId, { signals: true })`), `status` is a short line about what
|
|
234
237
|
* the running turn is doing, and `typing` is true while the model writes a message to the user. Both
|
|
235
238
|
* come from the chat's signals (see `ChatSignal`): they go when the turn ends, and a timeline
|
|
236
239
|
* folded from the log alone has neither.
|
|
@@ -293,7 +296,12 @@ export interface Change<Events = never> {
|
|
|
293
296
|
}
|
|
294
297
|
|
|
295
298
|
const eventItem = (schema: AssistantEvent.AppEventSchema) =>
|
|
296
|
-
Schema.Struct({
|
|
299
|
+
Schema.Struct({
|
|
300
|
+
_tag: Schema.Literal(AppEvents.tagOf(schema)),
|
|
301
|
+
id: Schema.String,
|
|
302
|
+
at: Schema.DateTimeUtcFromMillis,
|
|
303
|
+
event: schema
|
|
304
|
+
})
|
|
297
305
|
|
|
298
306
|
function makeChange<const Events extends ReadonlyArray<AssistantEvent.AppEventSchema> = readonly []>(
|
|
299
307
|
events?: Events
|
|
@@ -467,7 +475,7 @@ export const isIdle = <Events>(timeline: Timeline<Events>): boolean =>
|
|
|
467
475
|
interface AnyEventItem {
|
|
468
476
|
readonly _tag: string
|
|
469
477
|
readonly id: string
|
|
470
|
-
readonly at:
|
|
478
|
+
readonly at: DateTime.Utc
|
|
471
479
|
readonly event: { readonly _tag: string }
|
|
472
480
|
}
|
|
473
481
|
|
|
@@ -652,7 +660,7 @@ const sameActivity = (a: Activity, b: Activity) =>
|
|
|
652
660
|
a.specialists.every((run, i) => {
|
|
653
661
|
const other = b.specialists[i]
|
|
654
662
|
|
|
655
|
-
return other !== undefined && run.specialist === other.specialist && run.since
|
|
663
|
+
return other !== undefined && run.specialist === other.specialist && DateTime.Equivalence(run.since, other.since)
|
|
656
664
|
})
|
|
657
665
|
|
|
658
666
|
const folding = (show: ReadonlyArray<AssistantEvent.AppEventSchema>): Folding => {
|
|
@@ -664,7 +672,7 @@ const folding = (show: ReadonlyArray<AssistantEvent.AppEventSchema>): Folding =>
|
|
|
664
672
|
let activity = AssistantActivity.empty
|
|
665
673
|
let live = noLive
|
|
666
674
|
let blocks: ReadonlyMap<string, BlockKit.State> = new Map()
|
|
667
|
-
const answeredAt = new Map<string,
|
|
675
|
+
const answeredAt = new Map<string, DateTime.Utc>()
|
|
668
676
|
// The items in order, and the assistant's messages as stored: their blocks change as the chat goes on.
|
|
669
677
|
const items = new Map<string, AnyItem>()
|
|
670
678
|
const sent = new Map<string, AssistantEvent.AssistantMessage>()
|
|
@@ -689,7 +697,7 @@ const folding = (show: ReadonlyArray<AssistantEvent.AppEventSchema>): Folding =>
|
|
|
689
697
|
return at === undefined ? answered : { ...answered, answeredAt: at }
|
|
690
698
|
}
|
|
691
699
|
|
|
692
|
-
const itemOf = (message: AssistantEvent.AssistantMessage, at:
|
|
700
|
+
const itemOf = (message: AssistantEvent.AssistantMessage, at: DateTime.Utc): AssistantMessage => {
|
|
693
701
|
const block = blockOf(message)
|
|
694
702
|
|
|
695
703
|
return block === undefined
|
|
@@ -697,7 +705,7 @@ const folding = (show: ReadonlyArray<AssistantEvent.AppEventSchema>): Folding =>
|
|
|
697
705
|
: AssistantMessage.make({ id: message.id, text: message.text, at, block })
|
|
698
706
|
}
|
|
699
707
|
|
|
700
|
-
const touched = (event: AssistantEvent.AssistantEvent, at:
|
|
708
|
+
const touched = (event: AssistantEvent.AssistantEvent, at: DateTime.Utc): ReadonlyArray<string> =>
|
|
701
709
|
Match.value(event).pipe(
|
|
702
710
|
Match.tagsExhaustive({
|
|
703
711
|
UserMessage: (message) => {
|
package/src/ToolApproval.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @since 0.4.0
|
|
13
13
|
*/
|
|
14
|
+
import type * as DateTime from "effect/DateTime"
|
|
14
15
|
import * as Effect from "effect/Effect"
|
|
15
16
|
import * as Predicate from "effect/Predicate"
|
|
16
17
|
import * as AssistantEvent from "./AssistantEvent.ts"
|
|
@@ -34,8 +35,8 @@ export type Status = "pending" | "approved" | "rejected" | "expired"
|
|
|
34
35
|
*/
|
|
35
36
|
export interface State {
|
|
36
37
|
readonly request: AssistantEvent.ApprovalRequested
|
|
37
|
-
/** When the call started waiting
|
|
38
|
-
readonly at:
|
|
38
|
+
/** When the call started waiting. */
|
|
39
|
+
readonly at: DateTime.Utc
|
|
39
40
|
readonly status: Status
|
|
40
41
|
/** The user's reason, when they rejected it with one. */
|
|
41
42
|
readonly reason: string | undefined
|
package/src/internal/history.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as Prompt from "effect/ai/Prompt"
|
|
2
2
|
import * as Response from "effect/ai/Response"
|
|
3
|
+
import * as DateTime from "effect/DateTime"
|
|
4
|
+
import * as Duration from "effect/Duration"
|
|
3
5
|
import * as Match from "effect/Match"
|
|
4
6
|
import * as Option from "effect/Option"
|
|
5
7
|
import * as Predicate from "effect/Predicate"
|
|
@@ -61,8 +63,8 @@ export const notRunOutput = "Not run: the turn ended before this call ran."
|
|
|
61
63
|
export const mayHaveRunOutput =
|
|
62
64
|
"Stopped: the turn ended while this call ran. It may have done its work; check before doing it again."
|
|
63
65
|
|
|
64
|
-
const ago = (
|
|
65
|
-
const seconds = Math.max(0, Math.round(
|
|
66
|
+
const ago = (duration: Duration.Duration) => {
|
|
67
|
+
const seconds = Math.max(0, Math.round(Duration.toSeconds(duration)))
|
|
66
68
|
|
|
67
69
|
return seconds < 90 ? `${seconds} seconds` : `${Math.round(seconds / 60)} minutes`
|
|
68
70
|
}
|
|
@@ -88,7 +90,7 @@ const finishedText = (
|
|
|
88
90
|
"A report from a specialist you started. The user hasn't seen it.",
|
|
89
91
|
started === undefined
|
|
90
92
|
? `You started it for: ${finished.goal}`
|
|
91
|
-
: `You started it ${ago(
|
|
93
|
+
: `You started it ${ago(DateTime.distance(started.at, at.at))} ago for: ${finished.goal}`,
|
|
92
94
|
wrote ? "The user has written since you started it." : "The user hasn't written since you started it.",
|
|
93
95
|
Match.value(finished.status).pipe(
|
|
94
96
|
Match.when("answered", () => `Report:\n${finished.report ?? ""}`),
|