@agentshouse/mdruntime 0.1.0-cebcd51f70ed1 → 0.1.0-cf24798931067

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/AGENTS.md +58 -12
  2. package/README.md +3 -2
  3. package/dist/adapter.d.ts +13 -3
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +15 -2
  7. package/dist/attempt.d.ts +16 -0
  8. package/dist/attempt.d.ts.map +1 -0
  9. package/dist/attempt.js +57 -0
  10. package/dist/bootstrap.d.ts +17 -5
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +88 -35
  13. package/dist/change-set.d.ts.map +1 -1
  14. package/dist/change-set.js +13 -7
  15. package/dist/change.d.ts +4 -0
  16. package/dist/change.d.ts.map +1 -1
  17. package/dist/chat/acts.d.ts +34 -0
  18. package/dist/chat/acts.d.ts.map +1 -0
  19. package/dist/chat/acts.js +36 -0
  20. package/dist/chat/messages.d.ts +21 -0
  21. package/dist/chat/messages.d.ts.map +1 -0
  22. package/dist/chat/messages.js +151 -0
  23. package/dist/chat/overlay.d.ts +31 -0
  24. package/dist/chat/overlay.d.ts.map +1 -0
  25. package/dist/chat/overlay.js +97 -0
  26. package/dist/chat/parts.d.ts +57 -0
  27. package/dist/chat/parts.d.ts.map +1 -0
  28. package/dist/chat/parts.js +119 -0
  29. package/dist/chat/process.d.ts +20 -0
  30. package/dist/chat/process.d.ts.map +1 -0
  31. package/dist/chat/process.js +32 -0
  32. package/dist/chat/provider.d.ts +57 -0
  33. package/dist/chat/provider.d.ts.map +1 -0
  34. package/dist/chat/provider.js +637 -0
  35. package/dist/chat/questions.d.ts +31 -0
  36. package/dist/chat/questions.d.ts.map +1 -0
  37. package/dist/chat/questions.js +111 -0
  38. package/dist/chat/read.d.ts +5 -0
  39. package/dist/chat/read.d.ts.map +1 -0
  40. package/dist/chat/read.js +13 -0
  41. package/dist/chat.d.ts +7 -0
  42. package/dist/chat.d.ts.map +1 -0
  43. package/dist/chat.js +2 -0
  44. package/dist/client.d.ts +8 -5
  45. package/dist/client.d.ts.map +1 -1
  46. package/dist/client.js +55 -15
  47. package/dist/collection.d.ts +6 -11
  48. package/dist/collection.d.ts.map +1 -1
  49. package/dist/collection.js +56 -19
  50. package/dist/connection.d.ts +14 -7
  51. package/dist/connection.d.ts.map +1 -1
  52. package/dist/connection.js +239 -102
  53. package/dist/conversation.d.ts +11 -3
  54. package/dist/conversation.d.ts.map +1 -1
  55. package/dist/conversation.js +47 -7
  56. package/dist/expectation.d.ts +21 -0
  57. package/dist/expectation.d.ts.map +1 -0
  58. package/dist/expectation.js +70 -0
  59. package/dist/failure.d.ts +13 -0
  60. package/dist/failure.d.ts.map +1 -0
  61. package/dist/failure.js +19 -0
  62. package/dist/host.d.ts +1 -0
  63. package/dist/host.d.ts.map +1 -1
  64. package/dist/host.js +5 -8
  65. package/dist/identity.d.ts +2 -0
  66. package/dist/identity.d.ts.map +1 -1
  67. package/dist/identity.js +10 -1
  68. package/dist/index.d.ts +7 -4
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +2 -0
  71. package/dist/memory.d.ts +2 -1
  72. package/dist/memory.d.ts.map +1 -1
  73. package/dist/memory.js +31 -11
  74. package/dist/model.d.ts +10 -2
  75. package/dist/model.d.ts.map +1 -1
  76. package/dist/model.js +2 -0
  77. package/dist/open.d.ts +2 -0
  78. package/dist/open.d.ts.map +1 -0
  79. package/dist/open.js +1 -0
  80. package/dist/outcome.d.ts +22 -3
  81. package/dist/outcome.d.ts.map +1 -1
  82. package/dist/outcome.js +35 -1
  83. package/dist/overlay.d.ts +1 -1
  84. package/dist/overlay.d.ts.map +1 -1
  85. package/dist/overlay.js +19 -15
  86. package/dist/query.d.ts +2 -0
  87. package/dist/query.d.ts.map +1 -1
  88. package/dist/query.js +5 -31
  89. package/dist/reach.d.ts.map +1 -1
  90. package/dist/reach.js +21 -19
  91. package/dist/react.d.ts +25 -16
  92. package/dist/react.d.ts.map +1 -1
  93. package/dist/react.js +8 -6
  94. package/dist/refresh.d.ts +10 -0
  95. package/dist/refresh.d.ts.map +1 -1
  96. package/dist/refresh.js +33 -24
  97. package/dist/replica.d.ts +5 -5
  98. package/dist/replica.d.ts.map +1 -1
  99. package/dist/replica.js +44 -29
  100. package/dist/room-draft.d.ts +8 -8
  101. package/dist/room-draft.d.ts.map +1 -1
  102. package/dist/room-draft.js +13 -22
  103. package/dist/rows.d.ts +2 -0
  104. package/dist/rows.d.ts.map +1 -1
  105. package/dist/rows.js +7 -1
  106. package/dist/save.d.ts +3 -1
  107. package/dist/save.d.ts.map +1 -1
  108. package/dist/save.js +38 -21
  109. package/dist/search.d.ts +3 -2
  110. package/dist/search.d.ts.map +1 -1
  111. package/dist/status.d.ts +2 -2
  112. package/dist/status.d.ts.map +1 -1
  113. package/dist/status.js +0 -8
  114. package/dist/store.d.ts +25 -1
  115. package/dist/store.d.ts.map +1 -1
  116. package/dist/store.js +206 -90
  117. package/dist/wire.d.ts +5 -3
  118. package/dist/wire.d.ts.map +1 -1
  119. package/dist/wire.js +13 -2
  120. package/package.json +7 -7
@@ -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 document = replica.visible.collection.documents[path];
9
- if (document === undefined && !replica.visible.binaryTargets.includes(path)) {
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: rowsAt(locator, before, path),
49
- after: rowsAt(locator, after, path),
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;
@@ -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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pB,QAAQ,CAAC,eAAe,EAAE,MAAM,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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acts.d.ts","sourceRoot":"","sources":["../../src/chat/acts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAA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C,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,21 @@
1
+ import type { ThreadMessageLike } from '@assistant-ui/react';
2
+ import type { TurnContext } from '../adapter.js';
3
+ import type { ConversationView } from '../conversation.js';
4
+ import { type Part } from './parts.js';
5
+ type Entry = ConversationView['messages'][number];
6
+ export type Said = {
7
+ readonly turn: string;
8
+ readonly user: boolean;
9
+ readonly text: string;
10
+ readonly parts: readonly Part[];
11
+ readonly context: TurnContext | null;
12
+ readonly failure: string | null;
13
+ readonly undelivered: boolean;
14
+ readonly files: readonly string[];
15
+ };
16
+ export declare function saidOf(entry: Entry): Said;
17
+ export declare function askedBefore(view: ConversationView | null, id: string | null): string | null;
18
+ export declare function chatMessages(view: ConversationView | null): ThreadMessageLike[];
19
+ export declare function contextOf(view: ConversationView | null): TurnContext | null;
20
+ export {};
21
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/chat/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAA0D,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAO/F,KAAK,KAAK,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAYzC;AAkED,wBAAgB,WAAW,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAO3F;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,iBAAiB,EAAE,CAsD/E;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAS3E"}
@@ -0,0 +1,151 @@
1
+ import { contextIn, jobOf, partsOf, stillRunning } from './parts.js';
2
+ import { list, record, text } from './read.js';
3
+ export function saidOf(entry) {
4
+ const message = record(entry.message);
5
+ return {
6
+ turn: text(message, 'turn_id') ?? entry.turn,
7
+ user: text(message, 'role') === 'user',
8
+ text: text(message, 'text') ?? '',
9
+ parts: partsOf(list(message, 'parts')),
10
+ context: contextIn(message.context),
11
+ failure: text(message, 'failure'),
12
+ undelivered: message.telegram_undelivered === true,
13
+ files: list(message, 'files').flatMap((one) => text(record(one), 'name') ?? []),
14
+ };
15
+ }
16
+ function markerArgs(part) {
17
+ if (part.marker !== 'job')
18
+ return { marker: part.marker, text: part.text };
19
+ const job = jobOf(part.text);
20
+ return {
21
+ marker: part.marker,
22
+ text: part.text,
23
+ job: job.kind,
24
+ label: job.label,
25
+ state: job.state,
26
+ next: job.next ?? '',
27
+ };
28
+ }
29
+ function contentOf(id, parts, live) {
30
+ return parts.map((part, at) => {
31
+ const done = !live || at < parts.length - 1;
32
+ const call = (toolName, args) => ({
33
+ type: 'tool-call',
34
+ toolCallId: `${id}:${at}`,
35
+ toolName,
36
+ args,
37
+ result: done ? null : undefined,
38
+ });
39
+ switch (part.type) {
40
+ case 'text':
41
+ return { type: 'text', text: part.text };
42
+ case 'reasoning':
43
+ return { type: 'reasoning', text: part.text };
44
+ case 'commands':
45
+ return call('commands', { count: part.count });
46
+ case 'subagent':
47
+ return {
48
+ ...call('subagent', { description: part.description }),
49
+ result: part.done ? part.result : undefined,
50
+ };
51
+ case 'message':
52
+ return call('message', { command: part.command, target: part.target ?? '' });
53
+ case 'marker':
54
+ return call('marker', markerArgs(part));
55
+ case 'plan':
56
+ return {
57
+ ...call('plan', {}),
58
+ args: { steps: part.steps.map((step) => ({ ...step })) },
59
+ };
60
+ case 'image':
61
+ return { type: 'file', filename: part.name, mimeType: part.mediaType, data: '' };
62
+ }
63
+ });
64
+ }
65
+ function leftRunning(view) {
66
+ if (view.process?.running === false)
67
+ return new Map();
68
+ const turns = view.messages.flatMap((entry) => {
69
+ const one = saidOf(entry);
70
+ return one.user ? [] : [{ turn: one.turn, parts: one.parts, ended: true }];
71
+ });
72
+ return stillRunning(view.turn === null
73
+ ? turns
74
+ : [...turns, { turn: view.turn.turn, parts: partsOf(view.turn.parts), ended: false }]);
75
+ }
76
+ export function askedBefore(view, id) {
77
+ const said = (view?.messages ?? []).map((entry) => ({ ...saidOf(entry), id: entry.identity }));
78
+ const asked = said
79
+ .slice(0, said.findIndex((one) => one.id === id) + 1)
80
+ .reverse()
81
+ .find((one) => one.user);
82
+ return asked === undefined || asked.text === '' ? null : asked.text;
83
+ }
84
+ export function chatMessages(view) {
85
+ if (view === null)
86
+ return [];
87
+ const lasting = leftRunning(view);
88
+ const said = view.messages.map((entry, at) => {
89
+ const one = saidOf(entry);
90
+ const custom = { undelivered: one.undelivered };
91
+ if (one.user) {
92
+ return {
93
+ id: entry.identity,
94
+ role: 'user',
95
+ content: [{ type: 'text', text: one.text }],
96
+ attachments: one.files.map((name, at) => ({
97
+ id: `${entry.identity}:${at}`,
98
+ type: 'file',
99
+ name,
100
+ status: { type: 'complete' },
101
+ content: [],
102
+ })),
103
+ metadata: { custom },
104
+ };
105
+ }
106
+ const failed = one.failure === null
107
+ ? undefined
108
+ : { type: 'incomplete', reason: 'error', error: one.failure };
109
+ return {
110
+ id: entry.identity,
111
+ role: 'assistant',
112
+ content: contentOf(entry.identity, one.parts, false),
113
+ status: failed,
114
+ metadata: {
115
+ custom: {
116
+ ...custom,
117
+ lasting: lasting.get(one.turn) ?? [],
118
+ again: failed !== undefined &&
119
+ view.turn === null &&
120
+ at === view.messages.length - 1 &&
121
+ askedBefore(view, view.messages[at - 1]?.identity ?? null) !== null,
122
+ },
123
+ },
124
+ };
125
+ });
126
+ if (view.turn === null)
127
+ return said;
128
+ const running = `running:${view.turn.turn}`;
129
+ return [
130
+ ...said,
131
+ {
132
+ id: running,
133
+ role: 'assistant',
134
+ content: contentOf(running, partsOf(view.turn.parts), true),
135
+ status: { type: 'running' },
136
+ },
137
+ ];
138
+ }
139
+ export function contextOf(view) {
140
+ if (view === null)
141
+ return null;
142
+ const running = view.turn === null ? null : contextIn(view.turn.context);
143
+ if (running !== null)
144
+ return running;
145
+ for (const entry of [...view.messages].reverse()) {
146
+ const held = contextIn(record(entry.message).context);
147
+ if (held !== null)
148
+ return held;
149
+ }
150
+ return null;
151
+ }
@@ -0,0 +1,31 @@
1
+ import type { ChatDraft, ConversationEntry, ConversationView } from '../conversation.js';
2
+ import { type ExpectedOf, type Expecting } from '../expectation.js';
3
+ type Entries = readonly ConversationEntry[];
4
+ export type Expectation = {
5
+ readonly key: string;
6
+ readonly view: 'conversation';
7
+ draw(held: ConversationView): ConversationView;
8
+ shown(held: ConversationView): boolean;
9
+ } | {
10
+ readonly key: string;
11
+ readonly view: 'conversations';
12
+ draw(held: Entries): Entries;
13
+ shown(held: Entries): boolean;
14
+ };
15
+ export type Expected = ExpectedOf<Expectation>;
16
+ export type Overlay = Omit<Expecting<Expectation>, 'expect' | 'heard' | 'drawn'> & {
17
+ expect(act: number, expected: Expected): void;
18
+ heard(held: ConversationView): void;
19
+ heardList(held: Entries): void;
20
+ conversation(held: ConversationView): ConversationView;
21
+ conversations(held: Entries): Entries;
22
+ };
23
+ export declare function overlay(): Overlay;
24
+ export declare function sentMessage(key: string, into: readonly string[], said: ChatDraft, turn: string | null): Expectation;
25
+ export declare function optionChosen(conversation: string, option: string, value: string): Expectation;
26
+ export declare function questionAnswered(conversation: string, interaction: string): Expectation;
27
+ export declare function conversationListed(entry: ConversationEntry): Expectation;
28
+ export declare function conversationChanged(conversation: string, changes: Partial<Pick<ConversationEntry, 'name' | 'finished'>>, shown: (entry: ConversationEntry) => boolean): Expectation;
29
+ export declare function conversationGone(conversation: string): Expectation;
30
+ export {};
31
+ //# sourceMappingURL=overlay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"over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B,OAAO,IAAI,OAAO,CAiBjC;AAED,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,MAAM,GAAG,IAAI,GAClB,WAAW,CA2Bb;AAED,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAkB7F;AAED,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,WAAW,CAWvF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,WAAW,CAQxE;AAED,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,EAC9D,KAAK,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,GAC3C,WAAW,CAQb;AAED,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,WAAW,CAQlE"}
@@ -0,0 +1,97 @@
1
+ import { expecting } from '../expectation.js';
2
+ import { record, text } from './read.js';
3
+ export function overlay() {
4
+ const held = expecting();
5
+ return {
6
+ subscribe: held.subscribe,
7
+ version: held.version,
8
+ begin: held.begin,
9
+ drop: held.drop,
10
+ expect: (act, expected) => held.expect(act, expected),
11
+ heard: (view) => held.heard((one) => one.view === 'conversation' && one.shown(view)),
12
+ heardList: (entries) => held.heard((one) => one.view === 'conversations' && one.shown(entries)),
13
+ conversation: (view) => held.drawn().reduce((now, one) => (one.view === 'conversation' ? one.draw(now) : now), view),
14
+ conversations: (entries) => held
15
+ .drawn()
16
+ .reduce((now, one) => (one.view === 'conversations' ? one.draw(now) : now), entries),
17
+ };
18
+ }
19
+ export function sentMessage(key, into, said, turn) {
20
+ const sealed = (held) => turn !== null && held.messages.some((one) => one.turn === turn);
21
+ return {
22
+ key,
23
+ view: 'conversation',
24
+ draw: (held) => !into.includes(held.conversation) || sealed(held)
25
+ ? held
26
+ : {
27
+ ...held,
28
+ messages: [
29
+ ...held.messages,
30
+ {
31
+ identity: key,
32
+ turn: turn ?? key,
33
+ text: said.text,
34
+ message: {
35
+ role: 'user',
36
+ text: said.text,
37
+ files: said.files.map((file) => ({ name: file.name })),
38
+ },
39
+ },
40
+ ],
41
+ },
42
+ shown: sealed,
43
+ };
44
+ }
45
+ export function optionChosen(conversation, option, value) {
46
+ const ours = (entry) => text(record(entry), 'id') === option;
47
+ return {
48
+ key: `option ${conversation} ${option}`,
49
+ view: 'conversation',
50
+ draw: (held) => held.conversation !== conversation
51
+ ? held
52
+ : {
53
+ ...held,
54
+ options: held.options.map((entry) => ours(entry) && entry.type === 'select' ? { ...entry, currentValue: value } : entry),
55
+ },
56
+ shown: (held) => held.conversation === conversation &&
57
+ held.options.some((entry) => ours(entry) && text(record(entry), 'currentValue') === value),
58
+ };
59
+ }
60
+ export function questionAnswered(conversation, interaction) {
61
+ const ours = (entry) => text(record(entry), 'interaction_id') === interaction;
62
+ return {
63
+ key: `answer ${conversation} ${interaction}`,
64
+ view: 'conversation',
65
+ draw: (held) => held.conversation !== conversation
66
+ ? held
67
+ : { ...held, questions: held.questions.filter((entry) => !ours(entry)) },
68
+ shown: (held) => held.conversation === conversation && !held.questions.some(ours),
69
+ };
70
+ }
71
+ export function conversationListed(entry) {
72
+ const ours = (one) => one.conversation === entry.conversation;
73
+ return {
74
+ key: `conversation ${entry.conversation}`,
75
+ view: 'conversations',
76
+ draw: (held) => (held.some(ours) ? held : [...held, entry]),
77
+ shown: (held) => held.some(ours),
78
+ };
79
+ }
80
+ export function conversationChanged(conversation, changes, shown) {
81
+ const ours = (one) => one.conversation === conversation;
82
+ return {
83
+ key: `conversation ${conversation} ${Object.keys(changes).sort().join(' ')}`,
84
+ view: 'conversations',
85
+ draw: (held) => held.map((one) => (ours(one) ? { ...one, ...changes } : one)),
86
+ shown: (held) => held.some((one) => ours(one) && shown(one)),
87
+ };
88
+ }
89
+ export function conversationGone(conversation) {
90
+ const ours = (one) => one.conversation === conversation;
91
+ return {
92
+ key: `conversation ${conversation}`,
93
+ view: 'conversations',
94
+ draw: (held) => held.filter((one) => !ours(one)),
95
+ shown: (held) => !held.some(ours),
96
+ };
97
+ }
@@ -0,0 +1,57 @@
1
+ import type { TurnContext } from '../adapter.js';
2
+ export type PlanStep = {
3
+ readonly content: string;
4
+ readonly status: string;
5
+ };
6
+ export type Marker = 'mode' | 'compaction' | 'retry' | 'model' | 'job';
7
+ export type Part = {
8
+ readonly type: 'text';
9
+ readonly text: string;
10
+ } | {
11
+ readonly type: 'reasoning';
12
+ readonly text: string;
13
+ } | {
14
+ readonly type: 'commands';
15
+ readonly count: number;
16
+ } | {
17
+ readonly type: 'subagent';
18
+ readonly description: string;
19
+ readonly done: boolean;
20
+ readonly result: string | null;
21
+ } | {
22
+ readonly type: 'message';
23
+ readonly command: string;
24
+ readonly target: string | null;
25
+ } | {
26
+ readonly type: 'image';
27
+ readonly name: string;
28
+ readonly mediaType: string;
29
+ } | {
30
+ readonly type: 'marker';
31
+ readonly marker: Marker;
32
+ readonly text: string;
33
+ } | {
34
+ readonly type: 'plan';
35
+ readonly steps: readonly PlanStep[];
36
+ };
37
+ export declare function partsOf(raw: readonly unknown[]): readonly Part[];
38
+ export declare function contextIn(raw: unknown): TurnContext | null;
39
+ export type Turn = {
40
+ readonly turn: string;
41
+ readonly parts: readonly Part[];
42
+ readonly ended: boolean;
43
+ };
44
+ export type ChatWork = {
45
+ readonly kind: 'job' | 'schedule' | 'subagent';
46
+ readonly title: string;
47
+ readonly next: string | null;
48
+ };
49
+ export type Job = {
50
+ readonly label: string;
51
+ readonly kind: 'started' | 'scheduled' | 'ended';
52
+ readonly state: string;
53
+ readonly next: string | null;
54
+ };
55
+ export declare function jobOf(said: string): Job;
56
+ export declare function stillRunning(turns: readonly Tur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E,SAAS,QAAQ,EAAE,CAAC,CA0C7F"}
@@ -0,0 +1,119 @@
1
+ import { list, record, text } from './read.js';
2
+ const MARKERS = ['mode', 'compaction', 'retry', 'model', 'job'];
3
+ function partOf(raw) {
4
+ const part = record(raw);
5
+ switch (text(part, 'type')) {
6
+ case 'text':
7
+ case 'reasoning': {
8
+ const said = text(part, 'text');
9
+ return said === null ? null : { type: part.type, text: said };
10
+ }
11
+ case 'commands':
12
+ return typeof part.count === 'number' ? { type: 'commands', count: part.count } : null;
13
+ case 'subagent':
14
+ return {
15
+ type: 'subagent',
16
+ description: text(part, 'description') ?? '',
17
+ done: part.status === 'done',
18
+ result: text(part, 'result'),
19
+ };
20
+ case 'message': {
21
+ const command = text(part, 'command');
22
+ return command === null ? null : { type: 'message', command, target: text(part, 'target') };
23
+ }
24
+ case 'image': {
25
+ const name = text(part, 'name');
26
+ return name === null
27
+ ? null
28
+ : { type: 'image', name, mediaType: text(part, 'media_type') ?? '' };
29
+ }
30
+ case 'marker': {
31
+ const marker = text(part, 'marker');
32
+ return marker === null || !MARKERS.includes(marker)
33
+ ? null
34
+ : { type: 'marker', marker: marker, text: text(part, 'text') ?? '' };
35
+ }
36
+ case 'plan':
37
+ return {
38
+ type: 'plan',
39
+ steps: list(part, 'entries').flatMap((entry) => {
40
+ const step = record(entry);
41
+ const content = text(step, 'content');
42
+ return content === null ? [] : [{ content, status: text(step, 'status') ?? '' }];
43
+ }),
44
+ };
45
+ default:
46
+ return null;
47
+ }
48
+ }
49
+ export function partsOf(raw) {
50
+ return raw.flatMap((one) => partOf(one) ?? []);
51
+ }
52
+ export function contextIn(raw) {
53
+ const held = record(raw);
54
+ return typeof held.used === 'number' && typeof held.window === 'number' && held.window > 0
55
+ ? { used: held.used, window: held.window }
56
+ : null;
57
+ }
58
+ const NEXT_RUN = 'next run ';
59
+ export function jobOf(said) {
60
+ const at = said.lastIndexOf(': ');
61
+ const label = at === -1 ? said : said.slice(0, at);
62
+ const state = at === -1 ? '' : said.slice(at + 2);
63
+ if (state === 'running')
64
+ return { label, kind: 'started', state, next: null };
65
+ if (state === 'scheduled')
66
+ return { label, kind: 'scheduled', state, next: null };
67
+ return state.startsWith(NEXT_RUN)
68
+ ? { label, kind: 'scheduled', state, next: state.slice(NEXT_RUN.length) }
69
+ : { label, kind: 'ended', state, next: null };
70
+ }
71
+ export function stillRunning(turns) {
72
+ const open = [];
73
+ const close = (key) => {
74
+ const at = open.map((one) => one.key).lastIndexOf(key);
75
+ if (at !== -1)
76
+ open.splice(at, 1);
77
+ };
78
+ for (const { turn, parts, ended } of turns) {
79
+ for (const part of parts) {
80
+ if (part.type === 'subagent') {
81
+ const key = `subagent\u0000${part.description}`;
82
+ if (part.done)
83
+ close(key);
84
+ else if (ended) {
85
+ open.push({ turn, key, work: { kind: 'subagent', title: part.description, next: null } });
86
+ }
87
+ continue;
88
+ }
89
+ if (part.type !== 'marker' || part.marker !== 'job')
90
+ continue;
91
+ const job = jobOf(part.text);
92
+ const started = `job\u0000${job.label}`;
93
+ const schedule = `schedule\u0000${job.label}`;
94
+ if (job.kind === 'scheduled') {
95
+ close(schedule);
96
+ if (ended) {
97
+ open.push({
98
+ turn,
99
+ key: schedule,
100
+ work: { kind: 'schedule', title: job.label, next: job.next },
101
+ });
102
+ }
103
+ }
104
+ else if (job.kind === 'started') {
105
+ if (ended) {
106
+ open.push({ turn, key: started, work: { kind: 'job', title: job.label, next: null } });
107
+ }
108
+ }
109
+ else {
110
+ close(started);
111
+ close(schedule);
112
+ }
113
+ }
114
+ }
115
+ const under = new Map();
116
+ for (const one of open)
117
+ under.set(one.turn, [...(under.get(one.turn) ?? []), one.work]);
118
+ return under;
119
+ }
@@ -0,0 +1,20 @@
1
+ import type { ConversationView } from '../conversation.js';
2
+ export type ChatOptionValue = {
3
+ readonly value: string;
4
+ readonly name: string;
5
+ };
6
+ export type ChatOption = {
7
+ readonly id: string;
8
+ readonly name: string;
9
+ readonly value: string;
10
+ readonly values: readonly ChatOptionValue[];
11
+ };
12
+ export type ChatCommand = {
13
+ readonly name: string;
14
+ readonly description: string;
15
+ };
16
+ export declare function optionsOf(view: ConversationView | null): readonly ChatOption[];
17
+ export declare function commandsOf(view: ConversationView | null): readonly ChatCommand[];
18
+ export declare const COMMAND = "/";
19
+ export declare function commandIn(said: string, commands: readonly ChatCommand[]): boolean;
20
+ //# sourceMappingURL=process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/chat/process.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG3D,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B,CAAC;AAWF,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,UAAU,EAAE,CAU9E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,WAAW,EAAE,CAMhF;AAED,eAAO,MAAM,OAAO,MAAM,CAAC;AAE3B,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,OAAO,CAGjF"}