@vantageos/agent-engine 0.1.0-alpha.5 → 0.1.0-alpha.6
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 +229 -40
- package/dist/component/_generated/api.d.ts +31 -0
- package/dist/component/_generated/component.d.ts +346 -2
- package/dist/component/convex.config.js +19 -0
- package/dist/component/engine/agents.d.ts +10 -0
- package/dist/component/engine/agents.js +21 -0
- package/dist/component/engine/awaitEventTimeout.d.ts +13 -0
- package/dist/component/engine/awaitEventTimeout.js +82 -0
- package/dist/component/engine/delegation.d.ts +75 -0
- package/dist/component/engine/delegation.js +329 -0
- package/dist/component/engine/directory.d.ts +9 -0
- package/dist/component/engine/directory.js +45 -0
- package/dist/component/engine/habits.d.ts +70 -0
- package/dist/component/engine/habits.js +219 -0
- package/dist/component/engine/mandates.d.ts +74 -0
- package/dist/component/engine/mandates.js +272 -0
- package/dist/component/engine/sandboxCallback.d.ts +36 -0
- package/dist/component/engine/sandboxCallback.js +262 -0
- package/dist/component/engine/sessions.d.ts +6 -2
- package/dist/component/engine/sessions.js +42 -5
- package/dist/component/engine/vpConnection.d.ts +69 -0
- package/dist/component/engine/vpConnection.js +221 -0
- package/dist/component/engine/wakeup.d.ts +33 -0
- package/dist/component/engine/wakeup.js +230 -0
- package/dist/component/engine/workflows.d.ts +11 -0
- package/dist/component/engine/workflows.js +87 -0
- package/dist/component/schema.d.ts +365 -4
- package/dist/component/schema.js +353 -1
- package/dist/component/testFixtures/delegationDemoWorkflow.d.ts +18 -0
- package/dist/component/testFixtures/delegationDemoWorkflow.js +76 -0
- package/dist/component/testFixtures/sandboxDemoWorkflow.d.ts +19 -0
- package/dist/component/testFixtures/sandboxDemoWorkflow.js +69 -0
- package/dist/component/testFixtures/vpTool.d.ts +4 -0
- package/dist/component/testFixtures/vpTool.js +25 -0
- package/dist/component/testFixtures/wakeupDemoWorkflow.d.ts +19 -0
- package/dist/component/testFixtures/wakeupDemoWorkflow.js +77 -0
- package/dist/component/testFixtures/wakeupWork.d.ts +8 -0
- package/dist/component/testFixtures/wakeupWork.js +21 -0
- package/package.json +2 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { WorkflowManager } from "@convex-dev/workflow";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { components, internal } from "../_generated/api.js";
|
|
4
|
+
import { internalMutation, mutation } from "../_generated/server.js";
|
|
5
|
+
import { requireOrgId } from "../lib/auth.js";
|
|
6
|
+
// testFixtures/wakeupDemoWorkflow — TEST-ONLY reference recipient for the
|
|
7
|
+
// wake-up mechanism (C2), ported from convex/engine/wakeupDemoWorkflow.ts.
|
|
8
|
+
// A real consumer's own workflow does exactly this shape: call
|
|
9
|
+
// `step.awaitEvent({ name: <same name passed to engine/wakeup.enqueue> })`
|
|
10
|
+
// and do nothing else until it resolves. Proves (and is exercised by the
|
|
11
|
+
// contract tests in component/wakeup.componentPackaging.test.ts) that the
|
|
12
|
+
// ONLY way this resumes is `engine/wakeup.onWorkComplete`'s `sendEvent`
|
|
13
|
+
// call -- there is no poll, no re-check, no scheduled interval anywhere in
|
|
14
|
+
// this file. Also exercises `engine/awaitEventTimeout` by accepting the
|
|
15
|
+
// blank `sandbox.timeout` event name as an alternate wake source.
|
|
16
|
+
//
|
|
17
|
+
// Versioned workflow discipline (workflow#35, I0 §7.1): ship
|
|
18
|
+
// `...V2` rather than editing `wakeupDemoWorkflowV1` in place once
|
|
19
|
+
// referenced by live work (not a live concern for a test fixture, kept for
|
|
20
|
+
// parity with the app-level source it was ported from).
|
|
21
|
+
export const workflow = new WorkflowManager(components.workflow);
|
|
22
|
+
// start -- creates the demo result row, starts the demo workflow parked on
|
|
23
|
+
// `step.awaitEvent`, and hands back both the `workflowId` (to pass as
|
|
24
|
+
// `engine/wakeup.enqueue`'s `workflowId` arg) and the `resultId` (to poll
|
|
25
|
+
// in tests -- polling the TEST OBSERVATION POINT is not the mechanism
|
|
26
|
+
// under test; the mechanism is that `wokenAt` gets set with zero polling
|
|
27
|
+
// FROM THE ENGINE SIDE, which finishAllScheduledFunctions proves).
|
|
28
|
+
export const start = mutation({
|
|
29
|
+
args: { orgId: v.string(), awaitedEventName: v.string() },
|
|
30
|
+
returns: v.object({
|
|
31
|
+
workflowId: v.string(),
|
|
32
|
+
resultId: v.id("wakeupDemoResults"),
|
|
33
|
+
}),
|
|
34
|
+
handler: async (ctx, args) => {
|
|
35
|
+
const orgId = requireOrgId(args.orgId);
|
|
36
|
+
const resultId = await ctx.db.insert("wakeupDemoResults", { orgId, enqueuedAt: Date.now() });
|
|
37
|
+
const workflowId = await workflow.start(ctx, internal.testFixtures.wakeupDemoWorkflow.wakeupDemoWorkflowV1, { resultId, awaitedEventName: args.awaitedEventName });
|
|
38
|
+
return { workflowId, resultId };
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
export const recordWokenInternal = internalMutation({
|
|
42
|
+
args: {
|
|
43
|
+
resultId: v.id("wakeupDemoResults"),
|
|
44
|
+
status: v.union(v.literal("completed"), v.literal("failed"), v.literal("cancelled")),
|
|
45
|
+
resultSummary: v.optional(v.string()),
|
|
46
|
+
},
|
|
47
|
+
returns: v.null(),
|
|
48
|
+
handler: async (ctx, args) => {
|
|
49
|
+
await ctx.db.patch(args.resultId, {
|
|
50
|
+
wokenAt: Date.now(),
|
|
51
|
+
observedStatus: args.status,
|
|
52
|
+
observedResultSummary: args.resultSummary,
|
|
53
|
+
});
|
|
54
|
+
return null;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
export const wakeupDemoWorkflowV1 = workflow.define({
|
|
58
|
+
args: { resultId: v.id("wakeupDemoResults"), awaitedEventName: v.string() },
|
|
59
|
+
returns: v.null(),
|
|
60
|
+
handler: async (step, args) => {
|
|
61
|
+
// Blocks here -- resumes ONLY when engine/wakeup.onWorkComplete calls
|
|
62
|
+
// workflow.sendEvent with this exact name. No loop, no timer.
|
|
63
|
+
const result = await step.awaitEvent({
|
|
64
|
+
name: args.awaitedEventName,
|
|
65
|
+
validator: v.object({
|
|
66
|
+
status: v.union(v.literal("completed"), v.literal("failed"), v.literal("cancelled")),
|
|
67
|
+
resultSummary: v.optional(v.string()),
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
await step.runMutation(internal.testFixtures.wakeupDemoWorkflow.recordWokenInternal, {
|
|
71
|
+
resultId: args.resultId,
|
|
72
|
+
status: result.status,
|
|
73
|
+
resultSummary: result.resultSummary,
|
|
74
|
+
});
|
|
75
|
+
return null;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const succeeds: import("convex/server").RegisteredAction<"internal", {
|
|
2
|
+
payload?: string | undefined;
|
|
3
|
+
orgId: string;
|
|
4
|
+
}, Promise<null>>;
|
|
5
|
+
export declare const fails: import("convex/server").RegisteredAction<"internal", {
|
|
6
|
+
payload?: string | undefined;
|
|
7
|
+
orgId: string;
|
|
8
|
+
}, Promise<never>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { internalAction } from "../_generated/server.js";
|
|
3
|
+
// testFixtures/wakeupWork — stand-ins for a CALLER'S OWN unit of work (an
|
|
4
|
+
// action the caller passes to `engine/wakeup.enqueue` via
|
|
5
|
+
// `createFunctionHandle`, same component-isolation discipline as
|
|
6
|
+
// `testFixtures/callerSteps`). Exist ONLY to drive the component-level
|
|
7
|
+
// wakeup contract tests. Ported from convex/testFixtures/wakeupWork.ts.
|
|
8
|
+
export const succeeds = internalAction({
|
|
9
|
+
args: { orgId: v.string(), payload: v.optional(v.string()) },
|
|
10
|
+
returns: v.null(),
|
|
11
|
+
handler: async () => {
|
|
12
|
+
return null;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
export const fails = internalAction({
|
|
16
|
+
args: { orgId: v.string(), payload: v.optional(v.string()) },
|
|
17
|
+
returns: v.null(),
|
|
18
|
+
handler: async () => {
|
|
19
|
+
throw new Error("simulated wakeup-work failure");
|
|
20
|
+
},
|
|
21
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vantageos/agent-engine",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.6",
|
|
4
4
|
"description": "Reusable Convex component: durable agent engine. Agent = data aggregate (root sheet + child tables), never compiled code. Built on @convex-dev/workflow + @convex-dev/workpool (+ @convex-dev/agent). Eve parity by design.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@convex-dev/sharded-counter": "^0.2.1",
|
|
45
45
|
"@convex-dev/workflow": "0.4.4",
|
|
46
46
|
"@convex-dev/workpool": "0.4.7",
|
|
47
|
+
"@vercel/sandbox": "^2.6.1",
|
|
47
48
|
"ai": "6.0.35",
|
|
48
49
|
"convex": "1.42.1",
|
|
49
50
|
"convex-helpers": "0.1.103"
|