Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

end: add my sessions and my schedules filter (#604)

Heer Ambavi2dcb3a0f2064
diff --git a/.changeset/created-by-me-list-filter.md b/.changeset/created-by-me-list-filter.md
new file mode 100644
index 000000000..9f5db715b
--- /dev/null
+++ b/.changeset/created-by-me-list-filter.md
@@ -0,0 +1,6 @@
+---
+"@truefoundry/trueforge": patch
+"@truefoundry/trueforge-sdk": patch
+---
+
+Add `created_by_me` to list sessions and list schedules so callers can restrict results to resources they created (excluding managed-agent visibility).
diff --git a/.github/fern/openapi/openapi.json b/.github/fern/openapi/openapi.json
index e3b9b82e1..ebc8cc0b3 100644
--- a/.github/fern/openapi/openapi.json
+++ b/.github/fern/openapi/openapi.json
@@ -6268,7 +6268,7 @@
},
"/api/v1/schedules": {
"get": {
- "description": "List schedules for the tenant, newest first. Optionally filter by `agent_names`.",
+ "description": "List schedules for the tenant, newest first.",
"parameters": [
{
"description": "Page size. Defaults to 25",
@@ -6302,6 +6302,16 @@
"description": "Filter by one or more agent names (comma-separated). When set, at least one name is required.",
"type": "string"
}
+ },
+ {
+ "description": "When true, only schedules created by the authenticated subject.",
+ "in": "query",
+ "name": "created_by_me",
+ "required": false,
+ "schema": {
+ "description": "When true, only schedules created by the authenticated subject.",
+ "type": "boolean"
+ }
}
],
"responses": {
@@ -6763,7 +6773,7 @@
},
"/api/v1/sessions": {
"get": {
- "description": "List the caller's sessions (newest first by default), token-paginated. Results are scoped to the authenticated identity via the session store's `created_by_subject.subject_id` filter (not a client query param). Optional `agent_id` filters to sessions bound to that named agent. Pass `page_token` to fetch the next page, keeping the other query params constant.",
+ "description": "List the caller's sessions (newest first by default).",
"parameters": [
{
"description": "Page size. Defaults to 25, max 25.",
@@ -6830,6 +6840,16 @@
"minLength": 1,
"type": "string"
}
+ },
+ {
+ "description": "When true, only sessions created by the authenticated subject.",
+ "in": "query",
+ "name": "created_by_me",
+ "required": false,
+ "schema": {
+ "description": "When true, only sessions created by the authenticated subject.",
+ "type": "boolean"
+ }
}
],
"responses": {
diff --git a/docs/openapi.json b/docs/openapi.json
index e3b9b82e1..ebc8cc0b3 100644
--- a/docs/openapi.json
+++ b/docs/openapi.json
@@ -6268,7 +6268,7 @@
},
"/api/v1/schedules": {
"get": {
- "description": "List schedules for the tenant, newest first. Optionally filter by `agent_names`.",
+ "description": "List schedules for the tenant, newest first.",
"parameters": [
{
"description": "Page size. Defaults to 25",
@@ -6302,6 +6302,16 @@
"description": "Filter by one or more agent names (comma-separated). When set, at least one name is required.",
"type": "string"
}
+ },
+ {
+ "description": "When true, only schedules created by the authenticated subject.",
+ "in": "query",
+ "name": "created_by_me",
+ "required": false,
+ "schema": {
+ "description": "When true, only schedules created by the authenticated subject.",
+ "type": "boolean"
+ }
}
],
"responses": {
@@ -6763,7 +6773,7 @@
},
"/api/v1/sessions": {
"get": {
- "description": "List the caller's sessions (newest first by default), token-paginated. Results are scoped to the authenticated identity via the session store's `created_by_subject.subject_id` filter (not a client query param). Optional `agent_id` filters to sessions bound to that named agent. Pass `page_token` to fetch the next page, keeping the other query params constant.",
+ "description": "List the caller's sessions (newest first by default).",
"parameters": [
{
"description": "Page size. Defaults to 25, max 25.",
@@ -6830,6 +6840,16 @@
"minLength": 1,
"type": "string"
}
+ },
+ {
+ "description": "When true, only sessions created by the authenticated subject.",
+ "in": "query",
+ "name": "created_by_me",
+ "required": false,
+ "schema": {
+ "description": "When true, only sessions created by the authenticated subject.",
+ "type": "boolean"
+ }
}
],
"responses": {
diff --git a/packages/trueforge-sdk/reference.md b/packages/trueforge-sdk/reference.md
index ebbb9baf2..26b25f48b 100644
--- a/packages/trueforge-sdk/reference.md
+++ b/packages/trueforge-sdk/reference.md
@@ -770,7 +770,7 @@ await client.models.list();
<dl>
<dd>
-List schedules for the tenant, newest first. Optionally filter by `agent_names`.
+List schedules for the tenant, newest first.
</dd>
</dl>
</dd>
@@ -1235,7 +1235,7 @@ await client.schedules.listRuns("schedule_id");
<dl>
<dd>
-List the caller's sessions (newest first by default), token-paginated. Results are scoped to the authenticated identity via the session store's `created_by_subject.subject_id` filter (not a client query param). Optional `agent_id` filters to sessions bound to that named agent. Pass `page_token` to fetch the next page, keeping the other query params constant.
+List the caller's sessions (newest first by default).
</dd>
</dl>
</dd>
diff --git a/packages/trueforge-sdk/src/api/resources/schedules/client/Client.ts b/packages/trueforge-sdk/src/api/resources/schedules/client/Client.ts
index 2b9c87680..d14d741bb 100644
--- a/packages/trueforge-sdk/src/api/resources/schedules/client/Client.ts
+++ b/packages/trueforge-sdk/src/api/resources/schedules/client/Client.ts
@@ -24,7 +24,7 @@ export class SchedulesClient {
}
/**
- * List schedules for the tenant, newest first. Optionally filter by `agent_names`.
+ * List schedules for the tenant, newest first.
*
* @param {TrueForge.ListSchedulesRequest} request
* @param {SchedulesClient.RequestOptions} requestOptions - Request-specific configuration.
@@ -45,11 +45,12 @@ export class SchedulesClient {
async (
request: TrueForge.ListSchedulesRequest,
): Promise<core.WithRawResponse<TrueForge.ListSchedulesResponse>> => {
- const { limit = 25, pageToken, agentNames } = request;
+ const { limit = 25, pageToken, agentNames, createdByMe } = request;
const _queryParams: Record<string, unknown> = {
limit,
page_token: pageToken,
agent_names: agentNames,
+ created_by_me: createdByMe,
};
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
diff --git a/packages/trueforge-sdk/src/api/resources/schedules/client/requests/ListSchedulesRequest.ts b/packages/trueforge-sdk/src/api/resources/schedules/client/requests/ListSchedulesRequest.ts
index 4bb5272d3..355eb168b 100644
--- a/packages/trueforge-sdk/src/api/resources/schedules/client/requests/ListSchedulesRequest.ts
+++ b/packages/trueforge-sdk/src/api/resources/schedules/client/requests/ListSchedulesRequest.ts
@@ -11,4 +11,6 @@ export interface ListSchedulesRequest {
pageToken?: string;
/** Filter by one or more agent names (comma-separated). When set, at least one name is required. */
agentNames?: string;
+ /** When true, only schedules created by the authenticated subject. */
+ createdByMe?: boolean;
}
diff --git a/packages/trueforge-sdk/src/api/resources/sessions/client/Client.ts b/packages/trueforge-sdk/src/api/resources/sessions/client/Client.ts
index d4c868844..b5fdd7780 100644
--- a/packages/trueforge-sdk/src/api/resources/sessions/client/Client.ts
+++ b/packages/trueforge-sdk/src/api/resources/sessions/client/Client.ts
@@ -24,7 +24,7 @@ export class SessionsClient {
}
/**
- * List the caller's sessions (newest first by default), token-paginated. Results are scoped to the authenticated identity via the session store's `created_by_subject.subject_id` filter (not a client query param). Optional `agent_id` filters to sessions bound to that named agent. Pass `page_token` to fetch the next page, keeping the other query params constant.
+ * List the caller's sessions (newest first by default).
*
* @param {TrueForge.ListSessionsRequest} request
* @param {SessionsClient.RequestOptions} requestOptions - Request-specific configuration.
@@ -44,7 +44,7 @@ export class SessionsClient {
async (
request: TrueForge.ListSessionsRequest,
): Promise<core.WithRawResponse<TrueForge.ListSessionsResponse>> => {
- const { limit = 25, order, pageToken, startTimestamp, endTimestamp, agentId } = request;
+ const { limit = 25, order, pageToken, startTimestamp, endTimestamp, agentId, createdByMe } = request;
const _queryParams: Record<string, unknown> = {
limit,
order:
@@ -60,6 +60,7 @@ export class SessionsClient {
start_timestamp: startTimestamp != null ? startTimestamp?.toISOString() : undefined,
end_timestamp: endTimestamp != null ? endTimestamp?.toISOString() : undefined,
agent_id: agentId,
+ created_by_me: createdByMe,
};
const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
diff --git a/packages/trueforge-sdk/src/api/resources/sessions/client/requests/ListSessionsRequest.ts b/packages/trueforge-sdk/src/api/resources/sessions/client/requests/ListSessionsRequest.ts
index c760f093e..ce257215a 100644
--- a/packages/trueforge-sdk/src/api/resources/sessions/client/requests/ListSessionsRequest.ts
+++ b/packages/trueforge-sdk/src/api/resources/sessions/client/requests/ListSessionsRequest.ts
@@ -19,4 +19,6 @@ export interface ListSessionsRequest {
endTimestamp?: Date;
/** When set, only sessions bound to this agent id are returned. */
agentId?: string;
+ /** When true, only sessions created by the authenticated subject. */
+ createdByMe?: boolean;
}
diff --git a/packages/trueforge/src/apis/schedules.ts b/packages/trueforge/src/apis/schedules.ts
index b293b8f53..127edc271 100644
--- a/packages/trueforge/src/apis/schedules.ts
+++ b/packages/trueforge/src/apis/schedules.ts
@@ -112,14 +112,16 @@ function isScheduleOwner(requestContext: Pick<RequestContext, 'subject'>, create
export function createSchedulesRouter<TTransaction>(deps: SchedulesRouterDeps<TTransaction>) {
const listHandler: RouteHandler<typeof listSchedulesRoute> = async c => {
- const { agent_names: agentNames, limit, page_token: pageToken } = c.req.valid('query');
+ const { agent_names: agentNames, limit, page_token: pageToken, created_by_me: createdByMe } = c.req.valid('query');
const requestContext = deps.resolveRequestContext(c);
try {
- const managedAgentIds = await resolveManagedAgentIds({
- store: deps.resolveAgentStore(c),
- context: requestContext,
- authorizer: deps.authorizer,
- });
+ const managedAgentIds = createdByMe
+ ? []
+ : await resolveManagedAgentIds({
+ store: deps.resolveAgentStore(c),
+ context: requestContext,
+ authorizer: deps.authorizer,
+ });
const { data, pagination } = await deps.scheduleStore.listSchedules({
tenant_id: requestContext.tenant_id,
limit,
diff --git a/packages/trueforge/src/apis/sessions.ts b/packages/trueforge/src/apis/sessions.ts
index 936d2e515..1fe8a6ebd 100644
--- a/packages/trueforge/src/apis/sessions.ts
+++ b/packages/trueforge/src/apis/sessions.ts
@@ -483,11 +483,13 @@ export function createSessionsRouter(deps: SessionsRouterDeps) {
const query = c.req.valid('query');
const requestContext = deps.resolveRequestContext(c);
try {
- const managedAgentIds = await resolveManagedAgentIds({
- store: deps.resolveAgentStore(c),
- context: requestContext,
- authorizer: deps.authorizer,
- });
+ const managedAgentIds = query.created_by_me
+ ? []
+ : await resolveManagedAgentIds({
+ store: deps.resolveAgentStore(c),
+ context: requestContext,
+ authorizer: deps.authorizer,
+ });
const { data, pagination } = await deps.sessionStore.listSessions({
agent_id: query.agent_id,
created_by_or_agent_ids: {
diff --git a/packages/trueforge/src/routes/scheduleRoutes.ts b/packages/trueforge/src/routes/scheduleRoutes.ts
index 5779d496a..04c45e1db 100644
--- a/packages/trueforge/src/routes/scheduleRoutes.ts
+++ b/packages/trueforge/src/routes/scheduleRoutes.ts
@@ -43,6 +43,11 @@ export const ListSchedulesQuerySchema = z
})
.transform(value => parseCommaSeparatedQuery(value))
.pipe(z.array(NameSchema).min(1).optional()),
+ created_by_me: z
+ .stringbool()
+ .optional()
+ .describe('When true, only schedules created by the authenticated subject.')
+ .openapi({ type: 'boolean' }),
})
.openapi('ListSchedulesQuery');
@@ -51,7 +56,7 @@ export const listSchedulesRoute = createRoute({
path: '/',
tags: [OpenApiTag.SCHEDULES],
summary: 'List schedules',
- description: 'List schedules for the tenant, newest first. Optionally filter by `agent_names`.',
+ description: 'List schedules for the tenant, newest first.',
'x-fern-sdk-group-name': ['schedules'],
'x-fern-sdk-method-name': 'list',
'x-fern-pagination': TOKEN_PAGINATION,
diff --git a/packages/trueforge/src/routes/sessionRoutes.ts b/packages/trueforge/src/routes/sessionRoutes.ts
index 0a7ad7c14..87f3972a3 100644
--- a/packages/trueforge/src/routes/sessionRoutes.ts
+++ b/packages/trueforge/src/routes/sessionRoutes.ts
@@ -202,8 +202,7 @@ export const listSessionsRoute = createRoute({
path: '/',
tags: [OpenApiTag.AGENT_SESSIONS],
summary: 'List sessions',
- description:
- "List the caller's sessions (newest first by default), token-paginated. Results are scoped to the authenticated identity via the session store's `created_by_subject.subject_id` filter (not a client query param). Optional `agent_id` filters to sessions bound to that named agent. Pass `page_token` to fetch the next page, keeping the other query params constant.",
+ description: "List the caller's sessions (newest first by default).",
'x-fern-sdk-group-name': ['sessions'],
'x-fern-sdk-method-name': 'list',
'x-fern-pagination': TOKEN_PAGINATION,
diff --git a/packages/trueforge/src/schemas/session.ts b/packages/trueforge/src/schemas/session.ts
index 2dad089bb..96eac8594 100644
--- a/packages/trueforge/src/schemas/session.ts
+++ b/packages/trueforge/src/schemas/session.ts
@@ -92,6 +92,11 @@ export const ListSessionsRequestQuerySchema = z
'Inclusive upper bound on `created_at` (ISO-8601 / RFC 3339).',
),
agent_id: z.string().min(1).optional().describe('When set, only sessions bound to this agent id are returned.'),
+ created_by_me: z
+ .stringbool()
+ .optional()
+ .describe('When true, only sessions created by the authenticated subject.')
+ .openapi({ type: 'boolean' }),
})
.openapi('ListSessionsRequestQuery');
diff --git a/packages/trueforge/tests/unit/apis/schedules.test.ts b/packages/trueforge/tests/unit/apis/schedules.test.ts
index 4b7f0bec4..f23572038 100644
--- a/packages/trueforge/tests/unit/apis/schedules.test.ts
+++ b/packages/trueforge/tests/unit/apis/schedules.test.ts
@@ -192,10 +192,20 @@ describe('schedule RBAC', () => {
asUser(BOB);
expect((await app.request(`/${id}`)).status).toBe(200);
expect(ListSchedulesResponseSchema.parse(await (await app.request('/')).json()).data).toHaveLength(1);
+ expect(
+ ListSchedulesResponseSchema.parse(await (await app.request('/?created_by_me=true')).json()).data,
+ ).toHaveLength(0);
expect(ListScheduleRunsResponseSchema.parse(await (await app.request(`/${id}/runs`)).json()).data).toHaveLength(1);
expect((await postJson(`/${id}`, 'PUT', { name: 'renamed', manifest: scheduleBody.manifest })).status).toBe(403);
expect((await app.request(`/${id}`, { method: 'DELETE' })).status).toBe(403);
expect((await postJson('/runs', 'POST', { schedule_id: id })).status).toBe(403);
+
+ asUser(ALICE);
+ expect(
+ ListSchedulesResponseSchema.parse(await (await app.request('/?created_by_me=true')).json()).data.map(
+ row => row.id,
+ ),
+ ).toEqual([id]);
});
});
diff --git a/packages/trueforge/tests/unit/apis/sessionHttp.test.ts b/packages/trueforge/tests/unit/apis/sessionHttp.test.ts
index b1a6f0995..135984fa9 100644
--- a/packages/trueforge/tests/unit/apis/sessionHttp.test.ts
+++ b/packages/trueforge/tests/unit/apis/sessionHttp.test.ts
@@ -284,6 +284,21 @@ describe('sessions HTTP agent binding', () => {
expect(ListSessionsResponseSchema.parse(await listed.json()).data.map(session => session.id)).toContain(
'managed-session',
);
+ const listedMine = await managerApp.request('/?created_by_me=true');
+ expect(listedMine.status).toBe(200);
+ expect(ListSessionsResponseSchema.parse(await listedMine.json()).data.map(session => session.id)).not.toContain(
+ 'managed-session',
+ );
+ expect((await managerApp.request('/?created_by_me=maybe')).status).toBe(400);
+
+ const own = await app.request('/', jsonInit('POST', { agent: { spec: inlineSpec } }));
+ expect(own.status).toBe(201);
+ const ownId = ((await own.json()) as { data: { id: string } }).data.id;
+ expect(
+ ListSessionsResponseSchema.parse(await (await app.request('/?created_by_me=true')).json()).data.map(
+ session => session.id,
+ ),
+ ).toContain(ownId);
const query = new URLSearchParams({
agent_id: agent.id,