@autumnsgrove/lyra 0.1.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/adapters/cloudflare/index.d.ts +1 -0
- package/dist/adapters/cloudflare/index.d.ts.map +1 -1
- package/dist/adapters/cloudflare/index.js +1 -0
- package/dist/adapters/cloudflare/index.js.map +1 -1
- package/dist/adapters/cloudflare/session.d.ts +102 -0
- package/dist/adapters/cloudflare/session.d.ts.map +1 -0
- package/dist/adapters/cloudflare/session.js +595 -0
- package/dist/adapters/cloudflare/session.js.map +1 -0
- package/dist/adapters/openai/errors.d.ts +36 -0
- package/dist/adapters/openai/errors.d.ts.map +1 -0
- package/dist/adapters/openai/errors.js +117 -0
- package/dist/adapters/openai/errors.js.map +1 -0
- package/dist/adapters/openai/index.d.ts +18 -0
- package/dist/adapters/openai/index.d.ts.map +1 -0
- package/dist/adapters/openai/index.js +18 -0
- package/dist/adapters/openai/index.js.map +1 -0
- package/dist/adapters/openai/model.d.ts +50 -0
- package/dist/adapters/openai/model.d.ts.map +1 -0
- package/dist/adapters/openai/model.js +169 -0
- package/dist/adapters/openai/model.js.map +1 -0
- package/dist/adapters/openai/presets.d.ts +36 -0
- package/dist/adapters/openai/presets.d.ts.map +1 -0
- package/dist/adapters/openai/presets.js +43 -0
- package/dist/adapters/openai/presets.js.map +1 -0
- package/dist/adapters/openai/request.d.ts +47 -0
- package/dist/adapters/openai/request.d.ts.map +1 -0
- package/dist/adapters/openai/request.js +93 -0
- package/dist/adapters/openai/request.js.map +1 -0
- package/dist/adapters/openai/sse.d.ts +44 -0
- package/dist/adapters/openai/sse.d.ts.map +1 -0
- package/dist/adapters/openai/sse.js +410 -0
- package/dist/adapters/openai/sse.js.map +1 -0
- package/dist/core/approval.d.ts +38 -0
- package/dist/core/approval.d.ts.map +1 -0
- package/dist/core/approval.js +47 -0
- package/dist/core/approval.js.map +1 -0
- package/dist/core/compaction.d.ts +193 -0
- package/dist/core/compaction.d.ts.map +1 -0
- package/dist/core/compaction.js +460 -0
- package/dist/core/compaction.js.map +1 -0
- package/dist/core/define-recipe.d.ts +8 -1
- package/dist/core/define-recipe.d.ts.map +1 -1
- package/dist/core/define-recipe.js +13 -0
- package/dist/core/define-recipe.js.map +1 -1
- package/dist/core/events.d.ts +32 -2
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/events.js +16 -1
- package/dist/core/events.js.map +1 -1
- package/dist/core/execute-tools.d.ts +7 -0
- package/dist/core/execute-tools.d.ts.map +1 -1
- package/dist/core/execute-tools.js +6 -0
- package/dist/core/execute-tools.js.map +1 -1
- package/dist/core/hash.d.ts +10 -0
- package/dist/core/hash.d.ts.map +1 -0
- package/dist/core/hash.js +14 -0
- package/dist/core/hash.js.map +1 -0
- package/dist/core/model.d.ts +12 -0
- package/dist/core/model.d.ts.map +1 -1
- package/dist/core/propose.d.ts +29 -0
- package/dist/core/propose.d.ts.map +1 -0
- package/dist/core/propose.js +75 -0
- package/dist/core/propose.js.map +1 -0
- package/dist/core/recipe.d.ts +2 -0
- package/dist/core/recipe.d.ts.map +1 -1
- package/dist/core/recipe.js +5 -8
- package/dist/core/recipe.js.map +1 -1
- package/dist/core/resume.d.ts +19 -1
- package/dist/core/resume.d.ts.map +1 -1
- package/dist/core/resume.js +64 -6
- package/dist/core/resume.js.map +1 -1
- package/dist/core/retry.d.ts +9 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +9 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/run-handle.d.ts +5 -0
- package/dist/core/run-handle.d.ts.map +1 -1
- package/dist/core/run-handle.js +1 -0
- package/dist/core/run-handle.js.map +1 -1
- package/dist/core/run.d.ts +29 -2
- package/dist/core/run.d.ts.map +1 -1
- package/dist/core/run.js +526 -132
- package/dist/core/run.js.map +1 -1
- package/dist/core/runtime.d.ts +12 -0
- package/dist/core/runtime.d.ts.map +1 -1
- package/dist/core/runtime.js +34 -2
- package/dist/core/runtime.js.map +1 -1
- package/dist/core/system-clock.d.ts.map +1 -1
- package/dist/core/system-clock.js +5 -1
- package/dist/core/system-clock.js.map +1 -1
- package/dist/core/tool.d.ts +55 -0
- package/dist/core/tool.d.ts.map +1 -1
- package/dist/core/tool.js +16 -0
- package/dist/core/tool.js.map +1 -1
- package/dist/core/usage.d.ts +27 -0
- package/dist/core/usage.d.ts.map +1 -0
- package/dist/core/usage.js +67 -0
- package/dist/core/usage.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/protocol/answers.d.ts +33 -0
- package/dist/protocol/answers.d.ts.map +1 -0
- package/dist/protocol/answers.js +86 -0
- package/dist/protocol/answers.js.map +1 -0
- package/dist/protocol/commands.d.ts +84 -0
- package/dist/protocol/commands.d.ts.map +1 -0
- package/dist/protocol/commands.js +232 -0
- package/dist/protocol/commands.js.map +1 -0
- package/dist/protocol/events.d.ts +145 -0
- package/dist/protocol/events.d.ts.map +1 -0
- package/dist/protocol/events.js +195 -0
- package/dist/protocol/events.js.map +1 -0
- package/dist/protocol/frames.d.ts +72 -0
- package/dist/protocol/frames.d.ts.map +1 -0
- package/dist/protocol/frames.js +134 -0
- package/dist/protocol/frames.js.map +1 -0
- package/dist/protocol/http.d.ts +52 -0
- package/dist/protocol/http.d.ts.map +1 -0
- package/dist/protocol/http.js +357 -0
- package/dist/protocol/http.js.map +1 -0
- package/dist/protocol/reader.d.ts +35 -0
- package/dist/protocol/reader.d.ts.map +1 -0
- package/dist/protocol/reader.js +71 -0
- package/dist/protocol/reader.js.map +1 -0
- package/dist/protocol/session.d.ts +85 -0
- package/dist/protocol/session.d.ts.map +1 -0
- package/dist/protocol/session.js +801 -0
- package/dist/protocol/session.js.map +1 -0
- package/dist/record/entries.d.ts +110 -2
- package/dist/record/entries.d.ts.map +1 -1
- package/dist/record/entries.js +337 -10
- package/dist/record/entries.js.map +1 -1
- package/dist/record/replay.d.ts +6 -0
- package/dist/record/replay.d.ts.map +1 -1
- package/dist/record/replay.js +11 -3
- package/dist/record/replay.js.map +1 -1
- package/dist/record/truncate.d.ts +12 -0
- package/dist/record/truncate.d.ts.map +1 -1
- package/dist/record/truncate.js +72 -1
- package/dist/record/truncate.js.map +1 -1
- package/dist/testkit/cassette.d.ts +91 -0
- package/dist/testkit/cassette.d.ts.map +1 -0
- package/dist/testkit/cassette.js +250 -0
- package/dist/testkit/cassette.js.map +1 -0
- package/dist/testkit/fake-model-server.d.ts +104 -0
- package/dist/testkit/fake-model-server.d.ts.map +1 -0
- package/dist/testkit/fake-model-server.js +251 -0
- package/dist/testkit/fake-model-server.js.map +1 -0
- package/dist/testkit/index.d.ts +5 -2
- package/dist/testkit/index.d.ts.map +1 -1
- package/dist/testkit/index.js +5 -2
- package/dist/testkit/index.js.map +1 -1
- package/dist/testkit/misbehaving-model.d.ts +40 -0
- package/dist/testkit/misbehaving-model.d.ts.map +1 -0
- package/dist/testkit/misbehaving-model.js +134 -0
- package/dist/testkit/misbehaving-model.js.map +1 -0
- package/dist/testkit/model.d.ts +20 -0
- package/dist/testkit/model.d.ts.map +1 -1
- package/dist/testkit/model.js +50 -3
- package/dist/testkit/model.js.map +1 -1
- package/dist/testkit/scenario.d.ts +36 -2
- package/dist/testkit/scenario.d.ts.map +1 -1
- package/dist/testkit/scenario.js +98 -13
- package/dist/testkit/scenario.js.map +1 -1
- package/dist/testkit/timeline-recipe.d.ts.map +1 -1
- package/dist/testkit/timeline-recipe.js +3 -0
- package/dist/testkit/timeline-recipe.js.map +1 -1
- package/dist/testkit/tools.d.ts +15 -1
- package/dist/testkit/tools.d.ts.map +1 -1
- package/dist/testkit/tools.js +19 -0
- package/dist/testkit/tools.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A record entry as the protocol's events (docs/protocol.md, "Replay from the
|
|
3
|
+
* record"; decision 86).
|
|
4
|
+
*
|
|
5
|
+
* The projection is a pure function of a whole record, so replaying a record
|
|
6
|
+
* always gives the same events with the same `seq`, and a client that reconnects
|
|
7
|
+
* reads the record and keeps the events after the one it last saw. The live-only
|
|
8
|
+
* events (`retry`, `tool_start`, `tool_update`, `text_delta`) never appear here:
|
|
9
|
+
* they are not in the record, and a reconnect must not be told about something
|
|
10
|
+
* that already passed.
|
|
11
|
+
*
|
|
12
|
+
* Several events come from one entry and share its `seq`, so a reconnect resumes
|
|
13
|
+
* "after entry n" and never sees half of an entry's events. The record is a
|
|
14
|
+
* straight line today, so an entry's position in the active path is the position
|
|
15
|
+
* storage appended it at.
|
|
16
|
+
*/
|
|
17
|
+
import { type ParkedReason, type RunEndReason } from "../core/events.js";
|
|
18
|
+
import type { FinishReason, ToolCall, Usage } from "../core/model.js";
|
|
19
|
+
import type { RecordEntry, RequestKind } from "../record/entries.js";
|
|
20
|
+
import type { JsonValue } from "../core/json.js";
|
|
21
|
+
/** What every projected event carries, whatever its type. */
|
|
22
|
+
interface EventBase {
|
|
23
|
+
/** The record entry's zero-based position, from `StorageSlot.append`. */
|
|
24
|
+
seq: number;
|
|
25
|
+
/** The entry's own time, not the time it was sent. */
|
|
26
|
+
ts: number;
|
|
27
|
+
session: string;
|
|
28
|
+
run: string;
|
|
29
|
+
}
|
|
30
|
+
export type RecordEvent = (EventBase & {
|
|
31
|
+
type: "run_start";
|
|
32
|
+
}) | (EventBase & {
|
|
33
|
+
type: "resumed";
|
|
34
|
+
}) | (EventBase & {
|
|
35
|
+
type: "message_end";
|
|
36
|
+
text: string;
|
|
37
|
+
toolCalls: ToolCall[];
|
|
38
|
+
}) | (EventBase & {
|
|
39
|
+
type: "tool_call";
|
|
40
|
+
call: ToolCall;
|
|
41
|
+
}) | (EventBase & {
|
|
42
|
+
type: "tool_end";
|
|
43
|
+
callId: string;
|
|
44
|
+
name: string;
|
|
45
|
+
isError: boolean;
|
|
46
|
+
content: string;
|
|
47
|
+
}) | (EventBase & {
|
|
48
|
+
type: "turn_end";
|
|
49
|
+
turn: number;
|
|
50
|
+
finishReason: FinishReason;
|
|
51
|
+
}) | (EventBase & {
|
|
52
|
+
type: "usage";
|
|
53
|
+
inputTokens: number;
|
|
54
|
+
outputTokens: number;
|
|
55
|
+
cost?: Usage["cost"];
|
|
56
|
+
}) | (EventBase & {
|
|
57
|
+
type: "fallback";
|
|
58
|
+
from: string;
|
|
59
|
+
to: string;
|
|
60
|
+
reason: string;
|
|
61
|
+
}) | (EventBase & {
|
|
62
|
+
type: "parked";
|
|
63
|
+
reason: ParkedReason;
|
|
64
|
+
detail?: string;
|
|
65
|
+
}) | (EventBase & {
|
|
66
|
+
type: "run_end";
|
|
67
|
+
reason: RunEndReason;
|
|
68
|
+
turn: number;
|
|
69
|
+
usage: Usage;
|
|
70
|
+
parkedReason?: ParkedReason;
|
|
71
|
+
detail?: string;
|
|
72
|
+
})
|
|
73
|
+
/** The run needs a person, and this is what it is asking (decision 34). */
|
|
74
|
+
| (EventBase & {
|
|
75
|
+
type: "ui_request";
|
|
76
|
+
request: string;
|
|
77
|
+
kind: RequestKind;
|
|
78
|
+
title: string;
|
|
79
|
+
message: string;
|
|
80
|
+
preview?: JsonValue;
|
|
81
|
+
callId?: string;
|
|
82
|
+
tool?: string;
|
|
83
|
+
args?: string;
|
|
84
|
+
risk?: string;
|
|
85
|
+
options?: readonly {
|
|
86
|
+
id: string;
|
|
87
|
+
label: string;
|
|
88
|
+
}[];
|
|
89
|
+
timeoutMs?: number;
|
|
90
|
+
})
|
|
91
|
+
/**
|
|
92
|
+
* A request was answered, so every other client can close the dialog it may be
|
|
93
|
+
* showing (EVT04, decision 34).
|
|
94
|
+
*/
|
|
95
|
+
| (EventBase & {
|
|
96
|
+
type: "ui_resolved";
|
|
97
|
+
request: string;
|
|
98
|
+
decision: "approve" | "deny";
|
|
99
|
+
note?: string;
|
|
100
|
+
})
|
|
101
|
+
/** Nobody answered in time, and the request resolved to deny (REQ05, decision 37). */
|
|
102
|
+
| (EventBase & {
|
|
103
|
+
type: "ui_expired";
|
|
104
|
+
request: string;
|
|
105
|
+
})
|
|
106
|
+
/** A finished run left a result for a person to decide on (decisions 50, 52). */
|
|
107
|
+
| (EventBase & {
|
|
108
|
+
type: "proposal";
|
|
109
|
+
proposal: string;
|
|
110
|
+
payload: JsonValue;
|
|
111
|
+
evidence: JsonValue[];
|
|
112
|
+
state: "open";
|
|
113
|
+
})
|
|
114
|
+
/** A person accepted or rejected it (decision 53, CMD10). */
|
|
115
|
+
| (EventBase & {
|
|
116
|
+
type: "proposal_decided";
|
|
117
|
+
proposal: string;
|
|
118
|
+
decision: "accept" | "reject";
|
|
119
|
+
note?: string;
|
|
120
|
+
})
|
|
121
|
+
/**
|
|
122
|
+
* The run summarized its older steps and moved the model's view forward
|
|
123
|
+
* (docs/context-size.md, decision 39). It comes from the `compaction` entry, so
|
|
124
|
+
* its `seq` is that entry's and a reconnect replays it.
|
|
125
|
+
*/
|
|
126
|
+
| (EventBase & {
|
|
127
|
+
type: "compaction";
|
|
128
|
+
summary: string;
|
|
129
|
+
replaces: number;
|
|
130
|
+
trigger: "auto" | "manual";
|
|
131
|
+
});
|
|
132
|
+
export interface ProjectionContext {
|
|
133
|
+
session: string;
|
|
134
|
+
run: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A record as the events a client watching it would have seen. The turn count and
|
|
138
|
+
* the usage total carry across a resume, because that is what a limit and a
|
|
139
|
+
* resume both count against, and a `run_end` reports the run, not the segment.
|
|
140
|
+
*/
|
|
141
|
+
export declare function projectEvents(entries: readonly RecordEntry[], context: ProjectionContext): RecordEvent[];
|
|
142
|
+
/** The events a client that last saw `seq` still needs, in the order they happened. */
|
|
143
|
+
export declare function eventsAfter(events: readonly RecordEvent[], seq: number): RecordEvent[];
|
|
144
|
+
export {};
|
|
145
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/protocol/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|
+
/**
|
|
2
|
+
* A record entry as the protocol's events (docs/protocol.md, "Replay from the
|
|
3
|
+
* record"; decision 86).
|
|
4
|
+
*
|
|
5
|
+
* The projection is a pure function of a whole record, so replaying a record
|
|
6
|
+
* always gives the same events with the same `seq`, and a client that reconnects
|
|
7
|
+
* reads the record and keeps the events after the one it last saw. The live-only
|
|
8
|
+
* events (`retry`, `tool_start`, `tool_update`, `text_delta`) never appear here:
|
|
9
|
+
* they are not in the record, and a reconnect must not be told about something
|
|
10
|
+
* that already passed.
|
|
11
|
+
*
|
|
12
|
+
* Several events come from one entry and share its `seq`, so a reconnect resumes
|
|
13
|
+
* "after entry n" and never sees half of an entry's events. The record is a
|
|
14
|
+
* straight line today, so an entry's position in the active path is the position
|
|
15
|
+
* storage appended it at.
|
|
16
|
+
*/
|
|
17
|
+
import { parkedReasonOf } from "../core/events.js";
|
|
18
|
+
import { createUsageTotal } from "../core/usage.js";
|
|
19
|
+
import { activePath } from "../record/replay.js";
|
|
20
|
+
/**
|
|
21
|
+
* A record as the events a client watching it would have seen. The turn count and
|
|
22
|
+
* the usage total carry across a resume, because that is what a limit and a
|
|
23
|
+
* resume both count against, and a `run_end` reports the run, not the segment.
|
|
24
|
+
*/
|
|
25
|
+
export function projectEvents(entries, context) {
|
|
26
|
+
const events = [];
|
|
27
|
+
const usage = createUsageTotal();
|
|
28
|
+
/** The tools each call id named, so a tool's own entry can say which tool it was. */
|
|
29
|
+
const callNames = new Map();
|
|
30
|
+
let turn = 0;
|
|
31
|
+
for (const [seq, entry] of activePath(entries).entries()) {
|
|
32
|
+
const base = { seq, ts: entry.ts, session: context.session, run: context.run };
|
|
33
|
+
switch (entry.type) {
|
|
34
|
+
case "status": {
|
|
35
|
+
const detail = entry.detail === undefined ? {} : { detail: entry.detail };
|
|
36
|
+
if (entry.state === "running" || entry.state === "resumed") {
|
|
37
|
+
// A resume begins a new segment of the same run (CMD07), so it is
|
|
38
|
+
// announced as both the resume and the start of work.
|
|
39
|
+
if (entry.state === "resumed") {
|
|
40
|
+
events.push({ ...base, type: "resumed" });
|
|
41
|
+
}
|
|
42
|
+
events.push({ ...base, type: "run_start" });
|
|
43
|
+
}
|
|
44
|
+
else if (entry.state === "parked") {
|
|
45
|
+
const reason = parkedReasonOf(entry.reason);
|
|
46
|
+
events.push({ ...base, type: "parked", reason, ...detail });
|
|
47
|
+
events.push({
|
|
48
|
+
...base,
|
|
49
|
+
type: "run_end",
|
|
50
|
+
reason: "parked",
|
|
51
|
+
parkedReason: reason,
|
|
52
|
+
turn,
|
|
53
|
+
usage: usage.total(),
|
|
54
|
+
...detail,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// `done` and `failed` are the only remaining states: both end the run.
|
|
59
|
+
events.push({
|
|
60
|
+
...base,
|
|
61
|
+
type: "run_end",
|
|
62
|
+
reason: entry.state,
|
|
63
|
+
turn,
|
|
64
|
+
usage: usage.total(),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "assistant_message": {
|
|
70
|
+
turn += 1;
|
|
71
|
+
usage.add(entry.usage);
|
|
72
|
+
for (const call of entry.toolCalls) {
|
|
73
|
+
callNames.set(call.id, call.name);
|
|
74
|
+
}
|
|
75
|
+
events.push({
|
|
76
|
+
...base,
|
|
77
|
+
type: "message_end",
|
|
78
|
+
text: entry.text,
|
|
79
|
+
toolCalls: entry.toolCalls,
|
|
80
|
+
});
|
|
81
|
+
for (const call of entry.toolCalls) {
|
|
82
|
+
events.push({ ...base, type: "tool_call", call });
|
|
83
|
+
}
|
|
84
|
+
events.push({
|
|
85
|
+
...base,
|
|
86
|
+
type: "turn_end",
|
|
87
|
+
turn,
|
|
88
|
+
finishReason: entry.finishReason,
|
|
89
|
+
});
|
|
90
|
+
const cost = entry.usage.cost === undefined ? {} : { cost: entry.usage.cost };
|
|
91
|
+
events.push({
|
|
92
|
+
...base,
|
|
93
|
+
type: "usage",
|
|
94
|
+
inputTokens: entry.usage.inputTokens,
|
|
95
|
+
outputTokens: entry.usage.outputTokens,
|
|
96
|
+
...cost,
|
|
97
|
+
});
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case "tool_message":
|
|
101
|
+
events.push({
|
|
102
|
+
...base,
|
|
103
|
+
type: "tool_end",
|
|
104
|
+
callId: entry.toolCallId,
|
|
105
|
+
// A result whose call is not in the path is still reported; the name it
|
|
106
|
+
// lost is the empty string rather than a guess.
|
|
107
|
+
name: callNames.get(entry.toolCallId) ?? "",
|
|
108
|
+
isError: entry.isError,
|
|
109
|
+
content: entry.content,
|
|
110
|
+
});
|
|
111
|
+
break;
|
|
112
|
+
case "fallback":
|
|
113
|
+
events.push({
|
|
114
|
+
...base,
|
|
115
|
+
type: "fallback",
|
|
116
|
+
from: entry.from,
|
|
117
|
+
to: entry.to,
|
|
118
|
+
reason: entry.reason,
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
121
|
+
case "request": {
|
|
122
|
+
events.push({
|
|
123
|
+
...base,
|
|
124
|
+
type: "ui_request",
|
|
125
|
+
request: entry.request,
|
|
126
|
+
kind: entry.kind,
|
|
127
|
+
title: entry.title,
|
|
128
|
+
message: entry.message,
|
|
129
|
+
...(entry.preview === undefined ? {} : { preview: entry.preview }),
|
|
130
|
+
...(entry.callId === undefined ? {} : { callId: entry.callId }),
|
|
131
|
+
...(entry.tool === undefined ? {} : { tool: entry.tool }),
|
|
132
|
+
...(entry.args === undefined ? {} : { args: entry.args }),
|
|
133
|
+
...(entry.risk === undefined ? {} : { risk: entry.risk }),
|
|
134
|
+
...(entry.options === undefined ? {} : { options: entry.options }),
|
|
135
|
+
...(entry.timeoutMs === undefined ? {} : { timeoutMs: entry.timeoutMs }),
|
|
136
|
+
});
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case "request_answered": {
|
|
140
|
+
events.push({
|
|
141
|
+
...base,
|
|
142
|
+
type: "ui_resolved",
|
|
143
|
+
request: entry.request,
|
|
144
|
+
decision: entry.decision,
|
|
145
|
+
...(entry.note === undefined ? {} : { note: entry.note }),
|
|
146
|
+
});
|
|
147
|
+
if (entry.timedOut === true) {
|
|
148
|
+
events.push({ ...base, type: "ui_expired", request: entry.request });
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case "proposal":
|
|
153
|
+
events.push({
|
|
154
|
+
...base,
|
|
155
|
+
type: "proposal",
|
|
156
|
+
proposal: entry.proposal,
|
|
157
|
+
payload: entry.payload,
|
|
158
|
+
evidence: entry.evidence,
|
|
159
|
+
state: entry.state,
|
|
160
|
+
});
|
|
161
|
+
break;
|
|
162
|
+
case "proposal_decided":
|
|
163
|
+
events.push({
|
|
164
|
+
...base,
|
|
165
|
+
type: "proposal_decided",
|
|
166
|
+
proposal: entry.proposal,
|
|
167
|
+
decision: entry.decision,
|
|
168
|
+
...(entry.note === undefined ? {} : { note: entry.note }),
|
|
169
|
+
});
|
|
170
|
+
break;
|
|
171
|
+
case "compaction":
|
|
172
|
+
events.push({
|
|
173
|
+
...base,
|
|
174
|
+
type: "compaction",
|
|
175
|
+
summary: entry.summary,
|
|
176
|
+
replaces: entry.replaces,
|
|
177
|
+
trigger: entry.trigger,
|
|
178
|
+
});
|
|
179
|
+
break;
|
|
180
|
+
case "user_message":
|
|
181
|
+
case "recipe_updated":
|
|
182
|
+
case "note":
|
|
183
|
+
case "unknown":
|
|
184
|
+
// A user message, a changed pin and a note for a person are in the record
|
|
185
|
+
// but are not protocol events; a kind this build does not know is not ours.
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return events;
|
|
190
|
+
}
|
|
191
|
+
/** The events a client that last saw `seq` still needs, in the order they happened. */
|
|
192
|
+
export function eventsAfter(events, seq) {
|
|
193
|
+
return events.filter((event) => event.seq > seq);
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js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,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;iBACzD,CAAC,CAAC;gBACH,MAAM;YACP,KAAK,YAAY;gBAChB,MAAM,CAAC,IAAI,CAAC;oBACX,GAAG,IAAI;oBACP,IAAI,EAAE,YAAY;oBAClB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,OAAO,EAAE,KAAK,CAAC,OAAO;iBACtB,CAAC,CAAC;gBACH,MAAM;YACP,KAAK,cAAc,CAAC;YACpB,KAAK,gBAAgB,CAAC;YACtB,KAAK,MAAM,CAAC;YACZ,KAAK,SAAS;gBACb,0EAA0E;gBAC1E,4EAA4E;gBAC5E,MAAM;QACR,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,WAAW,CAAC,MAA8B,EAAE,GAAW;IACtE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The frame envelope (docs/protocol.md, "Framing and hello"; decisions 43 and 83).
|
|
3
|
+
*
|
|
4
|
+
* One JSON object per line, with `type` saying what it is. This module owns the
|
|
5
|
+
* envelope and the response shape and nothing else: each command validates its
|
|
6
|
+
* own fields in `commands.ts`, so a decoder here cannot refuse a command it has
|
|
7
|
+
* not been taught, and a field nobody knows is ignored rather than fatal (as in
|
|
8
|
+
* Nova's protocol).
|
|
9
|
+
*/
|
|
10
|
+
import { type JsonObject, type JsonValue } from "../core/json.js";
|
|
11
|
+
import { type ErrorCode, type Result } from "../core/result.js";
|
|
12
|
+
/**
|
|
13
|
+
* The frame types Lyra speaks. `hello` is WebSocket-only (step 8); `ui_response`
|
|
14
|
+
* answers a request rather than telling Lyra to do something, which is why it is
|
|
15
|
+
* its own type and not a command (decision 34).
|
|
16
|
+
*/
|
|
17
|
+
export declare const FRAME_TYPES: readonly ["hello", "command", "response", "event", "ui_response"];
|
|
18
|
+
/**
|
|
19
|
+
* What a host says it can do in `hello` (step 8). A client reads it to know which
|
|
20
|
+
* commands will answer rather than refuse, so it is one list rather than a guess.
|
|
21
|
+
*/
|
|
22
|
+
export declare const CAPABILITIES: readonly ["steer", "follow_up", "compact", "resume", "proposals", "approvals"];
|
|
23
|
+
export type FrameType = (typeof FRAME_TYPES)[number];
|
|
24
|
+
export declare function isFrameType(value: unknown): value is FrameType;
|
|
25
|
+
/** A frame as it arrived: its type, and every other field, unvalidated. */
|
|
26
|
+
export interface DecodedFrame {
|
|
27
|
+
type: FrameType;
|
|
28
|
+
fields: JsonObject;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* One line to a frame. A bad line is `bad_request`; a frame type Lyra does not
|
|
32
|
+
* speak is `unsupported`. Neither is fatal to a connection, which is what lets a
|
|
33
|
+
* client send a command from a newer version and be told so.
|
|
34
|
+
*/
|
|
35
|
+
export declare function decodeFrame(line: string): Result<DecodedFrame>;
|
|
36
|
+
/**
|
|
37
|
+
* The id and command a line claims, for a refusal to name the frame it refuses.
|
|
38
|
+
* A line that is not an object claims nothing.
|
|
39
|
+
*/
|
|
40
|
+
export declare function claimedBy(line: string): {
|
|
41
|
+
id: string;
|
|
42
|
+
command: string;
|
|
43
|
+
};
|
|
44
|
+
/** One frame as one line, newline included. */
|
|
45
|
+
export declare function encodeFrame(frame: {
|
|
46
|
+
type: FrameType;
|
|
47
|
+
} & JsonObject): string;
|
|
48
|
+
/** The answer to a command, in Nova's shape (docs/protocol.md, "Commands"). */
|
|
49
|
+
export interface ResponseFrame {
|
|
50
|
+
type: "response";
|
|
51
|
+
id: string;
|
|
52
|
+
command: string;
|
|
53
|
+
ok: boolean;
|
|
54
|
+
data?: JsonValue;
|
|
55
|
+
error?: {
|
|
56
|
+
code: ErrorCode;
|
|
57
|
+
message: string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** A response frame from what the command did, which is always a `Result`. */
|
|
61
|
+
export declare function responseFrame(id: string, command: string, outcome: {
|
|
62
|
+
ok: true;
|
|
63
|
+
value: JsonValue;
|
|
64
|
+
} | {
|
|
65
|
+
ok: false;
|
|
66
|
+
error: {
|
|
67
|
+
code: string;
|
|
68
|
+
message: string;
|
|
69
|
+
};
|
|
70
|
+
}): ResponseFrame;
|
|
71
|
+
export declare function isResponseFrame(value: unknown): value is ResponseFrame;
|
|
72
|
+
//# sourceMappingURL=frames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frames.d.ts","sourceRoot":"","sources":["../../src/protocol/frames.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAA8B,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAe,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE7E;;;;GAIG;AACH,eAAO,MAAM,WAAW,YAAI,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,CAAU,CAAC;AAE7F;;;GAGG;AACH,eAAO,MAAM,YAAY,YACxB,OAAO,EACP,WAAW,EACX,SAAS,EACT,QAAQ,EACR,WAAW,EACX,WAAW,CACF,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D;AAED,2EAA2E;AAC3E,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,CAuC9D;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAevE;AAED,+CAA+C;AAC/C,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAAG,UAAU,GAAG,MAAM,CAE3E;AAED,+EAA+E;AAC/E,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAC5B,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,OAAO,EACN;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACvF,aAAa,CAYf;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAiBtE"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The frame envelope (docs/protocol.md, "Framing and hello"; decisions 43 and 83).
|
|
3
|
+
*
|
|
4
|
+
* One JSON object per line, with `type` saying what it is. This module owns the
|
|
5
|
+
* envelope and the response shape and nothing else: each command validates its
|
|
6
|
+
* own fields in `commands.ts`, so a decoder here cannot refuse a command it has
|
|
7
|
+
* not been taught, and a field nobody knows is ignored rather than fatal (as in
|
|
8
|
+
* Nova's protocol).
|
|
9
|
+
*/
|
|
10
|
+
import { isJsonValue, isPlainObject } from "../core/json.js";
|
|
11
|
+
import { isErrorCode } from "../core/result.js";
|
|
12
|
+
/**
|
|
13
|
+
* The frame types Lyra speaks. `hello` is WebSocket-only (step 8); `ui_response`
|
|
14
|
+
* answers a request rather than telling Lyra to do something, which is why it is
|
|
15
|
+
* its own type and not a command (decision 34).
|
|
16
|
+
*/
|
|
17
|
+
export const FRAME_TYPES = ["hello", "command", "response", "event", "ui_response"];
|
|
18
|
+
/**
|
|
19
|
+
* What a host says it can do in `hello` (step 8). A client reads it to know which
|
|
20
|
+
* commands will answer rather than refuse, so it is one list rather than a guess.
|
|
21
|
+
*/
|
|
22
|
+
export const CAPABILITIES = [
|
|
23
|
+
"steer",
|
|
24
|
+
"follow_up",
|
|
25
|
+
"compact",
|
|
26
|
+
"resume",
|
|
27
|
+
"proposals",
|
|
28
|
+
"approvals",
|
|
29
|
+
];
|
|
30
|
+
export function isFrameType(value) {
|
|
31
|
+
return FRAME_TYPES.some((type) => type === value);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* One line to a frame. A bad line is `bad_request`; a frame type Lyra does not
|
|
35
|
+
* speak is `unsupported`. Neither is fatal to a connection, which is what lets a
|
|
36
|
+
* client send a command from a newer version and be told so.
|
|
37
|
+
*/
|
|
38
|
+
export function decodeFrame(line) {
|
|
39
|
+
let parsed;
|
|
40
|
+
try {
|
|
41
|
+
parsed = JSON.parse(line);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return { ok: false, error: { code: "bad_request", message: "a frame was not JSON" } };
|
|
45
|
+
}
|
|
46
|
+
if (!isPlainObject(parsed)) {
|
|
47
|
+
return { ok: false, error: { code: "bad_request", message: "a frame was not an object" } };
|
|
48
|
+
}
|
|
49
|
+
const type = parsed["type"];
|
|
50
|
+
if (typeof type !== "string") {
|
|
51
|
+
return {
|
|
52
|
+
ok: false,
|
|
53
|
+
error: { code: "bad_request", message: "a frame had no type" },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (!isFrameType(type)) {
|
|
57
|
+
return {
|
|
58
|
+
ok: false,
|
|
59
|
+
error: {
|
|
60
|
+
code: "unsupported",
|
|
61
|
+
message: `the frame type "${type}" is not one Lyra speaks`,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const fields = {};
|
|
66
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
67
|
+
if (key === "type") {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// A frame's fields have to survive a round trip, because a record or a
|
|
71
|
+
// response echoes them back. Anything that is not JSON is dropped here rather
|
|
72
|
+
// than failing the frame, since JSON.parse can only produce JSON.
|
|
73
|
+
if (isJsonValue(value)) {
|
|
74
|
+
fields[key] = value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return { ok: true, value: { type, fields } };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The id and command a line claims, for a refusal to name the frame it refuses.
|
|
81
|
+
* A line that is not an object claims nothing.
|
|
82
|
+
*/
|
|
83
|
+
export function claimedBy(line) {
|
|
84
|
+
let parsed;
|
|
85
|
+
try {
|
|
86
|
+
parsed = JSON.parse(line);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return { id: "", command: "" };
|
|
90
|
+
}
|
|
91
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
92
|
+
return { id: "", command: "" };
|
|
93
|
+
}
|
|
94
|
+
const fields = parsed;
|
|
95
|
+
return {
|
|
96
|
+
id: typeof fields["id"] === "string" ? fields["id"] : "",
|
|
97
|
+
command: typeof fields["command"] === "string" ? fields["command"] : "",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** One frame as one line, newline included. */
|
|
101
|
+
export function encodeFrame(frame) {
|
|
102
|
+
return `${JSON.stringify(frame)}\n`;
|
|
103
|
+
}
|
|
104
|
+
/** A response frame from what the command did, which is always a `Result`. */
|
|
105
|
+
export function responseFrame(id, command, outcome) {
|
|
106
|
+
if (outcome.ok) {
|
|
107
|
+
return { type: "response", id, command, ok: true, data: outcome.value };
|
|
108
|
+
}
|
|
109
|
+
const code = isErrorCode(outcome.error.code) ? outcome.error.code : "internal";
|
|
110
|
+
return {
|
|
111
|
+
type: "response",
|
|
112
|
+
id,
|
|
113
|
+
command,
|
|
114
|
+
ok: false,
|
|
115
|
+
error: { code, message: outcome.error.message },
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export function isResponseFrame(value) {
|
|
119
|
+
if (!isPlainObject(value) || value["type"] !== "response") {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (typeof value["id"] !== "string" || typeof value["command"] !== "string") {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (typeof value["ok"] !== "boolean") {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (value["ok"]) {
|
|
129
|
+
return value["data"] === undefined || isJsonValue(value["data"]);
|
|
130
|
+
}
|
|
131
|
+
const error = value["error"];
|
|
132
|
+
return (isPlainObject(error) && isErrorCode(error["code"]) && typeof error["message"] === "string");
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=frames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frames.js","sourceRoot":"","sources":["../../src/protocol/frames.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,WAAW,EAAE,aAAa,EAAmC,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,WAAW,EAA+B,MAAM,mBAAmB,CAAC;AAE7E;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,CAAU,CAAC;AAE7F;;;GAGG;AACH,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AM,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,OAAO,CACN,aAAa,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,QAAQ,CAC1F,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The protocol over HTTP (docs/protocol.md, "Replay from the record", "Access"
|
|
3
|
+
* and the HTTP rows; decisions 45 and 87).
|
|
4
|
+
*
|
|
5
|
+
* A web-standard `(Request) => Promise<Response>`, so the same handler runs in a
|
|
6
|
+
* Durable Object (step 6), under `wrangler dev`, and in a test. It owns routing,
|
|
7
|
+
* the version header, the status each error code maps to, and the server-sent
|
|
8
|
+
* event stream; the session owns the commands and the record.
|
|
9
|
+
*
|
|
10
|
+
* Two things are deliberate. The body of every answer is a frame, even when the
|
|
11
|
+
* HTTP status already says what went wrong, so a client reads one shape. And a
|
|
12
|
+
* refusal from the host is never passed through word for word: a host's message
|
|
13
|
+
* can name a session id, and a keyed session's id is derived from its tenant, so
|
|
14
|
+
* another tenant's mistake must not hint at what is there (`ACC01`).
|
|
15
|
+
*/
|
|
16
|
+
import { type ErrorCode, type Result } from "../core/result.js";
|
|
17
|
+
import type { Session } from "./session.js";
|
|
18
|
+
/** The protocol version this build speaks, and what the header means when it is missing. */
|
|
19
|
+
export declare const PROTOCOL_VERSION = "1";
|
|
20
|
+
/**
|
|
21
|
+
* Where a session comes from. The handler never creates storage or objects; a
|
|
22
|
+
* Durable Object host or a test's in-memory host does, and answers `not_found`
|
|
23
|
+
* for a session that belongs to another tenant or does not exist.
|
|
24
|
+
*/
|
|
25
|
+
export interface SessionHost {
|
|
26
|
+
open(request: {
|
|
27
|
+
tenant: string;
|
|
28
|
+
session?: string;
|
|
29
|
+
key?: string;
|
|
30
|
+
}): Promise<Result<Session>>;
|
|
31
|
+
}
|
|
32
|
+
export interface HttpOptions {
|
|
33
|
+
/** The tenant a request may act as, or a refusal. A door with no token never gets here. */
|
|
34
|
+
tenantFor(request: Request): Promise<Result<string>>;
|
|
35
|
+
/** The most bytes one request body may carry. Defaults to the line cap. */
|
|
36
|
+
maxBodyBytes?: number;
|
|
37
|
+
/** How many events may queue for a client before it is dropped. */
|
|
38
|
+
maxQueuedEvents?: number;
|
|
39
|
+
}
|
|
40
|
+
/** The status each stable code maps to, so a plain HTTP client behaves (decision 45). */
|
|
41
|
+
export declare function statusForCode(code: ErrorCode): number;
|
|
42
|
+
/**
|
|
43
|
+
* The public door: a bearer token names its tenant, and the token is compared by
|
|
44
|
+
* digest so a wrong one costs the same time whatever it is. The secrets are a
|
|
45
|
+
* tenant-to-token map, as `docs/protocol.md` says; nothing here logs or records a
|
|
46
|
+
* token, and a refusal never repeats one.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createTokenDoor(tokens: Readonly<Record<string, string>>): (request: Request) => Promise<Result<string>>;
|
|
49
|
+
/** A refusal that has no command behind it: no token, no version, no route. */
|
|
50
|
+
export declare function refusalResponse(code: ErrorCode, message: string): Response;
|
|
51
|
+
export declare function createHttpHandler(host: SessionHost, options: HttpOptions): (request: Request) => Promise<Response>;
|
|
52
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/protocol/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAyB,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAMvF,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,cAAc,CAAC;AAE1D,4FAA4F;AAC5F,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B,IAAI,CAAC,OAAO,EAAE;QAAE,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