@jush-agent/sdk 0.2.6332 → 0.2.6346
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/README.md +418 -37
- package/dist/index.d.mts +50595 -11947
- package/dist/index.mjs +1749 -723
- package/package.json +7 -7
- package/release/commands/jush-browser/descriptor.json +13 -13
- package/release/commands/jush-fetch/descriptor.json +13 -13
- package/release/commands/jush-file/descriptor.json +13 -13
- package/release/commands/jush-mobile/descriptor.json +13 -13
- package/release/commands/jush-subscription-cli/descriptor.json +13 -13
package/dist/index.mjs
CHANGED
|
@@ -158,7 +158,15 @@ const queuedMessageSchema = z.object({
|
|
|
158
158
|
* The schedule's run that sent it, which its `user` block keeps;
|
|
159
159
|
* absent for a message the user wrote.
|
|
160
160
|
*/
|
|
161
|
-
schedule: scheduleMarkSchema.optional()
|
|
161
|
+
schedule: scheduleMarkSchema.optional(),
|
|
162
|
+
/** Who sent it, which its `user` block keeps. */
|
|
163
|
+
senderId: z.string().min(1).max(255).optional(),
|
|
164
|
+
/**
|
|
165
|
+
* The assignment it is part of, which its `user` block keeps: its own id
|
|
166
|
+
* for one that opens one, the work's for one that continues it; absent
|
|
167
|
+
* when it names none.
|
|
168
|
+
*/
|
|
169
|
+
assignmentId: z.string().min(1).optional()
|
|
162
170
|
});
|
|
163
171
|
/** What an `abort` stopped, and whether another `abort` would stop more. */
|
|
164
172
|
const abortResultSchema = z.object({
|
|
@@ -530,7 +538,9 @@ const pendingSteerSchema = z.object({
|
|
|
530
538
|
* The comments it carries, which its `steer` block keeps; omitted when
|
|
531
539
|
* there are none.
|
|
532
540
|
*/
|
|
533
|
-
comments: z.array(messageCommentSchema).optional()
|
|
541
|
+
comments: z.array(messageCommentSchema).optional(),
|
|
542
|
+
/** Who sent it, which its `steer` block keeps. */
|
|
543
|
+
senderId: z.string().min(1).max(255).optional()
|
|
534
544
|
});
|
|
535
545
|
/** One agent of the conversation. */
|
|
536
546
|
const agentEntrySchema = z.object({
|
|
@@ -723,7 +733,23 @@ const agentMessageSchema = z.object({
|
|
|
723
733
|
* last answer. None for any other completion, for a failure with no record
|
|
724
734
|
* and for a message no agent sent.
|
|
725
735
|
*/
|
|
726
|
-
origin: z.string().min(1).nullable().optional()
|
|
736
|
+
origin: z.string().min(1).nullable().optional(),
|
|
737
|
+
/**
|
|
738
|
+
* Whom the work the message tells of is for, by the id its program
|
|
739
|
+
* gave its sender (`crate::UserBlock`'s `sender_id`): for an explicit
|
|
740
|
+
* message, whom the sending agent worked for
|
|
741
|
+
* (`crate::Block::sender_id`); for a child's end, whom the child worked
|
|
742
|
+
* for as it closed; for the end of another conversation's work, whom
|
|
743
|
+
* the message that asked for it named. Absent for any other message,
|
|
744
|
+
* and when no one was named.
|
|
745
|
+
*/
|
|
746
|
+
senderId: z.string().min(1).max(255).nullable().optional(),
|
|
747
|
+
/**
|
|
748
|
+
* The assignment the work the message hands or tells of is part of, by
|
|
749
|
+
* the id of the message that opened it, as `sender_id` names whom it is
|
|
750
|
+
* for; absent when it names none.
|
|
751
|
+
*/
|
|
752
|
+
assignmentId: z.string().min(1).nullable().optional()
|
|
727
753
|
});
|
|
728
754
|
/** How the video an edit or an extension changes went to the vendor. */
|
|
729
755
|
const sentSourceSchema = z.discriminatedUnion("type", [
|
|
@@ -1031,7 +1057,18 @@ const commandReportSchema = z.object({
|
|
|
1031
1057
|
* reference, or the part that took its place, then the text of the
|
|
1032
1058
|
* lines about them; none for a report of progress.
|
|
1033
1059
|
*/
|
|
1034
|
-
media: z.array(toolResultContentBlockSchema).optional()
|
|
1060
|
+
media: z.array(toolResultContentBlockSchema).optional(),
|
|
1061
|
+
/**
|
|
1062
|
+
* Whom the command's work is for: the sender of the call that started
|
|
1063
|
+
* it, which its record keeps; absent when that call's work was for no
|
|
1064
|
+
* one named.
|
|
1065
|
+
*/
|
|
1066
|
+
senderId: z.string().min(1).max(255).optional(),
|
|
1067
|
+
/**
|
|
1068
|
+
* The assignment of the call that started it, which its record keeps; absent
|
|
1069
|
+
* when that call's turn named none.
|
|
1070
|
+
*/
|
|
1071
|
+
assignmentId: z.string().min(1).optional()
|
|
1035
1072
|
});
|
|
1036
1073
|
/** Where a vendor's step is. */
|
|
1037
1074
|
const opaqueStatusSchema = z.enum([
|
|
@@ -1455,7 +1492,21 @@ const blockSchema = z.discriminatedUnion("type", [
|
|
|
1455
1492
|
* names above it as a receipt names the agent that sent one; absent
|
|
1456
1493
|
* for a message the user wrote.
|
|
1457
1494
|
*/
|
|
1458
|
-
schedule: scheduleMarkSchema.optional()
|
|
1495
|
+
schedule: scheduleMarkSchema.optional(),
|
|
1496
|
+
/**
|
|
1497
|
+
* Who sent the message, by the id the program that sent it gave
|
|
1498
|
+
* ([`SENDER_ID_LIMIT`]); absent when it named no one.
|
|
1499
|
+
*/
|
|
1500
|
+
senderId: z.string().min(1).max(255).optional(),
|
|
1501
|
+
/**
|
|
1502
|
+
* The assignment the message is part of, by the id of the message that
|
|
1503
|
+
* opened it: its own for one the program, the user or a schedule sent,
|
|
1504
|
+
* the turn's that made it for a run of a schedule an agent made, and its
|
|
1505
|
+
* parent's for a subagent's. Absent when it names none, as the work it
|
|
1506
|
+
* continues named none, and in a block written before assignments were
|
|
1507
|
+
* kept.
|
|
1508
|
+
*/
|
|
1509
|
+
assignmentId: z.string().min(1).optional()
|
|
1459
1510
|
}),
|
|
1460
1511
|
z.object({
|
|
1461
1512
|
type: z.literal("context"),
|
|
@@ -1504,7 +1555,10 @@ const blockSchema = z.discriminatedUnion("type", [
|
|
|
1504
1555
|
request: z.string().min(1).optional(),
|
|
1505
1556
|
model: modelSelectionSchema,
|
|
1506
1557
|
placement: wakeupPlacementSchema,
|
|
1507
|
-
/**
|
|
1558
|
+
/**
|
|
1559
|
+
* The reports, in the order they arrived; for a block that opens its
|
|
1560
|
+
* turn, those that opened it first.
|
|
1561
|
+
*/
|
|
1508
1562
|
reports: z.array(commandReportSchema),
|
|
1509
1563
|
/**
|
|
1510
1564
|
* The run of steps the block belongs to: the id of the run's first
|
|
@@ -1531,7 +1585,14 @@ const blockSchema = z.discriminatedUnion("type", [
|
|
|
1531
1585
|
* The comments sent with it, which the model reads before its content
|
|
1532
1586
|
* as a message's; omitted when there are none.
|
|
1533
1587
|
*/
|
|
1534
|
-
comments: z.array(messageCommentSchema).optional()
|
|
1588
|
+
comments: z.array(messageCommentSchema).optional(),
|
|
1589
|
+
/** Who sent it, as a `user` block names its sender. */
|
|
1590
|
+
senderId: z.string().min(1).max(255).optional(),
|
|
1591
|
+
/**
|
|
1592
|
+
* The assignment of the turn that read it, which it joins; absent when that
|
|
1593
|
+
* turn named none.
|
|
1594
|
+
*/
|
|
1595
|
+
assignmentId: z.string().min(1).optional()
|
|
1535
1596
|
}),
|
|
1536
1597
|
z.object({
|
|
1537
1598
|
type: z.literal("agent_message"),
|
|
@@ -1548,6 +1609,11 @@ const blockSchema = z.discriminatedUnion("type", [
|
|
|
1548
1609
|
model: modelSelectionSchema,
|
|
1549
1610
|
message: agentMessageSchema,
|
|
1550
1611
|
/**
|
|
1612
|
+
* The message opened its turn, a continuation of an agent at rest, as
|
|
1613
|
+
* the first message written there; absent for any other.
|
|
1614
|
+
*/
|
|
1615
|
+
opensTurn: z.boolean().optional(),
|
|
1616
|
+
/**
|
|
1551
1617
|
* The run of steps the block belongs to: the id of the run's first
|
|
1552
1618
|
* block, which the backend sets as it stores the block and never
|
|
1553
1619
|
* changes.
|
|
@@ -2267,7 +2333,14 @@ z.discriminatedUnion("type", [
|
|
|
2267
2333
|
* The comments the message carries, which may make it without content;
|
|
2268
2334
|
* omitted when there are none.
|
|
2269
2335
|
*/
|
|
2270
|
-
comments: z.array(clientCommentSchema).optional()
|
|
2336
|
+
comments: z.array(clientCommentSchema).optional(),
|
|
2337
|
+
/**
|
|
2338
|
+
* Who sent it, by a program's own id, such as a person of a team's
|
|
2339
|
+
* chat, which its `user` block keeps: the calls its agent makes after
|
|
2340
|
+
* reading it are that sender's in the usage ledger. Absent for the
|
|
2341
|
+
* core's own user, as the web app sends.
|
|
2342
|
+
*/
|
|
2343
|
+
senderId: z.string().min(1).max(255).nullable().optional()
|
|
2271
2344
|
}),
|
|
2272
2345
|
z.strictObject({
|
|
2273
2346
|
type: z.literal("edit_and_send"),
|
|
@@ -2291,7 +2364,9 @@ z.discriminatedUnion("type", [
|
|
|
2291
2364
|
* The comments the steer carries, as a message's; omitted when
|
|
2292
2365
|
* there are none.
|
|
2293
2366
|
*/
|
|
2294
|
-
comments: z.array(clientCommentSchema).optional()
|
|
2367
|
+
comments: z.array(clientCommentSchema).optional(),
|
|
2368
|
+
/** Who sent it, as a message's sender. */
|
|
2369
|
+
senderId: z.string().min(1).max(255).nullable().optional()
|
|
2295
2370
|
}),
|
|
2296
2371
|
z.strictObject({
|
|
2297
2372
|
type: z.literal("send_saved"),
|
|
@@ -3091,7 +3166,18 @@ const jobCallerSchema = z.object({
|
|
|
3091
3166
|
* (`crates/core-store/src/usage.rs`); none for a job recorded before
|
|
3092
3167
|
* records kept it.
|
|
3093
3168
|
*/
|
|
3094
|
-
turn: z.string().min(1).nullable().optional()
|
|
3169
|
+
turn: z.string().min(1).nullable().optional(),
|
|
3170
|
+
/**
|
|
3171
|
+
* Whom the call's agent worked for, by its program's id, whom a
|
|
3172
|
+
* command's call to a vendor is counted for; none when no one was
|
|
3173
|
+
* named.
|
|
3174
|
+
*/
|
|
3175
|
+
senderId: z.string().nullable().optional(),
|
|
3176
|
+
/**
|
|
3177
|
+
* The assignment the call's agent worked in, which a command's call to a
|
|
3178
|
+
* vendor is counted in; none when its turn named none.
|
|
3179
|
+
*/
|
|
3180
|
+
assignmentId: z.string().min(1).nullable().optional()
|
|
3095
3181
|
});
|
|
3096
3182
|
/** The ids of a call's relayed pipes. */
|
|
3097
3183
|
const relayedPipesSchema = z.object({
|
|
@@ -3952,10 +4038,14 @@ z.discriminatedUnion("kind", [
|
|
|
3952
4038
|
kind: z.literal("debug"),
|
|
3953
4039
|
resume: z.string().nullable().optional()
|
|
3954
4040
|
}),
|
|
3955
|
-
z.strictObject({
|
|
4041
|
+
z.strictObject({
|
|
4042
|
+
kind: z.literal("starter"),
|
|
4043
|
+
version: z.string().nullable().optional()
|
|
4044
|
+
}),
|
|
3956
4045
|
z.strictObject({
|
|
3957
4046
|
kind: z.literal("plugin"),
|
|
3958
|
-
plugin: z.string()
|
|
4047
|
+
plugin: z.string(),
|
|
4048
|
+
version: z.string().nullable().optional()
|
|
3959
4049
|
})
|
|
3960
4050
|
]);
|
|
3961
4051
|
/** A point of the picture, in its coordinates. */
|
|
@@ -5409,7 +5499,12 @@ z.strictObject({
|
|
|
5409
5499
|
/** The picture asked of, for a side question about a picture. */
|
|
5410
5500
|
picture: mediaSourceSchema.nullable().optional(),
|
|
5411
5501
|
/** What is asked, a message's content, as a frame names it. */
|
|
5412
|
-
question: z.array(clientContentSchema)
|
|
5502
|
+
question: z.array(clientContentSchema),
|
|
5503
|
+
/**
|
|
5504
|
+
* Who asked, as a message's sender
|
|
5505
|
+
* (`crates/conversation-lane-protocol/src/client.rs`).
|
|
5506
|
+
*/
|
|
5507
|
+
senderId: z.string().min(1).max(255).nullable().optional()
|
|
5413
5508
|
});
|
|
5414
5509
|
/** `AuthenticatorAssertionResponseJSON`. */
|
|
5415
5510
|
const assertionResponseJsonSchema = z.strictObject({
|
|
@@ -5895,8 +5990,9 @@ const patchFieldSchema = z.enum([
|
|
|
5895
5990
|
"service_tier_id",
|
|
5896
5991
|
"workflow",
|
|
5897
5992
|
"browser_profile",
|
|
5898
|
-
"
|
|
5899
|
-
"
|
|
5993
|
+
"system_prompt",
|
|
5994
|
+
"commands",
|
|
5995
|
+
"plugin_versions",
|
|
5900
5996
|
"target"
|
|
5901
5997
|
]);
|
|
5902
5998
|
/**
|
|
@@ -5928,7 +6024,8 @@ const batchResultSchema = z.discriminatedUnion("status", [z.object({
|
|
|
5928
6024
|
code: errorCodeSchema,
|
|
5929
6025
|
message: z.string()
|
|
5930
6026
|
})]);
|
|
5931
|
-
|
|
6027
|
+
/** The answer of a batch: an outcome per item, in the order given. */
|
|
6028
|
+
const batchAnswerSchema = z.object({ results: z.array(batchResultSchema) });
|
|
5932
6029
|
/** A provider entry of the user's scope and one of its models. */
|
|
5933
6030
|
const modelChoiceSchema = z.strictObject({
|
|
5934
6031
|
providerId: z.string().min(1),
|
|
@@ -5968,15 +6065,23 @@ const conversationPatchSchema = z.strictObject({
|
|
|
5968
6065
|
*/
|
|
5969
6066
|
browserProfile: z.string().regex(/* @__PURE__ */ new RegExp("^[a-z0-9_-]{1,64}$", "u")).nullable().optional(),
|
|
5970
6067
|
/**
|
|
5971
|
-
* The
|
|
5972
|
-
*
|
|
6068
|
+
* The system prompt its agents read in place of Jush's, from each
|
|
6069
|
+
* agent's next request; null for Jush's.
|
|
5973
6070
|
*/
|
|
5974
|
-
|
|
6071
|
+
systemPrompt: z.string().nullable().optional(),
|
|
5975
6072
|
/**
|
|
5976
|
-
* The
|
|
5977
|
-
* command; null for
|
|
6073
|
+
* The commands its agents have, by path without `jush`, from each
|
|
6074
|
+
* agent's next command; null for every command.
|
|
5978
6075
|
*/
|
|
5979
|
-
|
|
6076
|
+
commands: z.array(z.string()).nullable().optional(),
|
|
6077
|
+
/**
|
|
6078
|
+
* The versions it runs on of the program's plugins, each by its
|
|
6079
|
+
* plugin's id, in place of those it named: its agents' commands, and
|
|
6080
|
+
* every request of the conversation, go to them from now on; a call
|
|
6081
|
+
* sent already goes on where it is. `{}` returns it to the current
|
|
6082
|
+
* versions.
|
|
6083
|
+
*/
|
|
6084
|
+
pluginVersions: z.record(z.string(), z.string()).optional(),
|
|
5980
6085
|
/** A switch of the conversation's execution target. */
|
|
5981
6086
|
target: conversationTargetSchema.optional()
|
|
5982
6087
|
});
|
|
@@ -6144,7 +6249,12 @@ z.strictObject({
|
|
|
6144
6249
|
lastModel: modelSettingsSchema.optional(),
|
|
6145
6250
|
lastWorkflow: workflowChoiceSchema.optional()
|
|
6146
6251
|
});
|
|
6147
|
-
|
|
6252
|
+
/**
|
|
6253
|
+
* One changed file's two sides: `original` as the last commit or the edit
|
|
6254
|
+
* has it, empty for a new file; `modified` as the working tree or the edit
|
|
6255
|
+
* has it, empty for a deleted one.
|
|
6256
|
+
*/
|
|
6257
|
+
const changeSidesSchema = z.object({
|
|
6148
6258
|
original: z.string(),
|
|
6149
6259
|
modified: z.string()
|
|
6150
6260
|
});
|
|
@@ -6505,13 +6615,6 @@ const cloudStorageSchema = z.object({
|
|
|
6505
6615
|
* counting from one, which `codesTaken` and a refusal of it then name.
|
|
6506
6616
|
*/
|
|
6507
6617
|
const codeTakenSchema = z.object({ code: z.int().min(0).max(4294967295) });
|
|
6508
|
-
z.object({
|
|
6509
|
-
commandId: z.string().min(1),
|
|
6510
|
-
/** The agent that ran it. */
|
|
6511
|
-
node: z.string().min(1),
|
|
6512
|
-
/** The call's block in that agent's transcript. */
|
|
6513
|
-
blockId: z.string().min(1)
|
|
6514
|
-
});
|
|
6515
6618
|
/**
|
|
6516
6619
|
* How a command ended, as the conversation's record of its output keeps
|
|
6517
6620
|
* it (`crates/core-store/src/command_outputs.rs`).
|
|
@@ -6528,6 +6631,77 @@ const commandEndSchema = z.discriminatedUnion("kind", [
|
|
|
6528
6631
|
}),
|
|
6529
6632
|
z.object({ kind: z.literal("unrecorded") })
|
|
6530
6633
|
]);
|
|
6634
|
+
/** How a command ended, or why a call started none. */
|
|
6635
|
+
const commandHistoryEndSchema = z.discriminatedUnion("kind", [
|
|
6636
|
+
z.object({
|
|
6637
|
+
kind: z.literal("exited"),
|
|
6638
|
+
exitCode: z.int().min(-2147483648).max(2147483647)
|
|
6639
|
+
}),
|
|
6640
|
+
z.object({ kind: z.literal("stopped") }),
|
|
6641
|
+
z.object({
|
|
6642
|
+
kind: z.literal("lost"),
|
|
6643
|
+
reason: z.string()
|
|
6644
|
+
}),
|
|
6645
|
+
z.object({
|
|
6646
|
+
kind: z.literal("not_started"),
|
|
6647
|
+
reason: z.string()
|
|
6648
|
+
})
|
|
6649
|
+
]);
|
|
6650
|
+
/**
|
|
6651
|
+
* A command an agent's `shell` call started, as it ended, or a call that
|
|
6652
|
+
* started none.
|
|
6653
|
+
*/
|
|
6654
|
+
const commandHistoryEntrySchema = z.object({
|
|
6655
|
+
conversation: z.string().regex(/* @__PURE__ */ new RegExp("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$", "u")),
|
|
6656
|
+
/**
|
|
6657
|
+
* The number its conversation knows the call's agent by, 0 for the
|
|
6658
|
+
* main agent; none for a side question's.
|
|
6659
|
+
*/
|
|
6660
|
+
agent: z.int().min(0).nullable().optional(),
|
|
6661
|
+
/** None for a call that started no command. */
|
|
6662
|
+
command: z.string().min(1).nullable().optional(),
|
|
6663
|
+
/** The device it ran on; none for a call that started no command. */
|
|
6664
|
+
device: z.string().min(1).nullable().optional(),
|
|
6665
|
+
/** The turn of the call. */
|
|
6666
|
+
turn: z.string().min(1).nullable().optional(),
|
|
6667
|
+
/** Whom the call's work was for, by the id the program gave its sender. */
|
|
6668
|
+
sender: z.string().nullable().optional(),
|
|
6669
|
+
/** The assignment the call's work was part of. */
|
|
6670
|
+
assignment: z.string().min(1).nullable().optional(),
|
|
6671
|
+
title: z.string(),
|
|
6672
|
+
script: z.string(),
|
|
6673
|
+
/**
|
|
6674
|
+
* When its call started it, a wait for its device to come online
|
|
6675
|
+
* included; none for a call that started no command, and for a
|
|
6676
|
+
* command that ended before its start was recorded.
|
|
6677
|
+
*/
|
|
6678
|
+
startedAt: z.iso.datetime({ precision: 3 }).nullable().optional(),
|
|
6679
|
+
endedAt: z.iso.datetime({ precision: 3 }),
|
|
6680
|
+
end: commandHistoryEndSchema
|
|
6681
|
+
});
|
|
6682
|
+
/** A page of the history. */
|
|
6683
|
+
const commandHistorySchema = z.object({
|
|
6684
|
+
commands: z.array(commandHistoryEntrySchema),
|
|
6685
|
+
/**
|
|
6686
|
+
* Where the page ends, which `after` takes to read on: its last row's
|
|
6687
|
+
* place; for an empty page, the `after` given, the newest row's when
|
|
6688
|
+
* nothing ended at `from` or after, or the place before the first row.
|
|
6689
|
+
*/
|
|
6690
|
+
next: z.string(),
|
|
6691
|
+
/** Whether rows were written after the page. */
|
|
6692
|
+
more: z.boolean()
|
|
6693
|
+
});
|
|
6694
|
+
/**
|
|
6695
|
+
* `GET /conversations/:id/commands/:commandId`: where the `shell` call that
|
|
6696
|
+
* started a command lies, which a report's title brings into view.
|
|
6697
|
+
*/
|
|
6698
|
+
const commandOriginSchema = z.object({
|
|
6699
|
+
commandId: z.string().min(1),
|
|
6700
|
+
/** The agent that ran it. */
|
|
6701
|
+
node: z.string().min(1),
|
|
6702
|
+
/** The call's block in that agent's transcript. */
|
|
6703
|
+
blockId: z.string().min(1)
|
|
6704
|
+
});
|
|
6531
6705
|
/** A compaction marker of a page and its boundary's summary size. */
|
|
6532
6706
|
const compactionSummarySchema = z.object({
|
|
6533
6707
|
marker: z.string().min(1),
|
|
@@ -6540,6 +6714,13 @@ const compactionSummarySchema = z.object({
|
|
|
6540
6714
|
* that vendor's entry with the gateway's endpoint.
|
|
6541
6715
|
*/
|
|
6542
6716
|
const compatibleShapesSchema = z.object({ audio: z.array(audioShapeSchema) });
|
|
6717
|
+
z.strictObject({
|
|
6718
|
+
/** The core that started the sign-in. */
|
|
6719
|
+
core: z.string(),
|
|
6720
|
+
plugin: z.string(),
|
|
6721
|
+
/** The query of the address, such as `code=…&state=…`. */
|
|
6722
|
+
query: z.string()
|
|
6723
|
+
});
|
|
6543
6724
|
/**
|
|
6544
6725
|
* What a configured model makes (`crates/core/src/provider_settings.rs`):
|
|
6545
6726
|
* text, the model menu's, unless its user added it as an audio model of a
|
|
@@ -6834,10 +7015,21 @@ const conversationMetadataSchema = z.object({
|
|
|
6834
7015
|
workflow: workflowChoiceSchema,
|
|
6835
7016
|
/** The browser profile it names; null for a profile of its own. */
|
|
6836
7017
|
browserProfile: z.string().regex(/* @__PURE__ */ new RegExp("^[a-z0-9_-]{1,64}$", "u")).nullable(),
|
|
6837
|
-
/**
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
7018
|
+
/**
|
|
7019
|
+
* The system prompt its agents read in place of Jush's; null for
|
|
7020
|
+
* Jush's.
|
|
7021
|
+
*/
|
|
7022
|
+
systemPrompt: z.string().nullable(),
|
|
7023
|
+
/**
|
|
7024
|
+
* The commands its agents have, by path without `jush`; null for every
|
|
7025
|
+
* command.
|
|
7026
|
+
*/
|
|
7027
|
+
commands: z.array(z.string()).nullable(),
|
|
7028
|
+
/**
|
|
7029
|
+
* The versions it runs on of the program's plugins, each by its
|
|
7030
|
+
* plugin's id; the current one of a plugin it names none of.
|
|
7031
|
+
*/
|
|
7032
|
+
pluginVersions: z.record(z.string(), z.string()),
|
|
6841
7033
|
/**
|
|
6842
7034
|
* The directory the conversation's work runs in, resolved by the backend
|
|
6843
7035
|
* for every kind of target, so the web app never derives it.
|
|
@@ -7251,7 +7443,11 @@ z.discriminatedUnion("type", [
|
|
|
7251
7443
|
keys: z.array(z.string()).max(4096)
|
|
7252
7444
|
})
|
|
7253
7445
|
]);
|
|
7254
|
-
|
|
7446
|
+
/**
|
|
7447
|
+
* `GET /conversations`: the caller's conversations: those not archived in
|
|
7448
|
+
* sidebar order, pinned first, or the archived ones, the last archived first.
|
|
7449
|
+
*/
|
|
7450
|
+
const conversationsSchema = z.object({ conversations: z.array(conversationSummarySchema) });
|
|
7255
7451
|
/**
|
|
7256
7452
|
* Who configures providers: each user their own, or the master for every
|
|
7257
7453
|
* user, which the master changes in Settings › Users.
|
|
@@ -8062,7 +8258,14 @@ const sendMessageSchema = z.strictObject({
|
|
|
8062
8258
|
* The comments the message carries, which may make it without content;
|
|
8063
8259
|
* omitted when there are none.
|
|
8064
8260
|
*/
|
|
8065
|
-
comments: z.array(clientCommentSchema).optional()
|
|
8261
|
+
comments: z.array(clientCommentSchema).optional(),
|
|
8262
|
+
/**
|
|
8263
|
+
* Who sent it, by a program's own id, such as a person of a team's
|
|
8264
|
+
* chat, which its `user` block keeps: the calls its agent makes after
|
|
8265
|
+
* reading it are that sender's in the usage ledger. Absent for the
|
|
8266
|
+
* core's own user, as the web app sends.
|
|
8267
|
+
*/
|
|
8268
|
+
senderId: z.string().min(1).max(255).nullable().optional()
|
|
8066
8269
|
});
|
|
8067
8270
|
z.strictObject({
|
|
8068
8271
|
id: z.string().regex(/* @__PURE__ */ new RegExp("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$", "u")),
|
|
@@ -8092,16 +8295,20 @@ z.strictObject({
|
|
|
8092
8295
|
*/
|
|
8093
8296
|
browserProfile: z.string().regex(/* @__PURE__ */ new RegExp("^[a-z0-9_-]{1,64}$", "u")).optional(),
|
|
8094
8297
|
/**
|
|
8095
|
-
* The
|
|
8096
|
-
*
|
|
8097
|
-
* absent.
|
|
8298
|
+
* The system prompt its agents read in place of Jush's, such as "You
|
|
8299
|
+
* are the help desk's assistant. …"; Jush's when absent.
|
|
8098
8300
|
*/
|
|
8099
|
-
|
|
8301
|
+
systemPrompt: z.string().optional(),
|
|
8100
8302
|
/**
|
|
8101
|
-
* The
|
|
8102
|
-
* absent.
|
|
8303
|
+
* The commands its agents have, by path without `jush`, such as
|
|
8304
|
+
* `browser` or `conversation history`; every command when absent.
|
|
8305
|
+
*/
|
|
8306
|
+
commands: z.array(z.string()).optional(),
|
|
8307
|
+
/**
|
|
8308
|
+
* The versions it runs on of the program's plugins, each by its
|
|
8309
|
+
* plugin's id; the current one of a plugin it names none of.
|
|
8103
8310
|
*/
|
|
8104
|
-
|
|
8311
|
+
pluginVersions: z.record(z.string(), z.string()).optional(),
|
|
8105
8312
|
/**
|
|
8106
8313
|
* The message the conversation starts with, as the socket's `send`
|
|
8107
8314
|
* frame carries it.
|
|
@@ -8202,7 +8409,8 @@ const createdConversationSchema = z.object({
|
|
|
8202
8409
|
/** Absent when the request carried no first message. */
|
|
8203
8410
|
firstMessage: firstMessageAnswerSchema.optional()
|
|
8204
8411
|
});
|
|
8205
|
-
|
|
8412
|
+
/** `{ path }`: the directory a create made. */
|
|
8413
|
+
const createdDirectorySchema = z.object({ path: z.string() });
|
|
8206
8414
|
/** An account's role. A role administers only the roles below it. */
|
|
8207
8415
|
const roleSchema = z.enum([
|
|
8208
8416
|
"admin",
|
|
@@ -8338,8 +8546,13 @@ const credentialDtoSchema = z.object({
|
|
|
8338
8546
|
createdAt: z.iso.datetime({ precision: 3 }),
|
|
8339
8547
|
updatedAt: z.iso.datetime({ precision: 3 })
|
|
8340
8548
|
});
|
|
8341
|
-
|
|
8342
|
-
z.object({
|
|
8549
|
+
/** What a route that saves a credential answers. */
|
|
8550
|
+
const credentialAnswerSchema = z.object({ credential: credentialDtoSchema });
|
|
8551
|
+
/**
|
|
8552
|
+
* `GET /credentials`, and the synchronization channel's `credentials`
|
|
8553
|
+
* part: the user's credentials in name order.
|
|
8554
|
+
*/
|
|
8555
|
+
const credentialListSchema = z.object({ credentials: z.array(credentialDtoSchema) });
|
|
8343
8556
|
z.strictObject({
|
|
8344
8557
|
/** A credential's name: trimmed, then at least one character. */
|
|
8345
8558
|
name: z.string().trim().min(1).optional(),
|
|
@@ -8442,7 +8655,13 @@ const deviceAnswerSchema = z.object({ device: deviceDtoSchema });
|
|
|
8442
8655
|
* elevated, and a No leaves it as it was.
|
|
8443
8656
|
*/
|
|
8444
8657
|
const elevationOutcomeSchema = z.enum(["shown", "unavailable"]);
|
|
8445
|
-
|
|
8658
|
+
/**
|
|
8659
|
+
* What came of a request that a device's Windows runner run elevated
|
|
8660
|
+
* (`POST /api/devices/{id}/elevation`): whether a User Account Control
|
|
8661
|
+
* prompt shows on its desktop. The device's elevation says later what came
|
|
8662
|
+
* of the prompt.
|
|
8663
|
+
*/
|
|
8664
|
+
const deviceElevationSchema = z.object({ outcome: elevationOutcomeSchema });
|
|
8446
8665
|
z.strictObject({
|
|
8447
8666
|
script: z.string(),
|
|
8448
8667
|
/**
|
|
@@ -8496,7 +8715,8 @@ const deviceStorageSchema = z.object({
|
|
|
8496
8715
|
/** Null before its runner first measured. */
|
|
8497
8716
|
report: deviceStorageReportSchema.nullable()
|
|
8498
8717
|
});
|
|
8499
|
-
|
|
8718
|
+
/** `GET /devices`: the caller's paired devices, oldest first. */
|
|
8719
|
+
const devicesSchema = z.object({ devices: z.array(deviceDtoSchema) });
|
|
8500
8720
|
/**
|
|
8501
8721
|
* Which of the page's two peers with a device a signaling message is about
|
|
8502
8722
|
* (`crates/runner-direct/src/lib.rs`): the one for files and calls,
|
|
@@ -8587,7 +8807,11 @@ const directoryEntrySchema = z.object({
|
|
|
8587
8807
|
modifiedAt: z.iso.datetime({ precision: 3 }),
|
|
8588
8808
|
link: symbolicLinkSchema.nullable().optional()
|
|
8589
8809
|
});
|
|
8590
|
-
|
|
8810
|
+
/**
|
|
8811
|
+
* `{ path, home, entries }`: a directory as a device lists it. `home` is the
|
|
8812
|
+
* device's home directory, null while it is unknown.
|
|
8813
|
+
*/
|
|
8814
|
+
const directorySchema = z.object({
|
|
8591
8815
|
path: z.string(),
|
|
8592
8816
|
home: z.string().nullable(),
|
|
8593
8817
|
entries: z.array(directoryEntrySchema)
|
|
@@ -8675,7 +8899,11 @@ z.strictObject({
|
|
|
8675
8899
|
password: z.string().min(1)
|
|
8676
8900
|
});
|
|
8677
8901
|
z.object({ challenge: emailChallengeDtoSchema });
|
|
8678
|
-
|
|
8902
|
+
/**
|
|
8903
|
+
* `GET /conversations/:id/commands/:commandId/output`: an ended command's
|
|
8904
|
+
* output as its terminal shows it, with the script its call ran.
|
|
8905
|
+
*/
|
|
8906
|
+
const endedOutputSchema = z.object({
|
|
8679
8907
|
/**
|
|
8680
8908
|
* The script its call ran; empty when the conversation holds no call
|
|
8681
8909
|
* of it.
|
|
@@ -8691,7 +8919,8 @@ z.object({
|
|
|
8691
8919
|
/** Why its output was not stored; null when it was. */
|
|
8692
8920
|
notStored: z.string().nullable()
|
|
8693
8921
|
});
|
|
8694
|
-
|
|
8922
|
+
/** `GET .../fs/file`: a file's text. */
|
|
8923
|
+
const fileTextSchema = z.object({
|
|
8695
8924
|
path: z.string(),
|
|
8696
8925
|
text: z.string()
|
|
8697
8926
|
});
|
|
@@ -8747,13 +8976,26 @@ z.discriminatedUnion("type", [
|
|
|
8747
8976
|
keys: z.array(z.string()).max(4096)
|
|
8748
8977
|
})
|
|
8749
8978
|
]);
|
|
8750
|
-
|
|
8979
|
+
/**
|
|
8980
|
+
* The answer of a Fork: the new conversation as the list shows it, and its
|
|
8981
|
+
* metadata, whose model settings are the ones it inherited from its source.
|
|
8982
|
+
*/
|
|
8983
|
+
const forkAnswerSchema = z.object({
|
|
8751
8984
|
conversation: conversationSummarySchema,
|
|
8752
8985
|
metadata: conversationMetadataSchema
|
|
8753
8986
|
});
|
|
8754
8987
|
z.strictObject({
|
|
8755
8988
|
id: z.string().regex(/* @__PURE__ */ new RegExp("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$", "u")),
|
|
8756
|
-
|
|
8989
|
+
/**
|
|
8990
|
+
* The main agent's completed assistant text the history is kept
|
|
8991
|
+
* through.
|
|
8992
|
+
*/
|
|
8993
|
+
blockId: z.string().min(1).nullable().optional(),
|
|
8994
|
+
/**
|
|
8995
|
+
* A turn of the main agent, by the id of the message that started it:
|
|
8996
|
+
* the history is everything before that message.
|
|
8997
|
+
*/
|
|
8998
|
+
beforeTurn: z.string().min(1).nullable().optional()
|
|
8757
8999
|
});
|
|
8758
9000
|
const forwardAddressSchema = z.string().min(3).max(260);
|
|
8759
9001
|
/** A side of a pair, as the direct channel names a page's and a device's. */
|
|
@@ -8820,7 +9062,12 @@ z.object({
|
|
|
8820
9062
|
draft: conversationDraftSchema,
|
|
8821
9063
|
revisions: revisionsSchema
|
|
8822
9064
|
});
|
|
8823
|
-
|
|
9065
|
+
/**
|
|
9066
|
+
* A repository's local branches (`crates/runner-device/src/git.rs`): by name,
|
|
9067
|
+
* most recently committed first; the one checked out, or null with `head`
|
|
9068
|
+
* when HEAD is detached.
|
|
9069
|
+
*/
|
|
9070
|
+
const gitBranchesSchema = z.object({
|
|
8824
9071
|
branches: z.array(z.string()),
|
|
8825
9072
|
/** Null while HEAD is detached. */
|
|
8826
9073
|
current: z.string().nullable(),
|
|
@@ -8863,7 +9110,12 @@ const gitCommitFileSchema = z.object({
|
|
|
8863
9110
|
added: z.int().min(0),
|
|
8864
9111
|
removed: z.int().min(0)
|
|
8865
9112
|
});
|
|
8866
|
-
|
|
9113
|
+
/**
|
|
9114
|
+
* A commit as `git_commit` answers it: its entry with its parents, its
|
|
9115
|
+
* files against its first parent, cut at 5,000 (`truncated`), and the local
|
|
9116
|
+
* branches it is on, the checked-out one first.
|
|
9117
|
+
*/
|
|
9118
|
+
const gitCommitSchema = z.object({
|
|
8867
9119
|
commit: gitCommitEntrySchema,
|
|
8868
9120
|
files: z.array(gitCommitFileSchema),
|
|
8869
9121
|
truncated: z.boolean(),
|
|
@@ -8879,11 +9131,16 @@ const gitLogEntrySchema = z.object({
|
|
|
8879
9131
|
author: z.string(),
|
|
8880
9132
|
time: z.iso.datetime({ precision: 3 })
|
|
8881
9133
|
});
|
|
8882
|
-
|
|
9134
|
+
/**
|
|
9135
|
+
* One page of a first-parent history, newest first; `more` when older
|
|
9136
|
+
* commits follow.
|
|
9137
|
+
*/
|
|
9138
|
+
const gitLogSchema = z.object({
|
|
8883
9139
|
commits: z.array(gitLogEntrySchema),
|
|
8884
9140
|
more: z.boolean()
|
|
8885
9141
|
});
|
|
8886
|
-
|
|
9142
|
+
/** The repositories around a directory (`crates/runner-device/src/repositories.rs`). */
|
|
9143
|
+
const gitRepositoriesSchema = z.object({
|
|
8887
9144
|
/** Whether the directory lies in a repository, at it or above it. */
|
|
8888
9145
|
inRepository: z.boolean(),
|
|
8889
9146
|
/**
|
|
@@ -8946,7 +9203,11 @@ const userUsageSchema = z.object({
|
|
|
8946
9203
|
totals: z.array(usageGroupSchema)
|
|
8947
9204
|
});
|
|
8948
9205
|
z.object({ users: z.array(userUsageSchema) });
|
|
8949
|
-
|
|
9206
|
+
/**
|
|
9207
|
+
* `GET /settings/instructions`: the caller's personal instructions; empty
|
|
9208
|
+
* when they have none.
|
|
9209
|
+
*/
|
|
9210
|
+
const instructionsAnswerSchema = z.object({ instructions: z.string() });
|
|
8950
9211
|
z.strictObject({ text: z.string() });
|
|
8951
9212
|
z.object({
|
|
8952
9213
|
ok: z.boolean(),
|
|
@@ -8973,7 +9234,8 @@ const listedDirectorySchema = z.discriminatedUnion("type", [z.object({
|
|
|
8973
9234
|
status: z.int().min(0).max(65535),
|
|
8974
9235
|
error: errorBodySchema
|
|
8975
9236
|
})]);
|
|
8976
|
-
|
|
9237
|
+
/** `POST .../fs/lists`: one answer for each path asked, in its order. */
|
|
9238
|
+
const listedDirectoriesSchema = z.object({ lists: z.array(listedDirectorySchema) });
|
|
8977
9239
|
/** An account as an administrator's list shows it. */
|
|
8978
9240
|
const listedUserSchema = z.object({
|
|
8979
9241
|
id: z.string().min(1),
|
|
@@ -9039,7 +9301,12 @@ const messageResultSchema = z.object({
|
|
|
9039
9301
|
text: z.string(),
|
|
9040
9302
|
ranges: z.array(z.array(z.int().min(0).max(4294967295)).min(2).max(2))
|
|
9041
9303
|
});
|
|
9042
|
-
|
|
9304
|
+
/**
|
|
9305
|
+
* What `GET /conversations/{id}/search` answers: the messages of the
|
|
9306
|
+
* conversation's main agent, the user's and the agent's answers, that hold
|
|
9307
|
+
* every word of the query, newest first, at most [`RESULTS_MAX`] of them.
|
|
9308
|
+
*/
|
|
9309
|
+
const messageResultsSchema = z.object({
|
|
9043
9310
|
messages: z.array(messageResultSchema),
|
|
9044
9311
|
/** More messages hold the words than the answer lists. */
|
|
9045
9312
|
limited: z.boolean()
|
|
@@ -9078,7 +9345,11 @@ const modelMatchSchema = z.object({
|
|
|
9078
9345
|
/** The release date as models.dev states it, such as `2026-06-17`. */
|
|
9079
9346
|
releaseDate: z.string().nullable()
|
|
9080
9347
|
});
|
|
9081
|
-
|
|
9348
|
+
/**
|
|
9349
|
+
* `{ results }`: at most 20 matches, newest release first, because the
|
|
9350
|
+
* catalogue has no end of matches and a search answers whole.
|
|
9351
|
+
*/
|
|
9352
|
+
const modelSearchResultsSchema = z.object({ results: z.array(modelMatchSchema) });
|
|
9082
9353
|
/** A plugin's reply block a reply names, by its tag and its ID. */
|
|
9083
9354
|
const namedReplyBlockSchema = z.strictObject({
|
|
9084
9355
|
tag: z.string().min(1).max(64),
|
|
@@ -9193,6 +9464,42 @@ z.object({ ok: z.boolean() });
|
|
|
9193
9464
|
* `/cores/{id}/api`.
|
|
9194
9465
|
*/
|
|
9195
9466
|
const openedCoreSchema = z.object({ id: z.string().min(1) });
|
|
9467
|
+
/**
|
|
9468
|
+
* What a user does on a program's page of a conversation, each a control
|
|
9469
|
+
* of its views and the requests behind it. A page reads its conversation
|
|
9470
|
+
* with none of them.
|
|
9471
|
+
*/
|
|
9472
|
+
const pageOperationSchema = z.enum([
|
|
9473
|
+
"send",
|
|
9474
|
+
"attach",
|
|
9475
|
+
"steer",
|
|
9476
|
+
"edit",
|
|
9477
|
+
"stop",
|
|
9478
|
+
"retry",
|
|
9479
|
+
"compact",
|
|
9480
|
+
"clear",
|
|
9481
|
+
"ask",
|
|
9482
|
+
"messageAgents",
|
|
9483
|
+
"decide",
|
|
9484
|
+
"fork",
|
|
9485
|
+
"delete",
|
|
9486
|
+
"rename",
|
|
9487
|
+
"chooseModel",
|
|
9488
|
+
"chooseDevice",
|
|
9489
|
+
"chooseWorkflow",
|
|
9490
|
+
"pins",
|
|
9491
|
+
"schedules",
|
|
9492
|
+
"files",
|
|
9493
|
+
"writeFiles",
|
|
9494
|
+
"changes",
|
|
9495
|
+
"browser",
|
|
9496
|
+
"simulators",
|
|
9497
|
+
"plugins"
|
|
9498
|
+
]);
|
|
9499
|
+
z.object({
|
|
9500
|
+
conversation: z.string().regex(/* @__PURE__ */ new RegExp("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$", "u")),
|
|
9501
|
+
allow: z.array(pageOperationSchema)
|
|
9502
|
+
});
|
|
9196
9503
|
/** The level of a line the page wrote. */
|
|
9197
9504
|
const pageLogLevelSchema = z.enum([
|
|
9198
9505
|
"debug",
|
|
@@ -9301,7 +9608,12 @@ z.strictObject({
|
|
|
9301
9608
|
current: z.string().nullable().optional(),
|
|
9302
9609
|
next: z.string().min(8)
|
|
9303
9610
|
});
|
|
9304
|
-
|
|
9611
|
+
/**
|
|
9612
|
+
* `GET /conversations/:id/plugins/:plugin/state`: the plugin's state for the
|
|
9613
|
+
* conversation, valid against the plugin's declared schema, and the revision
|
|
9614
|
+
* it was read at.
|
|
9615
|
+
*/
|
|
9616
|
+
const pluginStateAnswerSchema = z.object({
|
|
9305
9617
|
revision: z.int().min(0),
|
|
9306
9618
|
state: z.json()
|
|
9307
9619
|
});
|
|
@@ -9323,8 +9635,10 @@ const portForwardDtoSchema = z.object({
|
|
|
9323
9635
|
state: forwardRunStateSchema.nullable(),
|
|
9324
9636
|
createdAt: z.iso.datetime({ precision: 3 })
|
|
9325
9637
|
});
|
|
9326
|
-
|
|
9327
|
-
z.object({
|
|
9638
|
+
/** The answer of a create and a change: the forward as it stands. */
|
|
9639
|
+
const portForwardAnswerSchema = z.object({ forward: portForwardDtoSchema });
|
|
9640
|
+
/** `GET /port-forwards`: the user's forwards, oldest first. */
|
|
9641
|
+
const portForwardListSchema = z.object({ forwards: z.array(portForwardDtoSchema) });
|
|
9328
9642
|
z.strictObject({
|
|
9329
9643
|
listenDevice: z.string().min(1).optional(),
|
|
9330
9644
|
listenPort: z.int().min(1).max(65535).optional(),
|
|
@@ -9720,7 +10034,8 @@ const subagentProfileSchema = z.object({
|
|
|
9720
10034
|
/** Whether agents may use the profile. */
|
|
9721
10035
|
enabled: z.boolean()
|
|
9722
10036
|
});
|
|
9723
|
-
|
|
10037
|
+
/** `{ profile }`: the answer of a create and of a patch. */
|
|
10038
|
+
const profileAnswerSchema = z.object({ profile: subagentProfileSchema });
|
|
9724
10039
|
z.strictObject({
|
|
9725
10040
|
name: z.string().optional(),
|
|
9726
10041
|
description: z.string().optional(),
|
|
@@ -9730,8 +10045,23 @@ z.strictObject({
|
|
|
9730
10045
|
canSpawn: z.boolean().optional(),
|
|
9731
10046
|
enabled: z.boolean().optional()
|
|
9732
10047
|
});
|
|
9733
|
-
z.
|
|
9734
|
-
|
|
10048
|
+
z.strictObject({
|
|
10049
|
+
/**
|
|
10050
|
+
* A schedule's URL, with `{id}`, the schedule's id, such as
|
|
10051
|
+
* `https://bot.example.com/hooks/{id}`.
|
|
10052
|
+
*/
|
|
10053
|
+
schedule: z.string().nullable().optional(),
|
|
10054
|
+
/**
|
|
10055
|
+
* Where a plugin's sign-in sends the browser back to, with `{core}`,
|
|
10056
|
+
* the core's id, and `{plugin}`, the plugin's, as the program needs
|
|
10057
|
+
* them, such as `https://bot.example.com/sign-in/{core}/{plugin}`.
|
|
10058
|
+
*/
|
|
10059
|
+
signInReturn: z.string().nullable().optional()
|
|
10060
|
+
});
|
|
10061
|
+
/** `{ project }`: the answer of a creation and a change. */
|
|
10062
|
+
const projectAnswerSchema = z.object({ project: projectDtoSchema });
|
|
10063
|
+
/** `GET /projects`: the user's projects, in their sidebar order. */
|
|
10064
|
+
const projectsSchema = z.object({ projects: z.array(projectDtoSchema) });
|
|
9735
10065
|
/**
|
|
9736
10066
|
* An entry as the web app sees it: its family, label, kind, endpoint, vendor
|
|
9737
10067
|
* and model list, never its key.
|
|
@@ -9812,7 +10142,13 @@ const providerDtoSchema = z.object({
|
|
|
9812
10142
|
});
|
|
9813
10143
|
/** `{ provider }`: the answer of a create and an edit. */
|
|
9814
10144
|
const providerAnswerSchema = z.object({ provider: providerDtoSchema });
|
|
9815
|
-
|
|
10145
|
+
/**
|
|
10146
|
+
* `GET /providers/:id/cli`: the newest version of the command-line tool
|
|
10147
|
+
* of an entry whose provider runs one on the Subscriptions machine. Reading
|
|
10148
|
+
* it wakes nothing; the install's state is the entry's
|
|
10149
|
+
* ([`ProviderState::cli_install`]).
|
|
10150
|
+
*/
|
|
10151
|
+
const providerCliSchema = z.object({ newest: newestVersionSchema });
|
|
9816
10152
|
z.strictObject({ providerIds: z.array(z.string().min(1)) });
|
|
9817
10153
|
/**
|
|
9818
10154
|
* A change of an entry's search switches; each only for a search its
|
|
@@ -9951,7 +10287,11 @@ z.strictObject({
|
|
|
9951
10287
|
*/
|
|
9952
10288
|
quietWhileElsewhere: z.boolean()
|
|
9953
10289
|
});
|
|
9954
|
-
|
|
10290
|
+
/**
|
|
10291
|
+
* `{ quota }`: the account's snapshot after the probe, or the kept one of a
|
|
10292
|
+
* family that cannot probe; null when there is none.
|
|
10293
|
+
*/
|
|
10294
|
+
const quotaAnswerSchema = z.object({ quota: quotaSnapshotSchema.nullable() });
|
|
9955
10295
|
z.strictObject({ credentialId: z.string().min(1).optional() });
|
|
9956
10296
|
z.object({
|
|
9957
10297
|
ok: z.boolean(),
|
|
@@ -9976,7 +10316,12 @@ const recentAgentSchema = z.object({
|
|
|
9976
10316
|
*/
|
|
9977
10317
|
rate: z.number().nullable()
|
|
9978
10318
|
});
|
|
9979
|
-
|
|
10319
|
+
/**
|
|
10320
|
+
* `GET /conversations/:id/cost/recent?window=hour|day`: what the
|
|
10321
|
+
* conversation's calls of the window cost, counted by the backend from its
|
|
10322
|
+
* usage ledger.
|
|
10323
|
+
*/
|
|
10324
|
+
const recentCostSchema = z.object({
|
|
9980
10325
|
/**
|
|
9981
10326
|
* Each agent that made a call in the window, and the rows of no agent, such
|
|
9982
10327
|
* as a title's, when there are some: the rows of no agent first, then the
|
|
@@ -10030,7 +10375,11 @@ const restartStepSchema = z.object({
|
|
|
10030
10375
|
*/
|
|
10031
10376
|
kept: z.boolean().optional()
|
|
10032
10377
|
});
|
|
10033
|
-
|
|
10378
|
+
/**
|
|
10379
|
+
* `POST /credentials/:id/fields/:field/reveal`: one field's value, which
|
|
10380
|
+
* a card in a reply copies or shows to the vault's owner.
|
|
10381
|
+
*/
|
|
10382
|
+
const revealedValueSchema = z.object({ value: z.string() });
|
|
10034
10383
|
z.object({ removed: z.array(z.string().min(1)) });
|
|
10035
10384
|
/** What fired a run. */
|
|
10036
10385
|
const runCauseSchema = z.enum([
|
|
@@ -10130,6 +10479,21 @@ const scheduleAnswerSchema = z.object({
|
|
|
10130
10479
|
schedule: scheduleDtoSchema,
|
|
10131
10480
|
secret: z.string().nullable()
|
|
10132
10481
|
});
|
|
10482
|
+
/** Why a schedule refused a call. */
|
|
10483
|
+
const scheduleCallRefusalSchema = z.enum([
|
|
10484
|
+
"unknown",
|
|
10485
|
+
"secret",
|
|
10486
|
+
"tooMany",
|
|
10487
|
+
"tooLarge"
|
|
10488
|
+
]);
|
|
10489
|
+
/**
|
|
10490
|
+
* What became of a call of a schedule's URL that the program handed on
|
|
10491
|
+
* (`POST /schedules/calls?id=`).
|
|
10492
|
+
*/
|
|
10493
|
+
const scheduleCallAnswerSchema = z.discriminatedUnion("type", [z.object({ type: z.literal("taken") }), z.object({
|
|
10494
|
+
type: z.literal("refused"),
|
|
10495
|
+
reason: scheduleCallRefusalSchema
|
|
10496
|
+
})]);
|
|
10133
10497
|
z.strictObject({
|
|
10134
10498
|
name: z.string().trim().optional(),
|
|
10135
10499
|
trigger: triggerSchema.optional(),
|
|
@@ -10145,7 +10509,8 @@ z.strictObject({
|
|
|
10145
10509
|
* newest first, [`RUNS_SHOWN`] at most.
|
|
10146
10510
|
*/
|
|
10147
10511
|
const scheduleRunsSchema = z.object({ runs: z.array(scheduleRunDtoSchema) });
|
|
10148
|
-
|
|
10512
|
+
/** One line of a search's output. */
|
|
10513
|
+
const searchLineSchema = z.discriminatedUnion("type", [z.object({
|
|
10149
10514
|
type: z.literal("file"),
|
|
10150
10515
|
/** Relative to the directory searched, with `/` between its parts. */
|
|
10151
10516
|
path: z.string(),
|
|
@@ -10197,7 +10562,11 @@ const searchResultSchema = z.object({
|
|
|
10197
10562
|
/** The message that matched; null when only the title does. */
|
|
10198
10563
|
match: searchMatchSchema.nullable()
|
|
10199
10564
|
});
|
|
10200
|
-
|
|
10565
|
+
/**
|
|
10566
|
+
* What `GET /search` answers: the caller's conversations that match, title
|
|
10567
|
+
* matches first, then the others, each group most recently active first.
|
|
10568
|
+
*/
|
|
10569
|
+
const searchResultsSchema = z.object({ results: z.array(searchResultSchema) });
|
|
10201
10570
|
/**
|
|
10202
10571
|
* What the server keeps. An administrator sees all of it and the log's
|
|
10203
10572
|
* rules; anyone else sees only their own conversations and attachments,
|
|
@@ -10359,10 +10728,22 @@ z.object({
|
|
|
10359
10728
|
/** The reply blocks its texts name. */
|
|
10360
10729
|
replyBlocks: z.array(replyBlockFactsSchema).optional()
|
|
10361
10730
|
});
|
|
10362
|
-
z.strictObject({
|
|
10363
|
-
/**
|
|
10364
|
-
|
|
10365
|
-
|
|
10731
|
+
z.strictObject({
|
|
10732
|
+
/**
|
|
10733
|
+
* Its id, which names the assignment it opens, and which a retry
|
|
10734
|
+
* repeats so the side question takes it once; one is made when none.
|
|
10735
|
+
*/
|
|
10736
|
+
id: z.string().min(1).nullable().optional(),
|
|
10737
|
+
/** A message's content, as a frame names it. */
|
|
10738
|
+
content: z.array(clientContentSchema),
|
|
10739
|
+
/** Who sent it, as a message's sender. */
|
|
10740
|
+
senderId: z.string().min(1).max(255).nullable().optional()
|
|
10741
|
+
});
|
|
10742
|
+
/**
|
|
10743
|
+
* The answer of a side question's creation and of its patch: the side
|
|
10744
|
+
* question as its agent entry shows it.
|
|
10745
|
+
*/
|
|
10746
|
+
const sideQuestionAnswerSchema = z.object({
|
|
10366
10747
|
id: z.string().min(1),
|
|
10367
10748
|
sideQuestion: sideQuestionSchema
|
|
10368
10749
|
});
|
|
@@ -10376,6 +10757,21 @@ z.discriminatedUnion("kind", [z.strictObject({
|
|
|
10376
10757
|
id: z.string().min(1),
|
|
10377
10758
|
beforeId: z.string().min(1).nullable()
|
|
10378
10759
|
})]);
|
|
10760
|
+
/** Why a sign-in did not end signed in. */
|
|
10761
|
+
const signInRefusalSchema = z.enum([
|
|
10762
|
+
"unknownPlugin",
|
|
10763
|
+
"expired",
|
|
10764
|
+
"declined",
|
|
10765
|
+
"vendorFailed"
|
|
10766
|
+
]);
|
|
10767
|
+
/** How a plugin's sign-in ended. */
|
|
10768
|
+
const signInAnswerSchema = z.discriminatedUnion("type", [z.object({
|
|
10769
|
+
type: z.literal("signedIn"),
|
|
10770
|
+
vendor: z.string()
|
|
10771
|
+
}), z.object({
|
|
10772
|
+
type: z.literal("refused"),
|
|
10773
|
+
reason: signInRefusalSchema
|
|
10774
|
+
})]);
|
|
10379
10775
|
z.object({
|
|
10380
10776
|
challengeId: z.string().min(1),
|
|
10381
10777
|
options: requestOptionsJsonSchema
|
|
@@ -10452,7 +10848,12 @@ z.strictObject({
|
|
|
10452
10848
|
* when none.
|
|
10453
10849
|
*/
|
|
10454
10850
|
id: z.string().min(1).nullable().optional(),
|
|
10455
|
-
text: z.string()
|
|
10851
|
+
text: z.string(),
|
|
10852
|
+
/**
|
|
10853
|
+
* Who sent it, as a message's sender
|
|
10854
|
+
* (`crates/conversation-lane-protocol/src/client.rs`).
|
|
10855
|
+
*/
|
|
10856
|
+
senderId: z.string().min(1).max(255).nullable().optional()
|
|
10456
10857
|
});
|
|
10457
10858
|
/**
|
|
10458
10859
|
* What a message to a subagent answers: its id, the one it named or the one
|
|
@@ -10689,7 +11090,11 @@ z.strictObject({
|
|
|
10689
11090
|
modelId: z.string().optional(),
|
|
10690
11091
|
credentialId: z.string().min(1).optional()
|
|
10691
11092
|
});
|
|
10692
|
-
|
|
11093
|
+
/**
|
|
11094
|
+
* What a test found. A test that ran and failed is a result, with the
|
|
11095
|
+
* provider's own reason.
|
|
11096
|
+
*/
|
|
11097
|
+
const testResultSchema = z.discriminatedUnion("type", [z.object({
|
|
10693
11098
|
type: z.literal("passed"),
|
|
10694
11099
|
model: z.string()
|
|
10695
11100
|
}), z.object({
|
|
@@ -10774,7 +11179,74 @@ const turnStateSchema = z.discriminatedUnion("state", [
|
|
|
10774
11179
|
outcome: turnOutcomeSchema
|
|
10775
11180
|
})
|
|
10776
11181
|
]);
|
|
10777
|
-
|
|
11182
|
+
/** Amounts by currency; a currency no call cost in is absent. */
|
|
11183
|
+
const usageCostsSchema = z.object({
|
|
11184
|
+
usd: z.number().nullable().optional(),
|
|
11185
|
+
cny: z.number().nullable().optional()
|
|
11186
|
+
});
|
|
11187
|
+
/**
|
|
11188
|
+
* The calls of a bucket that share each of the report's dimensions, which
|
|
11189
|
+
* it names; a dimension the report does not group by is absent, and one
|
|
11190
|
+
* a call has no value of, such as the sender of a title's call, is null.
|
|
11191
|
+
*/
|
|
11192
|
+
const usageReportGroupSchema = z.object({
|
|
11193
|
+
conversation: z.string().nullable().optional(),
|
|
11194
|
+
agent: z.int().min(0).nullable().optional(),
|
|
11195
|
+
sender: z.string().nullable().optional(),
|
|
11196
|
+
model: z.string().nullable().optional(),
|
|
11197
|
+
provider: z.string().nullable().optional(),
|
|
11198
|
+
account: z.string().nullable().optional(),
|
|
11199
|
+
turn: z.string().nullable().optional(),
|
|
11200
|
+
assignment: z.string().nullable().optional(),
|
|
11201
|
+
purpose: z.string().nullable().optional(),
|
|
11202
|
+
calls: z.int().min(0),
|
|
11203
|
+
inputTokens: z.int().min(0),
|
|
11204
|
+
outputTokens: z.int().min(0),
|
|
11205
|
+
cacheReadTokens: z.int().min(0),
|
|
11206
|
+
cacheWriteTokens: z.int().min(0),
|
|
11207
|
+
/** What the vendors said the calls cost, by currency, never converted. */
|
|
11208
|
+
cost: usageCostsSchema,
|
|
11209
|
+
/**
|
|
11210
|
+
* What the calls' tokens would cost at their models' API prices, in
|
|
11211
|
+
* dollars, as each row fixed it when it was written.
|
|
11212
|
+
*/
|
|
11213
|
+
apiPrice: z.number(),
|
|
11214
|
+
/**
|
|
11215
|
+
* The calls whose tokens `api_price` leaves out, their model having no
|
|
11216
|
+
* price for a kind they used. A call the vendor counted no tokens
|
|
11217
|
+
* for, as a refused one, is none of them.
|
|
11218
|
+
*/
|
|
11219
|
+
unpricedCalls: z.int().min(0)
|
|
11220
|
+
});
|
|
11221
|
+
/** One minute, hour or day of a report, and its calls' groups. */
|
|
11222
|
+
const usageBucketSchema = z.object({
|
|
11223
|
+
start: z.iso.datetime({ precision: 3 }),
|
|
11224
|
+
end: z.iso.datetime({ precision: 3 }),
|
|
11225
|
+
groups: z.array(usageReportGroupSchema)
|
|
11226
|
+
});
|
|
11227
|
+
z.enum([
|
|
11228
|
+
"minute",
|
|
11229
|
+
"hour",
|
|
11230
|
+
"day"
|
|
11231
|
+
]);
|
|
11232
|
+
z.enum([
|
|
11233
|
+
"conversation",
|
|
11234
|
+
"model",
|
|
11235
|
+
"provider",
|
|
11236
|
+
"turn",
|
|
11237
|
+
"agent",
|
|
11238
|
+
"sender",
|
|
11239
|
+
"account",
|
|
11240
|
+
"assignment",
|
|
11241
|
+
"purpose"
|
|
11242
|
+
]);
|
|
11243
|
+
/**
|
|
11244
|
+
* `GET /usage/report`: each bucket of the period that holds a call, oldest
|
|
11245
|
+
* first; the first and the last start and end with the period.
|
|
11246
|
+
*/
|
|
11247
|
+
const usageReportSchema = z.object({ buckets: z.array(usageBucketSchema) });
|
|
11248
|
+
/** `GET /usage`: the caller's totals. */
|
|
11249
|
+
const usageTotalsSchema = z.object({ totals: z.array(usageGroupSchema) });
|
|
10778
11250
|
z.strictObject({
|
|
10779
11251
|
role: newRoleSchema.nullable().optional(),
|
|
10780
11252
|
disabled: z.boolean().nullable().optional(),
|
|
@@ -10805,7 +11277,12 @@ const vendorSchema = z.object({
|
|
|
10805
11277
|
baseUrl: z.string().nullable(),
|
|
10806
11278
|
doc: z.string().nullable()
|
|
10807
11279
|
});
|
|
10808
|
-
|
|
11280
|
+
/**
|
|
11281
|
+
* `GET /providers/catalog`: what the page can add, the same for every user
|
|
11282
|
+
* of a backend. The page reads it once per backend version, so a vendor
|
|
11283
|
+
* models.dev adds meanwhile is offered from the next version on.
|
|
11284
|
+
*/
|
|
11285
|
+
const vendorCatalogSchema = z.object({
|
|
10809
11286
|
/** Each subscription family. */
|
|
10810
11287
|
subscriptions: z.array(subscriptionFamilySchema),
|
|
10811
11288
|
/** The models.dev vendors a family speaks to, by name. */
|
|
@@ -10818,7 +11295,8 @@ z.object({
|
|
|
10818
11295
|
ok: z.boolean(),
|
|
10819
11296
|
id: z.int().min(0).max(4294967295)
|
|
10820
11297
|
});
|
|
10821
|
-
|
|
11298
|
+
/** `GET /conversations/:id/agents/:node/blocks/:blockId`: a block whole. */
|
|
11299
|
+
const wholeBlockSchema = z.object({
|
|
10822
11300
|
block: blockSchema,
|
|
10823
11301
|
failures: z.record(z.string(), providerFailureFactsSchema).optional()
|
|
10824
11302
|
});
|
|
@@ -10857,7 +11335,11 @@ const workChangeSchema = z.discriminatedUnion("op", [
|
|
|
10857
11335
|
]);
|
|
10858
11336
|
z.strictObject({ changes: z.array(workChangeSchema).min(1) });
|
|
10859
11337
|
z.object({ count: z.int().min(0).max(4294967295) });
|
|
10860
|
-
|
|
11338
|
+
/**
|
|
11339
|
+
* `GET .../changes`: the runner's list of uncommitted changes, and the
|
|
11340
|
+
* directory its paths are relative to.
|
|
11341
|
+
*/
|
|
11342
|
+
const workingTreeChangesSchema = z.object({
|
|
10861
11343
|
root: z.string(),
|
|
10862
11344
|
repository: z.boolean(),
|
|
10863
11345
|
/**
|
|
@@ -10872,13 +11354,15 @@ z.object({
|
|
|
10872
11354
|
truncated: z.boolean(),
|
|
10873
11355
|
watched: z.boolean()
|
|
10874
11356
|
});
|
|
10875
|
-
|
|
11357
|
+
/** `{ workspace }`: the answer of a creation and a change. */
|
|
11358
|
+
const workspaceAnswerSchema = z.object({ workspace: workspaceDtoSchema });
|
|
10876
11359
|
z.strictObject({
|
|
10877
11360
|
conversations: z.array(z.string().regex(/* @__PURE__ */ new RegExp("^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$", "u"))).optional(),
|
|
10878
11361
|
projects: z.array(z.string().min(1)).optional()
|
|
10879
11362
|
});
|
|
10880
11363
|
z.strictObject({ ids: z.array(z.string().min(1)).min(1) });
|
|
10881
|
-
|
|
11364
|
+
/** `GET /workspaces`: the user's workspaces, in their order. */
|
|
11365
|
+
const workspacesSchema = z.object({ workspaces: z.array(workspaceDtoSchema) });
|
|
10882
11366
|
z.strictObject({ end: z.boolean() });
|
|
10883
11367
|
//#endregion
|
|
10884
11368
|
//#region ../protocol/src/product-state.ts
|
|
@@ -11555,13 +12039,14 @@ var ConversationClient = class {
|
|
|
11555
12039
|
* the transcript or the queue. The wait has no deadline of its own: the
|
|
11556
12040
|
* backend decides that a delivery failed, and says why.
|
|
11557
12041
|
*/
|
|
11558
|
-
submit(content, messageId = createId(), comments = []) {
|
|
12042
|
+
submit(content, messageId = createId(), comments = [], senderId) {
|
|
11559
12043
|
let at;
|
|
11560
12044
|
return this.request({
|
|
11561
12045
|
type: "send",
|
|
11562
12046
|
messageId,
|
|
11563
12047
|
content,
|
|
11564
|
-
...comments.length > 0 ? { comments: [...comments] } : {}
|
|
12048
|
+
...comments.length > 0 ? { comments: [...comments] } : {},
|
|
12049
|
+
...senderId === void 0 ? {} : { senderId }
|
|
11565
12050
|
}, (event) => {
|
|
11566
12051
|
if (event.type === "send_result" && event.messageId === messageId) at = event.at;
|
|
11567
12052
|
if (at !== void 0 && this.holdsVersion(at)) return { resolve: void 0 };
|
|
@@ -11677,13 +12162,14 @@ var ConversationClient = class {
|
|
|
11677
12162
|
* version the answer names, which shows the steer, and rejects with
|
|
11678
12163
|
* `SteerRejectedError` when the session refuses it.
|
|
11679
12164
|
*/
|
|
11680
|
-
steer(content, steerId = createId(), comments = []) {
|
|
12165
|
+
steer(content, steerId = createId(), comments = [], senderId) {
|
|
11681
12166
|
let at;
|
|
11682
12167
|
return this.request({
|
|
11683
12168
|
type: "steer",
|
|
11684
12169
|
steerId,
|
|
11685
12170
|
content,
|
|
11686
|
-
...comments.length > 0 ? { comments: [...comments] } : {}
|
|
12171
|
+
...comments.length > 0 ? { comments: [...comments] } : {},
|
|
12172
|
+
...senderId === void 0 ? {} : { senderId }
|
|
11687
12173
|
}, (event) => {
|
|
11688
12174
|
if (event.type === "steer_result" && event.steerId === steerId) {
|
|
11689
12175
|
if (event.outcome.status !== "accepted") return { reject: new SteerRejectedError(event.outcome) };
|
|
@@ -13617,7 +14103,7 @@ var CoreRoutes = class {
|
|
|
13617
14103
|
}
|
|
13618
14104
|
/** The process's path of the core's route `path`, such as `/conversations`. */
|
|
13619
14105
|
path(path) {
|
|
13620
|
-
return `/cores/${
|
|
14106
|
+
return `/cores/${segment(this.id)}/api${path}`;
|
|
13621
14107
|
}
|
|
13622
14108
|
/**
|
|
13623
14109
|
* Calls the route `path` with `body`, a `Blob` as its bytes of its type
|
|
@@ -13655,272 +14141,751 @@ var CoreRoutes = class {
|
|
|
13655
14141
|
async send(method, path, body) {
|
|
13656
14142
|
await (await this.request(method, path, body)).body?.cancel();
|
|
13657
14143
|
}
|
|
14144
|
+
/** The bytes the route `path` answers. */
|
|
14145
|
+
async bytes(method, path, body, signal) {
|
|
14146
|
+
const response = await this.request(method, path, body, signal);
|
|
14147
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
14148
|
+
}
|
|
14149
|
+
/** Each JSON value the route `path` answers, one a line, read with `schema` as it comes. */
|
|
14150
|
+
async *lines(method, path, schema, body, signal) {
|
|
14151
|
+
const response = await this.request(method, path, body, signal);
|
|
14152
|
+
if (response.body === null) return;
|
|
14153
|
+
const decoder = new TextDecoder();
|
|
14154
|
+
let held = "";
|
|
14155
|
+
for await (const chunk of response.body) {
|
|
14156
|
+
held += decoder.decode(chunk, { stream: true });
|
|
14157
|
+
let end = held.indexOf("\n");
|
|
14158
|
+
while (end >= 0) {
|
|
14159
|
+
const line = held.slice(0, end).trim();
|
|
14160
|
+
held = held.slice(end + 1);
|
|
14161
|
+
if (line !== "") yield parsed(schema, line);
|
|
14162
|
+
end = held.indexOf("\n");
|
|
14163
|
+
}
|
|
14164
|
+
}
|
|
14165
|
+
const last = (held + decoder.decode()).trim();
|
|
14166
|
+
if (last !== "") yield parsed(schema, last);
|
|
14167
|
+
}
|
|
13658
14168
|
};
|
|
14169
|
+
/** `line`, one JSON value, read with `schema`. */
|
|
14170
|
+
function parsed(schema, line) {
|
|
14171
|
+
const read = schema.safeParse(JSON.parse(line));
|
|
14172
|
+
if (!read.success) throw new Error(schemaRefusal(read.error));
|
|
14173
|
+
return read.data;
|
|
14174
|
+
}
|
|
14175
|
+
/** The query of `values`, `?a=1&b=x`, leaving out each one undefined; empty for none. */
|
|
14176
|
+
function query(values) {
|
|
14177
|
+
const search = new URLSearchParams();
|
|
14178
|
+
for (const [name, value] of Object.entries(values)) if (value !== void 0) search.set(name, String(value));
|
|
14179
|
+
const text = search.toString();
|
|
14180
|
+
return text === "" ? "" : `?${text}`;
|
|
14181
|
+
}
|
|
14182
|
+
/** `segment` as one segment of a route's path. */
|
|
14183
|
+
const segment = encodeURIComponent;
|
|
13659
14184
|
//#endregion
|
|
13660
|
-
//#region src/
|
|
14185
|
+
//#region src/files.ts
|
|
13661
14186
|
/**
|
|
13662
|
-
*
|
|
13663
|
-
*
|
|
13664
|
-
* core's routes, holds the root's transcript with the one patch applier, and
|
|
13665
|
-
* sends what the program asks.
|
|
13666
|
-
*
|
|
13667
|
-
* `run(input)` sends a message and waits for the turn it starts to end, as
|
|
13668
|
-
* the Codex SDK's `thread.run`; `events()` is everything the conversation's
|
|
13669
|
-
* lane tells, as an async iterator, with a `permission` event for each
|
|
13670
|
-
* request the conversation's metadata adds.
|
|
14187
|
+
* The files of a conversation's devices and the working tree's changes, as
|
|
14188
|
+
* the conversation's Files and Changes show them.
|
|
13671
14189
|
*/
|
|
13672
|
-
|
|
13673
|
-
id
|
|
13674
|
-
|
|
13675
|
-
|
|
13676
|
-
|
|
13677
|
-
|
|
13678
|
-
|
|
13679
|
-
|
|
13680
|
-
|
|
13681
|
-
|
|
13682
|
-
|
|
13683
|
-
|
|
13684
|
-
|
|
13685
|
-
|
|
13686
|
-
|
|
13687
|
-
|
|
13688
|
-
|
|
13689
|
-
|
|
13690
|
-
|
|
13691
|
-
|
|
13692
|
-
|
|
13693
|
-
|
|
13694
|
-
|
|
13695
|
-
|
|
13696
|
-
|
|
13697
|
-
|
|
13698
|
-
|
|
13699
|
-
|
|
13700
|
-
|
|
13701
|
-
|
|
13702
|
-
|
|
13703
|
-
|
|
14190
|
+
function conversationFiles(routes, id) {
|
|
14191
|
+
const base = `/conversations/${segment(id)}`;
|
|
14192
|
+
return {
|
|
14193
|
+
list: (options = {}) => routes.json("GET", `${options.device === void 0 ? `${base}/fs` : `${base}/devices/${segment(options.device)}/fs`}${query({ path: options.path })}`, directorySchema),
|
|
14194
|
+
lists: (paths) => routes.json("POST", `${base}/fs/lists`, listedDirectoriesSchema, { paths }),
|
|
14195
|
+
read: (path) => routes.json("GET", `${base}/fs/file${query({ path })}`, fileTextSchema),
|
|
14196
|
+
readBytes: (path) => routes.bytes("GET", `${base}/fs/raw${query({ path })}`),
|
|
14197
|
+
write: (path, bytes, options = {}) => routes.send("PUT", `${base}/fs/raw${query({
|
|
14198
|
+
path,
|
|
14199
|
+
replace: options.replace
|
|
14200
|
+
})}`, bytes instanceof Blob ? bytes : new Blob([bytes])),
|
|
14201
|
+
makeDirectory: (path, options = {}) => routes.json("POST", options.device === void 0 ? `${base}/fs` : `${base}/devices/${segment(options.device)}/fs`, createdDirectorySchema, { path }),
|
|
14202
|
+
remove: (path) => routes.send("DELETE", `${base}/fs${query({ path })}`),
|
|
14203
|
+
search: (request, signal) => routes.lines("POST", `${base}/fs/search`, searchLineSchema, request, signal)
|
|
14204
|
+
};
|
|
14205
|
+
}
|
|
14206
|
+
function conversationChanges(routes, id) {
|
|
14207
|
+
const base = `/conversations/${segment(id)}/changes`;
|
|
14208
|
+
return {
|
|
14209
|
+
status: (options = {}) => routes.json("GET", `${base}${query({ directory: options.directory })}`, workingTreeChangesSchema),
|
|
14210
|
+
file: (path, options = {}) => routes.json("GET", `${base}/file${query({
|
|
14211
|
+
path,
|
|
14212
|
+
...options
|
|
14213
|
+
})}`, changeSidesSchema),
|
|
14214
|
+
committed: (path, options = {}) => routes.bytes("GET", `${base}/raw${query({
|
|
14215
|
+
path,
|
|
14216
|
+
...options
|
|
14217
|
+
})}`),
|
|
14218
|
+
branches: (options = {}) => routes.json("GET", `${base}/branches${query({ directory: options.directory })}`, gitBranchesSchema),
|
|
14219
|
+
repositories: (paths) => routes.json("POST", `${base}/repositories`, gitRepositoriesSchema, { paths }),
|
|
14220
|
+
log: (options = {}) => routes.json("GET", `${base}/log${query({ ...options })}`, gitLogSchema),
|
|
14221
|
+
show: (commit, options = {}) => routes.json("GET", `${base}/commit${query({
|
|
14222
|
+
commit,
|
|
14223
|
+
directory: options.directory
|
|
14224
|
+
})}`, gitCommitSchema)
|
|
14225
|
+
};
|
|
14226
|
+
}
|
|
14227
|
+
function deviceFiles(routes, id) {
|
|
14228
|
+
const base = `/devices/${segment(id)}/fs`;
|
|
14229
|
+
return {
|
|
14230
|
+
list: (path) => routes.json("GET", `${base}${query({ path })}`, directorySchema),
|
|
14231
|
+
makeDirectory: (path) => routes.json("POST", base, createdDirectorySchema, { path })
|
|
14232
|
+
};
|
|
14233
|
+
}
|
|
14234
|
+
//#endregion
|
|
14235
|
+
//#region src/history.ts
|
|
14236
|
+
/**
|
|
14237
|
+
* What a conversation holds beyond its lane's window: any agent's
|
|
14238
|
+
* transcript by pages, a whole block, a turn, and a command and its output.
|
|
14239
|
+
*/
|
|
14240
|
+
function conversationHistory(routes, id) {
|
|
14241
|
+
const base = `/conversations/${segment(id)}`;
|
|
14242
|
+
return {
|
|
14243
|
+
transcript: (agent, page) => {
|
|
14244
|
+
const values = "latest" in page ? {
|
|
14245
|
+
latest: true,
|
|
14246
|
+
blocks: page.blocks
|
|
14247
|
+
} : "around" in page ? { around: page.around } : "before" in page ? {
|
|
14248
|
+
before: page.before,
|
|
14249
|
+
edge: page.edge
|
|
14250
|
+
} : {
|
|
14251
|
+
after: page.after,
|
|
14252
|
+
edge: page.edge
|
|
14253
|
+
};
|
|
14254
|
+
return routes.json("GET", `${base}/agents/${segment(agent)}/transcript${query(values)}`, transcriptPageSchema);
|
|
14255
|
+
},
|
|
14256
|
+
block: (agent, block) => routes.json("GET", `${base}/agents/${segment(agent)}/blocks/${segment(block)}`, wholeBlockSchema),
|
|
14257
|
+
turn: (turn) => routes.json("GET", `${base}/turns/${segment(turn)}`, turnStateSchema),
|
|
14258
|
+
commandOrigin: (command) => routes.json("GET", `${base}/commands/${segment(command)}`, commandOriginSchema),
|
|
14259
|
+
commandOutput: (command) => routes.json("GET", `${base}/commands/${segment(command)}/output`, endedOutputSchema)
|
|
14260
|
+
};
|
|
14261
|
+
}
|
|
14262
|
+
//#endregion
|
|
14263
|
+
//#region src/input.ts
|
|
14264
|
+
/** `input` as content blocks. */
|
|
14265
|
+
function content(input) {
|
|
14266
|
+
return typeof input === "string" ? [{
|
|
14267
|
+
type: "text",
|
|
14268
|
+
text: input
|
|
14269
|
+
}] : input;
|
|
14270
|
+
}
|
|
14271
|
+
//#endregion
|
|
14272
|
+
//#region src/socket.ts
|
|
14273
|
+
/**
|
|
14274
|
+
* A WebSocket on a stream of the process's HTTP/2 connection (RFC 8441):
|
|
14275
|
+
* the stream is the socket's, and its bytes are WebSocket frames (RFC 6455),
|
|
14276
|
+
* which Node's `http2` does not write, so this module does. A client masks
|
|
14277
|
+
* each frame it sends; the process's frames come unmasked.
|
|
14278
|
+
*
|
|
14279
|
+
* It has the part of a browser's `WebSocket` the page connection and a
|
|
14280
|
+
* forwarded page's socket use: `send`, `close`, `bufferedAmount`,
|
|
14281
|
+
* `binaryType`, and the `open`, `message` and `close` events.
|
|
14282
|
+
*/
|
|
14283
|
+
const TEXT = 1;
|
|
14284
|
+
const BINARY = 2;
|
|
14285
|
+
const CLOSE = 8;
|
|
14286
|
+
const PING = 9;
|
|
14287
|
+
const PONG = 10;
|
|
14288
|
+
const CONTINUATION = 0;
|
|
14289
|
+
/** The close of a socket that ended without a close frame. */
|
|
14290
|
+
const ABNORMAL_CLOSURE = 1006;
|
|
14291
|
+
/** The close frame's code when it carries none. */
|
|
14292
|
+
const NO_STATUS = 1005;
|
|
14293
|
+
/** A WebSocket on the stream `opening` answers once the process took it. */
|
|
14294
|
+
var StreamSocket = class {
|
|
14295
|
+
binaryType = "arraybuffer";
|
|
14296
|
+
stream = null;
|
|
14297
|
+
listeners = /* @__PURE__ */ new Map();
|
|
14298
|
+
/** The bytes read that do not make a whole frame yet. */
|
|
14299
|
+
pending = /* @__PURE__ */ new Uint8Array(0);
|
|
14300
|
+
/** The fragments of a message whose last frame has not come. */
|
|
14301
|
+
fragments = null;
|
|
14302
|
+
closed = false;
|
|
14303
|
+
/** Whether this end sent its close frame. */
|
|
14304
|
+
closing = false;
|
|
14305
|
+
constructor(opening) {
|
|
14306
|
+
opening.then((stream) => {
|
|
14307
|
+
if (this.closed) {
|
|
14308
|
+
stream.close();
|
|
14309
|
+
return;
|
|
13704
14310
|
}
|
|
13705
|
-
|
|
14311
|
+
this.stream = stream;
|
|
14312
|
+
stream.on("data", (chunk) => this.read(chunk));
|
|
14313
|
+
stream.once("close", () => this.ended(ABNORMAL_CLOSURE, ""));
|
|
14314
|
+
stream.on("error", () => {});
|
|
14315
|
+
this.emit("open");
|
|
14316
|
+
}, () => this.ended(ABNORMAL_CLOSURE, ""));
|
|
13706
14317
|
}
|
|
13707
|
-
/**
|
|
13708
|
-
|
|
13709
|
-
|
|
13710
|
-
this.opening = null;
|
|
13711
|
-
throw error;
|
|
13712
|
-
});
|
|
13713
|
-
return this.opening;
|
|
14318
|
+
/** The bytes sent that the stream has not written yet. */
|
|
14319
|
+
get bufferedAmount() {
|
|
14320
|
+
return this.stream?.writableLength ?? 0;
|
|
13714
14321
|
}
|
|
13715
|
-
|
|
13716
|
-
|
|
13717
|
-
|
|
13718
|
-
|
|
13719
|
-
|
|
13720
|
-
const detail = await this.routes.json("GET", path, conversationDetailSchema, void 0, signal);
|
|
13721
|
-
this.takeMetadata(detail.metadata);
|
|
13722
|
-
return {
|
|
13723
|
-
agents: detail.agents,
|
|
13724
|
-
entries: detail.entries,
|
|
13725
|
-
tags: { metadata: detail.metadataTag }
|
|
13726
|
-
};
|
|
13727
|
-
},
|
|
13728
|
-
transcript: async (node, signal) => {
|
|
13729
|
-
const page = await this.routes.json("GET", `${path}/agents/${encodeURIComponent(node)}/transcript?latest=true`, transcriptPageSchema, void 0, signal);
|
|
13730
|
-
if (!page.version) throw new Error("The latest page names no version of its transcript");
|
|
13731
|
-
return {
|
|
13732
|
-
...page,
|
|
13733
|
-
version: page.version
|
|
13734
|
-
};
|
|
13735
|
-
}
|
|
13736
|
-
},
|
|
13737
|
-
shows: (node) => node === null || node === this.id,
|
|
13738
|
-
conversationFrame: (frame) => {
|
|
13739
|
-
const parsed = conversationFrameSchema.safeParse(frame);
|
|
13740
|
-
if (!parsed.success) return null;
|
|
13741
|
-
const data = parsed.data;
|
|
13742
|
-
if (data.type === "conversation") return {
|
|
13743
|
-
apply: () => this.takeMetadata(data.metadata),
|
|
13744
|
-
tagged: {
|
|
13745
|
-
value: "metadata",
|
|
13746
|
-
tag: data.etag
|
|
13747
|
-
}
|
|
13748
|
-
};
|
|
13749
|
-
return { apply: () => {} };
|
|
13750
|
-
}
|
|
13751
|
-
});
|
|
13752
|
-
client.subscribe((event) => this.receive(event));
|
|
13753
|
-
this.client = client;
|
|
13754
|
-
try {
|
|
13755
|
-
await client.open({ root: this.id });
|
|
13756
|
-
} catch (error) {
|
|
13757
|
-
client.dispose();
|
|
13758
|
-
if (this.client === client) this.client = null;
|
|
13759
|
-
throw error;
|
|
14322
|
+
addEventListener(type, listener) {
|
|
14323
|
+
let set = this.listeners.get(type);
|
|
14324
|
+
if (!set) {
|
|
14325
|
+
set = /* @__PURE__ */ new Set();
|
|
14326
|
+
this.listeners.set(type, set);
|
|
13760
14327
|
}
|
|
13761
|
-
|
|
14328
|
+
set.add(listener);
|
|
13762
14329
|
}
|
|
13763
|
-
|
|
13764
|
-
|
|
13765
|
-
case "closed":
|
|
13766
|
-
case "disconnected":
|
|
13767
|
-
this.reopen();
|
|
13768
|
-
break;
|
|
13769
|
-
case "transcript_reset":
|
|
13770
|
-
if (event.node === this.id) this.transcript = resetTranscript(this.transcript, event, event.asked);
|
|
13771
|
-
break;
|
|
13772
|
-
case "transcript_patch": if (event.node === this.id) this.transcript = applyTranscriptPatches(this.transcript, event.patches, performance.now(), event.version);
|
|
13773
|
-
}
|
|
13774
|
-
this.emit(event);
|
|
13775
|
-
this.changed();
|
|
14330
|
+
removeEventListener(type, listener) {
|
|
14331
|
+
this.listeners.get(type)?.delete(listener);
|
|
13776
14332
|
}
|
|
13777
|
-
/**
|
|
13778
|
-
|
|
13779
|
-
|
|
13780
|
-
|
|
13781
|
-
|
|
13782
|
-
|
|
14333
|
+
/** Sends a message: text for a string, binary for bytes. */
|
|
14334
|
+
send(data) {
|
|
14335
|
+
if (typeof data === "string") this.write(TEXT, new TextEncoder().encode(data));
|
|
14336
|
+
else this.write(BINARY, data instanceof ArrayBuffer ? new Uint8Array(data) : data);
|
|
14337
|
+
}
|
|
14338
|
+
/** Closes the socket with `code` and `reason`; its `close` event follows. */
|
|
14339
|
+
close(code = 1e3, reason = "") {
|
|
14340
|
+
if (this.closed || this.closing) return;
|
|
14341
|
+
this.closing = true;
|
|
14342
|
+
if (this.stream === null) {
|
|
14343
|
+
this.ended(ABNORMAL_CLOSURE, "");
|
|
13783
14344
|
return;
|
|
13784
14345
|
}
|
|
13785
|
-
|
|
13786
|
-
const
|
|
13787
|
-
|
|
13788
|
-
|
|
13789
|
-
|
|
13790
|
-
|
|
13791
|
-
await client.reopened();
|
|
13792
|
-
if (!this.droppedAgain) return client;
|
|
13793
|
-
} catch (error) {
|
|
13794
|
-
if (this.client !== client) throw error;
|
|
13795
|
-
await new Promise((resolve) => setTimeout(resolve, reconnectWait(failures)));
|
|
13796
|
-
}
|
|
13797
|
-
} finally {
|
|
13798
|
-
this.reopening = false;
|
|
13799
|
-
this.changed();
|
|
13800
|
-
}
|
|
13801
|
-
})();
|
|
13802
|
-
this.opening = opening;
|
|
13803
|
-
opening.catch(() => {});
|
|
14346
|
+
const text = new TextEncoder().encode(reason);
|
|
14347
|
+
const body = new Uint8Array(2 + text.length);
|
|
14348
|
+
new DataView(body.buffer).setUint16(0, code);
|
|
14349
|
+
body.set(text, 2);
|
|
14350
|
+
this.write(CLOSE, body);
|
|
14351
|
+
this.stream.end();
|
|
13804
14352
|
}
|
|
13805
|
-
|
|
13806
|
-
this.
|
|
13807
|
-
|
|
13808
|
-
|
|
13809
|
-
|
|
13810
|
-
|
|
13811
|
-
|
|
13812
|
-
|
|
14353
|
+
emit(type, ...event) {
|
|
14354
|
+
for (const listener of [...this.listeners.get(type) ?? []]) listener(...event);
|
|
14355
|
+
}
|
|
14356
|
+
/** Writes one frame of `opcode` with `payload`, masked. */
|
|
14357
|
+
write(opcode, payload) {
|
|
14358
|
+
const stream = this.stream;
|
|
14359
|
+
if (stream === null || this.closed || stream.destroyed) return;
|
|
14360
|
+
const length = payload.length;
|
|
14361
|
+
const extended = length < 126 ? 0 : length < 65536 ? 2 : 8;
|
|
14362
|
+
const frame = new Uint8Array(2 + extended + 4 + length);
|
|
14363
|
+
const view = new DataView(frame.buffer);
|
|
14364
|
+
frame[0] = 128 | opcode;
|
|
14365
|
+
if (extended === 0) frame[1] = 128 | length;
|
|
14366
|
+
else if (extended === 2) {
|
|
14367
|
+
frame[1] = 254;
|
|
14368
|
+
view.setUint16(2, length);
|
|
14369
|
+
} else {
|
|
14370
|
+
frame[1] = 255;
|
|
14371
|
+
view.setBigUint64(2, BigInt(length));
|
|
13813
14372
|
}
|
|
13814
|
-
|
|
14373
|
+
const at = 2 + extended;
|
|
14374
|
+
const mask = frame.subarray(at, at + 4);
|
|
14375
|
+
randomFillSync(mask);
|
|
14376
|
+
const body = frame.subarray(at + 4);
|
|
14377
|
+
for (let index = 0; index < length; index += 1) body[index] = payload[index] ^ mask[index & 3];
|
|
14378
|
+
stream.write(frame);
|
|
13815
14379
|
}
|
|
13816
|
-
|
|
13817
|
-
|
|
14380
|
+
/** Takes bytes of the stream, and handles each whole frame they complete. */
|
|
14381
|
+
read(chunk) {
|
|
14382
|
+
let bytes = this.pending.length === 0 ? chunk : concat([this.pending, chunk]);
|
|
14383
|
+
while (bytes.length >= 2) {
|
|
14384
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
14385
|
+
const fin = (bytes[0] & 128) !== 0;
|
|
14386
|
+
const opcode = bytes[0] & 15;
|
|
14387
|
+
let length = bytes[1] & 127;
|
|
14388
|
+
let at = 2;
|
|
14389
|
+
if (length === 126) {
|
|
14390
|
+
if (bytes.length < 4) break;
|
|
14391
|
+
length = view.getUint16(2);
|
|
14392
|
+
at = 4;
|
|
14393
|
+
} else if (length === 127) {
|
|
14394
|
+
if (bytes.length < 10) break;
|
|
14395
|
+
length = Number(view.getBigUint64(2));
|
|
14396
|
+
at = 10;
|
|
14397
|
+
}
|
|
14398
|
+
if (bytes.length < at + length) break;
|
|
14399
|
+
const payload = bytes.slice(at, at + length);
|
|
14400
|
+
bytes = bytes.subarray(at + length);
|
|
14401
|
+
this.frame(fin, opcode, payload);
|
|
14402
|
+
}
|
|
14403
|
+
this.pending = bytes.slice();
|
|
13818
14404
|
}
|
|
13819
|
-
|
|
13820
|
-
|
|
13821
|
-
|
|
13822
|
-
|
|
13823
|
-
|
|
13824
|
-
|
|
13825
|
-
|
|
13826
|
-
|
|
13827
|
-
|
|
13828
|
-
|
|
13829
|
-
|
|
13830
|
-
|
|
13831
|
-
|
|
14405
|
+
frame(fin, opcode, payload) {
|
|
14406
|
+
switch (opcode) {
|
|
14407
|
+
case PING:
|
|
14408
|
+
this.write(PONG, payload);
|
|
14409
|
+
return;
|
|
14410
|
+
case PONG: return;
|
|
14411
|
+
case CLOSE: {
|
|
14412
|
+
const code = payload.length >= 2 ? new DataView(payload.buffer, payload.byteOffset).getUint16(0) : NO_STATUS;
|
|
14413
|
+
const reason = new TextDecoder().decode(payload.subarray(2));
|
|
14414
|
+
if (!this.closing) {
|
|
14415
|
+
this.closing = true;
|
|
14416
|
+
this.write(CLOSE, payload.subarray(0, 2));
|
|
14417
|
+
this.stream?.end();
|
|
14418
|
+
}
|
|
14419
|
+
this.ended(code, reason);
|
|
14420
|
+
return;
|
|
14421
|
+
}
|
|
14422
|
+
case CONTINUATION:
|
|
14423
|
+
if (this.fragments === null) return;
|
|
14424
|
+
this.fragments.parts.push(payload);
|
|
14425
|
+
if (fin) {
|
|
14426
|
+
const { opcode: first, parts } = this.fragments;
|
|
14427
|
+
this.fragments = null;
|
|
14428
|
+
this.message(first, concat(parts));
|
|
14429
|
+
}
|
|
14430
|
+
return;
|
|
14431
|
+
case TEXT:
|
|
14432
|
+
case BINARY: if (fin) this.message(opcode, payload);
|
|
14433
|
+
else this.fragments = {
|
|
14434
|
+
opcode,
|
|
14435
|
+
parts: [payload]
|
|
14436
|
+
};
|
|
14437
|
+
}
|
|
13832
14438
|
}
|
|
13833
|
-
|
|
13834
|
-
|
|
13835
|
-
|
|
14439
|
+
message(opcode, payload) {
|
|
14440
|
+
const data = opcode === TEXT ? new TextDecoder().decode(payload) : payload.buffer.slice(payload.byteOffset, payload.byteOffset + payload.byteLength);
|
|
14441
|
+
this.emit("message", { data });
|
|
13836
14442
|
}
|
|
13837
|
-
|
|
13838
|
-
|
|
13839
|
-
|
|
14443
|
+
ended(code, reason) {
|
|
14444
|
+
if (this.closed) return;
|
|
14445
|
+
this.closed = true;
|
|
14446
|
+
this.stream?.close();
|
|
14447
|
+
this.emit("close", {
|
|
14448
|
+
code,
|
|
14449
|
+
reason
|
|
14450
|
+
});
|
|
13840
14451
|
}
|
|
13841
|
-
|
|
13842
|
-
|
|
13843
|
-
|
|
13844
|
-
|
|
13845
|
-
|
|
13846
|
-
|
|
13847
|
-
|
|
14452
|
+
};
|
|
14453
|
+
function concat(parts) {
|
|
14454
|
+
const whole = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
14455
|
+
let at = 0;
|
|
14456
|
+
for (const part of parts) {
|
|
14457
|
+
whole.set(part, at);
|
|
14458
|
+
at += part.length;
|
|
13848
14459
|
}
|
|
13849
|
-
|
|
13850
|
-
|
|
13851
|
-
|
|
13852
|
-
|
|
13853
|
-
|
|
13854
|
-
|
|
13855
|
-
|
|
14460
|
+
return whole;
|
|
14461
|
+
}
|
|
14462
|
+
//#endregion
|
|
14463
|
+
//#region src/page.ts
|
|
14464
|
+
/** The header that names the page's operations on the process's channel. */
|
|
14465
|
+
const OPERATIONS_HEADER = "jush-page-operations";
|
|
14466
|
+
/** A program's page of one conversation, which holds nothing: make one for each request. */
|
|
14467
|
+
var ConversationPage = class {
|
|
14468
|
+
routes;
|
|
14469
|
+
conversation;
|
|
14470
|
+
options;
|
|
14471
|
+
operations;
|
|
14472
|
+
constructor(routes, conversation, options) {
|
|
14473
|
+
this.routes = routes;
|
|
14474
|
+
this.conversation = conversation;
|
|
14475
|
+
this.options = options;
|
|
14476
|
+
this.operations = options.allow.join(",");
|
|
13856
14477
|
}
|
|
13857
|
-
/**
|
|
13858
|
-
|
|
13859
|
-
|
|
13860
|
-
|
|
13861
|
-
|
|
13862
|
-
|
|
13863
|
-
return this.routes.json("PATCH", `/conversations/${encodeURIComponent(this.id)}`, conversationUpdateSchema, patch);
|
|
14478
|
+
/** Answers one of the page's requests below `base`. */
|
|
14479
|
+
fetch(request) {
|
|
14480
|
+
const url = new URL(request.url);
|
|
14481
|
+
const forwarded = new Request(PROCESS_ORIGIN + this.path(below(url.pathname, this.options.base)) + url.search, request);
|
|
14482
|
+
forwarded.headers.set(OPERATIONS_HEADER, this.operations);
|
|
14483
|
+
return this.routes.process.fetch(forwarded);
|
|
13864
14484
|
}
|
|
13865
14485
|
/**
|
|
13866
|
-
*
|
|
13867
|
-
*
|
|
13868
|
-
*
|
|
13869
|
-
*
|
|
13870
|
-
* `messageId` is absent.
|
|
14486
|
+
* Carries the page's connection, `socket`, opened at `url` below `base`,
|
|
14487
|
+
* to the core, both ways, until either end closes; `socket` is a
|
|
14488
|
+
* WebSocket of the standard interface, as Deno's `upgradeWebSocket` and
|
|
14489
|
+
* the `ws` package give.
|
|
13871
14490
|
*/
|
|
13872
|
-
|
|
13873
|
-
const
|
|
13874
|
-
const
|
|
13875
|
-
|
|
13876
|
-
|
|
14491
|
+
accept(socket, url) {
|
|
14492
|
+
const query = new URL(url, PROCESS_ORIGIN).search;
|
|
14493
|
+
const core = new StreamSocket(this.routes.process.connect(this.path(`/connect${query}`), "websocket", {
|
|
14494
|
+
"sec-websocket-version": "13",
|
|
14495
|
+
[OPERATIONS_HEADER]: this.operations
|
|
14496
|
+
}));
|
|
14497
|
+
const early = [];
|
|
14498
|
+
let open = false;
|
|
14499
|
+
let pageClosed = false;
|
|
14500
|
+
socket.binaryType = "arraybuffer";
|
|
14501
|
+
socket.addEventListener("message", (event) => {
|
|
14502
|
+
const data = event.data;
|
|
14503
|
+
if (open) core.send(data);
|
|
14504
|
+
else early.push(data);
|
|
14505
|
+
});
|
|
14506
|
+
socket.addEventListener("close", () => {
|
|
14507
|
+
pageClosed = true;
|
|
14508
|
+
core.close();
|
|
14509
|
+
});
|
|
14510
|
+
core.addEventListener("open", () => {
|
|
14511
|
+
open = true;
|
|
14512
|
+
for (const data of early.splice(0)) core.send(data);
|
|
14513
|
+
});
|
|
14514
|
+
core.addEventListener("message", (event) => socket.send(event.data));
|
|
14515
|
+
core.addEventListener("close", (event) => {
|
|
14516
|
+
if (!pageClosed) socket.close(event.code === 1006 || event.code === 1005 ? 1011 : event.code, event.reason);
|
|
13877
14517
|
});
|
|
13878
|
-
return id;
|
|
13879
14518
|
}
|
|
13880
|
-
/**
|
|
13881
|
-
|
|
13882
|
-
|
|
13883
|
-
* `steerId`, which messages and steers share.
|
|
13884
|
-
*/
|
|
13885
|
-
async steer(input, steerId = randomUUID()) {
|
|
13886
|
-
await (await this.open()).steer(content(input), steerId);
|
|
14519
|
+
/** The process's path of the page's route `path`. */
|
|
14520
|
+
path(path) {
|
|
14521
|
+
return `/cores/${segment(this.routes.id)}/pages/${segment(this.conversation)}${path}`;
|
|
13887
14522
|
}
|
|
13888
|
-
|
|
13889
|
-
|
|
14523
|
+
};
|
|
14524
|
+
//#endregion
|
|
14525
|
+
//#region src/side-questions.ts
|
|
14526
|
+
/**
|
|
14527
|
+
* A conversation's side questions: a question about a passage of an answer,
|
|
14528
|
+
* which its own agent answers beside the conversation.
|
|
14529
|
+
*/
|
|
14530
|
+
function sideQuestions(routes, id) {
|
|
14531
|
+
const base = `/conversations/${segment(id)}/side-questions`;
|
|
14532
|
+
const one = (side) => `${base}/${segment(side)}`;
|
|
14533
|
+
return {
|
|
14534
|
+
ask: (question) => routes.json("POST", base, sideQuestionAnswerSchema, {
|
|
14535
|
+
...question,
|
|
14536
|
+
id: question.id ?? randomUUID(),
|
|
14537
|
+
question: content(question.question)
|
|
14538
|
+
}),
|
|
14539
|
+
followUp: (side, input, messageId = randomUUID(), options = {}) => routes.send("POST", `${one(side)}/messages`, {
|
|
14540
|
+
id: messageId,
|
|
14541
|
+
content: content(input),
|
|
14542
|
+
senderId: options.senderId
|
|
14543
|
+
}),
|
|
14544
|
+
retry: (side) => routes.send("POST", `${one(side)}/retry`),
|
|
14545
|
+
stop: (side) => routes.send("POST", `${one(side)}/stop`),
|
|
14546
|
+
fold: (side, folded) => routes.json("PATCH", one(side), sideQuestionAnswerSchema, { folded }),
|
|
14547
|
+
remove: (side) => routes.send("DELETE", one(side))
|
|
14548
|
+
};
|
|
14549
|
+
}
|
|
14550
|
+
//#endregion
|
|
14551
|
+
//#region src/conversation.ts
|
|
14552
|
+
/**
|
|
14553
|
+
* A conversation of a core, driven as the web app drives one: a
|
|
14554
|
+
* `ConversationClient` on the conversation's lane, which reads with the
|
|
14555
|
+
* core's routes, holds the root's transcript with the one patch applier, and
|
|
14556
|
+
* sends what the program asks.
|
|
14557
|
+
*
|
|
14558
|
+
* `run(input)` sends a message and waits for the turn it starts to end, as
|
|
14559
|
+
* the Codex SDK's `thread.run`; `events()` is everything the conversation's
|
|
14560
|
+
* lane tells, as an async iterator, with a `permission` event for each
|
|
14561
|
+
* request the conversation's metadata adds.
|
|
14562
|
+
*/
|
|
14563
|
+
var Conversation = class {
|
|
14564
|
+
id;
|
|
14565
|
+
routes;
|
|
14566
|
+
registry;
|
|
14567
|
+
client = null;
|
|
14568
|
+
opening = null;
|
|
14569
|
+
/** The root's transcript, as the lane keeps it. */
|
|
14570
|
+
transcript = EMPTY_TRANSCRIPT;
|
|
14571
|
+
metadata = null;
|
|
14572
|
+
/** The permission requests told already. */
|
|
14573
|
+
told = /* @__PURE__ */ new Set();
|
|
14574
|
+
listeners = /* @__PURE__ */ new Set();
|
|
14575
|
+
/** What waits for a change of the transcript or the metadata, and fails once the conversation closes. */
|
|
14576
|
+
waiters = /* @__PURE__ */ new Set();
|
|
14577
|
+
/** Whether the lane is being opened again after it dropped. */
|
|
14578
|
+
reopening = false;
|
|
14579
|
+
/** Whether the lane dropped again while it was being opened again. */
|
|
14580
|
+
droppedAgain = false;
|
|
14581
|
+
schedules;
|
|
14582
|
+
/** Any agent's transcript by pages, and the turns and commands it names. */
|
|
14583
|
+
history;
|
|
14584
|
+
sideQuestions;
|
|
14585
|
+
/** The files of the conversation's devices. */
|
|
14586
|
+
files;
|
|
14587
|
+
/** The working tree's changes. */
|
|
14588
|
+
changes;
|
|
14589
|
+
plugins;
|
|
14590
|
+
constructor(id, routes, registry) {
|
|
14591
|
+
this.id = id;
|
|
14592
|
+
this.routes = routes;
|
|
14593
|
+
this.registry = registry;
|
|
14594
|
+
this.history = conversationHistory(routes, id);
|
|
14595
|
+
this.sideQuestions = sideQuestions(routes, id);
|
|
14596
|
+
this.files = conversationFiles(routes, id);
|
|
14597
|
+
this.changes = conversationChanges(routes, id);
|
|
14598
|
+
const plugin = (name) => `/conversations/${segment(id)}/plugins/${segment(name)}`;
|
|
14599
|
+
this.plugins = {
|
|
14600
|
+
state: (name) => routes.json("GET", `${plugin(name)}/state`, pluginStateAnswerSchema),
|
|
14601
|
+
call: (name, method, input = {}, options = {}) => routes.json("POST", `${plugin(name)}/calls/${segment(method)}${query({ device: options.device })}`, z.unknown(), input)
|
|
14602
|
+
};
|
|
14603
|
+
const path = `/conversations/${segment(id)}/schedules`;
|
|
14604
|
+
const one = (schedule) => `${path}/${segment(schedule)}`;
|
|
14605
|
+
this.schedules = {
|
|
14606
|
+
create: (patch) => routes.json("POST", path, scheduleAnswerSchema, patch),
|
|
14607
|
+
get: (schedule) => routes.json("GET", one(schedule), scheduleDtoSchema),
|
|
14608
|
+
update: (schedule, patch) => routes.json("PATCH", one(schedule), scheduleAnswerSchema, patch),
|
|
14609
|
+
remove: (schedule) => routes.send("DELETE", one(schedule)),
|
|
14610
|
+
run: (schedule, task) => routes.json("POST", `${one(schedule)}/runs`, scheduleRunDtoSchema, task === void 0 ? {} : { task }),
|
|
14611
|
+
runs: async (schedule, before) => {
|
|
14612
|
+
return (await routes.json("GET", `${one(schedule)}/runs${query({ before })}`, scheduleRunsSchema)).runs;
|
|
14613
|
+
}
|
|
14614
|
+
};
|
|
13890
14615
|
}
|
|
13891
|
-
|
|
13892
|
-
|
|
14616
|
+
/** Opens the conversation's lane, once; each action opens it first. */
|
|
14617
|
+
open() {
|
|
14618
|
+
this.opening ??= this.connect().catch((error) => {
|
|
14619
|
+
this.opening = null;
|
|
14620
|
+
throw error;
|
|
14621
|
+
});
|
|
14622
|
+
return this.opening;
|
|
13893
14623
|
}
|
|
13894
|
-
async
|
|
13895
|
-
|
|
14624
|
+
async connect() {
|
|
14625
|
+
const path = `/conversations/${segment(this.id)}`;
|
|
14626
|
+
const client = createConversationClient(this.routes.connection, this.id, {
|
|
14627
|
+
reader: {
|
|
14628
|
+
conversation: async (signal) => {
|
|
14629
|
+
const detail = await this.routes.json("GET", path, conversationDetailSchema, void 0, signal);
|
|
14630
|
+
this.takeMetadata(detail.metadata);
|
|
14631
|
+
return {
|
|
14632
|
+
agents: detail.agents,
|
|
14633
|
+
entries: detail.entries,
|
|
14634
|
+
tags: { metadata: detail.metadataTag }
|
|
14635
|
+
};
|
|
14636
|
+
},
|
|
14637
|
+
transcript: async (node, signal) => {
|
|
14638
|
+
const page = await this.routes.json("GET", `${path}/agents/${segment(node)}/transcript${query({ latest: true })}`, transcriptPageSchema, void 0, signal);
|
|
14639
|
+
if (!page.version) throw new Error("The latest page names no version of its transcript");
|
|
14640
|
+
return {
|
|
14641
|
+
...page,
|
|
14642
|
+
version: page.version
|
|
14643
|
+
};
|
|
14644
|
+
}
|
|
14645
|
+
},
|
|
14646
|
+
shows: (node) => node === null || node === this.id,
|
|
14647
|
+
conversationFrame: (frame) => {
|
|
14648
|
+
const parsed = conversationFrameSchema.safeParse(frame);
|
|
14649
|
+
if (!parsed.success) return null;
|
|
14650
|
+
const data = parsed.data;
|
|
14651
|
+
if (data.type === "conversation") return {
|
|
14652
|
+
apply: () => this.takeMetadata(data.metadata),
|
|
14653
|
+
tagged: {
|
|
14654
|
+
value: "metadata",
|
|
14655
|
+
tag: data.etag
|
|
14656
|
+
}
|
|
14657
|
+
};
|
|
14658
|
+
return { apply: () => {} };
|
|
14659
|
+
}
|
|
14660
|
+
});
|
|
14661
|
+
client.subscribe((event) => this.receive(event));
|
|
14662
|
+
this.client = client;
|
|
14663
|
+
try {
|
|
14664
|
+
await client.open({ root: this.id });
|
|
14665
|
+
} catch (error) {
|
|
14666
|
+
client.dispose();
|
|
14667
|
+
if (this.client === client) this.client = null;
|
|
14668
|
+
throw error;
|
|
14669
|
+
}
|
|
14670
|
+
return client;
|
|
13896
14671
|
}
|
|
13897
|
-
|
|
13898
|
-
|
|
14672
|
+
receive(event) {
|
|
14673
|
+
switch (event.type) {
|
|
14674
|
+
case "closed":
|
|
14675
|
+
case "disconnected":
|
|
14676
|
+
this.reopen();
|
|
14677
|
+
break;
|
|
14678
|
+
case "transcript_reset":
|
|
14679
|
+
if (event.node === this.id) this.transcript = resetTranscript(this.transcript, event, event.asked);
|
|
14680
|
+
break;
|
|
14681
|
+
case "transcript_patch": if (event.node === this.id) this.transcript = applyTranscriptPatches(this.transcript, event.patches, performance.now(), event.version);
|
|
14682
|
+
}
|
|
14683
|
+
this.emit(event);
|
|
14684
|
+
this.changed();
|
|
13899
14685
|
}
|
|
13900
|
-
/**
|
|
13901
|
-
|
|
13902
|
-
|
|
13903
|
-
|
|
13904
|
-
|
|
14686
|
+
/** Opens the lane of the client again until it opens, unless the program closes the conversation first. */
|
|
14687
|
+
reopen() {
|
|
14688
|
+
const client = this.client;
|
|
14689
|
+
if (client === null) return;
|
|
14690
|
+
if (this.reopening) {
|
|
14691
|
+
this.droppedAgain = true;
|
|
14692
|
+
return;
|
|
14693
|
+
}
|
|
14694
|
+
this.reopening = true;
|
|
14695
|
+
const opening = (async () => {
|
|
14696
|
+
try {
|
|
14697
|
+
for (let failures = 0;; failures++) try {
|
|
14698
|
+
this.droppedAgain = false;
|
|
14699
|
+
await client.open({ root: this.id });
|
|
14700
|
+
await client.reopened();
|
|
14701
|
+
if (!this.droppedAgain) return client;
|
|
14702
|
+
} catch (error) {
|
|
14703
|
+
if (this.client !== client) throw error;
|
|
14704
|
+
await new Promise((resolve) => setTimeout(resolve, reconnectWait(failures)));
|
|
14705
|
+
}
|
|
14706
|
+
} finally {
|
|
14707
|
+
this.reopening = false;
|
|
14708
|
+
this.changed();
|
|
14709
|
+
}
|
|
14710
|
+
})();
|
|
14711
|
+
this.opening = opening;
|
|
14712
|
+
opening.catch(() => {});
|
|
14713
|
+
}
|
|
14714
|
+
takeMetadata(metadata) {
|
|
14715
|
+
this.metadata = metadata;
|
|
14716
|
+
for (const request of metadata.permissions.requests) if (!this.told.has(request.id)) {
|
|
14717
|
+
this.told.add(request.id);
|
|
14718
|
+
this.emit({
|
|
14719
|
+
type: "permission",
|
|
14720
|
+
permission: this.permission(request)
|
|
14721
|
+
});
|
|
14722
|
+
}
|
|
14723
|
+
this.changed();
|
|
14724
|
+
}
|
|
14725
|
+
changed() {
|
|
14726
|
+
for (const waiter of [...this.waiters]) waiter.changed();
|
|
14727
|
+
}
|
|
14728
|
+
permission(request) {
|
|
14729
|
+
const decide = (body) => this.routes.send("POST", `/conversations/${segment(this.id)}/permissions/requests/${segment(request.id)}`, body);
|
|
14730
|
+
return {
|
|
14731
|
+
request,
|
|
14732
|
+
allow: (values) => decide({
|
|
14733
|
+
decision: "allow",
|
|
14734
|
+
...values === void 0 ? {} : { credential: values }
|
|
14735
|
+
}),
|
|
14736
|
+
deny: () => decide({ decision: "deny" })
|
|
14737
|
+
};
|
|
14738
|
+
}
|
|
14739
|
+
emit(event) {
|
|
14740
|
+
for (const listener of [...this.listeners]) listener(event);
|
|
14741
|
+
}
|
|
14742
|
+
/** The permission requests waiting for a decision. */
|
|
14743
|
+
get permissions() {
|
|
14744
|
+
return (this.metadata?.permissions.requests ?? []).map((request) => this.permission(request));
|
|
14745
|
+
}
|
|
14746
|
+
/** The root's blocks the conversation holds, oldest first. */
|
|
14747
|
+
get blocks() {
|
|
14748
|
+
return heldBlocks(this.transcript);
|
|
14749
|
+
}
|
|
14750
|
+
/**
|
|
14751
|
+
* The conversation's agents as its lane holds them: the root's entry,
|
|
14752
|
+
* whose id is the conversation's, each subagent's, whose id `sendToAgent`
|
|
14753
|
+
* takes, and each side question's. Empty until the lane opens.
|
|
14754
|
+
*/
|
|
14755
|
+
get agents() {
|
|
14756
|
+
return this.client?.agentEntries() ?? [];
|
|
14757
|
+
}
|
|
14758
|
+
/**
|
|
14759
|
+
* Sends a message; resolves once it is in the transcript or the queue.
|
|
14760
|
+
* The conversation takes it once however often it is sent under
|
|
14761
|
+
* `messageId`, which messages and steers share.
|
|
14762
|
+
*/
|
|
14763
|
+
async send(input, messageId = randomUUID(), options = {}) {
|
|
14764
|
+
await (await this.open()).submit(content(input), messageId, [], options.senderId);
|
|
14765
|
+
}
|
|
14766
|
+
/**
|
|
14767
|
+
* Changes what `patch` names of the conversation, as the app's settings
|
|
14768
|
+
* change it, and resolves with how each field went: one field can be
|
|
14769
|
+
* refused while the others apply.
|
|
14770
|
+
*/
|
|
14771
|
+
async update(patch) {
|
|
14772
|
+
return this.routes.json("PATCH", `/conversations/${segment(this.id)}`, conversationUpdateSchema, patch);
|
|
14773
|
+
}
|
|
14774
|
+
/** The conversation as the list shows it, with its metadata and its agents. */
|
|
14775
|
+
get() {
|
|
14776
|
+
return this.routes.json("GET", `/conversations/${segment(this.id)}`, conversationDetailSchema);
|
|
14777
|
+
}
|
|
14778
|
+
/** Deletes the conversation, with its history and its files. */
|
|
14779
|
+
async remove() {
|
|
14780
|
+
await this.routes.send("DELETE", `/conversations/${segment(this.id)}`);
|
|
14781
|
+
this.close();
|
|
14782
|
+
this.registry.removed(this.id);
|
|
14783
|
+
}
|
|
14784
|
+
/**
|
|
14785
|
+
* The conversation's page for `<jush-conversation src>`, which the
|
|
14786
|
+
* program's server answers below `options.base` with `fetch` and `accept`,
|
|
14787
|
+
* doing what `options.allow` names; make one for each request.
|
|
14788
|
+
*/
|
|
14789
|
+
page(options) {
|
|
14790
|
+
return new ConversationPage(this.routes, this.id, options);
|
|
14791
|
+
}
|
|
14792
|
+
/**
|
|
14793
|
+
* A new conversation holding this one's history through the completed text
|
|
14794
|
+
* `through`, or everything before the turn `before`, which the message of
|
|
14795
|
+
* that id started; under `id`, made unless named, which a retry repeats.
|
|
14796
|
+
*/
|
|
14797
|
+
async fork(options) {
|
|
14798
|
+
const answer = await this.routes.json("POST", `/conversations/${segment(this.id)}/fork`, forkAnswerSchema, {
|
|
14799
|
+
id: options.id ?? randomUUID(),
|
|
14800
|
+
blockId: options.through,
|
|
14801
|
+
beforeTurn: options.before
|
|
14802
|
+
});
|
|
14803
|
+
return this.registry.open(answer.conversation.id);
|
|
14804
|
+
}
|
|
14805
|
+
/** Opens the conversation's agents again with the core's plugins as they are now, as after `core.plugins.enable`. */
|
|
14806
|
+
reloadPlugins() {
|
|
14807
|
+
return this.routes.send("POST", `/conversations/${segment(this.id)}/reload`);
|
|
14808
|
+
}
|
|
14809
|
+
/** The conversation's messages that match `text`. */
|
|
14810
|
+
search(text) {
|
|
14811
|
+
return this.routes.json("GET", `/conversations/${segment(this.id)}/search${query({ q: text })}`, messageResultsSchema);
|
|
14812
|
+
}
|
|
14813
|
+
/** What the calls of the last hour or day cost, by agent. */
|
|
14814
|
+
cost(window) {
|
|
14815
|
+
return this.routes.json("GET", `/conversations/${segment(this.id)}/cost/recent${query({ window })}`, recentCostSchema);
|
|
14816
|
+
}
|
|
14817
|
+
/** The workflows the conversation's agents can start, as its directory keeps them. */
|
|
14818
|
+
workflows() {
|
|
14819
|
+
return this.routes.json("GET", `/conversations/${segment(this.id)}/workflows`, conversationWorkflowListSchema);
|
|
14820
|
+
}
|
|
14821
|
+
/** Takes the pinned document `pin`, one of the metadata's `pins`, back from the conversation's agents. */
|
|
14822
|
+
unpin(pin) {
|
|
14823
|
+
return this.routes.send("DELETE", `/conversations/${segment(this.id)}/pins/${pin}`);
|
|
14824
|
+
}
|
|
14825
|
+
/** Detaches the device `device` the conversation brought in. */
|
|
14826
|
+
detach(device) {
|
|
14827
|
+
return this.routes.send("DELETE", `/conversations/${segment(this.id)}/devices/${segment(device)}`);
|
|
14828
|
+
}
|
|
14829
|
+
/**
|
|
14830
|
+
* Sends `text` to the subagent `node`, the id of one of `agents` whose
|
|
14831
|
+
* role is a subagent's, which takes it once however often it is sent
|
|
14832
|
+
* under `messageId`: a live one as a steer, and an ended one is resumed
|
|
14833
|
+
* with it. Resolves with the message's id, the one made for it when
|
|
14834
|
+
* `messageId` is absent.
|
|
14835
|
+
*/
|
|
14836
|
+
async sendToAgent(node, text, messageId, options = {}) {
|
|
14837
|
+
const path = `/conversations/${segment(this.id)}/agents/${segment(node)}/messages`;
|
|
14838
|
+
const { id } = await this.routes.json("POST", path, subagentMessageAnswerSchema, {
|
|
14839
|
+
id: messageId,
|
|
14840
|
+
text,
|
|
14841
|
+
senderId: options.senderId
|
|
14842
|
+
});
|
|
14843
|
+
return id;
|
|
14844
|
+
}
|
|
14845
|
+
/**
|
|
14846
|
+
* Steers the running turn with `input`; resolves once the turn took it.
|
|
14847
|
+
* The conversation takes it once however often it is sent under
|
|
14848
|
+
* `steerId`, which messages and steers share.
|
|
14849
|
+
*/
|
|
14850
|
+
async steer(input, steerId = randomUUID(), options = {}) {
|
|
14851
|
+
await (await this.open()).steer(content(input), steerId, [], options.senderId);
|
|
14852
|
+
}
|
|
14853
|
+
async abort() {
|
|
14854
|
+
return (await this.open()).abort();
|
|
14855
|
+
}
|
|
14856
|
+
async retry() {
|
|
14857
|
+
return (await this.open()).retry();
|
|
14858
|
+
}
|
|
14859
|
+
async resume() {
|
|
14860
|
+
return (await this.open()).resume();
|
|
14861
|
+
}
|
|
14862
|
+
async compact() {
|
|
14863
|
+
return (await this.open()).compact();
|
|
14864
|
+
}
|
|
14865
|
+
/**
|
|
14866
|
+
* Sends `input`, and answers the turn it starts once the turn ended: once
|
|
14867
|
+
* the conversation's last ended turn is its own, as a turn the root
|
|
14868
|
+
* resumes ends anew. When the lane's view cannot tell, as after its
|
|
14869
|
+
* connection dropped while the turn ended, it asks the conversation where
|
|
13905
14870
|
* the turn stands, again at each view that cannot tell. It reads the
|
|
13906
14871
|
* transcript back to the message when the turn ended past what the lane
|
|
13907
14872
|
* holds. It fails when the message left the queue without running, as an
|
|
13908
14873
|
* abort's clearing of the queue removes it.
|
|
13909
14874
|
*/
|
|
13910
|
-
async run(input) {
|
|
14875
|
+
async run(input, options = {}) {
|
|
13911
14876
|
const messageId = randomUUID();
|
|
13912
14877
|
let sent = false;
|
|
13913
14878
|
let answered = null;
|
|
13914
14879
|
let asked = null;
|
|
13915
14880
|
let reading = false;
|
|
13916
14881
|
let failures = 0;
|
|
13917
|
-
let
|
|
14882
|
+
let waiter = {
|
|
13918
14883
|
changed: () => {},
|
|
13919
14884
|
closed: () => {}
|
|
13920
14885
|
};
|
|
13921
14886
|
const ended = new Promise((resolve, reject) => {
|
|
13922
14887
|
const again = () => {
|
|
13923
|
-
if (this.
|
|
14888
|
+
if (this.waiters.has(waiter)) waiter.changed();
|
|
13924
14889
|
};
|
|
13925
14890
|
const later = () => {
|
|
13926
14891
|
failures += 1;
|
|
@@ -13931,7 +14896,7 @@ var Conversation = class {
|
|
|
13931
14896
|
this.turnState(messageId).then((state) => {
|
|
13932
14897
|
if (asked !== view) return;
|
|
13933
14898
|
if (state === null) {
|
|
13934
|
-
this.
|
|
14899
|
+
this.waiters.delete(waiter);
|
|
13935
14900
|
reject(/* @__PURE__ */ new Error("The message left the queue without running"));
|
|
13936
14901
|
} else if (state.state === "ended") {
|
|
13937
14902
|
failures = 0;
|
|
@@ -13962,7 +14927,7 @@ var Conversation = class {
|
|
|
13962
14927
|
later();
|
|
13963
14928
|
});
|
|
13964
14929
|
};
|
|
13965
|
-
|
|
14930
|
+
waiter = {
|
|
13966
14931
|
changed: () => {
|
|
13967
14932
|
const last = this.metadata?.lastTurn;
|
|
13968
14933
|
const end = last?.turnId === messageId ? {
|
|
@@ -13972,7 +14937,7 @@ var Conversation = class {
|
|
|
13972
14937
|
if (end) {
|
|
13973
14938
|
const turn = this.turnOf(messageId, end);
|
|
13974
14939
|
if (turn) {
|
|
13975
|
-
this.
|
|
14940
|
+
this.waiters.delete(waiter);
|
|
13976
14941
|
resolve(turn);
|
|
13977
14942
|
return;
|
|
13978
14943
|
}
|
|
@@ -13986,15 +14951,15 @@ var Conversation = class {
|
|
|
13986
14951
|
};
|
|
13987
14952
|
});
|
|
13988
14953
|
ended.catch(() => {});
|
|
13989
|
-
this.
|
|
14954
|
+
this.waiters.add(waiter);
|
|
13990
14955
|
try {
|
|
13991
|
-
await this.send(input, messageId);
|
|
14956
|
+
await this.send(input, messageId, options);
|
|
13992
14957
|
} catch (error) {
|
|
13993
|
-
this.
|
|
14958
|
+
this.waiters.delete(waiter);
|
|
13994
14959
|
throw error;
|
|
13995
14960
|
}
|
|
13996
14961
|
sent = true;
|
|
13997
|
-
|
|
14962
|
+
waiter.changed();
|
|
13998
14963
|
return ended;
|
|
13999
14964
|
}
|
|
14000
14965
|
/**
|
|
@@ -14021,7 +14986,7 @@ var Conversation = class {
|
|
|
14021
14986
|
}
|
|
14022
14987
|
/** Where the turn `messageId` stands, as the conversation answers; null when it holds no turn of it. */
|
|
14023
14988
|
async turnState(messageId) {
|
|
14024
|
-
const path = `/conversations/${
|
|
14989
|
+
const path = `/conversations/${segment(this.id)}/turns/${segment(messageId)}`;
|
|
14025
14990
|
try {
|
|
14026
14991
|
return await this.routes.json("GET", path, turnStateSchema);
|
|
14027
14992
|
} catch (error) {
|
|
@@ -14038,6 +15003,7 @@ var Conversation = class {
|
|
|
14038
15003
|
const after = blocks.slice(at + 1, end + 1);
|
|
14039
15004
|
const text = after.flatMap((block) => block.type === "text" ? [block.text] : []).join("\n\n");
|
|
14040
15005
|
return {
|
|
15006
|
+
id: messageId,
|
|
14041
15007
|
outcome: ending.outcome,
|
|
14042
15008
|
blocks: after,
|
|
14043
15009
|
text
|
|
@@ -14055,8 +15021,8 @@ var Conversation = class {
|
|
|
14055
15021
|
}
|
|
14056
15022
|
/** Reads the page of the root's transcript before `window` into what the conversation holds. */
|
|
14057
15023
|
async readBefore(window) {
|
|
14058
|
-
const root =
|
|
14059
|
-
const edge =
|
|
15024
|
+
const root = segment(this.id);
|
|
15025
|
+
const edge = segment(window.blocks[0].id);
|
|
14060
15026
|
const path = `/conversations/${root}/agents/${root}/transcript?before=${window.start}&edge=${edge}`;
|
|
14061
15027
|
const page = await this.routes.json("GET", path, transcriptPageSchema);
|
|
14062
15028
|
this.transcript = addPage(this.transcript, page, true);
|
|
@@ -14073,7 +15039,7 @@ var Conversation = class {
|
|
|
14073
15039
|
waiting.push(event);
|
|
14074
15040
|
wake?.();
|
|
14075
15041
|
};
|
|
14076
|
-
const
|
|
15042
|
+
const waiter = {
|
|
14077
15043
|
changed: () => {},
|
|
14078
15044
|
closed: () => {
|
|
14079
15045
|
closed = true;
|
|
@@ -14081,7 +15047,7 @@ var Conversation = class {
|
|
|
14081
15047
|
}
|
|
14082
15048
|
};
|
|
14083
15049
|
this.listeners.add(listener);
|
|
14084
|
-
this.
|
|
15050
|
+
this.waiters.add(waiter);
|
|
14085
15051
|
try {
|
|
14086
15052
|
await this.open();
|
|
14087
15053
|
for (;;) {
|
|
@@ -14096,7 +15062,7 @@ var Conversation = class {
|
|
|
14096
15062
|
}
|
|
14097
15063
|
} finally {
|
|
14098
15064
|
this.listeners.delete(listener);
|
|
14099
|
-
this.
|
|
15065
|
+
this.waiters.delete(waiter);
|
|
14100
15066
|
}
|
|
14101
15067
|
}
|
|
14102
15068
|
/**
|
|
@@ -14109,17 +15075,73 @@ var Conversation = class {
|
|
|
14109
15075
|
this.client = null;
|
|
14110
15076
|
this.opening = null;
|
|
14111
15077
|
client?.dispose();
|
|
14112
|
-
for (const
|
|
14113
|
-
this.
|
|
14114
|
-
|
|
15078
|
+
for (const waiter of [...this.waiters]) {
|
|
15079
|
+
this.waiters.delete(waiter);
|
|
15080
|
+
waiter.closed();
|
|
14115
15081
|
}
|
|
14116
15082
|
}
|
|
14117
15083
|
};
|
|
14118
|
-
|
|
14119
|
-
|
|
14120
|
-
|
|
14121
|
-
|
|
14122
|
-
|
|
15084
|
+
//#endregion
|
|
15085
|
+
//#region src/models.ts
|
|
15086
|
+
/** The models a core's entries offer, and what their calls used. */
|
|
15087
|
+
function models(routes) {
|
|
15088
|
+
return {
|
|
15089
|
+
search: async (text, options = {}) => (await routes.json("GET", `/models/search${query({
|
|
15090
|
+
q: text,
|
|
15091
|
+
entry: options.provider
|
|
15092
|
+
})}`, modelSearchResultsSchema)).results,
|
|
15093
|
+
refresh: () => routes.send("POST", "/models/refresh")
|
|
15094
|
+
};
|
|
15095
|
+
}
|
|
15096
|
+
function usage$1(routes) {
|
|
15097
|
+
return {
|
|
15098
|
+
totals: async () => (await routes.json("GET", "/usage", usageTotalsSchema)).totals,
|
|
15099
|
+
report: async (options) => routes.json("GET", `/usage/report${query({
|
|
15100
|
+
from: options.from.toISOString(),
|
|
15101
|
+
to: options.to.toISOString(),
|
|
15102
|
+
bucket: options.bucket,
|
|
15103
|
+
timeZone: options.timeZone,
|
|
15104
|
+
groupBy: options.groupBy !== void 0 && options.groupBy.length > 0 ? options.groupBy.join(",") : void 0,
|
|
15105
|
+
conversations: options.conversations?.join(","),
|
|
15106
|
+
agents: options.agents?.join(",")
|
|
15107
|
+
})}`, usageReportSchema)
|
|
15108
|
+
};
|
|
15109
|
+
}
|
|
15110
|
+
//#endregion
|
|
15111
|
+
//#region src/commands.ts
|
|
15112
|
+
/** The commands a core's agents ran, as the core's command history keeps them. */
|
|
15113
|
+
function commands(routes) {
|
|
15114
|
+
return { history: (options = {}) => routes.json("GET", `/commands/history${query({
|
|
15115
|
+
after: options.after,
|
|
15116
|
+
from: options.from?.toISOString(),
|
|
15117
|
+
limit: options.limit
|
|
15118
|
+
})}`, commandHistorySchema) };
|
|
15119
|
+
}
|
|
15120
|
+
//#endregion
|
|
15121
|
+
//#region src/organize.ts
|
|
15122
|
+
/** How a core's conversations are organized: workspaces and projects. */
|
|
15123
|
+
function workspaces(routes) {
|
|
15124
|
+
const one = (id) => `/workspaces/${segment(id)}`;
|
|
15125
|
+
return {
|
|
15126
|
+
list: async () => (await routes.json("GET", "/workspaces", workspacesSchema)).workspaces,
|
|
15127
|
+
create: async (workspace) => (await routes.json("POST", "/workspaces", workspaceAnswerSchema, workspace)).workspace,
|
|
15128
|
+
update: async (id, patch) => (await routes.json("PATCH", one(id), workspaceAnswerSchema, patch)).workspace,
|
|
15129
|
+
remove: (id) => routes.send("DELETE", one(id)),
|
|
15130
|
+
order: (ids) => routes.send("PUT", "/workspaces/order", { ids }),
|
|
15131
|
+
move: (id, moved) => routes.send("POST", `${one(id)}/moves`, {
|
|
15132
|
+
conversations: moved.conversations ?? [],
|
|
15133
|
+
projects: moved.projects ?? []
|
|
15134
|
+
})
|
|
15135
|
+
};
|
|
15136
|
+
}
|
|
15137
|
+
function projects(routes) {
|
|
15138
|
+
const one = (id) => `/projects/${segment(id)}`;
|
|
15139
|
+
return {
|
|
15140
|
+
list: async () => (await routes.json("GET", "/projects", projectsSchema)).projects,
|
|
15141
|
+
create: async (project) => (await routes.json("POST", "/projects", projectAnswerSchema, project)).project,
|
|
15142
|
+
update: async (id, patch) => (await routes.json("PATCH", one(id), projectAnswerSchema, patch)).project,
|
|
15143
|
+
remove: (id) => routes.send("DELETE", one(id))
|
|
15144
|
+
};
|
|
14123
15145
|
}
|
|
14124
15146
|
//#endregion
|
|
14125
15147
|
//#region src/apart.ts
|
|
@@ -14376,320 +15398,184 @@ function portOf(number, resent, request, send) {
|
|
|
14376
15398
|
request: number,
|
|
14377
15399
|
resent,
|
|
14378
15400
|
signal: request.stop.signal,
|
|
14379
|
-
ask: (message) => new Promise((resolve, reject) => {
|
|
14380
|
-
if (request.over) {
|
|
14381
|
-
reject(new PortFailure("The request is over"));
|
|
14382
|
-
return;
|
|
14383
|
-
}
|
|
14384
|
-
const port = request.nextPort;
|
|
14385
|
-
request.nextPort += 1;
|
|
14386
|
-
request.answers.set(port, {
|
|
14387
|
-
resolve,
|
|
14388
|
-
reject
|
|
14389
|
-
});
|
|
14390
|
-
send({
|
|
14391
|
-
request: number,
|
|
14392
|
-
port,
|
|
14393
|
-
message
|
|
14394
|
-
});
|
|
14395
|
-
})
|
|
14396
|
-
};
|
|
14397
|
-
}
|
|
14398
|
-
/** The command call of `invocation` on `port`. */
|
|
14399
|
-
function commandCall(invocation, port) {
|
|
14400
|
-
const rpc = async (request) => {
|
|
14401
|
-
const answer = await port.ask({
|
|
14402
|
-
type: "rpc",
|
|
14403
|
-
request
|
|
14404
|
-
});
|
|
14405
|
-
if (answer.type !== "rpc") throw new PortFailure(`The port answered ${answer.type} to an rpc operation`);
|
|
14406
|
-
return answer.response;
|
|
14407
|
-
};
|
|
14408
|
-
const bytes = (data) => typeof data === "string" ? new TextEncoder().encode(data) : data.buffer instanceof ArrayBuffer ? data : new Uint8Array(data);
|
|
14409
|
-
return {
|
|
14410
|
-
...port,
|
|
14411
|
-
invocation,
|
|
14412
|
-
stdout: async (data) => void await rpc({
|
|
14413
|
-
type: "stdout",
|
|
14414
|
-
bytes: bytes(data)
|
|
14415
|
-
}),
|
|
14416
|
-
stderr: async (data) => void await rpc({
|
|
14417
|
-
type: "stderr",
|
|
14418
|
-
bytes: bytes(data)
|
|
14419
|
-
}),
|
|
14420
|
-
readStdin: async () => {
|
|
14421
|
-
const response = await rpc({ type: "read_stdin" });
|
|
14422
|
-
return response.type === "input" ? response.bytes ?? null : null;
|
|
14423
|
-
},
|
|
14424
|
-
awaitsUser: async (awaits) => void await rpc({
|
|
14425
|
-
type: "awaits_user",
|
|
14426
|
-
awaits
|
|
14427
|
-
}),
|
|
14428
|
-
medium: async (facts, data) => void await rpc({
|
|
14429
|
-
type: "medium",
|
|
14430
|
-
facts,
|
|
14431
|
-
bytes: bytes(data)
|
|
14432
|
-
})
|
|
14433
|
-
};
|
|
14434
|
-
}
|
|
14435
|
-
/** The reply to `call`, by the definition's handler of it. */
|
|
14436
|
-
async function answer(definition, call, port) {
|
|
14437
|
-
switch (call.type) {
|
|
14438
|
-
case "command": {
|
|
14439
|
-
const leaf = leafAt(definition, call.invocation.path);
|
|
14440
|
-
if (leaf === void 0) throw usage(`No command ${call.invocation.path.join(" ")}`);
|
|
14441
|
-
const parsed = (leaf.input ?? z.object({})).safeParse(call.invocation.args);
|
|
14442
|
-
if (!parsed.success) throw usage(schemaRefusal(parsed.error));
|
|
14443
|
-
const commandPort = commandCall(call.invocation, port);
|
|
14444
|
-
try {
|
|
14445
|
-
return {
|
|
14446
|
-
type: "exit",
|
|
14447
|
-
code: await leaf.run(parsed.data, commandPort) ?? 0
|
|
14448
|
-
};
|
|
14449
|
-
} catch (error) {
|
|
14450
|
-
if (error instanceof PortFailure) throw error;
|
|
14451
|
-
await commandPort.stderr(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
14452
|
-
return {
|
|
14453
|
-
type: "exit",
|
|
14454
|
-
code: 1
|
|
14455
|
-
};
|
|
14456
|
-
}
|
|
14457
|
-
}
|
|
14458
|
-
case "context": {
|
|
14459
|
-
const text = await definition.context?.(call, port);
|
|
14460
|
-
return text === void 0 ? { type: "context" } : {
|
|
14461
|
-
type: "context",
|
|
14462
|
-
text
|
|
14463
|
-
};
|
|
14464
|
-
}
|
|
14465
|
-
case "project_search":
|
|
14466
|
-
if (definition.projectSearch === void 0) throw undeclared("a project search");
|
|
14467
|
-
return await definition.projectSearch(call, port);
|
|
14468
|
-
case "conversation_deleted":
|
|
14469
|
-
await definition.onConversationDeleted?.(call, port);
|
|
14470
|
-
return { type: "done" };
|
|
14471
|
-
case "conversation_forked":
|
|
14472
|
-
await definition.onConversationForked?.(call, port);
|
|
14473
|
-
return { type: "done" };
|
|
14474
|
-
default: throw undeclared(call.type);
|
|
14475
|
-
}
|
|
14476
|
-
}
|
|
14477
|
-
var RequestFailure = class extends Error {
|
|
14478
|
-
error;
|
|
14479
|
-
constructor(error) {
|
|
14480
|
-
super("message" in error ? error.message : error.type);
|
|
14481
|
-
this.error = error;
|
|
14482
|
-
}
|
|
14483
|
-
};
|
|
14484
|
-
function usage(message) {
|
|
14485
|
-
return new RequestFailure({
|
|
14486
|
-
type: "usage",
|
|
14487
|
-
message
|
|
14488
|
-
});
|
|
14489
|
-
}
|
|
14490
|
-
function undeclared(what) {
|
|
14491
|
-
return new RequestFailure({
|
|
14492
|
-
type: "failed",
|
|
14493
|
-
message: `The plugin declares no ${what}`
|
|
14494
|
-
});
|
|
14495
|
-
}
|
|
14496
|
-
function pluginError(error) {
|
|
14497
|
-
if (error instanceof RequestFailure) return error.error;
|
|
14498
|
-
return {
|
|
14499
|
-
type: "failed",
|
|
14500
|
-
message: error instanceof Error ? error.message : String(error)
|
|
14501
|
-
};
|
|
14502
|
-
}
|
|
14503
|
-
//#endregion
|
|
14504
|
-
//#region src/socket.ts
|
|
14505
|
-
/**
|
|
14506
|
-
* A WebSocket on a stream of the process's HTTP/2 connection (RFC 8441):
|
|
14507
|
-
* the stream is the socket's, and its bytes are WebSocket frames (RFC 6455),
|
|
14508
|
-
* which Node's `http2` does not write, so this module does. A client masks
|
|
14509
|
-
* each frame it sends; the process's frames come unmasked.
|
|
14510
|
-
*
|
|
14511
|
-
* It has the part of a browser's `WebSocket` the page connection and a
|
|
14512
|
-
* forwarded page's socket use: `send`, `close`, `bufferedAmount`,
|
|
14513
|
-
* `binaryType`, and the `open`, `message` and `close` events.
|
|
14514
|
-
*/
|
|
14515
|
-
const TEXT = 1;
|
|
14516
|
-
const BINARY = 2;
|
|
14517
|
-
const CLOSE = 8;
|
|
14518
|
-
const PING = 9;
|
|
14519
|
-
const PONG = 10;
|
|
14520
|
-
const CONTINUATION = 0;
|
|
14521
|
-
/** The close of a socket that ended without a close frame. */
|
|
14522
|
-
const ABNORMAL_CLOSURE = 1006;
|
|
14523
|
-
/** The close frame's code when it carries none. */
|
|
14524
|
-
const NO_STATUS = 1005;
|
|
14525
|
-
/** A WebSocket on the stream `opening` answers once the process took it. */
|
|
14526
|
-
var StreamSocket = class {
|
|
14527
|
-
binaryType = "arraybuffer";
|
|
14528
|
-
stream = null;
|
|
14529
|
-
listeners = /* @__PURE__ */ new Map();
|
|
14530
|
-
/** The bytes read that do not make a whole frame yet. */
|
|
14531
|
-
pending = /* @__PURE__ */ new Uint8Array(0);
|
|
14532
|
-
/** The fragments of a message whose last frame has not come. */
|
|
14533
|
-
fragments = null;
|
|
14534
|
-
closed = false;
|
|
14535
|
-
/** Whether this end sent its close frame. */
|
|
14536
|
-
closing = false;
|
|
14537
|
-
constructor(opening) {
|
|
14538
|
-
opening.then((stream) => {
|
|
14539
|
-
if (this.closed) {
|
|
14540
|
-
stream.close();
|
|
14541
|
-
return;
|
|
14542
|
-
}
|
|
14543
|
-
this.stream = stream;
|
|
14544
|
-
stream.on("data", (chunk) => this.read(chunk));
|
|
14545
|
-
stream.once("close", () => this.ended(ABNORMAL_CLOSURE, ""));
|
|
14546
|
-
stream.on("error", () => {});
|
|
14547
|
-
this.emit("open");
|
|
14548
|
-
}, () => this.ended(ABNORMAL_CLOSURE, ""));
|
|
14549
|
-
}
|
|
14550
|
-
/** The bytes sent that the stream has not written yet. */
|
|
14551
|
-
get bufferedAmount() {
|
|
14552
|
-
return this.stream?.writableLength ?? 0;
|
|
14553
|
-
}
|
|
14554
|
-
addEventListener(type, listener) {
|
|
14555
|
-
let set = this.listeners.get(type);
|
|
14556
|
-
if (!set) {
|
|
14557
|
-
set = /* @__PURE__ */ new Set();
|
|
14558
|
-
this.listeners.set(type, set);
|
|
14559
|
-
}
|
|
14560
|
-
set.add(listener);
|
|
14561
|
-
}
|
|
14562
|
-
removeEventListener(type, listener) {
|
|
14563
|
-
this.listeners.get(type)?.delete(listener);
|
|
14564
|
-
}
|
|
14565
|
-
/** Sends a message: text for a string, binary for bytes. */
|
|
14566
|
-
send(data) {
|
|
14567
|
-
if (typeof data === "string") this.write(TEXT, new TextEncoder().encode(data));
|
|
14568
|
-
else this.write(BINARY, data instanceof ArrayBuffer ? new Uint8Array(data) : data);
|
|
14569
|
-
}
|
|
14570
|
-
/** Closes the socket with `code` and `reason`; its `close` event follows. */
|
|
14571
|
-
close(code = 1e3, reason = "") {
|
|
14572
|
-
if (this.closed || this.closing) return;
|
|
14573
|
-
this.closing = true;
|
|
14574
|
-
if (this.stream === null) {
|
|
14575
|
-
this.ended(ABNORMAL_CLOSURE, "");
|
|
14576
|
-
return;
|
|
14577
|
-
}
|
|
14578
|
-
const text = new TextEncoder().encode(reason);
|
|
14579
|
-
const body = new Uint8Array(2 + text.length);
|
|
14580
|
-
new DataView(body.buffer).setUint16(0, code);
|
|
14581
|
-
body.set(text, 2);
|
|
14582
|
-
this.write(CLOSE, body);
|
|
14583
|
-
this.stream.end();
|
|
14584
|
-
}
|
|
14585
|
-
emit(type, ...event) {
|
|
14586
|
-
for (const listener of [...this.listeners.get(type) ?? []]) listener(...event);
|
|
14587
|
-
}
|
|
14588
|
-
/** Writes one frame of `opcode` with `payload`, masked. */
|
|
14589
|
-
write(opcode, payload) {
|
|
14590
|
-
const stream = this.stream;
|
|
14591
|
-
if (stream === null || this.closed || stream.destroyed) return;
|
|
14592
|
-
const length = payload.length;
|
|
14593
|
-
const extended = length < 126 ? 0 : length < 65536 ? 2 : 8;
|
|
14594
|
-
const frame = new Uint8Array(2 + extended + 4 + length);
|
|
14595
|
-
const view = new DataView(frame.buffer);
|
|
14596
|
-
frame[0] = 128 | opcode;
|
|
14597
|
-
if (extended === 0) frame[1] = 128 | length;
|
|
14598
|
-
else if (extended === 2) {
|
|
14599
|
-
frame[1] = 254;
|
|
14600
|
-
view.setUint16(2, length);
|
|
14601
|
-
} else {
|
|
14602
|
-
frame[1] = 255;
|
|
14603
|
-
view.setBigUint64(2, BigInt(length));
|
|
14604
|
-
}
|
|
14605
|
-
const at = 2 + extended;
|
|
14606
|
-
const mask = frame.subarray(at, at + 4);
|
|
14607
|
-
randomFillSync(mask);
|
|
14608
|
-
const body = frame.subarray(at + 4);
|
|
14609
|
-
for (let index = 0; index < length; index += 1) body[index] = payload[index] ^ mask[index & 3];
|
|
14610
|
-
stream.write(frame);
|
|
14611
|
-
}
|
|
14612
|
-
/** Takes bytes of the stream, and handles each whole frame they complete. */
|
|
14613
|
-
read(chunk) {
|
|
14614
|
-
let bytes = this.pending.length === 0 ? chunk : concat([this.pending, chunk]);
|
|
14615
|
-
while (bytes.length >= 2) {
|
|
14616
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
14617
|
-
const fin = (bytes[0] & 128) !== 0;
|
|
14618
|
-
const opcode = bytes[0] & 15;
|
|
14619
|
-
let length = bytes[1] & 127;
|
|
14620
|
-
let at = 2;
|
|
14621
|
-
if (length === 126) {
|
|
14622
|
-
if (bytes.length < 4) break;
|
|
14623
|
-
length = view.getUint16(2);
|
|
14624
|
-
at = 4;
|
|
14625
|
-
} else if (length === 127) {
|
|
14626
|
-
if (bytes.length < 10) break;
|
|
14627
|
-
length = Number(view.getBigUint64(2));
|
|
14628
|
-
at = 10;
|
|
14629
|
-
}
|
|
14630
|
-
if (bytes.length < at + length) break;
|
|
14631
|
-
const payload = bytes.slice(at, at + length);
|
|
14632
|
-
bytes = bytes.subarray(at + length);
|
|
14633
|
-
this.frame(fin, opcode, payload);
|
|
14634
|
-
}
|
|
14635
|
-
this.pending = bytes.slice();
|
|
14636
|
-
}
|
|
14637
|
-
frame(fin, opcode, payload) {
|
|
14638
|
-
switch (opcode) {
|
|
14639
|
-
case PING:
|
|
14640
|
-
this.write(PONG, payload);
|
|
14641
|
-
return;
|
|
14642
|
-
case PONG: return;
|
|
14643
|
-
case CLOSE: {
|
|
14644
|
-
const code = payload.length >= 2 ? new DataView(payload.buffer, payload.byteOffset).getUint16(0) : NO_STATUS;
|
|
14645
|
-
const reason = new TextDecoder().decode(payload.subarray(2));
|
|
14646
|
-
if (!this.closing) {
|
|
14647
|
-
this.closing = true;
|
|
14648
|
-
this.write(CLOSE, payload.subarray(0, 2));
|
|
14649
|
-
this.stream?.end();
|
|
14650
|
-
}
|
|
14651
|
-
this.ended(code, reason);
|
|
15401
|
+
ask: (message) => new Promise((resolve, reject) => {
|
|
15402
|
+
if (request.over) {
|
|
15403
|
+
reject(new PortFailure("The request is over"));
|
|
14652
15404
|
return;
|
|
14653
15405
|
}
|
|
14654
|
-
|
|
14655
|
-
|
|
14656
|
-
|
|
14657
|
-
|
|
14658
|
-
|
|
14659
|
-
|
|
14660
|
-
|
|
14661
|
-
|
|
14662
|
-
|
|
14663
|
-
|
|
14664
|
-
|
|
14665
|
-
|
|
14666
|
-
|
|
14667
|
-
|
|
15406
|
+
const port = request.nextPort;
|
|
15407
|
+
request.nextPort += 1;
|
|
15408
|
+
request.answers.set(port, {
|
|
15409
|
+
resolve,
|
|
15410
|
+
reject
|
|
15411
|
+
});
|
|
15412
|
+
send({
|
|
15413
|
+
request: number,
|
|
15414
|
+
port,
|
|
15415
|
+
message
|
|
15416
|
+
});
|
|
15417
|
+
})
|
|
15418
|
+
};
|
|
15419
|
+
}
|
|
15420
|
+
/** The command call of `invocation` on `port`. */
|
|
15421
|
+
function commandCall(invocation, port) {
|
|
15422
|
+
const rpc = async (request) => {
|
|
15423
|
+
const answer = await port.ask({
|
|
15424
|
+
type: "rpc",
|
|
15425
|
+
request
|
|
15426
|
+
});
|
|
15427
|
+
if (answer.type !== "rpc") throw new PortFailure(`The port answered ${answer.type} to an rpc operation`);
|
|
15428
|
+
return answer.response;
|
|
15429
|
+
};
|
|
15430
|
+
const bytes = (data) => typeof data === "string" ? new TextEncoder().encode(data) : data.buffer instanceof ArrayBuffer ? data : new Uint8Array(data);
|
|
15431
|
+
return {
|
|
15432
|
+
...port,
|
|
15433
|
+
invocation,
|
|
15434
|
+
stdout: async (data) => void await rpc({
|
|
15435
|
+
type: "stdout",
|
|
15436
|
+
bytes: bytes(data)
|
|
15437
|
+
}),
|
|
15438
|
+
stderr: async (data) => void await rpc({
|
|
15439
|
+
type: "stderr",
|
|
15440
|
+
bytes: bytes(data)
|
|
15441
|
+
}),
|
|
15442
|
+
readStdin: async () => {
|
|
15443
|
+
const response = await rpc({ type: "read_stdin" });
|
|
15444
|
+
return response.type === "input" ? response.bytes ?? null : null;
|
|
15445
|
+
},
|
|
15446
|
+
awaitsUser: async (awaits) => void await rpc({
|
|
15447
|
+
type: "awaits_user",
|
|
15448
|
+
awaits
|
|
15449
|
+
}),
|
|
15450
|
+
medium: async (facts, data) => void await rpc({
|
|
15451
|
+
type: "medium",
|
|
15452
|
+
facts,
|
|
15453
|
+
bytes: bytes(data)
|
|
15454
|
+
})
|
|
15455
|
+
};
|
|
15456
|
+
}
|
|
15457
|
+
/** The reply to `call`, by the definition's handler of it. */
|
|
15458
|
+
async function answer(definition, call, port) {
|
|
15459
|
+
switch (call.type) {
|
|
15460
|
+
case "command": {
|
|
15461
|
+
const leaf = leafAt(definition, call.invocation.path);
|
|
15462
|
+
if (leaf === void 0) throw usage(`No command ${call.invocation.path.join(" ")}`);
|
|
15463
|
+
const parsed = (leaf.input ?? z.object({})).safeParse(call.invocation.args);
|
|
15464
|
+
if (!parsed.success) throw usage(schemaRefusal(parsed.error));
|
|
15465
|
+
const commandPort = commandCall(call.invocation, port);
|
|
15466
|
+
try {
|
|
15467
|
+
return {
|
|
15468
|
+
type: "exit",
|
|
15469
|
+
code: await leaf.run(parsed.data, commandPort) ?? 0
|
|
15470
|
+
};
|
|
15471
|
+
} catch (error) {
|
|
15472
|
+
if (error instanceof PortFailure) throw error;
|
|
15473
|
+
await commandPort.stderr(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
15474
|
+
return {
|
|
15475
|
+
type: "exit",
|
|
15476
|
+
code: 1
|
|
15477
|
+
};
|
|
15478
|
+
}
|
|
15479
|
+
}
|
|
15480
|
+
case "context": {
|
|
15481
|
+
const text = await definition.context?.(call, port);
|
|
15482
|
+
return text === void 0 ? { type: "context" } : {
|
|
15483
|
+
type: "context",
|
|
15484
|
+
text
|
|
14668
15485
|
};
|
|
14669
15486
|
}
|
|
15487
|
+
case "project_search":
|
|
15488
|
+
if (definition.projectSearch === void 0) throw undeclared("a project search");
|
|
15489
|
+
return await definition.projectSearch(call, port);
|
|
15490
|
+
case "conversation_deleted":
|
|
15491
|
+
await definition.onConversationDeleted?.(call, port);
|
|
15492
|
+
return { type: "done" };
|
|
15493
|
+
case "conversation_forked":
|
|
15494
|
+
await definition.onConversationForked?.(call, port);
|
|
15495
|
+
return { type: "done" };
|
|
15496
|
+
default: throw undeclared(call.type);
|
|
14670
15497
|
}
|
|
14671
|
-
|
|
14672
|
-
|
|
14673
|
-
|
|
14674
|
-
|
|
14675
|
-
|
|
14676
|
-
|
|
14677
|
-
this.closed = true;
|
|
14678
|
-
this.stream?.close();
|
|
14679
|
-
this.emit("close", {
|
|
14680
|
-
code,
|
|
14681
|
-
reason
|
|
14682
|
-
});
|
|
15498
|
+
}
|
|
15499
|
+
var RequestFailure = class extends Error {
|
|
15500
|
+
error;
|
|
15501
|
+
constructor(error) {
|
|
15502
|
+
super("message" in error ? error.message : error.type);
|
|
15503
|
+
this.error = error;
|
|
14683
15504
|
}
|
|
14684
15505
|
};
|
|
14685
|
-
function
|
|
14686
|
-
|
|
14687
|
-
|
|
14688
|
-
|
|
14689
|
-
|
|
14690
|
-
|
|
14691
|
-
|
|
14692
|
-
return
|
|
15506
|
+
function usage(message) {
|
|
15507
|
+
return new RequestFailure({
|
|
15508
|
+
type: "usage",
|
|
15509
|
+
message
|
|
15510
|
+
});
|
|
15511
|
+
}
|
|
15512
|
+
function undeclared(what) {
|
|
15513
|
+
return new RequestFailure({
|
|
15514
|
+
type: "failed",
|
|
15515
|
+
message: `The plugin declares no ${what}`
|
|
15516
|
+
});
|
|
15517
|
+
}
|
|
15518
|
+
function pluginError(error) {
|
|
15519
|
+
if (error instanceof RequestFailure) return error.error;
|
|
15520
|
+
return {
|
|
15521
|
+
type: "failed",
|
|
15522
|
+
message: error instanceof Error ? error.message : String(error)
|
|
15523
|
+
};
|
|
15524
|
+
}
|
|
15525
|
+
//#endregion
|
|
15526
|
+
//#region src/port-forwards.ts
|
|
15527
|
+
/** The ports a core's devices forward. */
|
|
15528
|
+
function portForwards(routes) {
|
|
15529
|
+
const one = (id) => `/port-forwards/${segment(id)}`;
|
|
15530
|
+
return {
|
|
15531
|
+
list: async () => (await routes.json("GET", "/port-forwards", portForwardListSchema)).forwards,
|
|
15532
|
+
create: async (forward) => (await routes.json("POST", "/port-forwards", portForwardAnswerSchema, forward)).forward,
|
|
15533
|
+
update: async (id, patch) => (await routes.json("PATCH", one(id), portForwardAnswerSchema, patch)).forward,
|
|
15534
|
+
remove: (id) => routes.send("DELETE", one(id)),
|
|
15535
|
+
retry: (id) => routes.send("POST", `${one(id)}/retry`)
|
|
15536
|
+
};
|
|
15537
|
+
}
|
|
15538
|
+
//#endregion
|
|
15539
|
+
//#region src/settings.ts
|
|
15540
|
+
/**
|
|
15541
|
+
* A core's settings a program manages: credentials, the instructions every
|
|
15542
|
+
* agent reads, subagents and their profiles, and plugins.
|
|
15543
|
+
*/
|
|
15544
|
+
function credentials(routes) {
|
|
15545
|
+
const one = (id) => `/credentials/${segment(id)}`;
|
|
15546
|
+
return {
|
|
15547
|
+
list: async () => (await routes.json("GET", "/credentials", credentialListSchema)).credentials,
|
|
15548
|
+
create: async (credential) => (await routes.json("POST", "/credentials", credentialAnswerSchema, credential)).credential,
|
|
15549
|
+
update: async (id, patch) => (await routes.json("PATCH", one(id), credentialAnswerSchema, patch)).credential,
|
|
15550
|
+
remove: (id) => routes.send("DELETE", one(id)),
|
|
15551
|
+
reveal: async (id, field) => (await routes.json("POST", `${one(id)}/fields/${segment(field)}/reveal`, revealedValueSchema)).value
|
|
15552
|
+
};
|
|
15553
|
+
}
|
|
15554
|
+
function instructions(routes) {
|
|
15555
|
+
return {
|
|
15556
|
+
get: async () => (await routes.json("GET", "/settings/instructions", instructionsAnswerSchema)).instructions,
|
|
15557
|
+
set: (text) => routes.send("PUT", "/instructions", { text })
|
|
15558
|
+
};
|
|
15559
|
+
}
|
|
15560
|
+
function subagents(routes) {
|
|
15561
|
+
const one = (id) => `/subagents/profiles/${segment(id)}`;
|
|
15562
|
+
return {
|
|
15563
|
+
get: () => routes.json("GET", "/settings/subagents", subagentSettingsSchema),
|
|
15564
|
+
update: (patch) => routes.send("PUT", "/subagents", patch),
|
|
15565
|
+
profiles: {
|
|
15566
|
+
create: async (profile) => (await routes.json("POST", "/subagents/profiles", profileAnswerSchema, profile)).profile,
|
|
15567
|
+
update: async (id, patch) => (await routes.json("PATCH", one(id), profileAnswerSchema, patch)).profile,
|
|
15568
|
+
remove: (id) => routes.send("DELETE", one(id))
|
|
15569
|
+
}
|
|
15570
|
+
};
|
|
15571
|
+
}
|
|
15572
|
+
function corePlugins(routes) {
|
|
15573
|
+
const one = (plugin) => `/plugins/${segment(plugin)}`;
|
|
15574
|
+
return {
|
|
15575
|
+
enable: (plugin, enabled) => routes.send("PUT", one(plugin), { enabled }),
|
|
15576
|
+
enableFeature: (plugin, feature, enabled) => routes.send("PUT", `${one(plugin)}/features/${segment(feature)}`, { enabled }),
|
|
15577
|
+
call: (plugin, method, input = {}) => routes.json("POST", `${one(plugin)}/calls/${segment(method)}`, z.unknown(), input)
|
|
15578
|
+
};
|
|
14693
15579
|
}
|
|
14694
15580
|
//#endregion
|
|
14695
15581
|
//#region src/core.ts
|
|
@@ -14708,8 +15594,20 @@ var Core = class {
|
|
|
14708
15594
|
conversations;
|
|
14709
15595
|
providers;
|
|
14710
15596
|
devices;
|
|
15597
|
+
credentials;
|
|
15598
|
+
instructions;
|
|
15599
|
+
subagents;
|
|
15600
|
+
plugins;
|
|
15601
|
+
models;
|
|
15602
|
+
usage;
|
|
15603
|
+
commands;
|
|
15604
|
+
workspaces;
|
|
15605
|
+
projects;
|
|
15606
|
+
portForwards;
|
|
14711
15607
|
routes;
|
|
14712
15608
|
connection;
|
|
15609
|
+
/** The version the program's plugins are; none for their current one. */
|
|
15610
|
+
pluginVersion;
|
|
14713
15611
|
stateRead;
|
|
14714
15612
|
stateListeners = /* @__PURE__ */ new Set();
|
|
14715
15613
|
notify = null;
|
|
@@ -14720,12 +15618,23 @@ var Core = class {
|
|
|
14720
15618
|
this.closing = closing;
|
|
14721
15619
|
this.id = opening.id;
|
|
14722
15620
|
this.dir = opening.dir;
|
|
14723
|
-
this.connection = new PageConnection(processConnection(opening.process, `/cores/${
|
|
15621
|
+
this.connection = new PageConnection(processConnection(opening.process, `/cores/${segment(opening.id)}/api/connect`));
|
|
15622
|
+
this.pluginVersion = opening.pluginVersion;
|
|
14724
15623
|
this.connection.start();
|
|
14725
15624
|
this.routes = new CoreRoutes(opening.process, opening.id, this.connection);
|
|
14726
15625
|
this.conversations = new Conversations(this.routes, () => this.stateRead);
|
|
14727
15626
|
this.providers = new Providers(this.routes);
|
|
14728
15627
|
this.devices = new Devices(this.routes, opening.process, opening.runner, opening.dir, (id, ended) => this.online(id, ended));
|
|
15628
|
+
this.credentials = credentials(this.routes);
|
|
15629
|
+
this.instructions = instructions(this.routes);
|
|
15630
|
+
this.subagents = subagents(this.routes);
|
|
15631
|
+
this.plugins = corePlugins(this.routes);
|
|
15632
|
+
this.models = models(this.routes);
|
|
15633
|
+
this.usage = usage$1(this.routes);
|
|
15634
|
+
this.commands = commands(this.routes);
|
|
15635
|
+
this.workspaces = workspaces(this.routes);
|
|
15636
|
+
this.projects = projects(this.routes);
|
|
15637
|
+
this.portForwards = portForwards(this.routes);
|
|
14729
15638
|
for (const plugin of opening.plugins) this.servePlugin(plugin);
|
|
14730
15639
|
}
|
|
14731
15640
|
/** Reads the core's product state and follows it from then on. */
|
|
@@ -14773,6 +15682,17 @@ var Core = class {
|
|
|
14773
15682
|
fileName: file.name
|
|
14774
15683
|
};
|
|
14775
15684
|
}
|
|
15685
|
+
/** The conversations whose titles and messages match `text`, of the workspace `workspace` alone when named. */
|
|
15686
|
+
async search(text, options = {}) {
|
|
15687
|
+
return (await this.routes.json("GET", `/search${query({
|
|
15688
|
+
q: text,
|
|
15689
|
+
workspace: options.workspace
|
|
15690
|
+
})}`, searchResultsSchema)).results;
|
|
15691
|
+
}
|
|
15692
|
+
/** The bytes of the blob `sha256`, such as a medium a block names. */
|
|
15693
|
+
blob(sha256) {
|
|
15694
|
+
return this.routes.bytes("GET", `/blobs/${segment(sha256)}`);
|
|
15695
|
+
}
|
|
14776
15696
|
/**
|
|
14777
15697
|
* Changes what `patch` names of the core's preferences, the web app's
|
|
14778
15698
|
* Settings, and answers them, such as `commandLocale`, the time zone and
|
|
@@ -14781,46 +15701,6 @@ var Core = class {
|
|
|
14781
15701
|
async updatePreferences(patch) {
|
|
14782
15702
|
return (await this.routes.json("PATCH", "/settings/preferences", userPreferencesSchema, patch)).preferences;
|
|
14783
15703
|
}
|
|
14784
|
-
/**
|
|
14785
|
-
* Answers `request` with the core's route it names below `base`, such as
|
|
14786
|
-
* `/jush/api/conversations` below `/jush/api`, as the program's server
|
|
14787
|
-
* forwards a page's request.
|
|
14788
|
-
*/
|
|
14789
|
-
fetch(request, base = "/api") {
|
|
14790
|
-
const url = new URL(request.url);
|
|
14791
|
-
const forwarded = new Request(PROCESS_ORIGIN + this.routes.path(below(url.pathname, base)) + url.search, request);
|
|
14792
|
-
return this.routes.process.fetch(forwarded);
|
|
14793
|
-
}
|
|
14794
|
-
/**
|
|
14795
|
-
* Carries the page connection a page opened on the program's server,
|
|
14796
|
-
* `socket`, to the core, both ways, until either end closes; `url` is the
|
|
14797
|
-
* address the page opened, whose query goes with it.
|
|
14798
|
-
*/
|
|
14799
|
-
accept(socket, url) {
|
|
14800
|
-
const query = url === void 0 ? "" : new URL(url, PROCESS_ORIGIN).search;
|
|
14801
|
-
const core = new StreamSocket(this.routes.process.connect(this.routes.path(`/connect${query}`), "websocket", { "sec-websocket-version": "13" }));
|
|
14802
|
-
const early = [];
|
|
14803
|
-
let open = false;
|
|
14804
|
-
let pageClosed = false;
|
|
14805
|
-
socket.binaryType = "arraybuffer";
|
|
14806
|
-
socket.addEventListener("message", (event) => {
|
|
14807
|
-
const data = event.data;
|
|
14808
|
-
if (open) core.send(data);
|
|
14809
|
-
else early.push(data);
|
|
14810
|
-
});
|
|
14811
|
-
socket.addEventListener("close", () => {
|
|
14812
|
-
pageClosed = true;
|
|
14813
|
-
core.close();
|
|
14814
|
-
});
|
|
14815
|
-
core.addEventListener("open", () => {
|
|
14816
|
-
open = true;
|
|
14817
|
-
for (const data of early.splice(0)) core.send(data);
|
|
14818
|
-
});
|
|
14819
|
-
core.addEventListener("message", (event) => socket.send(event.data));
|
|
14820
|
-
core.addEventListener("close", (event) => {
|
|
14821
|
-
if (!pageClosed) socket.close(event.code === 1006 || event.code === 1005 ? 1011 : event.code, event.reason);
|
|
14822
|
-
});
|
|
14823
|
-
}
|
|
14824
15704
|
/** Closes the core, for every program: its lanes end, and the process closes it. */
|
|
14825
15705
|
async close() {
|
|
14826
15706
|
if (this.closed) return;
|
|
@@ -14913,7 +15793,10 @@ var Core = class {
|
|
|
14913
15793
|
}
|
|
14914
15794
|
openStarter() {
|
|
14915
15795
|
if (this.closed || this.starter !== null) return;
|
|
14916
|
-
const lane = this.connection.openLane({
|
|
15796
|
+
const lane = this.connection.openLane({
|
|
15797
|
+
kind: "starter",
|
|
15798
|
+
version: this.pluginVersion
|
|
15799
|
+
}, "starter lane");
|
|
14917
15800
|
this.starter = lane;
|
|
14918
15801
|
lane.addEventListener("message", (message) => {
|
|
14919
15802
|
const parsed = starterRequestSchema.safeParse(JSON.parse(message.data));
|
|
@@ -14939,7 +15822,8 @@ var Core = class {
|
|
|
14939
15822
|
if (this.closed) return;
|
|
14940
15823
|
const lane = this.connection.openLane({
|
|
14941
15824
|
kind: "plugin",
|
|
14942
|
-
plugin: plugin.manifest.id
|
|
15825
|
+
plugin: plugin.manifest.id,
|
|
15826
|
+
version: this.pluginVersion
|
|
14943
15827
|
}, `plugin lane of ${plugin.manifest.id}`);
|
|
14944
15828
|
servePlugin(plugin, lane, (error) => process.emitWarning(error));
|
|
14945
15829
|
lane.addEventListener("close", () => {
|
|
@@ -14997,11 +15881,30 @@ var Conversations = class {
|
|
|
14997
15881
|
const created = await this.routes.json("POST", "/conversations", createdConversationSchema, body);
|
|
14998
15882
|
return this.open(created.conversation.id);
|
|
14999
15883
|
}
|
|
15884
|
+
/** The core's conversations that are not archived, or with `archived` the ones that are. */
|
|
15885
|
+
async list(options = {}) {
|
|
15886
|
+
return (await this.routes.json("GET", `/conversations${query({ archived: options.archived })}`, conversationsSchema)).conversations;
|
|
15887
|
+
}
|
|
15888
|
+
/** The conversation `id` as the list shows it, with its metadata and its agents. */
|
|
15889
|
+
get(id) {
|
|
15890
|
+
return this.open(id).get();
|
|
15891
|
+
}
|
|
15892
|
+
/** Deletes the conversation `id`, with its history and its files. */
|
|
15893
|
+
remove(id) {
|
|
15894
|
+
return this.open(id).remove();
|
|
15895
|
+
}
|
|
15896
|
+
/** Changes several conversations at once, such as archiving them; each item answers apart. */
|
|
15897
|
+
async updateMany(items) {
|
|
15898
|
+
return (await this.routes.json("POST", "/conversations/batch", batchAnswerSchema, { items })).results;
|
|
15899
|
+
}
|
|
15000
15900
|
/** The conversation `id`, whose lane opens at its first use. */
|
|
15001
15901
|
open(id) {
|
|
15002
15902
|
let conversation = this.opened.get(id);
|
|
15003
15903
|
if (conversation === void 0) {
|
|
15004
|
-
conversation = new Conversation(id, this.routes
|
|
15904
|
+
conversation = new Conversation(id, this.routes, {
|
|
15905
|
+
open: (other) => this.open(other),
|
|
15906
|
+
removed: (gone) => this.opened.delete(gone)
|
|
15907
|
+
});
|
|
15005
15908
|
this.opened.set(id, conversation);
|
|
15006
15909
|
}
|
|
15007
15910
|
return conversation;
|
|
@@ -15024,18 +15927,46 @@ var Providers = class {
|
|
|
15024
15927
|
return (await this.routes.json("POST", "/providers", providerAnswerSchema, provider)).provider;
|
|
15025
15928
|
}
|
|
15026
15929
|
async update(id, patch) {
|
|
15027
|
-
return (await this.routes.json("PATCH", `/providers/${
|
|
15930
|
+
return (await this.routes.json("PATCH", `/providers/${segment(id)}`, providerAnswerSchema, patch)).provider;
|
|
15028
15931
|
}
|
|
15029
15932
|
async remove(id) {
|
|
15030
|
-
await this.routes.send("DELETE", `/providers/${
|
|
15933
|
+
await this.routes.send("DELETE", `/providers/${segment(id)}`);
|
|
15934
|
+
}
|
|
15935
|
+
/** The vendors and subscriptions an entry can be made of, and the shapes of a compatible endpoint. */
|
|
15936
|
+
catalog() {
|
|
15937
|
+
return this.routes.json("GET", "/providers/catalog", vendorCatalogSchema);
|
|
15938
|
+
}
|
|
15939
|
+
/** Orders the entries, each once. */
|
|
15940
|
+
order(providerIds) {
|
|
15941
|
+
return this.routes.send("PUT", "/providers/order", { providerIds });
|
|
15942
|
+
}
|
|
15943
|
+
/** The entry `id` as Settings shows it: its models, accounts and state. */
|
|
15944
|
+
status(id) {
|
|
15945
|
+
return this.routes.json("GET", `/providers/${segment(id)}/status`, providerDetailsSchema);
|
|
15946
|
+
}
|
|
15947
|
+
/** The quota of the entry's subscription, its active account's or `credentialId`'s, read now. */
|
|
15948
|
+
async quota(id, options = {}) {
|
|
15949
|
+
return (await this.routes.json("POST", `/providers/${segment(id)}/quota`, quotaAnswerSchema, options)).quota;
|
|
15950
|
+
}
|
|
15951
|
+
/** Calls the entry's model, or `modelId`, once, with its active account or `credentialId`. */
|
|
15952
|
+
test(id, options = {}) {
|
|
15953
|
+
return this.routes.json("POST", `/providers/${segment(id)}/test`, testResultSchema, options);
|
|
15954
|
+
}
|
|
15955
|
+
/** The newest version of the command-line program the entry's subscription runs, read again with `refresh`. */
|
|
15956
|
+
async cli(id, options = {}) {
|
|
15957
|
+
return (await this.routes.json("GET", `/providers/${segment(id)}/cli${query({ refresh: options.refresh })}`, providerCliSchema)).newest;
|
|
15958
|
+
}
|
|
15959
|
+
/** Starts installing that program's newest version; the entry's status says when it is in place. */
|
|
15960
|
+
installCli(id) {
|
|
15961
|
+
return this.routes.send("POST", `/providers/${segment(id)}/cli/install`);
|
|
15031
15962
|
}
|
|
15032
15963
|
accounts(id) {
|
|
15033
|
-
const path = `/providers/${
|
|
15964
|
+
const path = `/providers/${segment(id)}/accounts`;
|
|
15034
15965
|
return {
|
|
15035
15966
|
list: () => this.routes.json("GET", path, accountsSchema),
|
|
15036
15967
|
activate: async (credentialId) => void await this.routes.json("PUT", `${path}/active`, activeAccountSchema, { credentialId }),
|
|
15037
15968
|
order: (credentialIds) => this.routes.send("PUT", `${path}/order`, { credentialIds }),
|
|
15038
|
-
remove: async (credentialId) => void await this.routes.json("DELETE", `${path}/${
|
|
15969
|
+
remove: async (credentialId) => void await this.routes.json("DELETE", `${path}/${segment(credentialId)}`, removedAccountSchema),
|
|
15039
15970
|
signIn: async () => this.signInOf((await this.routes.json("POST", `${path}/login`, loginStartedSchema)).login.id)
|
|
15040
15971
|
};
|
|
15041
15972
|
}
|
|
@@ -15044,7 +15975,7 @@ var Providers = class {
|
|
|
15044
15975
|
return this.signInOf((await this.routes.json("POST", "/providers/subscription-login", loginStartedSchema, login)).login.id);
|
|
15045
15976
|
}
|
|
15046
15977
|
signInOf(id) {
|
|
15047
|
-
const path = `/providers/subscription-login/${
|
|
15978
|
+
const path = `/providers/subscription-login/${segment(id)}`;
|
|
15048
15979
|
return {
|
|
15049
15980
|
id,
|
|
15050
15981
|
submitCode: async (code) => void await this.routes.json("POST", `${path}/code`, codeTakenSchema, { code }),
|
|
@@ -15078,7 +16009,7 @@ var Device = class {
|
|
|
15078
16009
|
* channel ends before the device came online.
|
|
15079
16010
|
*/
|
|
15080
16011
|
async connect(stream) {
|
|
15081
|
-
const channel = await this.process.connect(this.routes.path(`/devices/${
|
|
16012
|
+
const channel = await this.process.connect(this.routes.path(`/devices/${segment(this.id)}/runner`), "h2c");
|
|
15082
16013
|
stream.readable.pipe(channel);
|
|
15083
16014
|
channel.pipe(stream.writable);
|
|
15084
16015
|
const ended = new Promise((resolve) => {
|
|
@@ -15157,7 +16088,7 @@ var Device = class {
|
|
|
15157
16088
|
...where,
|
|
15158
16089
|
...limited ? { timeoutMs: Math.ceil(timeout) } : {}
|
|
15159
16090
|
};
|
|
15160
|
-
const ran = await this.routes.json("POST", `/devices/${
|
|
16091
|
+
const ran = await this.routes.json("POST", `/devices/${segment(this.id)}/exec`, deviceExecResultSchema, body, signal);
|
|
15161
16092
|
return {
|
|
15162
16093
|
exitCode: ran.exitCode,
|
|
15163
16094
|
...ran.output
|
|
@@ -15172,7 +16103,23 @@ var Device = class {
|
|
|
15172
16103
|
* or is a filesystem's root, such as a volume's mount point.
|
|
15173
16104
|
*/
|
|
15174
16105
|
async revoke() {
|
|
15175
|
-
await this.routes.send("DELETE", `/devices/${
|
|
16106
|
+
await this.routes.send("DELETE", `/devices/${segment(this.id)}`);
|
|
16107
|
+
}
|
|
16108
|
+
/** Renames the device, or changes how the core reaches it. */
|
|
16109
|
+
async update(patch) {
|
|
16110
|
+
return (await this.routes.json("PATCH", `/devices/${segment(this.id)}`, deviceAnswerSchema, patch)).device;
|
|
16111
|
+
}
|
|
16112
|
+
/** Asks the device's runner to run as an administrator, as the user allows on the device. */
|
|
16113
|
+
async elevate() {
|
|
16114
|
+
return (await this.routes.json("POST", `/devices/${segment(this.id)}/elevation`, deviceElevationSchema)).outcome;
|
|
16115
|
+
}
|
|
16116
|
+
/** The device's files, by absolute paths. */
|
|
16117
|
+
get files() {
|
|
16118
|
+
return deviceFiles(this.routes, this.id);
|
|
16119
|
+
}
|
|
16120
|
+
/** The workflows a new conversation working in the absolute `directory` on the device would offer. */
|
|
16121
|
+
workflows(directory) {
|
|
16122
|
+
return this.routes.json("GET", `/devices/${segment(this.id)}/workflows${query({ directory })}`, keptWorkflowListSchema);
|
|
15176
16123
|
}
|
|
15177
16124
|
};
|
|
15178
16125
|
var Devices = class {
|
|
@@ -15188,6 +16135,10 @@ var Devices = class {
|
|
|
15188
16135
|
this.dir = dir;
|
|
15189
16136
|
this.online = online;
|
|
15190
16137
|
}
|
|
16138
|
+
/** The core's devices, as the product state lists them; `of` gives the one a listing names. */
|
|
16139
|
+
async list() {
|
|
16140
|
+
return (await this.routes.json("GET", "/devices", devicesSchema)).devices;
|
|
16141
|
+
}
|
|
15191
16142
|
/** Creates a device, which serves the core once a runner connects to it. */
|
|
15192
16143
|
async create() {
|
|
15193
16144
|
const { device } = await this.routes.json("POST", "/devices", deviceAnswerSchema);
|
|
@@ -15267,7 +16218,6 @@ var Process = class Process {
|
|
|
15267
16218
|
...process.env,
|
|
15268
16219
|
JUSH_RELEASE: start.release.join(pathListSeparator())
|
|
15269
16220
|
};
|
|
15270
|
-
if (start.publicUrl !== void 0) env.JUSH_PUBLIC_URL = start.publicUrl;
|
|
15271
16221
|
const child = spawn(start.executable, [], {
|
|
15272
16222
|
stdio: [
|
|
15273
16223
|
"pipe",
|
|
@@ -15363,17 +16313,27 @@ var Process = class Process {
|
|
|
15363
16313
|
Object.assign(headers, this.credentials);
|
|
15364
16314
|
const stream = session.request(headers, { endStream: request.body === null });
|
|
15365
16315
|
stream.on("error", () => {});
|
|
16316
|
+
let broken;
|
|
15366
16317
|
if (request.body !== null) {
|
|
15367
16318
|
const body = Readable.fromWeb(request.body);
|
|
15368
16319
|
body.pipe(stream);
|
|
15369
|
-
|
|
16320
|
+
body.once("error", (error) => {
|
|
16321
|
+
broken = error;
|
|
16322
|
+
stream.close(http2.constants.NGHTTP2_CANCEL);
|
|
16323
|
+
});
|
|
16324
|
+
const stop = () => {
|
|
16325
|
+
body.unpipe(stream);
|
|
16326
|
+
body.destroy();
|
|
16327
|
+
};
|
|
16328
|
+
stream.once("aborted", stop);
|
|
16329
|
+
stream.once("close", stop);
|
|
15370
16330
|
}
|
|
15371
16331
|
const abort = () => stream.close(http2.constants.NGHTTP2_CANCEL);
|
|
15372
16332
|
if (request.signal.aborted) abort();
|
|
15373
16333
|
request.signal.addEventListener("abort", abort, { once: true });
|
|
15374
16334
|
const bodied = (status) => request.method !== "HEAD" && status !== 204 && status !== 304;
|
|
15375
16335
|
const response = await answered(stream, bodied).catch((error) => {
|
|
15376
|
-
throw request.signal.aborted ? request.signal.reason : error;
|
|
16336
|
+
throw request.signal.aborted ? request.signal.reason : broken ?? error;
|
|
15377
16337
|
}).finally(() => request.signal.removeEventListener("abort", abort));
|
|
15378
16338
|
if (response.body === null) stream.resume();
|
|
15379
16339
|
return response;
|
|
@@ -15514,47 +16474,67 @@ function pathListSeparator() {
|
|
|
15514
16474
|
//#region src/jush.ts
|
|
15515
16475
|
/**
|
|
15516
16476
|
* A program's Jush: the process its cores run in, which `Jush.start` starts
|
|
15517
|
-
* or `Jush.connect` connects to, with the program's plugins
|
|
15518
|
-
* it opens
|
|
16477
|
+
* or `Jush.connect` connects to, with the program's plugins and addresses,
|
|
16478
|
+
* the cores it opens, and the calls from outside that the program's server
|
|
16479
|
+
* takes at its addresses and hands on.
|
|
15519
16480
|
*/
|
|
15520
16481
|
var Jush = class Jush {
|
|
15521
16482
|
process;
|
|
15522
|
-
|
|
16483
|
+
declared;
|
|
16484
|
+
pluginVersion;
|
|
16485
|
+
addresses;
|
|
15523
16486
|
runner;
|
|
15524
16487
|
owned;
|
|
16488
|
+
/** A schedule's URL, as the program's server takes its calls. */
|
|
16489
|
+
schedules;
|
|
16490
|
+
/** The plugins' sign-ins, as the program's server takes their returns. */
|
|
16491
|
+
plugins;
|
|
15525
16492
|
cores = /* @__PURE__ */ new Map();
|
|
15526
|
-
constructor(process,
|
|
16493
|
+
constructor(process, declared, pluginVersion, addresses, runner, owned) {
|
|
15527
16494
|
this.process = process;
|
|
15528
|
-
this.
|
|
16495
|
+
this.declared = declared;
|
|
16496
|
+
this.pluginVersion = pluginVersion;
|
|
16497
|
+
this.addresses = addresses;
|
|
15529
16498
|
this.runner = runner;
|
|
15530
16499
|
this.owned = owned;
|
|
16500
|
+
this.schedules = { call: (id, request) => this.callSchedule(id, request) };
|
|
16501
|
+
this.plugins = { completeSignIn: (signIn) => this.completeSignIn(signIn) };
|
|
15531
16502
|
}
|
|
15532
|
-
/** Starts a process of the program's own, with the program's plugins. */
|
|
16503
|
+
/** Starts a process of the program's own, with the program's plugins and addresses. */
|
|
15533
16504
|
static async start(options = {}) {
|
|
15534
16505
|
const found = binaries();
|
|
15535
16506
|
const process = Process.start({
|
|
15536
16507
|
executable: found.core,
|
|
15537
|
-
release: found.release
|
|
15538
|
-
...options.publicUrl === void 0 ? {} : { publicUrl: options.publicUrl }
|
|
16508
|
+
release: found.release
|
|
15539
16509
|
});
|
|
15540
|
-
|
|
15541
|
-
await process.greet((fetch) => jush.greet(fetch));
|
|
15542
|
-
return jush;
|
|
16510
|
+
return Jush.greeted(new Jush(process, options.plugins ?? [], options.pluginVersion, options.addresses, () => found.runner, true));
|
|
15543
16511
|
}
|
|
15544
16512
|
/**
|
|
15545
16513
|
* Connects to a process that runs on its own, and declares the program's
|
|
15546
|
-
* plugins: the cores it holds, their conversations and
|
|
15547
|
-
* on while the program was away. A connection made
|
|
15548
|
-
* process restarted, declares them again and opens
|
|
15549
|
-
* again before anything else.
|
|
16514
|
+
* addresses and plugins: the cores it holds, their conversations and
|
|
16515
|
+
* their turns went on while the program was away. A connection made
|
|
16516
|
+
* again, as after the process restarted, declares them again and opens
|
|
16517
|
+
* the program's cores again before anything else.
|
|
15550
16518
|
*/
|
|
15551
16519
|
static async connect(connection) {
|
|
15552
16520
|
const process = Process.connect({
|
|
15553
16521
|
url: connection.url,
|
|
15554
16522
|
token: connection.token
|
|
15555
16523
|
});
|
|
15556
|
-
|
|
15557
|
-
|
|
16524
|
+
return Jush.greeted(new Jush(process, connection.plugins ?? [], connection.pluginVersion, connection.addresses, () => binaries().runner, false));
|
|
16525
|
+
}
|
|
16526
|
+
/**
|
|
16527
|
+
* `jush` once it greeted its process; a greeting the process refused,
|
|
16528
|
+
* such as an address that is no template, ends the process the program
|
|
16529
|
+
* started, or the connection to one on its own.
|
|
16530
|
+
*/
|
|
16531
|
+
static async greeted(jush) {
|
|
16532
|
+
try {
|
|
16533
|
+
await jush.process.greet((fetch) => jush.greet(fetch));
|
|
16534
|
+
} catch (error) {
|
|
16535
|
+
await jush.process.close();
|
|
16536
|
+
throw error;
|
|
16537
|
+
}
|
|
15558
16538
|
return jush;
|
|
15559
16539
|
}
|
|
15560
16540
|
/**
|
|
@@ -15573,25 +16553,18 @@ var Jush = class Jush {
|
|
|
15573
16553
|
process: this.process,
|
|
15574
16554
|
id,
|
|
15575
16555
|
dir: path,
|
|
15576
|
-
plugins: this.
|
|
16556
|
+
plugins: this.declared,
|
|
16557
|
+
pluginVersion: this.pluginVersion,
|
|
15577
16558
|
runner: this.runner
|
|
15578
16559
|
}, async () => {
|
|
15579
16560
|
this.cores.delete(id);
|
|
15580
|
-
await (await this.call("DELETE", `/cores/${
|
|
16561
|
+
await (await this.call("DELETE", `/cores/${segment(id)}`)).body?.cancel();
|
|
15581
16562
|
});
|
|
15582
16563
|
this.cores.set(id, core);
|
|
15583
16564
|
await core.follow();
|
|
15584
16565
|
return core;
|
|
15585
16566
|
}
|
|
15586
16567
|
/**
|
|
15587
|
-
* Answers a call of a schedule's URL, `/hooks/{id}` below `base`, as the
|
|
15588
|
-
* program's server forwards it.
|
|
15589
|
-
*/
|
|
15590
|
-
fetch(request, base = "") {
|
|
15591
|
-
const url = new URL(request.url);
|
|
15592
|
-
return this.process.fetch(new Request(PROCESS_ORIGIN + below(url.pathname, base) + url.search, request));
|
|
15593
|
-
}
|
|
15594
|
-
/**
|
|
15595
16568
|
* Ends the program's use of Jush: a process the program started closes
|
|
15596
16569
|
* every core and exits; one on its own keeps its cores, which the
|
|
15597
16570
|
* program's next run opens again.
|
|
@@ -15604,12 +16577,44 @@ var Jush = class Jush {
|
|
|
15604
16577
|
await this.process.close();
|
|
15605
16578
|
}
|
|
15606
16579
|
/**
|
|
16580
|
+
* The call `request` as one HTTP message (`message/http`, RFC 9112
|
|
16581
|
+
* § 10.1): its head, then its body's bytes as they arrive, which a
|
|
16582
|
+
* signature over them verifies.
|
|
16583
|
+
*/
|
|
16584
|
+
async callSchedule(id, request) {
|
|
16585
|
+
const url = new URL(request.url);
|
|
16586
|
+
const lines = [`${request.method} ${url.pathname}${url.search} HTTP/1.1`];
|
|
16587
|
+
request.headers.forEach((value, name) => lines.push(`${name}: ${value}`));
|
|
16588
|
+
const head = Buffer.from(`${lines.join("\r\n")}\r\n\r\n`, "latin1");
|
|
16589
|
+
const path = `/schedules/calls?${new URLSearchParams({ id })}`;
|
|
16590
|
+
const sent = {
|
|
16591
|
+
method: "POST",
|
|
16592
|
+
body: request.body === null ? head : headed(head, request.body),
|
|
16593
|
+
headers: { "content-type": "message/http" },
|
|
16594
|
+
duplex: "half"
|
|
16595
|
+
};
|
|
16596
|
+
const response = await this.process.fetch(new Request(PROCESS_ORIGIN + path, sent));
|
|
16597
|
+
if (!response.ok) throw await refusal(response, `POST ${path}`);
|
|
16598
|
+
return scheduleCallAnswerSchema.parse(await response.json());
|
|
16599
|
+
}
|
|
16600
|
+
async completeSignIn(signIn) {
|
|
16601
|
+
const query = new URLSearchParams(signIn.query).toString();
|
|
16602
|
+
const response = await this.call("POST", "/sign-ins", {
|
|
16603
|
+
core: signIn.core,
|
|
16604
|
+
plugin: signIn.plugin,
|
|
16605
|
+
query
|
|
16606
|
+
});
|
|
16607
|
+
return signInAnswerSchema.parse(await response.json());
|
|
16608
|
+
}
|
|
16609
|
+
/**
|
|
15607
16610
|
* What each connection to the process begins with: the program's
|
|
15608
|
-
* plugins, then its cores, which a process that
|
|
15609
|
-
* longer.
|
|
16611
|
+
* addresses and plugins, then its cores, which a process that
|
|
16612
|
+
* restarted holds no longer.
|
|
15610
16613
|
*/
|
|
15611
16614
|
async greet(fetch) {
|
|
15612
|
-
|
|
16615
|
+
if (this.addresses !== void 0) await (await this.call("PUT", "/addresses", this.addresses, fetch)).body?.cancel();
|
|
16616
|
+
const version = this.pluginVersion === void 0 ? "" : `/versions/${segment(this.pluginVersion)}`;
|
|
16617
|
+
for (const plugin of this.declared) await (await this.call("PUT", `/plugins/${segment(plugin.manifest.id)}${version}`, plugin.manifest, fetch)).body?.cancel();
|
|
15613
16618
|
for (const core of this.cores.values()) await (await this.call("POST", "/cores", { dir: core.dir }, fetch)).body?.cancel();
|
|
15614
16619
|
}
|
|
15615
16620
|
async call(method, path, body, fetch = (request) => this.process.fetch(request)) {
|
|
@@ -15624,5 +16629,26 @@ var Jush = class Jush {
|
|
|
15624
16629
|
return response;
|
|
15625
16630
|
}
|
|
15626
16631
|
};
|
|
16632
|
+
/**
|
|
16633
|
+
* `head`, then `body`'s bytes as they arrive; cancelling it, as the process
|
|
16634
|
+
* does once it answered, cancels `body`.
|
|
16635
|
+
*/
|
|
16636
|
+
function headed(head, body) {
|
|
16637
|
+
const reader = body.getReader();
|
|
16638
|
+
let sent = false;
|
|
16639
|
+
return new ReadableStream({
|
|
16640
|
+
async pull(controller) {
|
|
16641
|
+
if (!sent) {
|
|
16642
|
+
sent = true;
|
|
16643
|
+
controller.enqueue(head);
|
|
16644
|
+
return;
|
|
16645
|
+
}
|
|
16646
|
+
const read = await reader.read();
|
|
16647
|
+
if (read.done) controller.close();
|
|
16648
|
+
else controller.enqueue(read.value);
|
|
16649
|
+
},
|
|
16650
|
+
cancel: (reason) => reader.cancel(reason)
|
|
16651
|
+
});
|
|
16652
|
+
}
|
|
15627
16653
|
//#endregion
|
|
15628
|
-
export { Conversation, Conversations, Core, Device, Devices, Jush, JushError, PortFailure, Providers, definePlugin, leaf };
|
|
16654
|
+
export { Conversation, ConversationPage, Conversations, Core, Device, Devices, Jush, JushError, PortFailure, Providers, definePlugin, leaf };
|