@otium-team/negotium 0.23.11 → 0.23.13
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/agent-helpers.js +510 -1323
- package/dist/agent-helpers.js.map +10 -10
- package/dist/background-bash.js +12 -12
- package/dist/background-bash.js.map +3 -3
- package/dist/browser-runtime.js +42 -44
- package/dist/browser-runtime.js.map +3 -3
- package/dist/canonical-mcp-bridge.js +8 -9
- package/dist/canonical-mcp-bridge.js.map +1 -1
- package/dist/chunk-22kg3fsw.js +79 -0
- package/dist/{chunk-ad7kxsaq.js.map → chunk-22kg3fsw.js.map} +1 -1
- package/dist/{chunk-mxxwx5mg.js → chunk-d4j77adx.js} +96 -135
- package/dist/{chunk-mxxwx5mg.js.map → chunk-d4j77adx.js.map} +6 -6
- package/dist/{chunk-0fenxbe6.js → chunk-mk9x18jn.js} +4 -5
- package/dist/{chunk-0fenxbe6.js.map → chunk-mk9x18jn.js.map} +2 -2
- package/dist/{chunk-da9ad838.js → chunk-qd0vtfm2.js} +115 -119
- package/dist/{chunk-da9ad838.js.map → chunk-qd0vtfm2.js.map} +7 -7
- package/dist/{chunk-jtv8yzy1.js → chunk-wf7ny8eq.js} +12 -12
- package/dist/{chunk-jtv8yzy1.js.map → chunk-wf7ny8eq.js.map} +2 -2
- package/dist/{chunk-f7p0h1gs.js → chunk-ww8a4ej4.js} +5 -5
- package/dist/{chunk-f7p0h1gs.js.map → chunk-ww8a4ej4.js.map} +2 -2
- package/dist/hosted-agent.js +198 -135
- package/dist/hosted-agent.js.map +4 -4
- package/dist/main.js +3906 -4213
- package/dist/main.js.map +20 -18
- package/dist/mcp-catalog.js +4 -4
- package/dist/mcp-catalog.js.map +1 -1
- package/dist/mcp-factories.js +753 -1558
- package/dist/mcp-factories.js.map +10 -10
- package/dist/mcp-servers.js +5 -5
- package/dist/mcp-servers.js.map +1 -1
- package/dist/media.js +3 -3
- package/dist/media.js.map +2 -2
- package/dist/outbox.js +15 -15
- package/dist/outbox.js.map +2 -2
- package/dist/platform-runtime.js +7 -7
- package/dist/platform-runtime.js.map +1 -1
- package/dist/prompts.js +6 -6
- package/dist/prompts.js.map +3 -3
- package/dist/query-runtime.js +16 -18
- package/dist/query-runtime.js.map +4 -4
- package/dist/registry.js +19 -20
- package/dist/registry.js.map +2 -2
- package/dist/rollout.js +41 -41
- package/dist/rollout.js.map +2 -2
- package/dist/runtime/src/agents/claude-provider.ts +80 -5
- package/dist/runtime/src/application/submit-runtime-gateway-turn.ts +84 -20
- package/dist/runtime/src/application/topic-service.ts +6 -2
- package/dist/runtime/src/application/turn-follow-ups.ts +291 -0
- package/dist/runtime/src/bus.ts +6 -0
- package/dist/runtime/src/node-host.ts +11 -0
- package/dist/runtime/src/query/active-rooms.ts +7 -1
- package/dist/runtime/src/runtime/turn-runner.ts +34 -7
- package/dist/runtime/src/runtime-gateway.ts +198 -1
- package/dist/runtime/src/storage/runtime-follow-ups.ts +212 -0
- package/dist/runtime/src/storage/runtime-turn-requests.ts +43 -2
- package/dist/runtime/src/types/api.ts +9 -0
- package/dist/runtime/src/types.ts +23 -0
- package/dist/runtime/src/version.ts +1 -1
- package/dist/runtime-gateway.js +73 -12
- package/dist/runtime-gateway.js.map +3 -3
- package/dist/runtime-helpers.js +52 -54
- package/dist/runtime-helpers.js.map +3 -3
- package/dist/sqlite.js +3 -5
- package/dist/sqlite.js.map +2 -2
- package/dist/storage.js +4841 -4812
- package/dist/storage.js.map +3 -3
- package/dist/types/packages/core/src/bus.d.ts +3 -0
- package/dist/types/packages/core/src/query/active-rooms.d.ts +7 -1
- package/dist/types/packages/core/src/runtime-gateway.d.ts +59 -1
- package/dist/types/packages/core/src/storage/runtime-turn-requests.d.ts +25 -0
- package/dist/types/packages/core/src/types/api.d.ts +5 -0
- package/dist/types/packages/core/src/types.d.ts +21 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/dist/vault.js +20 -22
- package/dist/vault.js.map +3 -3
- package/package.json +1 -1
- package/dist/chunk-2mx7fq49.js +0 -6
- package/dist/chunk-2mx7fq49.js.map +0 -9
- package/dist/chunk-ad7kxsaq.js +0 -202
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { db } from "#storage/forum-db";
|
|
2
|
+
import { registerStorageSchemaInitializer } from "#storage/storage-host";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Messages a person sent while the room's AI worked, held instead of queued as
|
|
6
|
+
* a turn (a host opts in per message with `hold`). They are not in the
|
|
7
|
+
* transcript yet: until one goes out it can be edited, reordered or deleted,
|
|
8
|
+
* and they go out one per turn, oldest first. `params_json` is the rest of the
|
|
9
|
+
* gateway submission, replayed as is when the message goes out.
|
|
10
|
+
*/
|
|
11
|
+
export interface RuntimeFollowUp {
|
|
12
|
+
followUpId: string;
|
|
13
|
+
topicId: string;
|
|
14
|
+
actorUserId: string;
|
|
15
|
+
text: string;
|
|
16
|
+
attachments: string[];
|
|
17
|
+
params: Record<string, unknown>;
|
|
18
|
+
createdAt: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface RuntimeFollowUpRow {
|
|
22
|
+
follow_up_id: string;
|
|
23
|
+
topic_id: string;
|
|
24
|
+
actor_user_id: string;
|
|
25
|
+
text: string;
|
|
26
|
+
attachments_json: string;
|
|
27
|
+
params_json: string;
|
|
28
|
+
position: number;
|
|
29
|
+
created_at: number | bigint;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
registerStorageSchemaInitializer((database) => {
|
|
33
|
+
database.exec(`
|
|
34
|
+
CREATE TABLE IF NOT EXISTS runtime_follow_ups (
|
|
35
|
+
follow_up_id TEXT PRIMARY KEY,
|
|
36
|
+
topic_id TEXT NOT NULL,
|
|
37
|
+
actor_user_id TEXT NOT NULL,
|
|
38
|
+
text TEXT NOT NULL,
|
|
39
|
+
attachments_json TEXT NOT NULL DEFAULT '[]',
|
|
40
|
+
params_json TEXT NOT NULL,
|
|
41
|
+
position INTEGER NOT NULL,
|
|
42
|
+
created_at INTEGER NOT NULL
|
|
43
|
+
)
|
|
44
|
+
`);
|
|
45
|
+
database.exec(
|
|
46
|
+
"CREATE INDEX IF NOT EXISTS idx_runtime_follow_ups_topic ON runtime_follow_ups(topic_id, position)",
|
|
47
|
+
);
|
|
48
|
+
// A room whose follow-ups wait for a person: they stopped the AI, so nothing
|
|
49
|
+
// restarts the work by itself until they send again.
|
|
50
|
+
database.exec(`
|
|
51
|
+
CREATE TABLE IF NOT EXISTS runtime_follow_up_pauses (
|
|
52
|
+
topic_id TEXT PRIMARY KEY,
|
|
53
|
+
paused_at INTEGER NOT NULL
|
|
54
|
+
)
|
|
55
|
+
`);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
function rowToFollowUp(row: RuntimeFollowUpRow): RuntimeFollowUp {
|
|
59
|
+
const attachments = JSON.parse(row.attachments_json) as unknown;
|
|
60
|
+
const params = JSON.parse(row.params_json) as unknown;
|
|
61
|
+
return {
|
|
62
|
+
followUpId: row.follow_up_id,
|
|
63
|
+
topicId: row.topic_id,
|
|
64
|
+
actorUserId: row.actor_user_id,
|
|
65
|
+
text: row.text,
|
|
66
|
+
attachments: Array.isArray(attachments)
|
|
67
|
+
? attachments.filter((id): id is string => typeof id === "string")
|
|
68
|
+
: [],
|
|
69
|
+
params: params && typeof params === "object" ? (params as Record<string, unknown>) : {},
|
|
70
|
+
createdAt: Number(row.created_at),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function listRuntimeFollowUps(topicId: string): RuntimeFollowUp[] {
|
|
75
|
+
return db
|
|
76
|
+
.query<RuntimeFollowUpRow, [string]>(
|
|
77
|
+
"SELECT * FROM runtime_follow_ups WHERE topic_id = ? ORDER BY position ASC, created_at ASC",
|
|
78
|
+
)
|
|
79
|
+
.all(topicId)
|
|
80
|
+
.map(rowToFollowUp);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getRuntimeFollowUp(followUpId: string): RuntimeFollowUp | null {
|
|
84
|
+
const row = db
|
|
85
|
+
.query<RuntimeFollowUpRow, [string]>("SELECT * FROM runtime_follow_ups WHERE follow_up_id = ?")
|
|
86
|
+
.get(followUpId);
|
|
87
|
+
return row ? rowToFollowUp(row) : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Hold one more, at the end. A replay of the same id keeps the first. */
|
|
91
|
+
export function holdRuntimeFollowUp(input: Omit<RuntimeFollowUp, "createdAt">): RuntimeFollowUp {
|
|
92
|
+
const now = Date.now();
|
|
93
|
+
db.transaction(() => {
|
|
94
|
+
const last = db
|
|
95
|
+
.query<{ position: number | null }, [string]>(
|
|
96
|
+
"SELECT MAX(position) AS position FROM runtime_follow_ups WHERE topic_id = ?",
|
|
97
|
+
)
|
|
98
|
+
.get(input.topicId);
|
|
99
|
+
db.query(
|
|
100
|
+
`INSERT OR IGNORE INTO runtime_follow_ups
|
|
101
|
+
(follow_up_id, topic_id, actor_user_id, text, attachments_json, params_json, position, created_at)
|
|
102
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
103
|
+
).run(
|
|
104
|
+
input.followUpId,
|
|
105
|
+
input.topicId,
|
|
106
|
+
input.actorUserId,
|
|
107
|
+
input.text,
|
|
108
|
+
JSON.stringify(input.attachments),
|
|
109
|
+
JSON.stringify(input.params),
|
|
110
|
+
Number(last?.position ?? -1) + 1,
|
|
111
|
+
now,
|
|
112
|
+
);
|
|
113
|
+
})();
|
|
114
|
+
const held = getRuntimeFollowUp(input.followUpId);
|
|
115
|
+
if (!held) throw new Error("follow-up was not stored");
|
|
116
|
+
return held;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Change the text in place: an edit keeps the message's place in line. */
|
|
120
|
+
export function editRuntimeFollowUpText(followUpId: string, text: string): boolean {
|
|
121
|
+
const result = db
|
|
122
|
+
.query("UPDATE runtime_follow_ups SET text = ? WHERE follow_up_id = ?")
|
|
123
|
+
.run(text, followUpId);
|
|
124
|
+
return Number(result.changes ?? 0) > 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Take one out of line, to send it or because it was deleted. */
|
|
128
|
+
export function takeRuntimeFollowUp(followUpId: string): RuntimeFollowUp | null {
|
|
129
|
+
return db.transaction(() => {
|
|
130
|
+
const followUp = getRuntimeFollowUp(followUpId);
|
|
131
|
+
if (!followUp) return null;
|
|
132
|
+
db.query("DELETE FROM runtime_follow_ups WHERE follow_up_id = ?").run(followUpId);
|
|
133
|
+
return followUp;
|
|
134
|
+
})();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Put a message that failed to go out back where it was. */
|
|
138
|
+
export function restoreRuntimeFollowUp(followUp: RuntimeFollowUp, index: number): void {
|
|
139
|
+
db.transaction(() => {
|
|
140
|
+
const ids = listRuntimeFollowUps(followUp.topicId).map((item) => item.followUpId);
|
|
141
|
+
if (ids.includes(followUp.followUpId)) return;
|
|
142
|
+
db.query(
|
|
143
|
+
`INSERT INTO runtime_follow_ups
|
|
144
|
+
(follow_up_id, topic_id, actor_user_id, text, attachments_json, params_json, position, created_at)
|
|
145
|
+
VALUES (?, ?, ?, ?, ?, ?, 0, ?)`,
|
|
146
|
+
).run(
|
|
147
|
+
followUp.followUpId,
|
|
148
|
+
followUp.topicId,
|
|
149
|
+
followUp.actorUserId,
|
|
150
|
+
followUp.text,
|
|
151
|
+
JSON.stringify(followUp.attachments),
|
|
152
|
+
JSON.stringify(followUp.params),
|
|
153
|
+
followUp.createdAt,
|
|
154
|
+
);
|
|
155
|
+
ids.splice(Math.max(0, Math.min(index, ids.length)), 0, followUp.followUpId);
|
|
156
|
+
renumber(ids);
|
|
157
|
+
})();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Move one to `toIndex` in its room's line. */
|
|
161
|
+
export function moveRuntimeFollowUp(followUpId: string, toIndex: number): boolean {
|
|
162
|
+
return db.transaction(() => {
|
|
163
|
+
const followUp = getRuntimeFollowUp(followUpId);
|
|
164
|
+
if (!followUp) return false;
|
|
165
|
+
const ids = listRuntimeFollowUps(followUp.topicId)
|
|
166
|
+
.map((item) => item.followUpId)
|
|
167
|
+
.filter((id) => id !== followUpId);
|
|
168
|
+
ids.splice(Math.max(0, Math.min(toIndex, ids.length)), 0, followUpId);
|
|
169
|
+
renumber(ids);
|
|
170
|
+
return true;
|
|
171
|
+
})();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function renumber(ids: readonly string[]): void {
|
|
175
|
+
const update = db.query("UPDATE runtime_follow_ups SET position = ? WHERE follow_up_id = ?");
|
|
176
|
+
for (const [position, id] of ids.entries()) update.run(position, id);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function deleteRuntimeFollowUpsForTopic(topicId: string): void {
|
|
180
|
+
db.query("DELETE FROM runtime_follow_ups WHERE topic_id = ?").run(topicId);
|
|
181
|
+
db.query("DELETE FROM runtime_follow_up_pauses WHERE topic_id = ?").run(topicId);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Rooms with follow-ups that may go out (not held after a stop). */
|
|
185
|
+
export function runtimeFollowUpTopicsReady(): string[] {
|
|
186
|
+
return db
|
|
187
|
+
.query<{ topic_id: string }, []>(
|
|
188
|
+
`SELECT DISTINCT f.topic_id FROM runtime_follow_ups f
|
|
189
|
+
WHERE NOT EXISTS (SELECT 1 FROM runtime_follow_up_pauses p WHERE p.topic_id = f.topic_id)`,
|
|
190
|
+
)
|
|
191
|
+
.all()
|
|
192
|
+
.map((row) => row.topic_id);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function areRuntimeFollowUpsPaused(topicId: string): boolean {
|
|
196
|
+
return (
|
|
197
|
+
db
|
|
198
|
+
.query<{ one: number }, [string]>(
|
|
199
|
+
"SELECT 1 AS one FROM runtime_follow_up_pauses WHERE topic_id = ?",
|
|
200
|
+
)
|
|
201
|
+
.get(topicId) !== null
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function setRuntimeFollowUpsPaused(topicId: string, paused: boolean): boolean {
|
|
206
|
+
const result = paused
|
|
207
|
+
? db
|
|
208
|
+
.query("INSERT OR IGNORE INTO runtime_follow_up_pauses (topic_id, paused_at) VALUES (?, ?)")
|
|
209
|
+
.run(topicId, Date.now())
|
|
210
|
+
: db.query("DELETE FROM runtime_follow_up_pauses WHERE topic_id = ?").run(topicId);
|
|
211
|
+
return Number(result.changes ?? 0) > 0;
|
|
212
|
+
}
|
|
@@ -57,6 +57,18 @@ export interface RuntimeUserTurnExecution {
|
|
|
57
57
|
providerSessionId?: string;
|
|
58
58
|
/** Request ids whose ordered messages were folded into this replacement. */
|
|
59
59
|
supersededRequestIds?: string[];
|
|
60
|
+
/**
|
|
61
|
+
* The message was also delivered into a running turn mid-way. Such a row is
|
|
62
|
+
* never folded into another: when that turn reads the message, exactly this
|
|
63
|
+
* row is dropped, and a batch holding it would answer it a second time.
|
|
64
|
+
*/
|
|
65
|
+
deliveredMidTurn?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* A held follow-up that went out (`runtime-follow-ups`): it is answered as a
|
|
68
|
+
* turn of its own, one per turn, so it is never folded into another request
|
|
69
|
+
* and never absorbs a later one.
|
|
70
|
+
*/
|
|
71
|
+
ownTurn?: boolean;
|
|
60
72
|
/**
|
|
61
73
|
* Slack-style thread this turn belongs to, when it was asked in one. Carried
|
|
62
74
|
* on the request rather than the message because it decides both where the
|
|
@@ -363,6 +375,12 @@ export function mergeRuntimeUserTurnRequest(input: {
|
|
|
363
375
|
* worker is running instead of steering (aborting and replacing) it.
|
|
364
376
|
*/
|
|
365
377
|
keepRequestIds?: string[];
|
|
378
|
+
/**
|
|
379
|
+
* Fold rows whose message was delivered into the running turn as well. Only
|
|
380
|
+
* an explicit steer does: the running turn is stopped, so whatever it was
|
|
381
|
+
* handed must ride the turn that replaces it.
|
|
382
|
+
*/
|
|
383
|
+
includeDeliveredMidTurn?: boolean;
|
|
366
384
|
}): { requestId: string; supersededRequestIds: string[] } {
|
|
367
385
|
const now = Date.now();
|
|
368
386
|
return db
|
|
@@ -383,7 +401,12 @@ export function mergeRuntimeUserTurnRequest(input: {
|
|
|
383
401
|
const sameThread = rows
|
|
384
402
|
.map(rowToRequest)
|
|
385
403
|
.filter(
|
|
386
|
-
(request) =>
|
|
404
|
+
(request) =>
|
|
405
|
+
request.execution?.threadRootId === thread &&
|
|
406
|
+
!kept.has(request.requestId) &&
|
|
407
|
+
request.execution?.ownTurn !== true &&
|
|
408
|
+
(input.includeDeliveredMidTurn === true ||
|
|
409
|
+
request.execution?.deliveredMidTurn !== true),
|
|
387
410
|
);
|
|
388
411
|
// Nor is a different person the same conversation for this purpose. A
|
|
389
412
|
// merged batch runs with one actor's identity and one room assertion,
|
|
@@ -721,6 +744,22 @@ export function completeRuntimeUserTurnRequest(
|
|
|
721
744
|
return Number(result.changes ?? 0) > 0;
|
|
722
745
|
}
|
|
723
746
|
|
|
747
|
+
/**
|
|
748
|
+
* Drop a queued request the running turn already read: its message was
|
|
749
|
+
* delivered into that turn mid-way (Codex-style steer), so it must not run
|
|
750
|
+
* again as a turn of its own. Only a still-pending row goes; a claimed one is
|
|
751
|
+
* already some worker's turn.
|
|
752
|
+
*/
|
|
753
|
+
export function dropReadMidTurnRequest(topicId: string, requestId: string): boolean {
|
|
754
|
+
const result = db
|
|
755
|
+
.query(
|
|
756
|
+
`DELETE FROM runtime_user_turn_requests
|
|
757
|
+
WHERE topic_id = ? AND request_id = ? AND status = 'pending' AND claimed_by IS NULL`,
|
|
758
|
+
)
|
|
759
|
+
.run(topicId, requestId);
|
|
760
|
+
return Number(result.changes ?? 0) > 0;
|
|
761
|
+
}
|
|
762
|
+
|
|
724
763
|
/** Cancel work captured before a reset/delete epoch began. */
|
|
725
764
|
export function cancelRuntimeUserTurnRequestsBeforeEpoch(topicId: string, epoch: number): string[] {
|
|
726
765
|
const rows = db
|
|
@@ -783,14 +822,16 @@ export function foldQueuedIntoActiveRuntimeUserTurnRequest(
|
|
|
783
822
|
if (requestActor(latest.execution.actorUserId) !== requestActor(active.execution?.actorUserId)) {
|
|
784
823
|
return null;
|
|
785
824
|
}
|
|
825
|
+
const { deliveredMidTurn: _delivered, ...execution } = latest.execution;
|
|
786
826
|
const merged = mergeRuntimeUserTurnRequest({
|
|
787
827
|
topicId,
|
|
788
828
|
userId: latest.userId,
|
|
789
829
|
userMessages: [],
|
|
790
830
|
allowAutoContinue: latest.allowAutoContinue,
|
|
791
831
|
requestId: newRequestId,
|
|
792
|
-
execution
|
|
832
|
+
execution,
|
|
793
833
|
topicEpoch: latest.topicEpoch,
|
|
834
|
+
includeDeliveredMidTurn: true,
|
|
794
835
|
});
|
|
795
836
|
return merged.supersededRequestIds.includes(active.requestId) ? active.requestId : null;
|
|
796
837
|
}
|
|
@@ -457,6 +457,15 @@ export type WsServerMessage =
|
|
|
457
457
|
// Absent on legacy emitters → clients treat as "stopped".
|
|
458
458
|
reason?: "superseded" | "stopped";
|
|
459
459
|
}
|
|
460
|
+
| {
|
|
461
|
+
// The running turn read these messages, which the person sent while it
|
|
462
|
+
// worked and which were delivered into it at its next step. A delivered
|
|
463
|
+
// message the turn did not read runs as the next turn instead.
|
|
464
|
+
type: "messages_read";
|
|
465
|
+
queryId: string;
|
|
466
|
+
topicId: string;
|
|
467
|
+
messageIds: string[];
|
|
468
|
+
}
|
|
460
469
|
| {
|
|
461
470
|
type: "tool_call";
|
|
462
471
|
queryId: string;
|
|
@@ -230,9 +230,32 @@ export interface RemoteSessionGrant {
|
|
|
230
230
|
capability: string;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
/** A message a person sent while a turn runs, for that turn to read at its next step. */
|
|
234
|
+
export interface MidTurnMessage {
|
|
235
|
+
/** Canonical message id. The provider names it back once the turn has read it. */
|
|
236
|
+
id: string;
|
|
237
|
+
/** The rendered prompt, as the turn's own first message is rendered. */
|
|
238
|
+
text: string;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* How a running turn takes messages sent while it works (Codex-style steer: the
|
|
243
|
+
* work goes on, and the agent reads the message after the step it is on).
|
|
244
|
+
* Only a provider that can feed a live turn opens it; for any other the
|
|
245
|
+
* message stays queued for the next turn.
|
|
246
|
+
*/
|
|
247
|
+
export interface MidTurnInput {
|
|
248
|
+
/** The turn can take messages from now on. `deliver` returns false once it no longer can. */
|
|
249
|
+
open(deliver: (message: MidTurnMessage) => boolean): void;
|
|
250
|
+
/** The turn ended. `read` are the delivered ids it read inside the turn; the rest were not read. */
|
|
251
|
+
close(read: readonly string[]): void;
|
|
252
|
+
}
|
|
253
|
+
|
|
233
254
|
export interface AgentQueryOptions {
|
|
234
255
|
agent: AgentKind;
|
|
235
256
|
prompt: string;
|
|
257
|
+
/** Present on a person's turn: messages they send while it runs are read inside it. */
|
|
258
|
+
midTurn?: MidTurnInput;
|
|
236
259
|
attachments?: AgentInputAttachment[];
|
|
237
260
|
sessionId?: string | null;
|
|
238
261
|
cwd: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const NEGOTIUM_VERSION = "0.23.
|
|
1
|
+
export const NEGOTIUM_VERSION = "0.23.13";
|
package/dist/runtime-gateway.js
CHANGED
|
@@ -105,6 +105,18 @@ function validTurnAck(value) {
|
|
|
105
105
|
const body = record(value);
|
|
106
106
|
return Boolean(body?.ok === true && body.v === RUNTIME_GATEWAY_VERSION && body.accepted === true && typeof body.deduplicated === "boolean" && typeof body.requestId === "string" && typeof body.clientMessageId === "string" && typeof body.topicId === "string" && typeof body.messageId === "string" && (body.message === undefined || validAcknowledgedMessage(body.message)) && typeof body.cursor === "number");
|
|
107
107
|
}
|
|
108
|
+
function validFollowUp(value) {
|
|
109
|
+
const item = record(value);
|
|
110
|
+
return Boolean(typeof item?.id === "string" && typeof item.text === "string" && typeof item.actorUserId === "string" && Array.isArray(item.attachments) && typeof item.createdAt === "string");
|
|
111
|
+
}
|
|
112
|
+
function validFollowUpLine(value) {
|
|
113
|
+
const body = record(value);
|
|
114
|
+
return Boolean(typeof body?.topicId === "string" && Array.isArray(body.followUps) && body.followUps.every(validFollowUp) && typeof body.paused === "boolean");
|
|
115
|
+
}
|
|
116
|
+
function validHeldTurn(value) {
|
|
117
|
+
const body = record(value);
|
|
118
|
+
return Boolean(body?.ok === true && body.v === RUNTIME_GATEWAY_VERSION && body.accepted === true && body.held === true && typeof body.clientMessageId === "string" && typeof body.topicId === "string" && validFollowUp(body.followUp));
|
|
119
|
+
}
|
|
108
120
|
function validManagerTopic(value) {
|
|
109
121
|
const topic = record(value);
|
|
110
122
|
return Boolean(typeof topic?.id === "string" && typeof topic.title === "string" && topic.kind === "manager" && Array.isArray(topic.participants));
|
|
@@ -152,15 +164,15 @@ async function* parseRuntimeGatewaySse(body) {
|
|
|
152
164
|
const line = buffer.slice(0, newline);
|
|
153
165
|
buffer = buffer.slice(newline + 1);
|
|
154
166
|
if (line === "") {
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
yield
|
|
167
|
+
const parsed = flush();
|
|
168
|
+
if (parsed)
|
|
169
|
+
yield parsed;
|
|
158
170
|
} else if (line.startsWith("event:")) {
|
|
159
171
|
event = line.slice(6).trim() || "message";
|
|
160
172
|
} else if (line.startsWith("id:")) {
|
|
161
|
-
const
|
|
162
|
-
if (Number.isFinite(
|
|
163
|
-
id =
|
|
173
|
+
const parsed = Number.parseInt(line.slice(3).trim(), 10);
|
|
174
|
+
if (Number.isFinite(parsed))
|
|
175
|
+
id = parsed;
|
|
164
176
|
} else if (line.startsWith("data:")) {
|
|
165
177
|
data.push(line.slice(5).trimStart());
|
|
166
178
|
}
|
|
@@ -247,6 +259,55 @@ class RuntimeGatewayClient {
|
|
|
247
259
|
}
|
|
248
260
|
return body;
|
|
249
261
|
}
|
|
262
|
+
async holdOrSubmitTurn(input) {
|
|
263
|
+
const response = await this.send("/turns", {
|
|
264
|
+
method: "POST",
|
|
265
|
+
headers: { "content-type": "application/json" },
|
|
266
|
+
body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input, hold: true })
|
|
267
|
+
}, this.requestTimeoutMs);
|
|
268
|
+
if (response.status !== 202) {
|
|
269
|
+
throw new RuntimeGatewayError("Runtime Gateway turn was not accepted", "http", response.status);
|
|
270
|
+
}
|
|
271
|
+
const body = await json(response);
|
|
272
|
+
if (validHeldTurn(body) || validTurnAck(body))
|
|
273
|
+
return body;
|
|
274
|
+
throw new RuntimeGatewayError("Runtime Gateway turn acknowledgement is incompatible", "protocol");
|
|
275
|
+
}
|
|
276
|
+
async followUps(topicId, userId) {
|
|
277
|
+
const response = await this.send(`/topics/${encodeURIComponent(topicId)}/follow-ups?userId=${encodeURIComponent(userId)}`, { method: "GET" }, this.requestTimeoutMs);
|
|
278
|
+
return this.followUpLineFrom(response, "list");
|
|
279
|
+
}
|
|
280
|
+
async editFollowUp(topicId, followUpId, actor, text) {
|
|
281
|
+
return this.changeFollowUp(topicId, followUpId, "", "PATCH", { ...actor, text });
|
|
282
|
+
}
|
|
283
|
+
async deleteFollowUp(topicId, followUpId, actor) {
|
|
284
|
+
return this.changeFollowUp(topicId, followUpId, "", "DELETE", { ...actor });
|
|
285
|
+
}
|
|
286
|
+
async moveFollowUp(topicId, followUpId, actor, toIndex) {
|
|
287
|
+
return this.changeFollowUp(topicId, followUpId, "/move", "POST", { ...actor, toIndex });
|
|
288
|
+
}
|
|
289
|
+
async sendFollowUpNow(topicId, followUpId, actor) {
|
|
290
|
+
const line = await this.changeFollowUp(topicId, followUpId, "/send", "POST", { ...actor });
|
|
291
|
+
return line;
|
|
292
|
+
}
|
|
293
|
+
async changeFollowUp(topicId, followUpId, suffix, method, body) {
|
|
294
|
+
const response = await this.send(`/topics/${encodeURIComponent(topicId)}/follow-ups/${encodeURIComponent(followUpId)}${suffix}`, {
|
|
295
|
+
method,
|
|
296
|
+
headers: { "content-type": "application/json" },
|
|
297
|
+
body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...body })
|
|
298
|
+
}, this.requestTimeoutMs);
|
|
299
|
+
return this.followUpLineFrom(response, method === "PATCH" ? "edit" : suffix || "delete");
|
|
300
|
+
}
|
|
301
|
+
async followUpLineFrom(response, what) {
|
|
302
|
+
if (!response.ok) {
|
|
303
|
+
throw new RuntimeGatewayError(`Runtime Gateway follow-up ${what} failed`, "http", response.status);
|
|
304
|
+
}
|
|
305
|
+
const body = await json(response);
|
|
306
|
+
if (!validFollowUpLine(body)) {
|
|
307
|
+
throw new RuntimeGatewayError(`Runtime Gateway follow-up ${what} response is incompatible`, "protocol");
|
|
308
|
+
}
|
|
309
|
+
return body;
|
|
310
|
+
}
|
|
250
311
|
async deriveTopic(topicId, input) {
|
|
251
312
|
const response = await this.send(`/topics/${encodeURIComponent(topicId)}/derive`, {
|
|
252
313
|
method: "POST",
|
|
@@ -442,12 +503,12 @@ class RuntimeGatewayClient {
|
|
|
442
503
|
}
|
|
443
504
|
}
|
|
444
505
|
export {
|
|
445
|
-
|
|
446
|
-
parseHostMcpServers,
|
|
447
|
-
RuntimeGatewayError,
|
|
448
|
-
RuntimeGatewayClient,
|
|
506
|
+
RUNTIME_GATEWAY_CONTROL_PATH,
|
|
449
507
|
RUNTIME_GATEWAY_VERSION,
|
|
450
|
-
|
|
508
|
+
RuntimeGatewayClient,
|
|
509
|
+
RuntimeGatewayError,
|
|
510
|
+
parseHostMcpServers,
|
|
511
|
+
parseRuntimeGatewaySse
|
|
451
512
|
};
|
|
452
513
|
|
|
453
|
-
//# debugId=
|
|
514
|
+
//# debugId=03FF2A0CA9E0E7D364756E2164756E21
|