@agentshouse/mdruntime 0.1.0-cebcd51f70ed1 → 0.1.0-cec6690d5712e
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/AGENTS.md +82 -27
- package/README.md +13 -3
- package/dist/adapter.d.ts +13 -3
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +15 -2
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +57 -0
- package/dist/bootstrap.d.ts +17 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +88 -35
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +13 -7
- package/dist/change.d.ts +4 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/chat/acts.d.ts +34 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +60 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +20 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +59 -0
- package/dist/chat/markdown.d.ts +19 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +187 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +21 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +151 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +645 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +33 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +9 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +61 -15
- package/dist/collection.d.ts +6 -11
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +56 -19
- package/dist/connection.d.ts +14 -7
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +239 -102
- package/dist/conversation.d.ts +11 -3
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +47 -7
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/host.d.ts +1 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +5 -8
- package/dist/identity.d.ts +2 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +10 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/memory.d.ts +2 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +31 -11
- package/dist/model.d.ts +10 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +2 -0
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +22 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +35 -1
- package/dist/overlay.d.ts +1 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +19 -15
- package/dist/query.d.ts +2 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +5 -31
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +21 -19
- package/dist/react.d.ts +25 -16
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +8 -6
- package/dist/refresh.d.ts +10 -0
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +33 -24
- package/dist/replica.d.ts +5 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +44 -29
- package/dist/room-draft.d.ts +8 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +13 -22
- package/dist/rows.d.ts +2 -0
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +7 -1
- package/dist/save.d.ts +3 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +38 -21
- package/dist/search.d.ts +3 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/status.d.ts +2 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +25 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +206 -90
- package/dist/wire.d.ts +5 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +13 -2
- package/package.json +17 -9
package/dist/bootstrap.js
CHANGED
|
@@ -1,57 +1,110 @@
|
|
|
1
1
|
import { declaredAttachments } from './attachment.js';
|
|
2
|
+
import { transferIdentity } from './identity.js';
|
|
3
|
+
import { advancement } from './refresh.js';
|
|
2
4
|
import { readStaged } from './replica.js';
|
|
3
5
|
import { unconfirmed } from './transfer.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
const RESUMABLE = new Set([
|
|
7
|
+
'transport-uncertainty',
|
|
8
|
+
'retryable-refusal',
|
|
9
|
+
'unconfirmed',
|
|
10
|
+
]);
|
|
11
|
+
function pageLayer(page) {
|
|
12
|
+
return {
|
|
13
|
+
documents: page.documents,
|
|
14
|
+
revisions: page.revisions,
|
|
15
|
+
changes: page.changes,
|
|
16
|
+
written: Object.fromEntries(Object.keys(page.documents).map((path) => [path, page.roomVersion])),
|
|
17
|
+
binaryTargets: page.binaryTargets,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async function heldTransfer(staging, room) {
|
|
21
|
+
const record = staging.held(room.locator);
|
|
22
|
+
if (record === null)
|
|
23
|
+
return null;
|
|
24
|
+
if (record.selection === room.replica.selection) {
|
|
25
|
+
return { record, layer: await staging.staged(record) };
|
|
26
|
+
}
|
|
27
|
+
await staging.abandon(room.locator);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
export async function bootstrapRoom(adapter, authorization, room, held, remodel, continuing, staging) {
|
|
31
|
+
const locator = room.locator;
|
|
32
|
+
const selection = room.replica.selection;
|
|
33
|
+
const kept = await heldTransfer(staging, room);
|
|
34
|
+
const documents = { ...kept?.layer.documents };
|
|
35
|
+
const revisions = { ...kept?.layer.revisions };
|
|
36
|
+
const changes = { ...kept?.layer.changes };
|
|
37
|
+
const written = { ...kept?.layer.written };
|
|
38
|
+
const binaryTargets = new Set(kept?.layer.binaryTargets);
|
|
39
|
+
let transfer = kept?.record ?? null;
|
|
40
|
+
while (transfer === null || transfer.pageToken !== null) {
|
|
20
41
|
if (!continuing())
|
|
21
42
|
return unconfirmed;
|
|
22
43
|
const page = await adapter.bootstrap(authorization, {
|
|
23
|
-
locator
|
|
24
|
-
selection
|
|
25
|
-
pageToken,
|
|
44
|
+
locator,
|
|
45
|
+
selection,
|
|
46
|
+
...(transfer?.pageToken == null ? {} : { pageToken: transfer.pageToken }),
|
|
26
47
|
});
|
|
27
|
-
if (page.kind !== 'bootstrap')
|
|
48
|
+
if (page.kind !== 'bootstrap') {
|
|
49
|
+
if (!RESUMABLE.has(page.kind))
|
|
50
|
+
await staging.abandon(locator);
|
|
28
51
|
return page;
|
|
29
|
-
|
|
52
|
+
}
|
|
53
|
+
transfer = {
|
|
54
|
+
locator,
|
|
55
|
+
transfer: transfer?.transfer ?? transferIdentity(),
|
|
56
|
+
selection,
|
|
57
|
+
from: transfer?.from ?? page.roomVersion,
|
|
58
|
+
last: page.roomVersion,
|
|
59
|
+
pageToken: page.pageToken ?? null,
|
|
60
|
+
models: remodel(page.models, transfer?.models ?? held),
|
|
61
|
+
attachments: [...(transfer?.attachments ?? []), page.attachments ?? []],
|
|
62
|
+
};
|
|
63
|
+
const staged = pageLayer(page);
|
|
64
|
+
if (!(await staging.stage(transfer, staged)))
|
|
30
65
|
return unconfirmed;
|
|
31
|
-
Object.assign(documents,
|
|
32
|
-
Object.assign(revisions,
|
|
33
|
-
Object.assign(changes,
|
|
34
|
-
|
|
66
|
+
Object.assign(documents, staged.documents);
|
|
67
|
+
Object.assign(revisions, staged.revisions);
|
|
68
|
+
Object.assign(changes, staged.changes);
|
|
69
|
+
Object.assign(written, staged.written);
|
|
70
|
+
for (const target of staged.binaryTargets)
|
|
35
71
|
binaryTargets.add(target);
|
|
36
|
-
attachments.push(page.attachments ?? []);
|
|
37
|
-
pageToken = page.pageToken;
|
|
38
72
|
}
|
|
39
|
-
|
|
40
|
-
locator
|
|
73
|
+
const record = {
|
|
74
|
+
locator,
|
|
41
75
|
name: room.name,
|
|
42
76
|
handle: room.handle,
|
|
43
77
|
operations: room.operations,
|
|
44
78
|
replica: room.replica,
|
|
45
|
-
model: models.collection,
|
|
79
|
+
model: transfer.models.collection,
|
|
46
80
|
typedSelection: room.typedSelection ?? null,
|
|
47
|
-
selectionModel: models.selection,
|
|
81
|
+
selectionModel: transfer.models.selection,
|
|
48
82
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
49
|
-
roomVersion,
|
|
83
|
+
roomVersion: transfer.from,
|
|
84
|
+
transfer: transfer.transfer,
|
|
50
85
|
documents,
|
|
51
86
|
binaryTargets: [...binaryTargets].sort(),
|
|
52
87
|
revisions,
|
|
53
88
|
changes,
|
|
54
|
-
written
|
|
55
|
-
attachments: declaredAttachments(attachments),
|
|
56
|
-
}
|
|
89
|
+
written,
|
|
90
|
+
attachments: declaredAttachments(transfer.attachments),
|
|
91
|
+
};
|
|
92
|
+
const reconciled = transfer.last === transfer.from
|
|
93
|
+
? { kind: 'still-current' }
|
|
94
|
+
: await advancement(adapter, authorization, record, remodel, continuing);
|
|
95
|
+
if (reconciled.kind === 'advanced' || reconciled.kind === 'still-current') {
|
|
96
|
+
const read = readStaged(reconciled.kind === 'advanced' ? reconciled.record : record);
|
|
97
|
+
if (read.kind === 'refused') {
|
|
98
|
+
await staging.abandon(locator);
|
|
99
|
+
return read;
|
|
100
|
+
}
|
|
101
|
+
return { kind: 'staged', confirmed: read.confirmed, stored: record };
|
|
102
|
+
}
|
|
103
|
+
if (reconciled.kind === 'beyond-horizon') {
|
|
104
|
+
await staging.abandon(locator);
|
|
105
|
+
return unconfirmed;
|
|
106
|
+
}
|
|
107
|
+
if (!RESUMABLE.has(reconciled.kind))
|
|
108
|
+
await staging.abandon(locator);
|
|
109
|
+
return reconciled;
|
|
57
110
|
}
|
package/dist/change-set.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiC,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAwB,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AAE3D,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,EAAE,CAAC;IACvB,KAAK,EAAE,SAAS,GAAG,EAAE,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvE,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,SAAS,cAAc,EAAE,CAAC;IACrC,MAAM,EAAE,SAAS;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrD,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IACnC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAqBF,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,OAAO,GAAG,IAAI,EACtB,KAAK,EAAE,OAAO,GAAG,IAAI,EACrB,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CAClB,GACL,SAAS,CAqDX;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,aAAa,EAAE,SAAS,MAAM,EAAE,GAC/B,SAAS,CAUX;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAUrE"}
|
package/dist/change-set.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import { passingDocument } from './collection.js';
|
|
1
2
|
import { sameChange } from './overlay.js';
|
|
2
3
|
import { beneath } from './paths.js';
|
|
3
4
|
import { compositionOf, sameMembership } from './replica.js';
|
|
4
|
-
import { rowsOf } from './rows.js';
|
|
5
|
+
import { markdownPath, rowsOf } from './rows.js';
|
|
5
6
|
function rowsAt(locator, replica, path) {
|
|
6
7
|
if (replica === null)
|
|
7
8
|
return [];
|
|
8
|
-
const
|
|
9
|
-
|
|
9
|
+
const visible = replica.visible;
|
|
10
|
+
const document = markdownPath(path) ? passingDocument(visible.collection, path) : null;
|
|
11
|
+
const held = visible.documents[path] !== undefined && document !== undefined;
|
|
12
|
+
if (!held && !visible.binaryTargets.includes(path))
|
|
10
13
|
return [];
|
|
11
|
-
|
|
12
|
-
return rowsOf(locator, path, document ?? null, compositionOf(replica.confirmed.record), replica.visible.changes[path] ?? null);
|
|
14
|
+
return rowsOf(locator, path, document ?? null, compositionOf(replica.confirmed.record), visible.changes[path] ?? null);
|
|
13
15
|
}
|
|
14
16
|
function modelShape(model) {
|
|
15
17
|
return model.status === 'unavailable' ? 'unavailable' : JSON.stringify(model.types);
|
|
@@ -45,8 +47,12 @@ export function changeSet(locator, before, after, changed = {}) {
|
|
|
45
47
|
documents.push({
|
|
46
48
|
locator,
|
|
47
49
|
path,
|
|
48
|
-
before
|
|
49
|
-
|
|
50
|
+
get before() {
|
|
51
|
+
return rowsAt(locator, before, path);
|
|
52
|
+
},
|
|
53
|
+
get after() {
|
|
54
|
+
return rowsAt(locator, after, path);
|
|
55
|
+
},
|
|
50
56
|
});
|
|
51
57
|
}
|
|
52
58
|
return {
|
package/dist/change.d.ts
CHANGED
|
@@ -51,6 +51,10 @@ export type Precondition = {
|
|
|
51
51
|
readonly kind: 'revision';
|
|
52
52
|
readonly path: string;
|
|
53
53
|
readonly revision: string;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: 'content';
|
|
56
|
+
readonly path: string;
|
|
57
|
+
readonly content: string;
|
|
54
58
|
} | {
|
|
55
59
|
readonly kind: 'present';
|
|
56
60
|
readonly path: string;
|
package/dist/change.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change.d.ts","sourceRoot":"","sources":["../src/change.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GACd;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC5E;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ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AAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,SAAS,YAAY,EAAE,CAAC;IAChD,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;CAChC,CAAC;AAUF,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,CAEzD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Answered } from '../attempt.js';
|
|
2
|
+
import { type CallResult } from '../outcome.js';
|
|
3
|
+
import type { Expected } from './overlay.js';
|
|
4
|
+
export type ChatResult = CallResult | {
|
|
5
|
+
readonly kind: 'offline';
|
|
6
|
+
};
|
|
7
|
+
export type ChatOutcome = {
|
|
8
|
+
readonly state: 'sending';
|
|
9
|
+
} | {
|
|
10
|
+
readonly state: 'offline';
|
|
11
|
+
} | {
|
|
12
|
+
readonly state: 'failed';
|
|
13
|
+
readonly result: CallResult;
|
|
14
|
+
};
|
|
15
|
+
export declare function accepted(result: ChatResult): result is Extract<CallResult, {
|
|
16
|
+
readonly kind: 'action';
|
|
17
|
+
}>;
|
|
18
|
+
export declare function unanswered(result: ChatResult): boolean;
|
|
19
|
+
export declare function outcomeOf(result: ChatResult): ChatOutcome | null;
|
|
20
|
+
export declare function answeredOf(result: ChatResult): Answered;
|
|
21
|
+
export type Sender = {
|
|
22
|
+
carried(name: string, about: unknown, sending: (operation: string) => Promise<CallResult>): Promise<ChatResult>;
|
|
23
|
+
expect(expected: Expected): void;
|
|
24
|
+
draw(expected: Expected): void;
|
|
25
|
+
};
|
|
26
|
+
type Senders = {
|
|
27
|
+
readonly online: boolean;
|
|
28
|
+
identity(intent: string): string;
|
|
29
|
+
expect(expected: Expected): void;
|
|
30
|
+
draw(expected: Expected): void;
|
|
31
|
+
};
|
|
32
|
+
export declare function sender({ online, identity, expect, draw }: Senders): Sender;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=acts.d.ts.map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AAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IACjC,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,wBAAgB,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,OAAO,GAAG,MAAM,CAa1E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { intentOf } from '../attempt.js';
|
|
2
|
+
import { UNCERTAIN } from '../outcome.js';
|
|
3
|
+
export function accepted(result) {
|
|
4
|
+
return result.kind === 'action';
|
|
5
|
+
}
|
|
6
|
+
export function unanswered(result) {
|
|
7
|
+
return result.kind === 'transport-uncertainty';
|
|
8
|
+
}
|
|
9
|
+
export function outcomeOf(result) {
|
|
10
|
+
if (accepted(result))
|
|
11
|
+
return null;
|
|
12
|
+
return result.kind === 'offline' ? { state: 'offline' } : { state: 'failed', result };
|
|
13
|
+
}
|
|
14
|
+
export function answeredOf(result) {
|
|
15
|
+
if (accepted(result))
|
|
16
|
+
return 'accepted';
|
|
17
|
+
if (result.kind === 'offline')
|
|
18
|
+
return 'offline';
|
|
19
|
+
return unanswered(result) ? 'unanswered' : 'refused';
|
|
20
|
+
}
|
|
21
|
+
export function sender({ online, identity, expect, draw }) {
|
|
22
|
+
return {
|
|
23
|
+
async carried(name, about, sending) {
|
|
24
|
+
if (!online)
|
|
25
|
+
return { kind: 'offline' };
|
|
26
|
+
try {
|
|
27
|
+
return await sending(identity(intentOf(name, about)));
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return UNCERTAIN;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
expect,
|
|
34
|
+
draw,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/chat/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQjD,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function figure(tokens) {
|
|
2
|
+
if (tokens >= 1_000_000)
|
|
3
|
+
return `${(tokens / 1_000_000).toFixed(1).replace(/\.0$/, '')}M`;
|
|
4
|
+
if (tokens >= 1_000)
|
|
5
|
+
return `${Math.round(tokens / 1_000)}k`;
|
|
6
|
+
return String(tokens);
|
|
7
|
+
}
|
|
8
|
+
export function contextText(context) {
|
|
9
|
+
return `${figure(context.used)}/${figure(context.window)}`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
import { type ChatNoteProps } from './kit.js';
|
|
3
|
+
export type ChatInputProps = {
|
|
4
|
+
readonly messageLength?: number;
|
|
5
|
+
readonly note?: (note: ChatNoteProps) => ReactNode;
|
|
6
|
+
readonly autoFocus?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function ChatInput({ messageLength, note, autoFocus, }: ChatInputProps): ReactElement;
|
|
9
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/chat/input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA0C,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAqBlG,OAAO,EAAsD,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAMlG,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,SAAS,CAAC;IACnD,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAiGF,wBAAgB,SAAS,CAAC,EACxB,aAAa,EACb,IAAY,EACZ,SAAiB,GAClB,EAAE,cAAc,GAAG,YAAY,CA+K/B"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import { ComposerPrimitive, useAui, useAuiState, } from '@assistant-ui/react';
|
|
4
|
+
import { DropdownMenu } from 'radix-ui';
|
|
5
|
+
import ArrowUp from 'lucide-react/dist/esm/icons/arrow-up.mjs';
|
|
6
|
+
import Check from 'lucide-react/dist/esm/icons/check.mjs';
|
|
7
|
+
import ChevronDown from 'lucide-react/dist/esm/icons/chevron-down.mjs';
|
|
8
|
+
import CornerDownRight from 'lucide-react/dist/esm/icons/corner-down-right.mjs';
|
|
9
|
+
import ListEnd from 'lucide-react/dist/esm/icons/list-end.mjs';
|
|
10
|
+
import Paperclip from 'lucide-react/dist/esm/icons/paperclip.mjs';
|
|
11
|
+
import Pencil from 'lucide-react/dist/esm/icons/pencil.mjs';
|
|
12
|
+
import Plus from 'lucide-react/dist/esm/icons/plus.mjs';
|
|
13
|
+
import Square from 'lucide-react/dist/esm/icons/square.mjs';
|
|
14
|
+
import X from 'lucide-react/dist/esm/icons/x.mjs';
|
|
15
|
+
import { contextText } from './context.js';
|
|
16
|
+
import { Button, ChatNote, IconButton, Name, Portal, Scoped } from './kit.js';
|
|
17
|
+
import { COMMAND } from './process.js';
|
|
18
|
+
import { useChat, useChatScope } from './provider.js';
|
|
19
|
+
import { forgetAnswers } from './question.js';
|
|
20
|
+
import { useOpened } from './opened.js';
|
|
21
|
+
const commanded = {
|
|
22
|
+
serialize: (item) => `${COMMAND}${item.id}`,
|
|
23
|
+
parse: (said) => [{ kind: 'text', text: said }],
|
|
24
|
+
};
|
|
25
|
+
const atStart = (said, char, cursor) => {
|
|
26
|
+
const typed = said.slice(0, cursor);
|
|
27
|
+
return typed.startsWith(char) && !/\s/.test(typed)
|
|
28
|
+
? { query: typed.slice(char.length), offset: 0, endOffset: cursor }
|
|
29
|
+
: null;
|
|
30
|
+
};
|
|
31
|
+
function commandItem(command) {
|
|
32
|
+
return {
|
|
33
|
+
id: command.name,
|
|
34
|
+
type: 'command',
|
|
35
|
+
label: `${COMMAND}${command.name}`,
|
|
36
|
+
description: command.description,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function commandsFound(commands, query) {
|
|
40
|
+
const asked = query.toLowerCase();
|
|
41
|
+
const named = commands.filter((one) => one.name.toLowerCase().startsWith(asked));
|
|
42
|
+
const within = commands.filter((one) => !named.includes(one) && one.name.toLowerCase().includes(asked));
|
|
43
|
+
return [...named, ...within].map(commandItem);
|
|
44
|
+
}
|
|
45
|
+
function Attached({ id, name }) {
|
|
46
|
+
const aui = useAui();
|
|
47
|
+
return (_jsxs("span", { className: "ahc-chip ahc-chip--removable", children: [_jsx(Paperclip, { "aria-hidden": "true" }), _jsx(Name, { text: name }), _jsx(IconButton, { label: `Remove ${name}`, compact: true, onClick: () => void aui.composer().attachment({ id }).remove(), children: _jsx(X, { "aria-hidden": "true" }) })] }));
|
|
48
|
+
}
|
|
49
|
+
function Picker({ option, choose, }) {
|
|
50
|
+
const container = useContext(Portal);
|
|
51
|
+
return (_jsxs(DropdownMenu.Root, { modal: false, children: [_jsxs(DropdownMenu.Trigger, { className: "ahc-btn ahc-picker", "aria-label": option.name, title: option.name, children: [_jsx(Name, { text: option.values.find((one) => one.value === option.value)?.name ?? option.value }), _jsx(ChevronDown, { "aria-hidden": "true" })] }), _jsx(DropdownMenu.Portal, { container: container, children: _jsxs(DropdownMenu.Content, { className: "ahc-menu", side: "top", align: "start", children: [_jsx(DropdownMenu.Label, { className: "ahc-menu__heading", children: option.name }), _jsx(DropdownMenu.RadioGroup, { value: option.value, onValueChange: (value) => {
|
|
52
|
+
if (value !== option.value)
|
|
53
|
+
void choose(option.id, value);
|
|
54
|
+
}, children: option.values.map((one) => (_jsxs(DropdownMenu.RadioItem, { value: one.value, className: "ahc-row", children: [_jsx("span", { className: "ahc-row__label", children: one.name }), _jsx(DropdownMenu.ItemIndicator, { asChild: true, children: _jsx(Check, { "aria-hidden": "true" }) })] }, one.value))) })] }) })] }));
|
|
55
|
+
}
|
|
56
|
+
function noted(note) {
|
|
57
|
+
return _jsx(ChatNote, { ...note });
|
|
58
|
+
}
|
|
59
|
+
export function ChatInput({ messageLength, note = noted, autoFocus = false, }) {
|
|
60
|
+
const chat = useChat();
|
|
61
|
+
const { client } = useChatScope();
|
|
62
|
+
const aui = useAui();
|
|
63
|
+
const opened = useOpened();
|
|
64
|
+
const { lone, commands, context, queued, running } = opened;
|
|
65
|
+
const conversation = chat.conversation ?? '';
|
|
66
|
+
const input = useRef(null);
|
|
67
|
+
const picker = useRef(null);
|
|
68
|
+
const thread = chat.conversation ?? `new:${chat.agent ?? ''}`;
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (autoFocus)
|
|
71
|
+
input.current?.focus();
|
|
72
|
+
}, [autoFocus, thread]);
|
|
73
|
+
const typed = useAuiState((s) => s.composer.text);
|
|
74
|
+
const attached = useAuiState((s) => s.composer.attachments.length > 0);
|
|
75
|
+
const fault = messageLength !== undefined && typed.length > messageLength
|
|
76
|
+
? `Keep it to ${messageLength} characters.`
|
|
77
|
+
: null;
|
|
78
|
+
const listed = useMemo(() => ({
|
|
79
|
+
categories: () => [],
|
|
80
|
+
categoryItems: () => [],
|
|
81
|
+
search: (query) => commandsFound(commands, query),
|
|
82
|
+
}), [commands]);
|
|
83
|
+
const interrupt = () => void chat.stop().then((stopped) => {
|
|
84
|
+
if (stopped)
|
|
85
|
+
void forgetAnswers(client, conversation);
|
|
86
|
+
});
|
|
87
|
+
const edit = (id) => {
|
|
88
|
+
chat.edit(id);
|
|
89
|
+
input.current?.focus();
|
|
90
|
+
};
|
|
91
|
+
const drafted = typed.trim() !== '' || attached;
|
|
92
|
+
const readOnly = opened.deleted;
|
|
93
|
+
return (_jsx(Scoped, { children: _jsxs("div", { className: "ahc-input-area", children: [readOnly || queued.length === 0 ? null : (_jsxs("div", { role: "group", "aria-label": "Queued messages", className: "ahc-queue", children: [_jsxs("div", { className: "ahc-queue__head", children: [_jsx(ListEnd, { "aria-hidden": "true" }), _jsx("span", { className: "ahc-queue__said", children: `${queued.length} ${queued.length === 1 ? 'message waits' : 'messages wait'} for ${opened.name} to finish` }), running ? (_jsx(Button, { variant: "outline", compact: true, onClick: interrupt, children: "Send now" })) : null] }), queued.map((item) => (_jsxs("div", { className: "ahc-queue-row", children: [_jsx(CornerDownRight, { "aria-hidden": "true", className: "ahc-muted" }), _jsx("span", { className: "ahc-queue-row__text", children: item.text }), _jsx(IconButton, { label: "Edit queued message", compact: true, onClick: () => edit(item.id), children: _jsx(Pencil, { "aria-hidden": "true" }) }), _jsx(IconButton, { label: "Remove queued message", compact: true, onClick: () => chat.unqueue(item.id), children: _jsx(X, { "aria-hidden": "true" }) })] }, item.id)))] })), readOnly ? null : (_jsx(ComposerPrimitive.Root, { className: "ahc-composer", children: _jsxs(ComposerPrimitive.Unstable_TriggerPopoverRoot, { children: [commands.length === 0 ? null : (_jsxs(ComposerPrimitive.Unstable_TriggerPopover, { char: COMMAND, matcher: atStart, adapter: listed, "aria-label": "Commands", className: "ahc-menu ahc-commands", children: [_jsx(ComposerPrimitive.Unstable_TriggerPopover.Directive, { formatter: commanded }), _jsx(ComposerPrimitive.Unstable_TriggerPopoverItems, { children: (items) => items.map((item, index) => (_jsx(ComposerPrimitive.Unstable_TriggerPopoverItem, { item: item, index: index, className: "ahc-row ahc-row--two", children: _jsxs("span", { className: "ahc-row__label", children: [_jsx("span", { className: "ahc-row__title ahc-mono", children: item.label }), _jsx("span", { className: "ahc-row__sub", children: item.description })] }) }, item.id))) })] })), attached ? (_jsx("div", { className: "ahc-chips", children: _jsx(ComposerPrimitive.Attachments, { children: ({ attachment }) => _jsx(Attached, { id: attachment.id, name: attachment.name }) }) })) : null, _jsx(ComposerPrimitive.Input, { asChild: true, "aria-label": "Message", placeholder: lone === null ? `Message ${opened.name}` : lone.field.prompt, submitMode: fault === null ? 'enter' : 'none', children: _jsx("textarea", { ref: input, className: "ahc-composer__input", rows: 1 }) }), _jsxs("div", { className: "ahc-composer__bar", children: [_jsx(IconButton, { label: "Add files", onClick: () => picker.current?.click(), children: _jsx(Plus, { size: 20, "aria-hidden": "true" }) }), _jsx("input", { ref: picker, type: "file", multiple: true, hidden: true, onChange: (event) => {
|
|
94
|
+
const chosen = [...(event.target.files ?? [])];
|
|
95
|
+
event.target.value = '';
|
|
96
|
+
for (const file of chosen)
|
|
97
|
+
void aui.composer().addAttachment(file);
|
|
98
|
+
} }), opened.options.map((option) => (_jsx(Picker, { option: option, choose: chat.choose }, option.id))), _jsx("span", { className: "ahc-spacer" }), context === null ? null : (_jsx("span", { title: "Context in use", className: "ahc-meta", children: contextText(context) })), running ? (_jsx("button", { type: "button", className: `ahc-btn ahc-btn--icon ${drafted ? 'ahc-btn--outline' : 'ahc-btn--ink'}`, "aria-label": "Stop", title: "Stop", onClick: interrupt, children: _jsx(Square, { "aria-hidden": "true" }) })) : null, running && !drafted ? null : (_jsx(ComposerPrimitive.Send, { className: "ahc-btn ahc-btn--icon ahc-btn--ink", "aria-label": running ? 'Queue message' : 'Send', disabled: fault !== null, children: _jsx(ArrowUp, { size: 20, "aria-hidden": "true" }) }))] })] }) })), fault === null ? null : (_jsx("p", { className: "ahc-note", role: "status", "data-state": "refused", children: fault })), note({ outcome: chat.acting.outcome }), note({ outcome: chat.sending.outcome, again: chat.sending.again ?? undefined })] }) }));
|
|
99
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef, type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
import type { ChatOutcome } from './acts.js';
|
|
3
|
+
export type Variant = 'quiet' | 'ink' | 'outline' | 'danger' | 'danger-outline';
|
|
4
|
+
export declare const Portal: import("react").Context<HTMLElement | null>;
|
|
5
|
+
export declare function Within({ root, children, }: {
|
|
6
|
+
root: HTMLElement;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}): ReactElement;
|
|
9
|
+
export declare function Scoped({ children }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}): ReactElement;
|
|
12
|
+
export declare function buttonClass(variant: Variant, compact: boolean, icon: boolean): string;
|
|
13
|
+
type Native = Omit<ComponentPropsWithRef<'button'>, 'className'>;
|
|
14
|
+
export declare function Button({ variant, compact, type, children, ...rest }: Native & {
|
|
15
|
+
variant?: Variant;
|
|
16
|
+
compact?: boolean;
|
|
17
|
+
}): ReactElement;
|
|
18
|
+
export declare function IconButton({ label, variant, compact, type, ...rest }: Native & {
|
|
19
|
+
label: string;
|
|
20
|
+
variant?: Variant;
|
|
21
|
+
compact?: boolean;
|
|
22
|
+
}): ReactElement;
|
|
23
|
+
export declare function Name({ text, className }: {
|
|
24
|
+
text: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
}): ReactElement;
|
|
27
|
+
export declare function Menu({ trigger, children, }: {
|
|
28
|
+
trigger: ReactElement;
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
}): ReactElement;
|
|
31
|
+
export declare function MenuGap(): ReactElement;
|
|
32
|
+
export declare function MenuItem({ icon, danger, onSelect, children, }: {
|
|
33
|
+
icon: ReactNode;
|
|
34
|
+
danger?: boolean;
|
|
35
|
+
onSelect: () => void;
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
}): ReactElement;
|
|
38
|
+
export declare function Confirm({ title, text, action, onConfirm, onClose, }: {
|
|
39
|
+
title: string;
|
|
40
|
+
text: string;
|
|
41
|
+
action: string;
|
|
42
|
+
onConfirm: () => void;
|
|
43
|
+
onClose: () => void;
|
|
44
|
+
}): ReactElement;
|
|
45
|
+
export declare function ItemRow({ lead, title, sub, trailing, }: {
|
|
46
|
+
lead: ReactNode;
|
|
47
|
+
title: ReactNode;
|
|
48
|
+
sub: ReactNode;
|
|
49
|
+
trailing: ReactNode;
|
|
50
|
+
}): ReactElement;
|
|
51
|
+
export declare function Working({ step }: {
|
|
52
|
+
step?: string | undefined;
|
|
53
|
+
}): ReactElement;
|
|
54
|
+
export type ChatNoteProps = {
|
|
55
|
+
readonly outcome: ChatOutcome | null;
|
|
56
|
+
readonly again?: (() => void) | undefined;
|
|
57
|
+
};
|
|
58
|
+
export declare function ChatNote({ outcome, again }: ChatNoteProps): ReactElement | null;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=kit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../../src/chat/kit.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,GAAG,gBAAgB,CAAC;AAEhF,eAAO,MAAM,MAAM,6CAA0C,CAAC;AAE9D,wBAAgB,MAAM,CAAC,EACrB,IAAI,EACJ,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,YAAY,CAQf;AAED,wBAAgB,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,GAAG,YAAY,CAa1E;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CASrF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AM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,GAAG,YAAY,CAsDf;AAED,wBAAgB,OAAO,CAAC,EACtB,IAAI,EACJ,KAAK,EACL,GAAG,EACH,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,GAAG,EAAE,SAAS,CAAC;IACf,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,YAAY,CAWf;AAMD,wBAAgB,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,YAAY,CAiB7E;AASD,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;CAC3C,CAAC;AAEF,wBAAgB,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,aAAa,GAAG,YAAY,GAAG,IAAI,CAuB/E"}
|
package/dist/chat/kit.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Children, createContext, useCallback, useContext, useEffect, useState, } from 'react';
|
|
3
|
+
import { Dialog, DropdownMenu } from 'radix-ui';
|
|
4
|
+
import { LucideProvider } from 'lucide-react/dist/esm/context.mjs';
|
|
5
|
+
import X from 'lucide-react/dist/esm/icons/x.mjs';
|
|
6
|
+
import { adopted } from './style.js';
|
|
7
|
+
export const Portal = createContext(null);
|
|
8
|
+
export function Within({ root, children, }) {
|
|
9
|
+
return (_jsx(Portal.Provider, { value: root, children: _jsx(LucideProvider, { size: 16, strokeWidth: 1.5, absoluteStrokeWidth: true, children: children }) }));
|
|
10
|
+
}
|
|
11
|
+
export function Scoped({ children }) {
|
|
12
|
+
const inside = useContext(Portal);
|
|
13
|
+
const [root, setRoot] = useState(null);
|
|
14
|
+
const attach = useCallback((element) => {
|
|
15
|
+
adopted(element);
|
|
16
|
+
setRoot(element);
|
|
17
|
+
}, []);
|
|
18
|
+
if (inside !== null)
|
|
19
|
+
return _jsx(_Fragment, { children: children });
|
|
20
|
+
return (_jsx("div", { ref: attach, className: "ahc ahc-scope", children: root === null ? null : _jsx(Within, { root: root, children: children }) }));
|
|
21
|
+
}
|
|
22
|
+
export function buttonClass(variant, compact, icon) {
|
|
23
|
+
return [
|
|
24
|
+
'ahc-btn',
|
|
25
|
+
icon ? 'ahc-btn--icon' : null,
|
|
26
|
+
variant === 'quiet' ? null : `ahc-btn--${variant}`,
|
|
27
|
+
compact ? 'ahc-btn--compact' : null,
|
|
28
|
+
]
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.join(' ');
|
|
31
|
+
}
|
|
32
|
+
function labelled(children) {
|
|
33
|
+
const parts = [];
|
|
34
|
+
let said = '';
|
|
35
|
+
const flush = () => {
|
|
36
|
+
if (said !== '') {
|
|
37
|
+
parts.push(_jsx("span", { className: "ahc-name", children: said }, `text-${parts.length}`));
|
|
38
|
+
}
|
|
39
|
+
said = '';
|
|
40
|
+
};
|
|
41
|
+
for (const child of Children.toArray(children)) {
|
|
42
|
+
if (typeof child === 'string' || typeof child === 'number')
|
|
43
|
+
said += String(child);
|
|
44
|
+
else {
|
|
45
|
+
flush();
|
|
46
|
+
parts.push(child);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
flush();
|
|
50
|
+
return parts;
|
|
51
|
+
}
|
|
52
|
+
export function Button({ variant = 'quiet', compact = false, type = 'button', children, ...rest }) {
|
|
53
|
+
return (_jsx("button", { type: type, className: buttonClass(variant, compact, false), ...rest, children: labelled(children) }));
|
|
54
|
+
}
|
|
55
|
+
export function IconButton({ label, variant = 'quiet', compact = false, type = 'button', ...rest }) {
|
|
56
|
+
return (_jsx("button", { type: type, "aria-label": label, className: buttonClass(variant, compact, true), ...rest }));
|
|
57
|
+
}
|
|
58
|
+
export function Name({ text, className }) {
|
|
59
|
+
return (_jsx("span", { className: className === undefined ? 'ahc-name' : `ahc-name ${className}`, title: text, children: text }));
|
|
60
|
+
}
|
|
61
|
+
export function Menu({ trigger, children, }) {
|
|
62
|
+
const container = useContext(Portal);
|
|
63
|
+
const [open, setOpen] = useState(false);
|
|
64
|
+
return (_jsxs(DropdownMenu.Root, { modal: false, open: open, onOpenChange: setOpen, children: [_jsx(DropdownMenu.Trigger, { asChild: true, children: trigger }), open ? (_jsx(DropdownMenu.Portal, { forceMount: true, container: container, children: _jsx(DropdownMenu.Content, { forceMount: true, className: "ahc-menu", align: "end", sideOffset: 4, collisionPadding: 8, children: children }) })) : null] }));
|
|
65
|
+
}
|
|
66
|
+
export function MenuGap() {
|
|
67
|
+
return _jsx(DropdownMenu.Separator, { className: "ahc-menu__gap" });
|
|
68
|
+
}
|
|
69
|
+
export function MenuItem({ icon, danger = false, onSelect, children, }) {
|
|
70
|
+
return (_jsxs(DropdownMenu.Item, { className: danger ? 'ahc-row ahc-row--danger' : 'ahc-row', onSelect: onSelect, children: [_jsx("span", { className: "ahc-row__icon", children: icon }), _jsx("span", { className: "ahc-row__label", children: _jsx("span", { className: "ahc-row__title", children: children }) })] }));
|
|
71
|
+
}
|
|
72
|
+
export function Confirm({ title, text, action, onConfirm, onClose, }) {
|
|
73
|
+
const container = useContext(Portal);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const behind = container?.querySelector('.ahc-frame');
|
|
76
|
+
if (behind === null || behind === undefined)
|
|
77
|
+
return;
|
|
78
|
+
behind.inert = true;
|
|
79
|
+
return () => {
|
|
80
|
+
behind.inert = false;
|
|
81
|
+
};
|
|
82
|
+
}, [container]);
|
|
83
|
+
return (_jsx(Dialog.Root, { open: true, modal: false, onOpenChange: (open) => {
|
|
84
|
+
if (!open)
|
|
85
|
+
onClose();
|
|
86
|
+
}, children: _jsxs(Dialog.Portal, { container: container, children: [_jsx("div", { className: "ahc-scrim", onClick: onClose }), _jsxs(Dialog.Content, { className: "ahc-dialog", role: "alertdialog", "aria-describedby": undefined, "aria-modal": true, onInteractOutside: (event) => event.preventDefault(), children: [_jsxs("div", { className: "ahc-dialog__head", children: [_jsx(Dialog.Title, { className: "ahc-dialog__title", children: title }), _jsx(Dialog.Close, { asChild: true, children: _jsx(IconButton, { label: "Close", compact: true, children: _jsx(X, { size: 20, "aria-hidden": "true" }) }) })] }), _jsx("div", { className: "ahc-dialog__body", children: _jsx("p", { className: "ahc-dialog__text", children: text }) }), _jsxs("div", { className: "ahc-dialog__actions", children: [_jsx(Button, { onClick: onClose, children: "Cancel" }), _jsx(Button, { variant: "danger", onClick: () => {
|
|
87
|
+
onConfirm();
|
|
88
|
+
onClose();
|
|
89
|
+
}, children: action })] })] })] }) }));
|
|
90
|
+
}
|
|
91
|
+
export function ItemRow({ lead, title, sub, trailing, }) {
|
|
92
|
+
return (_jsxs("div", { className: "ahc-row ahc-row--two ahc-item", children: [_jsx("span", { className: "ahc-item__lead", children: lead }), _jsxs("span", { className: "ahc-row__label", children: [_jsx("span", { className: "ahc-row__title ahc-item__title", children: title }), _jsx("span", { className: "ahc-row__sub", children: sub })] }), trailing] }));
|
|
93
|
+
}
|
|
94
|
+
function elapsed(seconds) {
|
|
95
|
+
return seconds >= 60 ? `${Math.floor(seconds / 60)}m ${seconds % 60}s` : `${seconds}s`;
|
|
96
|
+
}
|
|
97
|
+
export function Working({ step }) {
|
|
98
|
+
const [from] = useState(() => Date.now());
|
|
99
|
+
const [now, setNow] = useState(from);
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
// The elapsed time counts whole seconds, so it moves once a second.
|
|
102
|
+
const tick = setInterval(() => setNow(Date.now()), 1000);
|
|
103
|
+
return () => clearInterval(tick);
|
|
104
|
+
}, []);
|
|
105
|
+
return (_jsxs("div", { className: "ahc-toolline ahc-working", role: "status", children: [_jsx("span", { className: "ahc-shimmer", children: "Working" }), _jsx("span", { className: "ahc-figure", "aria-hidden": "true", children: elapsed(Math.floor((now - from) / 1000)) }), step === undefined ? null : _jsx("span", { children: step })] }));
|
|
106
|
+
}
|
|
107
|
+
const SAID = {
|
|
108
|
+
sending: 'Sending…',
|
|
109
|
+
offline: 'You are offline. Nothing was sent.',
|
|
110
|
+
};
|
|
111
|
+
const UNANSWERED = 'House did not answer.';
|
|
112
|
+
export function ChatNote({ outcome, again }) {
|
|
113
|
+
if (outcome === null)
|
|
114
|
+
return null;
|
|
115
|
+
const uncertain = outcome.state === 'failed' && outcome.result.kind === 'transport-uncertainty';
|
|
116
|
+
const said = outcome.state !== 'failed'
|
|
117
|
+
? SAID[outcome.state]
|
|
118
|
+
: uncertain
|
|
119
|
+
? 'House did not answer. Try again.'
|
|
120
|
+
: 'House refused this.';
|
|
121
|
+
const retried = again !== undefined && uncertain;
|
|
122
|
+
return (_jsxs("p", { className: "ahc-note", role: "status", "data-state": uncertain ? 'uncertain' : outcome.state, children: [retried ? UNANSWERED : said, retried ? (_jsxs(_Fragment, { children: [' ', _jsx("button", { type: "button", className: "ahc-again", onClick: again, children: "Try again" })] })) : null] }));
|
|
123
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lasting.d.ts","sourceRoot":"","sources":["../../src/chat/lasting.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAM1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAiB3C,wBAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAA;CAAE,GAAG,YAAY,CAyBxF"}
|