@finalai/agents 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HOSTING.md +334 -245
- package/README.md +214 -29
- package/dist/modules/agent-client/agent-input.d.mts +24 -0
- package/dist/modules/agent-client/agent-input.mjs +46 -0
- package/dist/modules/agent-client/agent-input.mjs.map +7 -0
- package/dist/modules/agent-client/channels.d.mts +52 -3
- package/dist/modules/agent-client/channels.mjs +71 -10
- package/dist/modules/agent-client/channels.mjs.map +2 -2
- package/dist/modules/agent-client/client.d.mts +85 -20
- package/dist/modules/agent-client/client.mjs +74 -21
- package/dist/modules/agent-client/client.mjs.map +2 -2
- package/dist/modules/agent-client/config-options.mjs +1 -2
- package/dist/modules/agent-client/config-options.mjs.map +2 -2
- package/dist/modules/agent-client/conversation-resources.d.mts +85 -0
- package/dist/modules/agent-client/conversation-resources.mjs +150 -0
- package/dist/modules/agent-client/conversation-resources.mjs.map +7 -0
- package/dist/modules/agent-client/conversations.d.mts +116 -38
- package/dist/modules/agent-client/conversations.mjs +379 -71
- package/dist/modules/agent-client/conversations.mjs.map +2 -2
- package/dist/modules/agent-client/defaults.d.mts +8 -0
- package/dist/modules/agent-client/defaults.mjs +77 -0
- package/dist/modules/agent-client/defaults.mjs.map +7 -0
- package/dist/modules/agent-client/errors.d.mts +22 -2
- package/dist/modules/agent-client/errors.mjs +19 -0
- package/dist/modules/agent-client/errors.mjs.map +2 -2
- package/dist/modules/agent-client/events.d.mts +62 -0
- package/dist/modules/agent-client/events.mjs +107 -0
- package/dist/modules/agent-client/events.mjs.map +7 -0
- package/dist/modules/agent-client/harnesses.d.mts +66 -0
- package/dist/modules/agent-client/harnesses.mjs +156 -0
- package/dist/modules/agent-client/harnesses.mjs.map +7 -0
- package/dist/modules/agent-client/http.d.mts +2 -1
- package/dist/modules/agent-client/http.mjs +21 -2
- package/dist/modules/agent-client/http.mjs.map +2 -2
- package/dist/modules/agent-client/index.d.mts +21 -6
- package/dist/modules/agent-client/index.mjs +26 -0
- package/dist/modules/agent-client/index.mjs.map +2 -2
- package/dist/modules/agent-client/integrations.d.mts +40 -0
- package/dist/modules/agent-client/integrations.mjs +92 -0
- package/dist/modules/agent-client/integrations.mjs.map +7 -0
- package/dist/modules/agent-client/local-host-protocol.d.mts +156 -0
- package/dist/modules/agent-client/local-host-protocol.mjs +258 -0
- package/dist/modules/agent-client/local-host-protocol.mjs.map +7 -0
- package/dist/modules/agent-client/local-host.d.mts +56 -0
- package/dist/modules/agent-client/local-host.mjs +200 -0
- package/dist/modules/agent-client/local-host.mjs.map +7 -0
- package/dist/modules/agent-client/oauth-clients.d.mts +36 -0
- package/dist/modules/agent-client/oauth-clients.mjs +67 -0
- package/dist/modules/agent-client/oauth-clients.mjs.map +7 -0
- package/dist/modules/agent-client/project-agents.d.mts +54 -0
- package/dist/modules/agent-client/project-agents.mjs +111 -0
- package/dist/modules/agent-client/project-agents.mjs.map +7 -0
- package/dist/modules/agent-client/project.d.mts +43 -0
- package/dist/modules/agent-client/project.mjs +66 -0
- package/dist/modules/agent-client/project.mjs.map +7 -0
- package/dist/modules/agent-client/projects.d.mts +61 -0
- package/dist/modules/agent-client/projects.mjs +145 -0
- package/dist/modules/agent-client/projects.mjs.map +7 -0
- package/dist/modules/agent-client/provide.d.mts +41 -0
- package/dist/modules/agent-client/provide.mjs +90 -0
- package/dist/modules/agent-client/provide.mjs.map +7 -0
- package/dist/modules/agent-client/publishers.d.mts +57 -0
- package/dist/modules/agent-client/publishers.mjs +109 -0
- package/dist/modules/agent-client/publishers.mjs.map +7 -0
- package/dist/modules/agent-client/requirements.d.mts +60 -0
- package/dist/modules/agent-client/requirements.mjs +83 -0
- package/dist/modules/agent-client/requirements.mjs.map +7 -0
- package/dist/modules/agent-client/sandbox-providers.d.mts +34 -0
- package/dist/modules/agent-client/sandbox-providers.mjs +75 -0
- package/dist/modules/agent-client/sandbox-providers.mjs.map +7 -0
- package/dist/modules/agent-client/sandbox-uri.d.mts +1 -1
- package/dist/modules/agent-client/sandbox-uri.mjs +4 -4
- package/dist/modules/agent-client/sandbox-uri.mjs.map +1 -1
- package/dist/modules/agent-client/sandboxes.d.mts +65 -0
- package/dist/modules/agent-client/sandboxes.mjs +130 -0
- package/dist/modules/agent-client/sandboxes.mjs.map +7 -0
- package/dist/modules/agent-client/schedules.d.mts +24 -0
- package/dist/modules/agent-client/schedules.mjs +56 -0
- package/dist/modules/agent-client/schedules.mjs.map +7 -0
- package/dist/modules/agent-client/sessions.d.mts +46 -8
- package/dist/modules/agent-client/sessions.mjs +91 -29
- package/dist/modules/agent-client/sessions.mjs.map +2 -2
- package/dist/modules/agent-client/start.d.mts +101 -0
- package/dist/modules/agent-client/start.mjs +260 -0
- package/dist/modules/agent-client/start.mjs.map +7 -0
- package/dist/modules/agent-client/test-fakes.d.mts +1 -0
- package/dist/modules/agent-client/test-fakes.mjs +3 -1
- package/dist/modules/agent-client/test-fakes.mjs.map +2 -2
- package/dist/modules/cli/agent-module.d.mts +39 -0
- package/dist/modules/cli/agent-module.mjs +89 -0
- package/dist/modules/cli/agent-module.mjs.map +7 -0
- package/dist/modules/cli/cli.d.mts +6 -6
- package/dist/modules/cli/cli.mjs +94 -120
- package/dist/modules/cli/cli.mjs.map +2 -2
- package/dist/modules/cli/conformance.d.mts +2 -6
- package/dist/modules/cli/conformance.mjs +5 -8
- package/dist/modules/cli/conformance.mjs.map +2 -2
- package/dist/modules/cli/main.mjs.map +1 -1
- package/dist/modules/cli/output.d.mts +0 -9
- package/dist/modules/cli/output.mjs +7 -85
- package/dist/modules/cli/output.mjs.map +2 -2
- package/dist/modules/harnesses.mjs.map +2 -2
- package/dist/modules/index.d.mts +0 -2
- package/dist/modules/index.mjs +0 -4
- package/dist/modules/index.mjs.map +2 -2
- package/dist/modules/integrations.d.mts +24 -0
- package/dist/modules/integrations.mjs +30 -0
- package/dist/modules/integrations.mjs.map +7 -0
- package/dist/modules/public.d.mts +10 -10
- package/dist/modules/public.mjs +29 -78
- package/dist/modules/public.mjs.map +2 -2
- package/dist/modules/sandboxes.d.mts +2 -0
- package/dist/modules/sandboxes.mjs +4 -0
- package/dist/modules/sandboxes.mjs.map +2 -2
- package/dist/modules/verify.d.mts +1 -0
- package/dist/modules/verify.mjs +2 -0
- package/dist/modules/verify.mjs.map +7 -0
- package/dist/modules/webhooks.d.mts +37 -0
- package/dist/modules/webhooks.mjs +100 -0
- package/dist/modules/webhooks.mjs.map +7 -0
- package/examples/release-scout/README.md +18 -10
- package/examples/release-scout/agent.ts +41 -0
- package/examples/release-scout/by-name.ts +43 -0
- package/examples/release-scout/db.ts +6 -0
- package/examples/release-scout/instructions.md +5 -0
- package/examples/release-scout/run-on-a-computer.ts +49 -0
- package/examples/release-scout/run.ts +38 -0
- package/package.json +42 -28
- package/dist/modules/agent-client/build.d.mts +0 -110
- package/dist/modules/agent-client/build.mjs +0 -213
- package/dist/modules/agent-client/build.mjs.map +0 -7
- package/dist/modules/authoring/index.d.mts +0 -1
- package/dist/modules/authoring/index.mjs +0 -2
- package/dist/modules/authoring/index.mjs.map +0 -7
- package/dist/modules/authoring/instructions.d.mts +0 -1
- package/dist/modules/authoring/instructions.mjs +0 -2
- package/dist/modules/authoring/instructions.mjs.map +0 -7
- package/dist/modules/authoring/providers.d.mts +0 -2
- package/dist/modules/authoring/providers.mjs +0 -1
- package/dist/modules/authoring/providers.mjs.map +0 -7
- package/dist/modules/cli/build.d.mts +0 -22
- package/dist/modules/cli/build.mjs +0 -77
- package/dist/modules/cli/build.mjs.map +0 -7
- package/dist/modules/cli/channel-install.d.mts +0 -12
- package/dist/modules/cli/channel-install.mjs +0 -25
- package/dist/modules/cli/channel-install.mjs.map +0 -7
- package/dist/modules/cli/channel-socket.d.mts +0 -9
- package/dist/modules/cli/channel-socket.mjs +0 -114
- package/dist/modules/cli/channel-socket.mjs.map +0 -7
- package/dist/modules/cli/dev.d.mts +0 -26
- package/dist/modules/cli/dev.mjs +0 -311
- package/dist/modules/cli/dev.mjs.map +0 -7
- package/dist/modules/cli/files.d.mts +0 -18
- package/dist/modules/cli/files.mjs +0 -66
- package/dist/modules/cli/files.mjs.map +0 -7
- package/dist/modules/cli/harness-descriptions.d.mts +0 -20
- package/dist/modules/cli/harness-descriptions.mjs +0 -70
- package/dist/modules/cli/harness-descriptions.mjs.map +0 -7
- package/dist/modules/cli/publish.d.mts +0 -15
- package/dist/modules/cli/publish.mjs +0 -92
- package/dist/modules/cli/publish.mjs.map +0 -7
- package/dist/modules/compile.d.mts +0 -3
- package/dist/modules/compile.mjs +0 -58
- package/dist/modules/compile.mjs.map +0 -7
- package/dist/modules/index.browser.d.mts +0 -4
- package/dist/modules/index.browser.mjs +0 -8
- package/dist/modules/index.browser.mjs.map +0 -7
- package/examples/custom-harness/README.md +0 -16
- package/examples/custom-harness/agent.ts +0 -154
- package/examples/custom-sandbox/README.md +0 -12
- package/examples/custom-sandbox/agent.ts +0 -14
- package/examples/custom-sandbox/sandbox.ts +0 -24
- package/examples/release-scout/agent/agent.ts +0 -22
- package/examples/release-scout/agent/channels/github-signature.ts +0 -27
- package/examples/release-scout/agent/channels/github.ts +0 -32
- package/examples/release-scout/agent/connections/linear.ts +0 -9
- package/examples/release-scout/agent/hooks/audit.ts +0 -24
- package/examples/release-scout/agent/instructions/org-context.ts +0 -26
- package/examples/release-scout/agent/instructions.md +0 -2
- package/examples/release-scout/agent/sandbox.ts +0 -20
- package/examples/release-scout/agent/schedules/daily-digest.md +0 -7
- package/examples/release-scout/agent/skills/triage/SKILL.md +0 -8
- package/examples/release-scout/agent/skills/triage/checklist.md +0 -3
- package/examples/release-scout/agent/tools/lookup_release_notes.ts +0 -24
- package/examples/release-scout/client.ts +0 -122
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
PROCESS_CAPABILITIES,
|
|
2
3
|
ProcessInspectionOperation,
|
|
3
4
|
processInspectionRequestSchema,
|
|
4
5
|
processInspectionResultSchema
|
|
@@ -21,6 +22,9 @@ import {
|
|
|
21
22
|
conversationSandboxSchema,
|
|
22
23
|
conversationScheduleListSchema,
|
|
23
24
|
conversationScheduleSchema,
|
|
25
|
+
conversationLabelFilter,
|
|
26
|
+
conversationLookupSchema,
|
|
27
|
+
conversationResponseSchema,
|
|
24
28
|
conversationSchema,
|
|
25
29
|
createAttachmentUploadRequestSchema,
|
|
26
30
|
createConversationLinkRequestSchema,
|
|
@@ -29,6 +33,7 @@ import {
|
|
|
29
33
|
createDirectConversationRequestSchema,
|
|
30
34
|
DecisionEventState,
|
|
31
35
|
decisionRecordListSchema,
|
|
36
|
+
homeConversationRequestSchema,
|
|
32
37
|
decisionsPageSchema,
|
|
33
38
|
markReadRequestSchema,
|
|
34
39
|
messageDeliveriesSchema,
|
|
@@ -39,8 +44,10 @@ import {
|
|
|
39
44
|
participantInputSchema,
|
|
40
45
|
ParticipantKind,
|
|
41
46
|
participantListSchema,
|
|
47
|
+
participantProvideResponseSchema,
|
|
42
48
|
participantSchema,
|
|
43
49
|
postConversationEventRequestSchema,
|
|
50
|
+
provideParticipantRequestSchema,
|
|
44
51
|
postConversationEventResponseSchema,
|
|
45
52
|
pushDeliveryOpenResponseSchema,
|
|
46
53
|
reactionRequestSchema,
|
|
@@ -64,9 +71,13 @@ import {
|
|
|
64
71
|
typingRequestSchema,
|
|
65
72
|
updateConversationRequestSchema,
|
|
66
73
|
updateConversationScheduleRequestSchema,
|
|
67
|
-
updateParticipantRequestSchema
|
|
74
|
+
updateParticipantRequestSchema,
|
|
75
|
+
SandboxProviderKind
|
|
68
76
|
} from "@finalai/agent-protocol/agent-platform";
|
|
69
77
|
import { createAsyncQueue, failOnAbort } from "./async-queue.mjs";
|
|
78
|
+
import {
|
|
79
|
+
createConversationResources
|
|
80
|
+
} from "./conversation-resources.mjs";
|
|
70
81
|
import {
|
|
71
82
|
streamCollectionEvents
|
|
72
83
|
} from "./collection-events.mjs";
|
|
@@ -77,12 +88,24 @@ import {
|
|
|
77
88
|
import {
|
|
78
89
|
clientError,
|
|
79
90
|
ClientErrorCode,
|
|
91
|
+
isClientError,
|
|
80
92
|
isRetryableClientError,
|
|
81
93
|
isTerminalRealtimeError,
|
|
82
94
|
realtimeSubscriptionError
|
|
83
95
|
} from "./errors.mjs";
|
|
84
96
|
import { errorFromResponse, HttpMethod } from "./http.mjs";
|
|
97
|
+
import { LocalHostOwnerKind } from "./local-host-protocol.mjs";
|
|
98
|
+
import {
|
|
99
|
+
provideDocumentOf,
|
|
100
|
+
provideDocumentOfView,
|
|
101
|
+
providePatchOf
|
|
102
|
+
} from "./provide.mjs";
|
|
103
|
+
import { createSandboxesApi } from "./sandboxes.mjs";
|
|
85
104
|
import { outcomeOf } from "./sessions.mjs";
|
|
105
|
+
import {
|
|
106
|
+
startAgent,
|
|
107
|
+
withWorkersEnvironment
|
|
108
|
+
} from "./start.mjs";
|
|
86
109
|
const TURN_OPEN_SESSION_STATES = /* @__PURE__ */ new Set([
|
|
87
110
|
AgentSessionState.Running,
|
|
88
111
|
AgentSessionState.RequiresAction
|
|
@@ -574,8 +597,9 @@ const streamConversationEvents = (args) => {
|
|
|
574
597
|
}
|
|
575
598
|
return queue.iterator;
|
|
576
599
|
};
|
|
577
|
-
const createConversationHandle = (context, conversationId) => {
|
|
600
|
+
const createConversationHandle = (context, conversationId, starter) => {
|
|
578
601
|
const { http } = context;
|
|
602
|
+
const participantPath = (participantId, suffix = "") => conversationPath(conversationId, `/participants/${encodePath(participantId)}${suffix}`);
|
|
579
603
|
const sandboxFileContentRequest = async (args) => {
|
|
580
604
|
if (args.path.length === 0 || args.path.length > 4096 || args.path.includes("\0")) {
|
|
581
605
|
throw clientError({
|
|
@@ -585,7 +609,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
585
609
|
});
|
|
586
610
|
}
|
|
587
611
|
const target = http.url(
|
|
588
|
-
conversationPath(conversationId, `/sandboxes/${encodePath(args.
|
|
612
|
+
conversationPath(conversationId, `/sandboxes/${encodePath(args.sandboxId)}/file/content`)
|
|
589
613
|
);
|
|
590
614
|
target.searchParams.set("path", args.path);
|
|
591
615
|
if (args.snapshotId != null) target.searchParams.set("snapshotId", args.snapshotId);
|
|
@@ -637,14 +661,20 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
637
661
|
response: reactionsResponseSchema,
|
|
638
662
|
signal: args.signal
|
|
639
663
|
})).reactions;
|
|
664
|
+
const info = (signal) => http.request({
|
|
665
|
+
method: HttpMethod.Get,
|
|
666
|
+
path: conversationPath(conversationId),
|
|
667
|
+
response: conversationSchema,
|
|
668
|
+
signal
|
|
669
|
+
});
|
|
670
|
+
const sharedProvide = async (signal) => {
|
|
671
|
+
const { provide } = await info(signal);
|
|
672
|
+
return provide == null ? null : provideDocumentOfView(provide);
|
|
673
|
+
};
|
|
640
674
|
return {
|
|
675
|
+
...createConversationResources(context, conversationId),
|
|
641
676
|
id: conversationId,
|
|
642
|
-
info: (options) =>
|
|
643
|
-
method: HttpMethod.Get,
|
|
644
|
-
path: conversationPath(conversationId),
|
|
645
|
-
response: conversationSchema,
|
|
646
|
-
signal: options?.signal
|
|
647
|
-
}),
|
|
677
|
+
info: (options) => info(options?.signal),
|
|
648
678
|
send: async (content, options) => {
|
|
649
679
|
const sent = await http.request({
|
|
650
680
|
method: HttpMethod.Post,
|
|
@@ -659,7 +689,8 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
659
689
|
quotes: options?.quotes,
|
|
660
690
|
mentions: options?.mentions,
|
|
661
691
|
attachmentIds: options?.attachmentIds,
|
|
662
|
-
clientSubmittedAtMs: options?.clientSubmittedAtMs ?? context.now()
|
|
692
|
+
clientSubmittedAtMs: options?.clientSubmittedAtMs ?? context.now(),
|
|
693
|
+
actor: options?.actor
|
|
663
694
|
}
|
|
664
695
|
},
|
|
665
696
|
response: sendMessageResponseSchema,
|
|
@@ -760,7 +791,36 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
760
791
|
signal: options?.signal
|
|
761
792
|
});
|
|
762
793
|
},
|
|
763
|
-
participants: (
|
|
794
|
+
participants: Object.assign(
|
|
795
|
+
(options) => listParticipants({ signal: options?.signal }),
|
|
796
|
+
{
|
|
797
|
+
settings: (participantId, options) => http.request({
|
|
798
|
+
method: HttpMethod.Get,
|
|
799
|
+
path: participantPath(participantId, "/provide"),
|
|
800
|
+
response: participantProvideResponseSchema,
|
|
801
|
+
signal: options?.signal
|
|
802
|
+
}),
|
|
803
|
+
provide: async (participantId, patch, options) => {
|
|
804
|
+
const harness = patch.harness == null || starter.projectId == null ? patch.harness : (await withWorkersEnvironment({
|
|
805
|
+
context,
|
|
806
|
+
projectId: starter.projectId,
|
|
807
|
+
harness: patch.harness,
|
|
808
|
+
owner: { kind: LocalHostOwnerKind.Conversation, id: conversationId },
|
|
809
|
+
signal: options?.signal
|
|
810
|
+
})).harness;
|
|
811
|
+
return http.request({
|
|
812
|
+
method: HttpMethod.Put,
|
|
813
|
+
path: participantPath(participantId, "/provide"),
|
|
814
|
+
body: {
|
|
815
|
+
schema: provideParticipantRequestSchema,
|
|
816
|
+
value: providePatchOf(harness == null ? patch : { ...patch, harness })
|
|
817
|
+
},
|
|
818
|
+
response: participantProvideResponseSchema,
|
|
819
|
+
signal: options?.signal
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
),
|
|
764
824
|
turns: async (options) => {
|
|
765
825
|
const participants = await listParticipants({ signal: options?.signal });
|
|
766
826
|
return Promise.all(
|
|
@@ -780,13 +840,50 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
780
840
|
})
|
|
781
841
|
);
|
|
782
842
|
},
|
|
783
|
-
addParticipant: (participant, options) =>
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
843
|
+
addParticipant: async (participant, options) => {
|
|
844
|
+
if ("user" in participant || "actor" in participant)
|
|
845
|
+
return http.request({
|
|
846
|
+
method: HttpMethod.Post,
|
|
847
|
+
path: conversationPath(conversationId, "/participants"),
|
|
848
|
+
body: {
|
|
849
|
+
schema: participantInputSchema,
|
|
850
|
+
value: "user" in participant ? { user: participant.user } : { actor: participant.actor }
|
|
851
|
+
},
|
|
852
|
+
response: participantSchema,
|
|
853
|
+
signal: options?.signal
|
|
854
|
+
});
|
|
855
|
+
const own = participant.provide;
|
|
856
|
+
const shared = own.harness != null && own.compute != null && own.integrations != null ? null : await sharedProvide(options?.signal);
|
|
857
|
+
const started = await startAgent(starter.deps, {
|
|
858
|
+
projectId: starter.projectId,
|
|
859
|
+
agent: participant.agent,
|
|
860
|
+
provide: own,
|
|
861
|
+
shared,
|
|
862
|
+
owner: { kind: LocalHostOwnerKind.Conversation, id: conversationId },
|
|
863
|
+
signal: options?.signal
|
|
864
|
+
});
|
|
865
|
+
try {
|
|
866
|
+
const added = await http.request({
|
|
867
|
+
method: HttpMethod.Post,
|
|
868
|
+
path: conversationPath(conversationId, "/participants"),
|
|
869
|
+
body: {
|
|
870
|
+
schema: participantInputSchema,
|
|
871
|
+
value: {
|
|
872
|
+
agent: started.ref,
|
|
873
|
+
routingMode: participant.routingMode,
|
|
874
|
+
provide: started.provide
|
|
875
|
+
}
|
|
876
|
+
},
|
|
877
|
+
response: participantSchema,
|
|
878
|
+
signal: options?.signal
|
|
879
|
+
});
|
|
880
|
+
started.established();
|
|
881
|
+
return added;
|
|
882
|
+
} catch (cause) {
|
|
883
|
+
started.abandon();
|
|
884
|
+
throw cause;
|
|
885
|
+
}
|
|
886
|
+
},
|
|
790
887
|
updateParticipant: ({ participantId, ...patch }, options) => http.request({
|
|
791
888
|
method: HttpMethod.Patch,
|
|
792
889
|
path: conversationPath(conversationId, `/participants/${encodePath(participantId)}`),
|
|
@@ -859,14 +956,14 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
859
956
|
})).sandboxes,
|
|
860
957
|
sandboxFiles: (args, options) => http.request({
|
|
861
958
|
method: HttpMethod.Get,
|
|
862
|
-
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.
|
|
959
|
+
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.sandboxId)}/files`),
|
|
863
960
|
query: { path: args.path, snapshotId: args.snapshotId },
|
|
864
961
|
response: sandboxDirectorySchema,
|
|
865
962
|
signal: options?.signal
|
|
866
963
|
}),
|
|
867
964
|
sandboxPath: (args, options) => http.request({
|
|
868
965
|
method: HttpMethod.Get,
|
|
869
|
-
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.
|
|
966
|
+
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.sandboxId)}/path`),
|
|
870
967
|
query: { path: args.path, snapshotId: args.snapshotId },
|
|
871
968
|
response: sandboxPathSchema,
|
|
872
969
|
signal: options?.signal
|
|
@@ -875,7 +972,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
875
972
|
method: HttpMethod.Get,
|
|
876
973
|
path: conversationPath(
|
|
877
974
|
conversationId,
|
|
878
|
-
`/sandboxes/${encodePath(args.
|
|
975
|
+
`/sandboxes/${encodePath(args.sandboxId)}/files/search`
|
|
879
976
|
),
|
|
880
977
|
query: { path: args.path, query: args.query, limit: args.limit },
|
|
881
978
|
response: sandboxSearchSchema,
|
|
@@ -883,7 +980,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
883
980
|
}),
|
|
884
981
|
sandboxFile: (args, options) => http.request({
|
|
885
982
|
method: HttpMethod.Get,
|
|
886
|
-
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.
|
|
983
|
+
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.sandboxId)}/file`),
|
|
887
984
|
query: {
|
|
888
985
|
path: args.path,
|
|
889
986
|
offset: args.offset,
|
|
@@ -896,7 +993,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
896
993
|
sandboxFileContentRequest,
|
|
897
994
|
openSandboxEditor: (args, options) => http.request({
|
|
898
995
|
method: HttpMethod.Post,
|
|
899
|
-
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.
|
|
996
|
+
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.sandboxId)}/editor`),
|
|
900
997
|
response: sandboxEditorSessionSchema,
|
|
901
998
|
signal: options?.signal
|
|
902
999
|
}),
|
|
@@ -904,7 +1001,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
904
1001
|
method: HttpMethod.Post,
|
|
905
1002
|
path: conversationPath(
|
|
906
1003
|
conversationId,
|
|
907
|
-
`/sandboxes/${encodePath(args.
|
|
1004
|
+
`/sandboxes/${encodePath(args.sandboxId)}/editor/${encodePath(args.editorId)}/refresh`
|
|
908
1005
|
),
|
|
909
1006
|
body: {
|
|
910
1007
|
schema: sandboxEditorAuthorizationSchema,
|
|
@@ -918,7 +1015,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
918
1015
|
method: HttpMethod.Delete,
|
|
919
1016
|
path: conversationPath(
|
|
920
1017
|
conversationId,
|
|
921
|
-
`/sandboxes/${encodePath(args.
|
|
1018
|
+
`/sandboxes/${encodePath(args.sandboxId)}/editor/${encodePath(args.editorId)}`
|
|
922
1019
|
),
|
|
923
1020
|
body: {
|
|
924
1021
|
schema: sandboxEditorAuthorizationSchema,
|
|
@@ -977,7 +1074,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
977
1074
|
method: operation === ProcessInspectionOperation.Stop ? HttpMethod.Delete : HttpMethod.Get,
|
|
978
1075
|
path: conversationPath(
|
|
979
1076
|
conversationId,
|
|
980
|
-
`/sandboxes/${encodePath(args.
|
|
1077
|
+
`/sandboxes/${encodePath(args.sandboxId)}/processes${suffix}`
|
|
981
1078
|
),
|
|
982
1079
|
query,
|
|
983
1080
|
response: processInspectionResultSchema,
|
|
@@ -987,7 +1084,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
987
1084
|
sandboxPreview: (args, options) => {
|
|
988
1085
|
const request = {
|
|
989
1086
|
method: args.viewOnly === false ? HttpMethod.Post : HttpMethod.Get,
|
|
990
|
-
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.
|
|
1087
|
+
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.sandboxId)}/preview`),
|
|
991
1088
|
response: sandboxPreviewSchema,
|
|
992
1089
|
signal: options?.signal
|
|
993
1090
|
};
|
|
@@ -997,7 +1094,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
997
1094
|
},
|
|
998
1095
|
wakeSandbox: (args, options) => http.request({
|
|
999
1096
|
method: HttpMethod.Post,
|
|
1000
|
-
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.
|
|
1097
|
+
path: conversationPath(conversationId, `/sandboxes/${encodePath(args.sandboxId)}/wake`),
|
|
1001
1098
|
response: conversationSandboxSchema,
|
|
1002
1099
|
signal: options?.signal
|
|
1003
1100
|
}),
|
|
@@ -1060,11 +1157,7 @@ const createConversationHandle = (context, conversationId) => {
|
|
|
1060
1157
|
}
|
|
1061
1158
|
};
|
|
1062
1159
|
};
|
|
1063
|
-
const createConversationsApi = (context) => {
|
|
1064
|
-
const opened = (conversation) => ({
|
|
1065
|
-
...createConversationHandle(context, conversation.id),
|
|
1066
|
-
conversation
|
|
1067
|
-
});
|
|
1160
|
+
const createConversationsApi = (context, starter) => {
|
|
1068
1161
|
return {
|
|
1069
1162
|
list: (options) => context.http.request({
|
|
1070
1163
|
method: HttpMethod.Get,
|
|
@@ -1073,48 +1166,16 @@ const createConversationsApi = (context) => {
|
|
|
1073
1166
|
cursor: options?.cursor,
|
|
1074
1167
|
limit: options?.limit,
|
|
1075
1168
|
includeArchived: options?.includeArchived,
|
|
1076
|
-
projectId: options?.projectId
|
|
1169
|
+
projectId: options?.projectId ?? starter.projectId ?? void 0,
|
|
1170
|
+
includeSubprojects: options?.includeSubprojects,
|
|
1171
|
+
label: options?.labels == null ? void 0 : Object.entries(options.labels).map(
|
|
1172
|
+
([key, value]) => conversationLabelFilter(key, value)
|
|
1173
|
+
)
|
|
1077
1174
|
},
|
|
1078
1175
|
response: conversationListSchema,
|
|
1079
1176
|
signal: options?.signal
|
|
1080
1177
|
}),
|
|
1081
|
-
|
|
1082
|
-
await context.http.request({
|
|
1083
|
-
method: HttpMethod.Post,
|
|
1084
|
-
path: "/v1/conversations/direct",
|
|
1085
|
-
body: { schema: createDirectConversationRequestSchema, value: { agent: args.agent } },
|
|
1086
|
-
response: conversationSchema,
|
|
1087
|
-
signal: args.signal
|
|
1088
|
-
})
|
|
1089
|
-
),
|
|
1090
|
-
home: async (options) => opened(
|
|
1091
|
-
await context.http.request({
|
|
1092
|
-
method: HttpMethod.Get,
|
|
1093
|
-
path: "/v1/conversations/home",
|
|
1094
|
-
query: { projectId: options?.projectId },
|
|
1095
|
-
response: conversationSchema,
|
|
1096
|
-
signal: options?.signal
|
|
1097
|
-
})
|
|
1098
|
-
),
|
|
1099
|
-
create: async (args) => opened(
|
|
1100
|
-
await context.http.request({
|
|
1101
|
-
method: HttpMethod.Post,
|
|
1102
|
-
path: "/v1/conversations",
|
|
1103
|
-
body: {
|
|
1104
|
-
schema: createConversationRequestSchema,
|
|
1105
|
-
value: {
|
|
1106
|
-
projectId: args.projectId,
|
|
1107
|
-
kind: args.kind,
|
|
1108
|
-
title: args.title,
|
|
1109
|
-
participants: args.participants,
|
|
1110
|
-
turnPolicy: args.turnPolicy
|
|
1111
|
-
}
|
|
1112
|
-
},
|
|
1113
|
-
response: conversationSchema,
|
|
1114
|
-
signal: args.signal
|
|
1115
|
-
})
|
|
1116
|
-
),
|
|
1117
|
-
get: (conversationId) => createConversationHandle(context, conversationId),
|
|
1178
|
+
get: (conversationId) => createConversationHandle(context, conversationId, starter),
|
|
1118
1179
|
search: (args) => context.http.request({
|
|
1119
1180
|
method: HttpMethod.Get,
|
|
1120
1181
|
path: "/v1/conversations/search",
|
|
@@ -1142,11 +1203,258 @@ const createConversationsApi = (context) => {
|
|
|
1142
1203
|
})
|
|
1143
1204
|
};
|
|
1144
1205
|
};
|
|
1206
|
+
const createProjectConversationsApi = (args) => {
|
|
1207
|
+
const { context, projectId } = args;
|
|
1208
|
+
const starter = { deps: args.start, projectId };
|
|
1209
|
+
const base = createConversationsApi(context, starter);
|
|
1210
|
+
const opened = (conversation) => ({
|
|
1211
|
+
...createConversationHandle(context, conversation.id, starter),
|
|
1212
|
+
conversation
|
|
1213
|
+
});
|
|
1214
|
+
const sandboxes = createSandboxesApi({ context, projectId });
|
|
1215
|
+
const chosenProcessCompute = async (compute, signal) => {
|
|
1216
|
+
const stored = {};
|
|
1217
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1218
|
+
for (const capability of PROCESS_CAPABILITIES) {
|
|
1219
|
+
const id = compute[capability];
|
|
1220
|
+
if (id == null) continue;
|
|
1221
|
+
stored[capability] = id;
|
|
1222
|
+
ids.add(id);
|
|
1223
|
+
}
|
|
1224
|
+
for (const id of ids) {
|
|
1225
|
+
const sandbox = await sandboxes.get(id, { signal }).catch((cause) => {
|
|
1226
|
+
if (isClientError(cause) && cause.status === 404) return null;
|
|
1227
|
+
throw cause;
|
|
1228
|
+
});
|
|
1229
|
+
if (sandbox != null && sandbox.resource.providerKind !== SandboxProviderKind.ClientHost)
|
|
1230
|
+
return stored;
|
|
1231
|
+
}
|
|
1232
|
+
return null;
|
|
1233
|
+
};
|
|
1234
|
+
const withProcessCompute = (provide, filesAndShell) => ({
|
|
1235
|
+
...provide,
|
|
1236
|
+
compute: {
|
|
1237
|
+
...Object.fromEntries(
|
|
1238
|
+
Object.entries(provide.compute ?? {}).filter(
|
|
1239
|
+
([key]) => !PROCESS_CAPABILITIES.some((capability) => capability === key)
|
|
1240
|
+
)
|
|
1241
|
+
),
|
|
1242
|
+
...filesAndShell
|
|
1243
|
+
}
|
|
1244
|
+
});
|
|
1245
|
+
const withStarted = async (started, send) => {
|
|
1246
|
+
try {
|
|
1247
|
+
const sent = await send();
|
|
1248
|
+
for (const agent of started) agent.established();
|
|
1249
|
+
return sent;
|
|
1250
|
+
} catch (cause) {
|
|
1251
|
+
for (const agent of started) agent.abandon();
|
|
1252
|
+
throw cause;
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
return {
|
|
1256
|
+
...base,
|
|
1257
|
+
create: async (create) => {
|
|
1258
|
+
const started = [];
|
|
1259
|
+
const participants = [];
|
|
1260
|
+
let conversationId = create.id;
|
|
1261
|
+
let shared = create.provide == null ? null : provideDocumentOf(create.provide);
|
|
1262
|
+
let sharedWorkers = null;
|
|
1263
|
+
const undoShared = () => {
|
|
1264
|
+
void sharedWorkers?.discard().catch(() => void 0);
|
|
1265
|
+
};
|
|
1266
|
+
try {
|
|
1267
|
+
if (shared?.harness != null) {
|
|
1268
|
+
const placed = await withWorkersEnvironment({
|
|
1269
|
+
context,
|
|
1270
|
+
projectId,
|
|
1271
|
+
harness: shared.harness,
|
|
1272
|
+
owner: { kind: LocalHostOwnerKind.Conversation, id: conversationId },
|
|
1273
|
+
signal: create.signal
|
|
1274
|
+
});
|
|
1275
|
+
shared = { ...shared, harness: placed.harness };
|
|
1276
|
+
conversationId = placed.ownerId;
|
|
1277
|
+
sharedWorkers = placed.created;
|
|
1278
|
+
}
|
|
1279
|
+
for (const participant of create.participants) {
|
|
1280
|
+
if ("user" in participant) {
|
|
1281
|
+
participants.push({ user: participant.user });
|
|
1282
|
+
continue;
|
|
1283
|
+
}
|
|
1284
|
+
if ("actor" in participant) {
|
|
1285
|
+
participants.push({ actor: participant.actor });
|
|
1286
|
+
continue;
|
|
1287
|
+
}
|
|
1288
|
+
const agent = await startAgent(args.start, {
|
|
1289
|
+
projectId,
|
|
1290
|
+
agent: participant.agent,
|
|
1291
|
+
provide: participant.provide,
|
|
1292
|
+
shared,
|
|
1293
|
+
owner: { kind: LocalHostOwnerKind.Conversation, id: conversationId },
|
|
1294
|
+
// An id an earlier participant's host or Workers sandbox reserved is not the caller's.
|
|
1295
|
+
ownerIdReserved: create.id == null,
|
|
1296
|
+
signal: create.signal
|
|
1297
|
+
});
|
|
1298
|
+
started.push(agent);
|
|
1299
|
+
conversationId = agent.ownerId ?? conversationId;
|
|
1300
|
+
participants.push({
|
|
1301
|
+
agent: agent.ref,
|
|
1302
|
+
routingMode: participant.routingMode,
|
|
1303
|
+
provide: agent.provide
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
} catch (cause) {
|
|
1307
|
+
for (const agent of started) agent.abandon();
|
|
1308
|
+
undoShared();
|
|
1309
|
+
throw cause;
|
|
1310
|
+
}
|
|
1311
|
+
const sent = withStarted(
|
|
1312
|
+
started,
|
|
1313
|
+
() => context.http.request({
|
|
1314
|
+
method: HttpMethod.Post,
|
|
1315
|
+
path: "/v1/conversations",
|
|
1316
|
+
body: {
|
|
1317
|
+
schema: createConversationRequestSchema,
|
|
1318
|
+
value: {
|
|
1319
|
+
id: conversationId,
|
|
1320
|
+
projectId,
|
|
1321
|
+
kind: create.kind,
|
|
1322
|
+
title: create.title,
|
|
1323
|
+
participants,
|
|
1324
|
+
turnPolicy: create.turnPolicy,
|
|
1325
|
+
provide: shared ?? void 0,
|
|
1326
|
+
primary: create.primary,
|
|
1327
|
+
labels: create.labels,
|
|
1328
|
+
actor: create.actor
|
|
1329
|
+
}
|
|
1330
|
+
},
|
|
1331
|
+
response: conversationResponseSchema,
|
|
1332
|
+
signal: create.signal
|
|
1333
|
+
})
|
|
1334
|
+
);
|
|
1335
|
+
const { conversation } = await sent.catch((cause) => {
|
|
1336
|
+
undoShared();
|
|
1337
|
+
throw cause;
|
|
1338
|
+
});
|
|
1339
|
+
if (conversationId != null && conversation.id !== conversationId) {
|
|
1340
|
+
for (const agent of started) agent.abandon();
|
|
1341
|
+
undoShared();
|
|
1342
|
+
}
|
|
1343
|
+
return opened(conversation);
|
|
1344
|
+
},
|
|
1345
|
+
home: async ({ id, provide, signal }) => {
|
|
1346
|
+
const document = provideDocumentOf(provide);
|
|
1347
|
+
const placed = document.harness == null ? null : await withWorkersEnvironment({
|
|
1348
|
+
context,
|
|
1349
|
+
projectId,
|
|
1350
|
+
harness: document.harness,
|
|
1351
|
+
owner: { kind: LocalHostOwnerKind.Conversation, id },
|
|
1352
|
+
signal
|
|
1353
|
+
});
|
|
1354
|
+
const homeId = placed?.ownerId ?? id;
|
|
1355
|
+
const discard = () => void placed?.created?.discard().catch(() => void 0);
|
|
1356
|
+
try {
|
|
1357
|
+
const { conversation } = await context.http.request({
|
|
1358
|
+
method: HttpMethod.Post,
|
|
1359
|
+
path: "/v1/conversations/home",
|
|
1360
|
+
body: {
|
|
1361
|
+
schema: homeConversationRequestSchema,
|
|
1362
|
+
value: {
|
|
1363
|
+
projectId,
|
|
1364
|
+
id: homeId,
|
|
1365
|
+
provide: placed == null ? document : { ...document, harness: placed.harness }
|
|
1366
|
+
}
|
|
1367
|
+
},
|
|
1368
|
+
response: conversationResponseSchema,
|
|
1369
|
+
signal
|
|
1370
|
+
});
|
|
1371
|
+
if (conversation.id !== homeId) discard();
|
|
1372
|
+
return opened(conversation);
|
|
1373
|
+
} catch (cause) {
|
|
1374
|
+
discard();
|
|
1375
|
+
throw cause;
|
|
1376
|
+
}
|
|
1377
|
+
},
|
|
1378
|
+
findHome: async (options) => (await context.http.request({
|
|
1379
|
+
method: HttpMethod.Get,
|
|
1380
|
+
path: "/v1/conversations/home",
|
|
1381
|
+
query: { projectId },
|
|
1382
|
+
response: conversationLookupSchema,
|
|
1383
|
+
signal: options?.signal
|
|
1384
|
+
})).conversation,
|
|
1385
|
+
direct: async ({ id, agent, provide, actor, signal }) => {
|
|
1386
|
+
const started = await startAgent(args.start, {
|
|
1387
|
+
projectId,
|
|
1388
|
+
agent,
|
|
1389
|
+
provide,
|
|
1390
|
+
owner: { kind: LocalHostOwnerKind.Conversation, id },
|
|
1391
|
+
signal
|
|
1392
|
+
});
|
|
1393
|
+
const { conversation } = await withStarted(
|
|
1394
|
+
[started],
|
|
1395
|
+
() => context.http.request({
|
|
1396
|
+
method: HttpMethod.Post,
|
|
1397
|
+
path: "/v1/conversations/direct",
|
|
1398
|
+
body: {
|
|
1399
|
+
schema: createDirectConversationRequestSchema,
|
|
1400
|
+
value: {
|
|
1401
|
+
id: started.ownerId ?? id,
|
|
1402
|
+
projectId,
|
|
1403
|
+
agent: started.ref,
|
|
1404
|
+
provide: started.provide,
|
|
1405
|
+
actor
|
|
1406
|
+
}
|
|
1407
|
+
},
|
|
1408
|
+
response: conversationResponseSchema,
|
|
1409
|
+
signal
|
|
1410
|
+
})
|
|
1411
|
+
);
|
|
1412
|
+
const chat = opened(conversation);
|
|
1413
|
+
if (conversation.id === started.ownerId) return chat;
|
|
1414
|
+
started.abandon();
|
|
1415
|
+
if (started.host == null) return chat;
|
|
1416
|
+
const participant = (await chat.participants({ signal })).find(
|
|
1417
|
+
(member) => member.kind === ParticipantKind.Agent && member.leftAt == null
|
|
1418
|
+
);
|
|
1419
|
+
if (participant == null) throw new Error("the direct chat has no agent participant");
|
|
1420
|
+
const { settings } = await chat.participants.settings(participant.id, { signal });
|
|
1421
|
+
const chosen = await chosenProcessCompute(settings.compute, signal);
|
|
1422
|
+
const attached = await startAgent(args.start, {
|
|
1423
|
+
projectId,
|
|
1424
|
+
agent,
|
|
1425
|
+
provide: chosen == null ? provide : withProcessCompute(provide, chosen),
|
|
1426
|
+
owner: { kind: LocalHostOwnerKind.Conversation, id: conversation.id },
|
|
1427
|
+
signal
|
|
1428
|
+
});
|
|
1429
|
+
await withStarted([attached], async () => {
|
|
1430
|
+
const sandboxId = attached.host?.sandboxId;
|
|
1431
|
+
const local = Object.entries(attached.provide.compute ?? {}).filter(
|
|
1432
|
+
([, value]) => sandboxId != null && value === sandboxId
|
|
1433
|
+
);
|
|
1434
|
+
if (local.length === 0) return;
|
|
1435
|
+
await chat.participants.provide(
|
|
1436
|
+
participant.id,
|
|
1437
|
+
{ compute: Object.fromEntries(local) },
|
|
1438
|
+
{ signal }
|
|
1439
|
+
);
|
|
1440
|
+
});
|
|
1441
|
+
return chat;
|
|
1442
|
+
},
|
|
1443
|
+
findDirect: async ({ agent, actorExternalId, signal }) => (await context.http.request({
|
|
1444
|
+
method: HttpMethod.Get,
|
|
1445
|
+
path: "/v1/conversations/direct",
|
|
1446
|
+
query: { projectId, agent, actorExternalId },
|
|
1447
|
+
response: conversationLookupSchema,
|
|
1448
|
+
signal
|
|
1449
|
+
})).conversation
|
|
1450
|
+
};
|
|
1451
|
+
};
|
|
1145
1452
|
export {
|
|
1146
1453
|
RECOVERY_SKEW_MS,
|
|
1147
1454
|
TURN_OPEN_SESSION_STATES,
|
|
1148
1455
|
createConversationHandle,
|
|
1149
1456
|
createConversationsApi,
|
|
1457
|
+
createProjectConversationsApi,
|
|
1150
1458
|
isNewerMessageVersion,
|
|
1151
1459
|
messageVersionOf
|
|
1152
1460
|
};
|