veryfront 0.1.232 → 0.1.234
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/esm/deno.d.ts +2 -0
- package/esm/deno.js +3 -1
- package/esm/src/agent/conversation-bootstrap.d.ts +61 -0
- package/esm/src/agent/conversation-bootstrap.d.ts.map +1 -0
- package/esm/src/agent/conversation-bootstrap.js +131 -0
- package/esm/src/agent/durable.d.ts +84 -0
- package/esm/src/agent/durable.d.ts.map +1 -1
- package/esm/src/agent/durable.js +193 -12
- package/esm/src/agent/index.d.ts +3 -1
- package/esm/src/agent/index.d.ts.map +1 -1
- package/esm/src/agent/index.js +3 -1
- package/esm/src/agent/invoke-agent-child-runs.d.ts +145 -0
- package/esm/src/agent/invoke-agent-child-runs.d.ts.map +1 -0
- package/esm/src/agent/invoke-agent-child-runs.js +101 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +9 -1
- package/src/deno.js +3 -1
- package/src/src/agent/conversation-bootstrap.ts +195 -0
- package/src/src/agent/durable.ts +257 -12
- package/src/src/agent/index.ts +35 -0
- package/src/src/agent/invoke-agent-child-runs.ts +170 -0
- package/src/src/utils/version-constant.ts +1 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import "../../_dnt.polyfills.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export declare const InvokeAgentChildRunLifecycleValueSchema: z.ZodObject<{
|
|
4
|
+
toolCallId: z.ZodString;
|
|
5
|
+
childConversationId: z.ZodString;
|
|
6
|
+
childRunId: z.ZodString;
|
|
7
|
+
childMessageId: z.ZodString;
|
|
8
|
+
childAgentId: z.ZodString;
|
|
9
|
+
description: z.ZodOptional<z.ZodString>;
|
|
10
|
+
status: z.ZodEnum<{
|
|
11
|
+
failed: "failed";
|
|
12
|
+
pending: "pending";
|
|
13
|
+
completed: "completed";
|
|
14
|
+
running: "running";
|
|
15
|
+
cancelled: "cancelled";
|
|
16
|
+
waiting_for_tool: "waiting_for_tool";
|
|
17
|
+
}>;
|
|
18
|
+
sourceTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
19
|
+
project: "project";
|
|
20
|
+
production: "production";
|
|
21
|
+
environment: "environment";
|
|
22
|
+
preview_branch: "preview_branch";
|
|
23
|
+
}>>>;
|
|
24
|
+
runtimeTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
25
|
+
production: "production";
|
|
26
|
+
environment: "environment";
|
|
27
|
+
preview_branch: "preview_branch";
|
|
28
|
+
}>>>;
|
|
29
|
+
targetEnvironmentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
30
|
+
targetBranchId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
export type InvokeAgentChildRunLifecycleValue = z.infer<typeof InvokeAgentChildRunLifecycleValueSchema>;
|
|
33
|
+
export declare const InvokeAgentChildRunStateDeltaSchema: z.ZodObject<{
|
|
34
|
+
type: z.ZodLiteral<"STATE_DELTA">;
|
|
35
|
+
delta: z.ZodArray<z.ZodObject<{
|
|
36
|
+
op: z.ZodEnum<{
|
|
37
|
+
replace: "replace";
|
|
38
|
+
add: "add";
|
|
39
|
+
}>;
|
|
40
|
+
path: z.ZodString;
|
|
41
|
+
value: z.ZodObject<{
|
|
42
|
+
toolCallId: z.ZodString;
|
|
43
|
+
childConversationId: z.ZodString;
|
|
44
|
+
childRunId: z.ZodString;
|
|
45
|
+
childMessageId: z.ZodString;
|
|
46
|
+
childAgentId: z.ZodString;
|
|
47
|
+
description: z.ZodOptional<z.ZodString>;
|
|
48
|
+
status: z.ZodEnum<{
|
|
49
|
+
failed: "failed";
|
|
50
|
+
pending: "pending";
|
|
51
|
+
completed: "completed";
|
|
52
|
+
running: "running";
|
|
53
|
+
cancelled: "cancelled";
|
|
54
|
+
waiting_for_tool: "waiting_for_tool";
|
|
55
|
+
}>;
|
|
56
|
+
sourceTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
57
|
+
project: "project";
|
|
58
|
+
production: "production";
|
|
59
|
+
environment: "environment";
|
|
60
|
+
preview_branch: "preview_branch";
|
|
61
|
+
}>>>;
|
|
62
|
+
runtimeTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
63
|
+
production: "production";
|
|
64
|
+
environment: "environment";
|
|
65
|
+
preview_branch: "preview_branch";
|
|
66
|
+
}>>>;
|
|
67
|
+
targetEnvironmentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
68
|
+
targetBranchId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
}, z.core.$strip>>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
export type InvokeAgentChildRunStateDelta = z.infer<typeof InvokeAgentChildRunStateDeltaSchema>;
|
|
73
|
+
export declare const InvokeAgentChildRunLifecycleCustomEventSchema: z.ZodObject<{
|
|
74
|
+
type: z.ZodLiteral<"CUSTOM">;
|
|
75
|
+
name: z.ZodLiteral<"veryfront.invoke_agent.lifecycle">;
|
|
76
|
+
value: z.ZodObject<{
|
|
77
|
+
toolCallId: z.ZodString;
|
|
78
|
+
childConversationId: z.ZodString;
|
|
79
|
+
childRunId: z.ZodString;
|
|
80
|
+
childMessageId: z.ZodString;
|
|
81
|
+
childAgentId: z.ZodString;
|
|
82
|
+
description: z.ZodOptional<z.ZodString>;
|
|
83
|
+
status: z.ZodEnum<{
|
|
84
|
+
failed: "failed";
|
|
85
|
+
pending: "pending";
|
|
86
|
+
completed: "completed";
|
|
87
|
+
running: "running";
|
|
88
|
+
cancelled: "cancelled";
|
|
89
|
+
waiting_for_tool: "waiting_for_tool";
|
|
90
|
+
}>;
|
|
91
|
+
sourceTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
92
|
+
project: "project";
|
|
93
|
+
production: "production";
|
|
94
|
+
environment: "environment";
|
|
95
|
+
preview_branch: "preview_branch";
|
|
96
|
+
}>>>;
|
|
97
|
+
runtimeTargetKind: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
98
|
+
production: "production";
|
|
99
|
+
environment: "environment";
|
|
100
|
+
preview_branch: "preview_branch";
|
|
101
|
+
}>>>;
|
|
102
|
+
targetEnvironmentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
103
|
+
targetBranchId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
104
|
+
}, z.core.$strip>;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
export type InvokeAgentChildRunLifecycleCustomEvent = z.infer<typeof InvokeAgentChildRunLifecycleCustomEventSchema>;
|
|
107
|
+
export type InvokeAgentChildRunProgressInput = {
|
|
108
|
+
toolCallId: string;
|
|
109
|
+
childConversationId: string;
|
|
110
|
+
childRunId: string;
|
|
111
|
+
childMessageId: string;
|
|
112
|
+
childAgentId: string;
|
|
113
|
+
description?: string;
|
|
114
|
+
status: "pending" | "running" | "waiting_for_tool" | "completed" | "failed" | "cancelled";
|
|
115
|
+
sourceTargetKind?: "project" | "production" | "environment" | "preview_branch" | null;
|
|
116
|
+
runtimeTargetKind?: "production" | "environment" | "preview_branch" | null;
|
|
117
|
+
targetEnvironmentId?: string | null;
|
|
118
|
+
targetBranchId?: string | null;
|
|
119
|
+
};
|
|
120
|
+
export type InvokeAgentChildRunProgressEvent = InvokeAgentChildRunStateDelta | InvokeAgentChildRunLifecycleCustomEvent;
|
|
121
|
+
export declare function buildInvokeAgentChildRunStateDelta(input: InvokeAgentChildRunProgressInput): InvokeAgentChildRunStateDelta;
|
|
122
|
+
export declare function buildInvokeAgentChildRunLifecycleCustomEvent(input: InvokeAgentChildRunProgressInput): InvokeAgentChildRunLifecycleCustomEvent;
|
|
123
|
+
export declare function buildInvokeAgentChildRunProgressEvents(input: InvokeAgentChildRunProgressInput): readonly [InvokeAgentChildRunStateDelta, InvokeAgentChildRunLifecycleCustomEvent];
|
|
124
|
+
export declare function publishInvokeAgentChildRunProgress(input: {
|
|
125
|
+
authToken: string;
|
|
126
|
+
apiUrl: string;
|
|
127
|
+
conversationId: string;
|
|
128
|
+
runId: string;
|
|
129
|
+
expectedPreviousEventId?: number;
|
|
130
|
+
expectedPreviousExternalEventSequence?: number;
|
|
131
|
+
toolCallId: string;
|
|
132
|
+
childAgentId: string;
|
|
133
|
+
childConversationId: string;
|
|
134
|
+
childRunId: string;
|
|
135
|
+
childMessageId: string;
|
|
136
|
+
description?: string;
|
|
137
|
+
status: "pending" | "running" | "waiting_for_tool" | "completed" | "failed" | "cancelled";
|
|
138
|
+
sourceTargetKind?: "project" | "production" | "environment" | "preview_branch" | null;
|
|
139
|
+
runtimeTargetKind?: "production" | "environment" | "preview_branch" | null;
|
|
140
|
+
targetEnvironmentId?: string | null;
|
|
141
|
+
targetBranchId?: string | null;
|
|
142
|
+
publishParentRunEvents?: (events: InvokeAgentChildRunProgressEvent[]) => Promise<void> | void;
|
|
143
|
+
abortSignal?: AbortSignal;
|
|
144
|
+
}): Promise<void>;
|
|
145
|
+
//# sourceMappingURL=invoke-agent-child-runs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoke-agent-child-runs.d.ts","sourceRoot":"","sources":["../../../src/src/agent/invoke-agent-child-runs.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import "../../_dnt.polyfills.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { appendConversationRunEvents, isIgnorableConversationRunAppendError } from "./durable.js";
|
|
4
|
+
const AG_UI_CUSTOM_EVENT_TYPE = "CUSTOM";
|
|
5
|
+
export const InvokeAgentChildRunLifecycleValueSchema = z.object({
|
|
6
|
+
toolCallId: z.string().min(1),
|
|
7
|
+
childConversationId: z.string().uuid(),
|
|
8
|
+
childRunId: z.string().min(1),
|
|
9
|
+
childMessageId: z.string().uuid(),
|
|
10
|
+
childAgentId: z.string().min(1),
|
|
11
|
+
description: z.string().min(1).optional(),
|
|
12
|
+
status: z.enum(["pending", "running", "waiting_for_tool", "completed", "failed", "cancelled"]),
|
|
13
|
+
sourceTargetKind: z.enum(["project", "production", "environment", "preview_branch"]).nullable()
|
|
14
|
+
.optional(),
|
|
15
|
+
runtimeTargetKind: z.enum(["production", "environment", "preview_branch"]).nullable().optional(),
|
|
16
|
+
targetEnvironmentId: z.string().uuid().nullable().optional(),
|
|
17
|
+
targetBranchId: z.string().uuid().nullable().optional(),
|
|
18
|
+
});
|
|
19
|
+
export const InvokeAgentChildRunStateDeltaSchema = z.object({
|
|
20
|
+
type: z.literal("STATE_DELTA"),
|
|
21
|
+
delta: z.array(z.object({
|
|
22
|
+
op: z.enum(["add", "replace"]),
|
|
23
|
+
path: z.string().min(1),
|
|
24
|
+
value: InvokeAgentChildRunLifecycleValueSchema,
|
|
25
|
+
})),
|
|
26
|
+
});
|
|
27
|
+
export const InvokeAgentChildRunLifecycleCustomEventSchema = z.object({
|
|
28
|
+
type: z.literal(AG_UI_CUSTOM_EVENT_TYPE),
|
|
29
|
+
name: z.literal("veryfront.invoke_agent.lifecycle"),
|
|
30
|
+
value: InvokeAgentChildRunLifecycleValueSchema,
|
|
31
|
+
});
|
|
32
|
+
function buildInvokeAgentChildRunLifecycleValue(input) {
|
|
33
|
+
return InvokeAgentChildRunLifecycleValueSchema.parse({
|
|
34
|
+
toolCallId: input.toolCallId,
|
|
35
|
+
childConversationId: input.childConversationId,
|
|
36
|
+
childRunId: input.childRunId,
|
|
37
|
+
childMessageId: input.childMessageId,
|
|
38
|
+
childAgentId: input.childAgentId,
|
|
39
|
+
...(input.description ? { description: input.description } : {}),
|
|
40
|
+
status: input.status,
|
|
41
|
+
...(input.sourceTargetKind !== undefined ? { sourceTargetKind: input.sourceTargetKind } : {}),
|
|
42
|
+
...(input.runtimeTargetKind !== undefined
|
|
43
|
+
? { runtimeTargetKind: input.runtimeTargetKind }
|
|
44
|
+
: {}),
|
|
45
|
+
...(input.targetEnvironmentId !== undefined
|
|
46
|
+
? { targetEnvironmentId: input.targetEnvironmentId }
|
|
47
|
+
: {}),
|
|
48
|
+
...(input.targetBranchId !== undefined ? { targetBranchId: input.targetBranchId } : {}),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export function buildInvokeAgentChildRunStateDelta(input) {
|
|
52
|
+
const escapedToolCallId = input.toolCallId.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
53
|
+
return InvokeAgentChildRunStateDeltaSchema.parse({
|
|
54
|
+
type: "STATE_DELTA",
|
|
55
|
+
delta: [
|
|
56
|
+
{
|
|
57
|
+
op: input.status === "pending" ? "add" : "replace",
|
|
58
|
+
path: `/invokeAgentChildRuns/${escapedToolCallId}`,
|
|
59
|
+
value: buildInvokeAgentChildRunLifecycleValue(input),
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export function buildInvokeAgentChildRunLifecycleCustomEvent(input) {
|
|
65
|
+
return InvokeAgentChildRunLifecycleCustomEventSchema.parse({
|
|
66
|
+
type: AG_UI_CUSTOM_EVENT_TYPE,
|
|
67
|
+
name: "veryfront.invoke_agent.lifecycle",
|
|
68
|
+
value: buildInvokeAgentChildRunLifecycleValue(input),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export function buildInvokeAgentChildRunProgressEvents(input) {
|
|
72
|
+
return [
|
|
73
|
+
buildInvokeAgentChildRunStateDelta(input),
|
|
74
|
+
buildInvokeAgentChildRunLifecycleCustomEvent(input),
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
export async function publishInvokeAgentChildRunProgress(input) {
|
|
78
|
+
const events = [...buildInvokeAgentChildRunProgressEvents(input)];
|
|
79
|
+
if (input.publishParentRunEvents) {
|
|
80
|
+
await input.publishParentRunEvents(events);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
await appendConversationRunEvents({
|
|
85
|
+
authToken: input.authToken,
|
|
86
|
+
apiUrl: input.apiUrl,
|
|
87
|
+
conversationId: input.conversationId,
|
|
88
|
+
runId: input.runId,
|
|
89
|
+
expectedPreviousEventId: input.expectedPreviousEventId,
|
|
90
|
+
expectedPreviousExternalEventSequence: input.expectedPreviousExternalEventSequence,
|
|
91
|
+
events,
|
|
92
|
+
abortSignal: input.abortSignal,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (isIgnorableConversationRunAppendError(error)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.234";
|
|
2
2
|
//# sourceMappingURL=version-constant.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "veryfront",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.234",
|
|
4
4
|
"description": "The simplest way to build AI-powered apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -69,10 +69,18 @@
|
|
|
69
69
|
"import": "./esm/src/agent/index.js",
|
|
70
70
|
"types": "./esm/src/agent/index.d.ts"
|
|
71
71
|
},
|
|
72
|
+
"./agent/conversation-bootstrap": {
|
|
73
|
+
"import": "./esm/src/agent/conversation-bootstrap.js",
|
|
74
|
+
"types": "./esm/src/agent/conversation-bootstrap.d.ts"
|
|
75
|
+
},
|
|
72
76
|
"./agent/durable": {
|
|
73
77
|
"import": "./esm/src/agent/durable.js",
|
|
74
78
|
"types": "./esm/src/agent/durable.d.ts"
|
|
75
79
|
},
|
|
80
|
+
"./agent/invoke-agent-child-runs": {
|
|
81
|
+
"import": "./esm/src/agent/invoke-agent-child-runs.js",
|
|
82
|
+
"types": "./esm/src/agent/invoke-agent-child-runs.d.ts"
|
|
83
|
+
},
|
|
76
84
|
"./channels/control-plane": {
|
|
77
85
|
"import": "./esm/src/channels/control-plane.js",
|
|
78
86
|
"types": "./esm/src/channels/control-plane.d.ts"
|
package/src/deno.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
"name": "veryfront",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.234",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"nodeModulesDir": "auto",
|
|
6
6
|
"workspace": [
|
|
@@ -30,7 +30,9 @@ export default {
|
|
|
30
30
|
"./markdown": "./src/markdown/index.ts",
|
|
31
31
|
"./mdx": "./src/mdx/index.ts",
|
|
32
32
|
"./agent": "./src/agent/index.ts",
|
|
33
|
+
"./agent/conversation-bootstrap": "./src/agent/conversation-bootstrap.ts",
|
|
33
34
|
"./agent/durable": "./src/agent/durable.ts",
|
|
35
|
+
"./agent/invoke-agent-child-runs": "./src/agent/invoke-agent-child-runs.ts",
|
|
34
36
|
"./channels/control-plane": "./src/channels/control-plane.ts",
|
|
35
37
|
"./channels/invoke": "./src/channels/invoke.ts",
|
|
36
38
|
"./tool": "./src/tool/index.ts",
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import "../../_dnt.polyfills.js";
|
|
2
|
+
import * as dntShim from "../../_dnt.shims.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { type ConversationRunProjection, createConversationAgentRun } from "./durable.js";
|
|
5
|
+
|
|
6
|
+
const CONVERSATION_API_TIMEOUT_MS = 15_000;
|
|
7
|
+
|
|
8
|
+
export const ConversationRecordSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
id: z.string(),
|
|
11
|
+
projectId: z.string().nullable().optional(),
|
|
12
|
+
project_id: z.string().nullable().optional(),
|
|
13
|
+
})
|
|
14
|
+
.passthrough()
|
|
15
|
+
.transform((data) => ({
|
|
16
|
+
id: data.id,
|
|
17
|
+
projectId: data.projectId ?? data.project_id ?? null,
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
export const ConversationMessageRecordSchema = z.object({
|
|
21
|
+
id: z.string().uuid(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export type ConversationRecord = z.infer<typeof ConversationRecordSchema>;
|
|
25
|
+
export type ConversationMessageRecord = z.infer<typeof ConversationMessageRecordSchema>;
|
|
26
|
+
|
|
27
|
+
async function controlPlaneJson<T>(input: {
|
|
28
|
+
authToken: string;
|
|
29
|
+
url: string;
|
|
30
|
+
method?: "GET" | "POST" | "PATCH";
|
|
31
|
+
body?: unknown;
|
|
32
|
+
responseSchema: z.ZodSchema<T>;
|
|
33
|
+
operation: string;
|
|
34
|
+
}): Promise<T> {
|
|
35
|
+
const controller = new AbortController();
|
|
36
|
+
const timeout = dntShim.setTimeout(() => controller.abort(), CONVERSATION_API_TIMEOUT_MS);
|
|
37
|
+
|
|
38
|
+
let response: Response;
|
|
39
|
+
try {
|
|
40
|
+
response = await fetch(input.url, {
|
|
41
|
+
method: input.method ?? "GET",
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: `Bearer ${input.authToken}`,
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
},
|
|
46
|
+
...(input.body !== undefined ? { body: JSON.stringify(input.body) } : {}),
|
|
47
|
+
signal: controller.signal,
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
51
|
+
throw new Error(`${input.operation} timed out after ${CONVERSATION_API_TIMEOUT_MS}ms`);
|
|
52
|
+
}
|
|
53
|
+
throw error;
|
|
54
|
+
} finally {
|
|
55
|
+
clearTimeout(timeout);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
const body = await response.text().catch(() => "");
|
|
60
|
+
throw new Error(
|
|
61
|
+
`${input.operation} failed (${response.status}): ${body || response.statusText}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return input.responseSchema.parse(await response.json());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function buildConversationPath(apiUrl: string, conversationId: string): string {
|
|
69
|
+
return `${apiUrl}/conversations/${conversationId}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function buildConversationMessagesPath(apiUrl: string, conversationId: string): string {
|
|
73
|
+
return `${buildConversationPath(apiUrl, conversationId)}/messages`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function fetchConversationRecord(input: {
|
|
77
|
+
authToken: string;
|
|
78
|
+
apiUrl: string;
|
|
79
|
+
conversationId: string;
|
|
80
|
+
}): Promise<ConversationRecord> {
|
|
81
|
+
return controlPlaneJson({
|
|
82
|
+
authToken: input.authToken,
|
|
83
|
+
url: buildConversationPath(input.apiUrl, input.conversationId),
|
|
84
|
+
responseSchema: ConversationRecordSchema,
|
|
85
|
+
operation: "Fetch conversation",
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function ensureConversationProjectLink(input: {
|
|
90
|
+
authToken: string;
|
|
91
|
+
apiUrl: string;
|
|
92
|
+
conversationId: string;
|
|
93
|
+
projectId: string;
|
|
94
|
+
}): Promise<void> {
|
|
95
|
+
const conversation = await fetchConversationRecord(input);
|
|
96
|
+
|
|
97
|
+
if (conversation.projectId === input.projectId) return;
|
|
98
|
+
if (conversation.projectId !== null) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`Conversation ${input.conversationId} is already linked to a different project (${conversation.projectId})`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
await controlPlaneJson({
|
|
105
|
+
authToken: input.authToken,
|
|
106
|
+
url: buildConversationPath(input.apiUrl, input.conversationId),
|
|
107
|
+
method: "PATCH",
|
|
108
|
+
body: { project_id: input.projectId },
|
|
109
|
+
responseSchema: ConversationRecordSchema,
|
|
110
|
+
operation: "Link conversation to project",
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function createConversationRecord(input: {
|
|
115
|
+
authToken: string;
|
|
116
|
+
apiUrl: string;
|
|
117
|
+
body: unknown;
|
|
118
|
+
}): Promise<ConversationRecord> {
|
|
119
|
+
return controlPlaneJson({
|
|
120
|
+
authToken: input.authToken,
|
|
121
|
+
url: `${input.apiUrl}/conversations`,
|
|
122
|
+
method: "POST",
|
|
123
|
+
body: input.body,
|
|
124
|
+
responseSchema: ConversationRecordSchema,
|
|
125
|
+
operation: "Create conversation",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function createConversationMessage(input: {
|
|
130
|
+
authToken: string;
|
|
131
|
+
apiUrl: string;
|
|
132
|
+
conversationId: string;
|
|
133
|
+
body: unknown;
|
|
134
|
+
}): Promise<ConversationMessageRecord> {
|
|
135
|
+
return controlPlaneJson({
|
|
136
|
+
authToken: input.authToken,
|
|
137
|
+
url: buildConversationMessagesPath(input.apiUrl, input.conversationId),
|
|
138
|
+
method: "POST",
|
|
139
|
+
body: input.body,
|
|
140
|
+
responseSchema: ConversationMessageRecordSchema,
|
|
141
|
+
operation: "Create conversation message",
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface BootstrapConversationAgentRunResult {
|
|
146
|
+
conversation: ConversationRecord;
|
|
147
|
+
message: ConversationMessageRecord;
|
|
148
|
+
run: ConversationRunProjection;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function bootstrapConversationAgentRun(input: {
|
|
152
|
+
authToken: string;
|
|
153
|
+
apiUrl: string;
|
|
154
|
+
parentConversationId?: string;
|
|
155
|
+
ensureProjectId?: string;
|
|
156
|
+
conversationBody: unknown;
|
|
157
|
+
handoffMessageBody: unknown;
|
|
158
|
+
runId?: string;
|
|
159
|
+
agentId: string;
|
|
160
|
+
projectId?: string | null;
|
|
161
|
+
branchId?: string | null;
|
|
162
|
+
}): Promise<BootstrapConversationAgentRunResult> {
|
|
163
|
+
if (input.parentConversationId && input.ensureProjectId) {
|
|
164
|
+
await ensureConversationProjectLink({
|
|
165
|
+
authToken: input.authToken,
|
|
166
|
+
apiUrl: input.apiUrl,
|
|
167
|
+
conversationId: input.parentConversationId,
|
|
168
|
+
projectId: input.ensureProjectId,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const conversation = await createConversationRecord({
|
|
173
|
+
authToken: input.authToken,
|
|
174
|
+
apiUrl: input.apiUrl,
|
|
175
|
+
body: input.conversationBody,
|
|
176
|
+
});
|
|
177
|
+
const effectiveProjectId = input.projectId ?? conversation.projectId;
|
|
178
|
+
const message = await createConversationMessage({
|
|
179
|
+
authToken: input.authToken,
|
|
180
|
+
apiUrl: input.apiUrl,
|
|
181
|
+
conversationId: conversation.id,
|
|
182
|
+
body: input.handoffMessageBody,
|
|
183
|
+
});
|
|
184
|
+
const run = await createConversationAgentRun({
|
|
185
|
+
authToken: input.authToken,
|
|
186
|
+
apiUrl: input.apiUrl,
|
|
187
|
+
conversationId: conversation.id,
|
|
188
|
+
runId: input.runId,
|
|
189
|
+
agentId: input.agentId,
|
|
190
|
+
projectId: effectiveProjectId,
|
|
191
|
+
branchId: input.branchId,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return { conversation, message, run };
|
|
195
|
+
}
|