Skip to content

Commit 5fabdf8

Browse files
committed
Format routine target discovery sources
1 parent ddb6baa commit 5fabdf8

4 files changed

Lines changed: 63 additions & 15 deletions

File tree

‎packages/routines/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ otherwise) only groups the picker.
9393
then applies the product filter (`@corbits/workflow-catalog`'s
9494
`isAutomatableWorkflowName` or `isConversationalWorkflowName`, never a
9595
workbench-host anchor name) and orders by `(name asc, definitionAssetId
96-
asc)`. Pagination is an opaque cursor over that key; `limit` defaults to
96+
asc)`. Pagination is an opaque cursor over that key; `limit` defaults to
9797
50 and caps at 200. A principal holding no definition grant gets an empty
9898
page, not a 403.
9999
- Wire shape (`@corbits/routines/client`): `RoutineTarget`
100100
`{ definitionAssetId, definitionId, assetName, name, description, kind,
101-
wireHash }`, `RoutineTargetsResponse` `{ items, nextCursor }`, and
101+
wireHash }`, `RoutineTargetsResponse` `{ items, nextCursor }`, and
102102
`routineTargetsPath(tenantId, { limit?, cursor? })`.
103103
`definitionAssetId` is the identity a routine stores; `definitionId` /
104104
`wireHash` name what would run right now.

‎packages/routines/src/targets-route.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ const LimitParam = type("string.integer.parse").narrow(
2121
(limit) => limit >= 1 && limit <= ROUTINE_TARGETS_MAX_LIMIT,
2222
);
2323

24-
export function createRoutineTargetRoutes(deps: RoutineTargetsDeps): Hono<TenantEnv> {
24+
export function createRoutineTargetRoutes(
25+
deps: RoutineTargetsDeps,
26+
): Hono<TenantEnv> {
2527
const app = new Hono<TenantEnv>();
2628

2729
app.get("/", async (c) => {
2830
const rawLimit = c.req.query("limit");
2931
const limit =
30-
rawLimit === undefined ? ROUTINE_TARGETS_DEFAULT_LIMIT : LimitParam(rawLimit);
32+
rawLimit === undefined
33+
? ROUTINE_TARGETS_DEFAULT_LIMIT
34+
: LimitParam(rawLimit);
3135
if (limit instanceof type.errors) {
3236
return c.json(
3337
makeErrorEnvelope({
@@ -49,7 +53,10 @@ export function createRoutineTargetRoutes(deps: RoutineTargetsDeps): Hono<Tenant
4953
} catch (error) {
5054
if (error instanceof InvalidRoutineTargetCursorError) {
5155
return c.json(
52-
makeErrorEnvelope({ code: "bad_request", userMessage: error.message }),
56+
makeErrorEnvelope({
57+
code: "bad_request",
58+
userMessage: error.message,
59+
}),
5360
400,
5461
);
5562
}

‎packages/routines/src/targets.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export async function listLaunchableDefinitions(
5757
workflowDefinitionVersion,
5858
and(
5959
eq(workflowDefinitionVersion.definitionId, workflowDefinition.id),
60-
eq(workflowDefinitionVersion.version, workflowDefinition.currentVersion),
60+
eq(
61+
workflowDefinitionVersion.version,
62+
workflowDefinition.currentVersion,
63+
),
6164
),
6265
)
6366
.where(
@@ -79,7 +82,13 @@ export async function listLaunchableDefinitions(
7982
return rows.flatMap((row) =>
8083
row.definitionAssetId === null || row.wireHash === null
8184
? []
82-
: [{ ...row, definitionAssetId: row.definitionAssetId, wireHash: row.wireHash }],
85+
: [
86+
{
87+
...row,
88+
definitionAssetId: row.definitionAssetId,
89+
wireHash: row.wireHash,
90+
},
91+
],
8392
);
8493
}
8594

@@ -213,7 +222,10 @@ export async function listRoutineTargets(
213222
const last = items.at(-1);
214223
const nextCursor =
215224
remaining.length > items.length && last !== undefined
216-
? encodeCursor({ name: last.name, definitionAssetId: last.definitionAssetId })
225+
? encodeCursor({
226+
name: last.name,
227+
definitionAssetId: last.definitionAssetId,
228+
})
217229
: null;
218230
return { items, nextCursor };
219231
}

‎packages/routines/test/targets.drizzle.test.ts‎

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import { type } from "arktype";
99
import { Hono } from "hono";
1010
import type { MiddlewareHandler } from "hono";
1111

12-
import { createDB, createGrantStore, dropSchema, runMigrations, schema } from "@intx/db";
12+
import {
13+
createDB,
14+
createGrantStore,
15+
dropSchema,
16+
runMigrations,
17+
schema,
18+
} from "@intx/db";
1319
import type { TenantEnv } from "@intx/hub-api";
1420

1521
import { dbTargetFromUrl } from "../../../scripts/db-setup";
@@ -46,8 +52,14 @@ const WORKFLOW_PROJECTION = {
4652
triggers: [],
4753
stepOrder: ["gather", "write"],
4854
steps: {
49-
gather: { kind: "step", agent: { systemPrompt: "Gather.", modelSources: [] } },
50-
write: { kind: "step", agent: { systemPrompt: "Write.", modelSources: [] } },
55+
gather: {
56+
kind: "step",
57+
agent: { systemPrompt: "Gather.", modelSources: [] },
58+
},
59+
write: {
60+
kind: "step",
61+
agent: { systemPrompt: "Write.", modelSources: [] },
62+
},
5163
},
5264
};
5365

@@ -141,8 +153,20 @@ describeIfDb("routine target discovery", () => {
141153
},
142154
]);
143155
await db.insert(schema.principal).values([
144-
{ id: READER, tenantId: TENANT, kind: "user", refId: "reader", status: "active" },
145-
{ id: STRANGER, tenantId: TENANT, kind: "user", refId: "stranger", status: "active" },
156+
{
157+
id: READER,
158+
tenantId: TENANT,
159+
kind: "user",
160+
refId: "reader",
161+
status: "active",
162+
},
163+
{
164+
id: STRANGER,
165+
tenantId: TENANT,
166+
kind: "user",
167+
refId: "stranger",
168+
status: "active",
169+
},
146170
{
147171
id: OTHER_TENANT_READER,
148172
tenantId: OTHER_TENANT,
@@ -335,7 +359,9 @@ describeIfDb("routine target discovery", () => {
335359
principalId: READER,
336360
limit: 1,
337361
});
338-
expect(first.items.map((item) => item.definitionId)).toEqual(["wfd_agent"]);
362+
expect(first.items.map((item) => item.definitionId)).toEqual([
363+
"wfd_agent",
364+
]);
339365
expect(first.nextCursor).not.toBeNull();
340366
const second = await listRoutineTargets(targetsFor(db), {
341367
tenantId: TENANT,
@@ -359,7 +385,10 @@ describeIfDb("routine target discovery", () => {
359385
};
360386
const app = new Hono<TenantEnv>();
361387
app.use("*", asReader);
362-
app.route("/workflows/targets", createRoutineTargetRoutes(targetsFor(db)));
388+
app.route(
389+
"/workflows/targets",
390+
createRoutineTargetRoutes(targetsFor(db)),
391+
);
363392

364393
const res = await app.request("/workflows/targets?limit=1");
365394
expect(res.status).toBe(200);

0 commit comments

Comments
 (0)