@vantageos/agent-engine 0.1.0-alpha.8 → 0.3.0-alpha.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/README.md +33 -8
- package/dist/component/_generated/api.d.ts +14 -27
- package/dist/component/_generated/api.js +0 -25
- package/dist/component/_generated/component.d.ts +369 -92
- package/dist/component/_generated/component.js +0 -9
- package/dist/component/_generated/dataModel.d.ts +0 -38
- package/dist/component/_generated/dataModel.js +0 -9
- package/dist/component/_generated/server.d.ts +0 -106
- package/dist/component/_generated/server.js +0 -69
- package/dist/component/convex.config.js +0 -44
- package/dist/component/engine/agents.js +0 -7
- package/dist/component/engine/awaitEventTimeout.d.ts +1 -1
- package/dist/component/engine/awaitEventTimeout.js +18 -26
- package/dist/component/engine/connections.d.ts +74 -0
- package/dist/component/engine/connections.js +254 -0
- package/dist/component/engine/delegation.d.ts +1 -1
- package/dist/component/engine/delegation.js +0 -74
- package/dist/component/engine/directory.js +0 -18
- package/dist/component/engine/durableJob.d.ts +34 -4
- package/dist/component/engine/durableJob.js +333 -86
- package/dist/component/engine/mandates.js +0 -59
- package/dist/component/engine/queue.d.ts +97 -0
- package/dist/component/engine/queue.js +201 -0
- package/dist/component/engine/resolvers.d.ts +1 -1
- package/dist/component/engine/resolvers.js +6 -18
- package/dist/component/engine/sandboxCallback.d.ts +1 -1
- package/dist/component/engine/sandboxCallback.js +2 -79
- package/dist/component/engine/sandboxConfigProvider.d.ts +9 -0
- package/dist/component/engine/sandboxConfigProvider.js +32 -0
- package/dist/component/engine/sessions.d.ts +28 -10
- package/dist/component/engine/sessions.js +153 -165
- package/dist/component/engine/streams.d.ts +47 -0
- package/dist/component/engine/streams.js +162 -0
- package/dist/component/engine/toolApprovals.d.ts +1 -1
- package/dist/component/engine/toolApprovals.js +12 -37
- package/dist/component/engine/vpConnection.js +0 -40
- package/dist/component/engine/wakeup.d.ts +5 -7
- package/dist/component/engine/wakeup.js +54 -127
- package/dist/component/engine/workflows.d.ts +42 -0
- package/dist/component/engine/workflows.js +100 -41
- package/dist/component/engine/world.d.ts +249 -0
- package/dist/component/engine/world.js +665 -0
- package/dist/component/lib/auth.js +0 -26
- package/dist/component/lib/connectionSecret.d.ts +5 -0
- package/dist/component/lib/connectionSecret.js +32 -0
- package/dist/component/schema.d.ts +227 -77
- package/dist/component/schema.js +137 -250
- package/package.json +17 -3
- package/dist/component/engine/habits.d.ts +0 -70
- package/dist/component/engine/habits.js +0 -218
- package/dist/component/testFixtures/callerSteps.d.ts +0 -20
- package/dist/component/testFixtures/callerSteps.js +0 -90
- package/dist/component/testFixtures/delegationDemoWorkflow.d.ts +0 -18
- package/dist/component/testFixtures/delegationDemoWorkflow.js +0 -75
- package/dist/component/testFixtures/sandboxDemoWorkflow.d.ts +0 -19
- package/dist/component/testFixtures/sandboxDemoWorkflow.js +0 -69
- package/dist/component/testFixtures/vpTool.d.ts +0 -4
- package/dist/component/testFixtures/vpTool.js +0 -25
- package/dist/component/testFixtures/wakeupDemoWorkflow.d.ts +0 -19
- package/dist/component/testFixtures/wakeupDemoWorkflow.js +0 -77
- package/dist/component/testFixtures/wakeupWork.d.ts +0 -8
- package/dist/component/testFixtures/wakeupWork.js +0 -21
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { WorkflowManager } from "@convex-dev/workflow";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { components } from "../_generated/api.js";
|
|
4
|
+
import { mutation, query } from "../_generated/server.js";
|
|
5
|
+
import { assertSameOrg, requireOrgId } from "../lib/auth.js";
|
|
6
|
+
import { encryptSecret } from "../lib/connectionSecret.js";
|
|
7
|
+
const workflow = new WorkflowManager(components.workflow);
|
|
8
|
+
const authModeValidator = v.union(v.literal("app-token"), v.literal("user-oauth"), v.literal("none"), v.literal("header"));
|
|
9
|
+
function principalTypeForAuthMode(authMode) {
|
|
10
|
+
return authMode === "user-oauth" ? "user" : "app";
|
|
11
|
+
}
|
|
12
|
+
const connectionTypeValidator = v.union(v.literal("mcp"), v.literal("openapi"));
|
|
13
|
+
const connectionStatusValidator = v.union(v.literal("active"), v.literal("pending_authorization"), v.literal("error"));
|
|
14
|
+
const connectionPublicDoc = v.object({
|
|
15
|
+
_id: v.id("connections"),
|
|
16
|
+
_creationTime: v.number(),
|
|
17
|
+
orgId: v.string(),
|
|
18
|
+
agentId: v.id("agents"),
|
|
19
|
+
type: connectionTypeValidator,
|
|
20
|
+
name: v.string(),
|
|
21
|
+
serverConfig: v.string(),
|
|
22
|
+
authMode: authModeValidator,
|
|
23
|
+
principalType: v.union(v.literal("app"), v.literal("user")),
|
|
24
|
+
status: connectionStatusValidator,
|
|
25
|
+
hasSecret: v.boolean(),
|
|
26
|
+
createdAt: v.number(),
|
|
27
|
+
updatedAt: v.number(),
|
|
28
|
+
});
|
|
29
|
+
function toPublicDoc(row) {
|
|
30
|
+
return {
|
|
31
|
+
_id: row._id,
|
|
32
|
+
_creationTime: row._creationTime,
|
|
33
|
+
orgId: row.orgId,
|
|
34
|
+
agentId: row.agentId,
|
|
35
|
+
type: row.type,
|
|
36
|
+
name: row.name,
|
|
37
|
+
serverConfig: row.serverConfig,
|
|
38
|
+
authMode: row.authMode,
|
|
39
|
+
principalType: principalTypeForAuthMode(row.authMode),
|
|
40
|
+
status: row.status,
|
|
41
|
+
hasSecret: row.encryptedSecretCiphertext !== undefined,
|
|
42
|
+
createdAt: row.createdAt,
|
|
43
|
+
updatedAt: row.updatedAt,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export const create = mutation({
|
|
47
|
+
args: {
|
|
48
|
+
orgId: v.string(),
|
|
49
|
+
agentId: v.id("agents"),
|
|
50
|
+
type: connectionTypeValidator,
|
|
51
|
+
name: v.string(),
|
|
52
|
+
serverConfig: v.string(),
|
|
53
|
+
authMode: authModeValidator,
|
|
54
|
+
secretPlaintext: v.optional(v.string()),
|
|
55
|
+
encryptionKeyBase64: v.optional(v.string()),
|
|
56
|
+
},
|
|
57
|
+
returns: v.id("connections"),
|
|
58
|
+
handler: async (ctx, args) => {
|
|
59
|
+
const orgId = requireOrgId(args.orgId);
|
|
60
|
+
const agent = await ctx.db.get(args.agentId);
|
|
61
|
+
assertSameOrg(orgId, agent, "Agent not found");
|
|
62
|
+
if (args.name.trim().length === 0) {
|
|
63
|
+
throw new Error("Validation: name must not be empty");
|
|
64
|
+
}
|
|
65
|
+
let encryptedSecretCiphertext;
|
|
66
|
+
let encryptedSecretIv;
|
|
67
|
+
if (args.authMode === "app-token" || args.authMode === "header") {
|
|
68
|
+
if (!args.secretPlaintext) {
|
|
69
|
+
throw new Error(`MUST_REFUSE: connection authMode "${args.authMode}" requires secretPlaintext, none was supplied`);
|
|
70
|
+
}
|
|
71
|
+
if (!args.encryptionKeyBase64) {
|
|
72
|
+
throw new Error(`MUST_REFUSE: connection authMode "${args.authMode}" requires encryptionKeyBase64, none was supplied`);
|
|
73
|
+
}
|
|
74
|
+
const encrypted = await encryptSecret(args.secretPlaintext, args.encryptionKeyBase64);
|
|
75
|
+
encryptedSecretCiphertext = encrypted.ciphertextBase64;
|
|
76
|
+
encryptedSecretIv = encrypted.ivBase64;
|
|
77
|
+
}
|
|
78
|
+
else if (args.authMode === "none") {
|
|
79
|
+
if (args.secretPlaintext) {
|
|
80
|
+
throw new Error('MUST_REFUSE: connection authMode "none" must not carry a secretPlaintext');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
return await ctx.db.insert("connections", {
|
|
85
|
+
orgId,
|
|
86
|
+
agentId: args.agentId,
|
|
87
|
+
type: args.type,
|
|
88
|
+
name: args.name,
|
|
89
|
+
serverConfig: args.serverConfig,
|
|
90
|
+
authMode: args.authMode,
|
|
91
|
+
encryptedSecretCiphertext,
|
|
92
|
+
encryptedSecretIv,
|
|
93
|
+
status: "active",
|
|
94
|
+
createdAt: now,
|
|
95
|
+
updatedAt: now,
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
export const get = query({
|
|
100
|
+
args: { orgId: v.string(), connectionId: v.id("connections") },
|
|
101
|
+
returns: connectionPublicDoc,
|
|
102
|
+
handler: async (ctx, args) => {
|
|
103
|
+
const orgId = requireOrgId(args.orgId);
|
|
104
|
+
const row = await ctx.db.get(args.connectionId);
|
|
105
|
+
assertSameOrg(orgId, row, "Connection not found");
|
|
106
|
+
return toPublicDoc(row);
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
export const listByAgent = query({
|
|
110
|
+
args: { orgId: v.string(), agentId: v.id("agents") },
|
|
111
|
+
returns: v.array(connectionPublicDoc),
|
|
112
|
+
handler: async (ctx, args) => {
|
|
113
|
+
const orgId = requireOrgId(args.orgId);
|
|
114
|
+
const agent = await ctx.db.get(args.agentId);
|
|
115
|
+
assertSameOrg(orgId, agent, "Agent not found");
|
|
116
|
+
const rows = await ctx.db
|
|
117
|
+
.query("connections")
|
|
118
|
+
.withIndex("by_org_agent", (q) => q.eq("orgId", orgId).eq("agentId", args.agentId))
|
|
119
|
+
.collect();
|
|
120
|
+
return rows.map((row) => toPublicDoc(row));
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
export const requestAuthorization = mutation({
|
|
124
|
+
args: {
|
|
125
|
+
orgId: v.string(),
|
|
126
|
+
connectionId: v.id("connections"),
|
|
127
|
+
workflowId: v.string(),
|
|
128
|
+
awaitedEventName: v.string(),
|
|
129
|
+
url: v.string(),
|
|
130
|
+
userCode: v.string(),
|
|
131
|
+
},
|
|
132
|
+
returns: v.id("connectionAuthorizations"),
|
|
133
|
+
handler: async (ctx, args) => {
|
|
134
|
+
const orgId = requireOrgId(args.orgId);
|
|
135
|
+
const connection = await ctx.db.get(args.connectionId);
|
|
136
|
+
assertSameOrg(orgId, connection, "Connection not found");
|
|
137
|
+
if (connection.authMode !== "user-oauth") {
|
|
138
|
+
throw new Error(`MUST_REFUSE: requestAuthorization requires authMode "user-oauth", connection has "${connection.authMode}"`);
|
|
139
|
+
}
|
|
140
|
+
if (args.workflowId.length === 0) {
|
|
141
|
+
throw new Error("MUST_REFUSE: workflowId must not be empty");
|
|
142
|
+
}
|
|
143
|
+
if (args.awaitedEventName.length === 0) {
|
|
144
|
+
throw new Error("MUST_REFUSE: awaitedEventName must not be empty");
|
|
145
|
+
}
|
|
146
|
+
if (args.url.trim().length === 0) {
|
|
147
|
+
throw new Error("MUST_REFUSE: authorization.required challenge requires a non-empty url, none was supplied");
|
|
148
|
+
}
|
|
149
|
+
if (args.userCode.trim().length === 0) {
|
|
150
|
+
throw new Error("MUST_REFUSE: authorization.required challenge requires a non-empty userCode, none was supplied");
|
|
151
|
+
}
|
|
152
|
+
const now = Date.now();
|
|
153
|
+
const authorizationId = await ctx.db.insert("connectionAuthorizations", {
|
|
154
|
+
orgId,
|
|
155
|
+
connectionId: args.connectionId,
|
|
156
|
+
workflowId: args.workflowId,
|
|
157
|
+
awaitedEventName: args.awaitedEventName,
|
|
158
|
+
url: args.url,
|
|
159
|
+
userCode: args.userCode,
|
|
160
|
+
status: "pending",
|
|
161
|
+
createdAt: now,
|
|
162
|
+
updatedAt: now,
|
|
163
|
+
});
|
|
164
|
+
await ctx.db.patch(args.connectionId, {
|
|
165
|
+
status: "pending_authorization",
|
|
166
|
+
updatedAt: now,
|
|
167
|
+
});
|
|
168
|
+
return authorizationId;
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
export const getAuthorizationStatus = query({
|
|
172
|
+
args: { orgId: v.string(), connectionAuthorizationId: v.id("connectionAuthorizations") },
|
|
173
|
+
returns: v.object({
|
|
174
|
+
status: v.union(v.literal("pending"), v.literal("authorized"), v.literal("denied")),
|
|
175
|
+
url: v.string(),
|
|
176
|
+
userCode: v.string(),
|
|
177
|
+
resultSummary: v.optional(v.string()),
|
|
178
|
+
}),
|
|
179
|
+
handler: async (ctx, args) => {
|
|
180
|
+
const orgId = requireOrgId(args.orgId);
|
|
181
|
+
const row = await ctx.db.get(args.connectionAuthorizationId);
|
|
182
|
+
assertSameOrg(orgId, row, "Connection authorization not found");
|
|
183
|
+
return {
|
|
184
|
+
status: row.status,
|
|
185
|
+
url: row.url,
|
|
186
|
+
userCode: row.userCode,
|
|
187
|
+
resultSummary: row.resultSummary,
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
export const completeAuthorization = mutation({
|
|
192
|
+
args: {
|
|
193
|
+
orgId: v.string(),
|
|
194
|
+
connectionAuthorizationId: v.id("connectionAuthorizations"),
|
|
195
|
+
outcome: v.union(v.literal("authorized"), v.literal("denied")),
|
|
196
|
+
secretPlaintext: v.optional(v.string()),
|
|
197
|
+
encryptionKeyBase64: v.optional(v.string()),
|
|
198
|
+
resultSummary: v.optional(v.string()),
|
|
199
|
+
},
|
|
200
|
+
returns: v.object({
|
|
201
|
+
outcome: v.union(v.literal("woke"), v.literal("already-resolved")),
|
|
202
|
+
}),
|
|
203
|
+
handler: async (ctx, args) => {
|
|
204
|
+
const orgId = requireOrgId(args.orgId);
|
|
205
|
+
const authorization = await ctx.db.get(args.connectionAuthorizationId);
|
|
206
|
+
assertSameOrg(orgId, authorization, "Connection authorization not found");
|
|
207
|
+
if (authorization.status !== "pending") {
|
|
208
|
+
return { outcome: "already-resolved" };
|
|
209
|
+
}
|
|
210
|
+
const connection = await ctx.db.get(authorization.connectionId);
|
|
211
|
+
assertSameOrg(orgId, connection, "Connection not found");
|
|
212
|
+
let encryptedSecretCiphertext = connection.encryptedSecretCiphertext;
|
|
213
|
+
let encryptedSecretIv = connection.encryptedSecretIv;
|
|
214
|
+
let connectionStatus = "error";
|
|
215
|
+
if (args.outcome === "authorized") {
|
|
216
|
+
if (!args.secretPlaintext) {
|
|
217
|
+
throw new Error('MUST_REFUSE: completeAuthorization outcome "authorized" requires secretPlaintext, none was supplied');
|
|
218
|
+
}
|
|
219
|
+
if (!args.encryptionKeyBase64) {
|
|
220
|
+
throw new Error('MUST_REFUSE: completeAuthorization outcome "authorized" requires encryptionKeyBase64, none was supplied');
|
|
221
|
+
}
|
|
222
|
+
const encrypted = await encryptSecret(args.secretPlaintext, args.encryptionKeyBase64);
|
|
223
|
+
encryptedSecretCiphertext = encrypted.ciphertextBase64;
|
|
224
|
+
encryptedSecretIv = encrypted.ivBase64;
|
|
225
|
+
connectionStatus = "active";
|
|
226
|
+
}
|
|
227
|
+
const now = Date.now();
|
|
228
|
+
await ctx.db.patch(authorization._id, {
|
|
229
|
+
status: args.outcome,
|
|
230
|
+
resultSummary: args.resultSummary,
|
|
231
|
+
updatedAt: now,
|
|
232
|
+
resolvedAt: now,
|
|
233
|
+
});
|
|
234
|
+
await ctx.db.patch(connection._id, {
|
|
235
|
+
encryptedSecretCiphertext,
|
|
236
|
+
encryptedSecretIv,
|
|
237
|
+
status: connectionStatus,
|
|
238
|
+
updatedAt: now,
|
|
239
|
+
});
|
|
240
|
+
await workflow.sendEvent(ctx, {
|
|
241
|
+
workflowId: authorization.workflowId,
|
|
242
|
+
name: authorization.awaitedEventName,
|
|
243
|
+
validator: v.object({
|
|
244
|
+
status: v.union(v.literal("completed"), v.literal("failed")),
|
|
245
|
+
resultSummary: v.optional(v.string()),
|
|
246
|
+
}),
|
|
247
|
+
value: {
|
|
248
|
+
status: args.outcome === "authorized" ? "completed" : "failed",
|
|
249
|
+
resultSummary: args.resultSummary,
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
return { outcome: "woke" };
|
|
253
|
+
},
|
|
254
|
+
});
|
|
@@ -17,9 +17,9 @@ export declare const listSubagents: import("convex/server").RegisteredQuery<"pub
|
|
|
17
17
|
orgId: string;
|
|
18
18
|
createdAt: number;
|
|
19
19
|
toolName: string;
|
|
20
|
-
enabled: boolean;
|
|
21
20
|
parentAgentId: import("convex/values").GenericId<"agents">;
|
|
22
21
|
childAgentId: import("convex/values").GenericId<"agents">;
|
|
22
|
+
enabled: boolean;
|
|
23
23
|
}[]>>;
|
|
24
24
|
export declare const delegateToSubagent: import("convex/server").RegisteredAction<"public", {
|
|
25
25
|
payload?: string | undefined;
|
|
@@ -2,46 +2,7 @@ import { v } from "convex/values";
|
|
|
2
2
|
import { api, internal } from "../_generated/api.js";
|
|
3
3
|
import { action, internalMutation, internalQuery, mutation, query, } from "../_generated/server.js";
|
|
4
4
|
import { assertSameOrg, requireOrgId } from "../lib/auth.js";
|
|
5
|
-
// engine/delegation — an agent delegating to another agent uses THE SAME
|
|
6
|
-
// pause/wake system (awaitEvent/sendEvent) as the sandbox bridge: one
|
|
7
|
-
// system to maintain, not two. Every delegation path below (declared
|
|
8
|
-
// subagent AND the built-in `agent` clone tool) terminates in exactly ONE
|
|
9
|
-
// call to `engine.wakeup.enqueue` -- the same public action this component
|
|
10
|
-
// already ships, imported here and never reimplemented.
|
|
11
|
-
// grep proof: this file makes zero calls to `wakeupPool.*` / `workflow.*`
|
|
12
|
-
// directly; the only wake-capable call in this module is
|
|
13
|
-
// `api.engine.wakeup.enqueue` at the bottom of `delegateToSubagent` and
|
|
14
|
-
// `invokeAgentClone`.
|
|
15
|
-
//
|
|
16
|
-
// orgId discipline (component/lib/auth.ts): every PUBLIC function takes
|
|
17
|
-
// `orgId` as an explicit ARGUMENT (auth does not propagate across a
|
|
18
|
-
// component boundary), same as engine/mandates.ts / engine/wakeup.ts.
|
|
19
|
-
// `delegateToSubagent`/`invokeAgentClone` are `action`s because they each
|
|
20
|
-
// call `api.engine.wakeup.enqueue` (itself an action: the two-transaction
|
|
21
|
-
// funding protocol) -- `orgId` is threaded explicitly through
|
|
22
|
-
// every hop, never relying on any identity propagation across the boundary.
|
|
23
|
-
// Reserved tool name for the built-in, root-only, non-recursive clone tool
|
|
24
|
-
// (eve.dev/docs/subagents). A declared subagent may never claim this name --
|
|
25
|
-
// that would silently shadow the built-in, which eve explicitly refuses to
|
|
26
|
-
// do ("eve rejects the build rather than picking a winner").
|
|
27
5
|
export const BUILTIN_AGENT_TOOL_NAME = "agent";
|
|
28
|
-
// ---------------------------------------------------------------------
|
|
29
|
-
// (a.1) DECLARED SUBAGENTS -- strict isolation, build-time collision guard
|
|
30
|
-
// ---------------------------------------------------------------------
|
|
31
|
-
// declareSubagent — registers a declared subagent as a NAMED tool on the
|
|
32
|
-
// parent. Isolation is by construction: this mutation writes ONLY the
|
|
33
|
-
// parent->child link + toolName; it never copies a single field out of the
|
|
34
|
-
// child's own `skills`/`connections`/`toolApprovals` rows onto the parent,
|
|
35
|
-
// and never will -- a declared subagent's own aggregate is the ONLY place
|
|
36
|
-
// its slots ever live (eve.dev/docs/subagents, verbatim: "a declared
|
|
37
|
-
// subagent inherits nothing from the root's authored slots").
|
|
38
|
-
//
|
|
39
|
-
// BUILD-TIME COLLISION GUARD: `toolName` must be unique among (1) the
|
|
40
|
-
// reserved built-in `agent` tool name, (2) every OTHER declared subagent of
|
|
41
|
-
// this same parent, and (3) every `toolApprovals` row already registered
|
|
42
|
-
// for this parent (a toolApprovals row is how this engine represents "a
|
|
43
|
-
// named tool this agent already exposes"). Any collision REJECTS the
|
|
44
|
-
// mutation -- the row is never written, there is no silent "last one wins".
|
|
45
6
|
export const declareSubagent = mutation({
|
|
46
7
|
args: {
|
|
47
8
|
orgId: v.string(),
|
|
@@ -119,18 +80,6 @@ export const listSubagents = query({
|
|
|
119
80
|
.collect();
|
|
120
81
|
},
|
|
121
82
|
});
|
|
122
|
-
// ---------------------------------------------------------------------
|
|
123
|
-
// (a.2) DELEGATION -- reuses `engine.wakeup.enqueue` end to end
|
|
124
|
-
// ---------------------------------------------------------------------
|
|
125
|
-
// delegateToSubagent — A delegates to a declared subagent B by the SAME
|
|
126
|
-
// pause/wake mechanism the sandbox bridge uses: it enqueues the
|
|
127
|
-
// caller-supplied `workFunctionHandle` (an action that performs B's turn)
|
|
128
|
-
// through `api.engine.wakeup.enqueue`. That enqueue funds through
|
|
129
|
-
// `mandates.spendInternal` (the funding choke point, untouched), puts the work
|
|
130
|
-
// into `wakeupPool`, and when it resolves, `engine.wakeup.onWorkComplete`
|
|
131
|
-
// calls `workflow.sendEvent` (workflowId, awaitedEventName, ...) -- waking
|
|
132
|
-
// whatever workflow step A's own session parked on `step.awaitEvent`. There
|
|
133
|
-
// is no second onComplete/sendEvent path anywhere in this file.
|
|
134
83
|
export const delegateToSubagent = action({
|
|
135
84
|
args: {
|
|
136
85
|
orgId: v.string(),
|
|
@@ -164,10 +113,6 @@ export const delegateToSubagent = action({
|
|
|
164
113
|
workflowId: args.workflowId,
|
|
165
114
|
awaitedEventName: args.awaitedEventName,
|
|
166
115
|
});
|
|
167
|
-
// THE reuse point: no bespoke pause/wake code below this line -- this
|
|
168
|
-
// is a direct call into this component's own PUBLIC `engine.wakeup.enqueue`
|
|
169
|
-
// action. `orgId` is threaded explicitly (no identity propagation
|
|
170
|
-
// across the component boundary).
|
|
171
116
|
await ctx.runAction(api.engine.wakeup.enqueue, {
|
|
172
117
|
orgId,
|
|
173
118
|
agentId: subagent.childAgentId,
|
|
@@ -182,19 +127,6 @@ export const delegateToSubagent = action({
|
|
|
182
127
|
return delegationRunId;
|
|
183
128
|
},
|
|
184
129
|
});
|
|
185
|
-
// ---------------------------------------------------------------------
|
|
186
|
-
// (a.3) BUILT-IN `agent` TOOL -- root-only clone, NOT recursive
|
|
187
|
-
// ---------------------------------------------------------------------
|
|
188
|
-
// invokeAgentClone — the built-in `agent` tool (eve.dev/docs/subagents): a
|
|
189
|
-
// clone of the ROOT agent, invocable by the root itself, but the clone
|
|
190
|
-
// CANNOT call itself again. `viaAgentTool` is the recursion guard: the
|
|
191
|
-
// root's own first call always passes `viaAgentTool: false` (or omits it).
|
|
192
|
-
// Anything invoking this action must set `viaAgentTool: true` on any call
|
|
193
|
-
// made FROM INSIDE a clone's own work -- and that is exactly the value this
|
|
194
|
-
// handler refuses. There is no code path in this engine that can reach the
|
|
195
|
-
// pool a second time for the same clone chain: the guard runs BEFORE
|
|
196
|
-
// `wakeup.enqueue` is ever called, so a recursive attempt never enters the
|
|
197
|
-
// workpool at all.
|
|
198
130
|
export const invokeAgentClone = action({
|
|
199
131
|
args: {
|
|
200
132
|
orgId: v.string(),
|
|
@@ -229,8 +161,6 @@ export const invokeAgentClone = action({
|
|
|
229
161
|
workflowId: args.workflowId,
|
|
230
162
|
awaitedEventName: args.awaitedEventName,
|
|
231
163
|
});
|
|
232
|
-
// Same reuse point as `delegateToSubagent`: one call into the SAME
|
|
233
|
-
// public `engine.wakeup.enqueue`, nothing bespoke.
|
|
234
164
|
await ctx.runAction(api.engine.wakeup.enqueue, {
|
|
235
165
|
orgId,
|
|
236
166
|
agentId: args.agentId,
|
|
@@ -245,10 +175,6 @@ export const invokeAgentClone = action({
|
|
|
245
175
|
return cloneRunId;
|
|
246
176
|
},
|
|
247
177
|
});
|
|
248
|
-
// ---------------------------------------------------------------------
|
|
249
|
-
// INTERNAL helpers -- unreachable from any client, same discipline as
|
|
250
|
-
// `engine/wakeup.enqueueInternal`.
|
|
251
|
-
// ---------------------------------------------------------------------
|
|
252
178
|
export const getSubagentInternal = internalQuery({
|
|
253
179
|
args: { orgId: v.string(), subagentId: v.id("subagents") },
|
|
254
180
|
returns: v.union(v.object({
|
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
import { v } from "convex/values";
|
|
2
2
|
import { query } from "../_generated/server.js";
|
|
3
3
|
import { requireOrgId } from "../lib/auth.js";
|
|
4
|
-
// engine/directory — component-boundary port of the app-level
|
|
5
|
-
// `convex/directory.ts:listByOrg`.
|
|
6
|
-
//
|
|
7
|
-
// Trust-boundary divergence from the app-level prototype (see
|
|
8
|
-
// component/lib/auth.ts): auth does NOT propagate across a component
|
|
9
|
-
// boundary, so `orgId` is a caller-supplied ARGUMENT here (deny by default
|
|
10
|
-
// via `requireOrgId(args.orgId)`), never read from `ctx.auth`. The consumer
|
|
11
|
-
// app has already authenticated its user and resolved orgId on its own
|
|
12
|
-
// side before calling in.
|
|
13
|
-
//
|
|
14
|
-
// Shape divergence: the app-level prototype also reports
|
|
15
|
-
// `subagentCount`/`connectionCount` by joining the `subagents` and
|
|
16
|
-
// `connections` tables. Those tables are NOT (yet) re-hosted inside this
|
|
17
|
-
// component boundary (see component/schema.ts SCOPE note) -- porting a
|
|
18
|
-
// join against tables this component does not own would violate component
|
|
19
|
-
// isolation. `listByOrg` here therefore returns only what this component's
|
|
20
|
-
// own `agents` table can answer; counts can be added once `subagents`/
|
|
21
|
-
// `connections` gain their own component-level test harness.
|
|
22
4
|
export const listByOrg = query({
|
|
23
5
|
args: { orgId: v.string() },
|
|
24
6
|
returns: v.array(v.object({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WorkflowManager, type WorkflowId } from "@convex-dev/workflow";
|
|
2
|
+
type JobRunStatus = "running" | "completed" | "abandoned" | "cancelled";
|
|
2
3
|
export declare const workflow: WorkflowManager;
|
|
3
4
|
export declare const start: import("convex/server").RegisteredMutation<"public", {
|
|
4
5
|
orgId: string;
|
|
@@ -6,12 +7,12 @@ export declare const start: import("convex/server").RegisteredMutation<"public",
|
|
|
6
7
|
totalSteps: number;
|
|
7
8
|
maxAttemptsPerStep: number;
|
|
8
9
|
kind: string;
|
|
9
|
-
}, Promise<
|
|
10
|
+
}, Promise<string>>;
|
|
10
11
|
export declare const getStatus: import("convex/server").RegisteredQuery<"public", {
|
|
11
12
|
orgId: string;
|
|
12
|
-
jobId:
|
|
13
|
+
jobId: string;
|
|
13
14
|
}, Promise<{
|
|
14
|
-
status:
|
|
15
|
+
status: JobRunStatus;
|
|
15
16
|
cursor: number;
|
|
16
17
|
totalSteps: number;
|
|
17
18
|
lastError: string | undefined;
|
|
@@ -19,7 +20,7 @@ export declare const getStatus: import("convex/server").RegisteredQuery<"public"
|
|
|
19
20
|
}>>;
|
|
20
21
|
export declare const cancel: import("convex/server").RegisteredMutation<"public", {
|
|
21
22
|
orgId: string;
|
|
22
|
-
jobId:
|
|
23
|
+
jobId: string;
|
|
23
24
|
}, Promise<null>>;
|
|
24
25
|
export declare const getJobInternal: import("convex/server").RegisteredQuery<"internal", {
|
|
25
26
|
jobId: import("convex/values").GenericId<"durableJobs">;
|
|
@@ -44,3 +45,32 @@ export declare const markCompletedInternal: import("convex/server").RegisteredMu
|
|
|
44
45
|
export declare const durableJobWorkflowV1: import("convex/server").RegisteredMutation<"internal", import("@convex-dev/workflow").WorkflowArgs<{
|
|
45
46
|
jobId: import("convex/values").VId<import("convex/values").GenericId<"durableJobs">, "required">;
|
|
46
47
|
}>, WorkflowId>;
|
|
48
|
+
export declare const getJobInternalV2: import("convex/server").RegisteredQuery<"internal", {
|
|
49
|
+
orgId: string;
|
|
50
|
+
runId: string;
|
|
51
|
+
}, Promise<{
|
|
52
|
+
cursor: number;
|
|
53
|
+
totalSteps: number;
|
|
54
|
+
maxAttemptsPerStep: number;
|
|
55
|
+
status: JobRunStatus;
|
|
56
|
+
} | null>>;
|
|
57
|
+
export declare const runStepInternalV2: import("convex/server").RegisteredMutation<"internal", {
|
|
58
|
+
orgId: string;
|
|
59
|
+
stepIndex: number;
|
|
60
|
+
runId: string;
|
|
61
|
+
}, Promise<null>>;
|
|
62
|
+
export declare const markAbandonedInternalV2: import("convex/server").RegisteredMutation<"internal", {
|
|
63
|
+
orgId: string;
|
|
64
|
+
stepIndex: number;
|
|
65
|
+
runId: string;
|
|
66
|
+
error: string;
|
|
67
|
+
}, Promise<null>>;
|
|
68
|
+
export declare const markCompletedInternalV2: import("convex/server").RegisteredMutation<"internal", {
|
|
69
|
+
orgId: string;
|
|
70
|
+
runId: string;
|
|
71
|
+
}, Promise<null>>;
|
|
72
|
+
export declare const durableJobWorkflowV2: import("convex/server").RegisteredMutation<"internal", import("@convex-dev/workflow").WorkflowArgs<{
|
|
73
|
+
orgId: import("convex/values").VString<string, "required">;
|
|
74
|
+
runId: import("convex/values").VString<string, "required">;
|
|
75
|
+
}>, WorkflowId>;
|
|
76
|
+
export {};
|