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