diff --git a/README.md b/README.md index 1dac7dd5..7eca1ebc 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ curl -X POST -H "Authorization: Bearer $FACTORIZE_ACCESS_TOKEN" \ https://app.factorize.sh/api/v1/runs/RUN_ID/stop ``` -Job CRUD is available at `/jobs` and `/jobs/:id`. Run collections return `{ "items": [...], "nextCursor": "..." }`; pass `nextCursor` back as the `cursor` query parameter. Runs can be filtered by `jobId`, `state`, and `contextQuery`; context queries use case-insensitive literal substring matching and matching items contain a bounded `context_excerpt`, never the full context. `GET /runs/:runId` returns the complete structured trigger `context` and invocation metadata, including the firing `trigger_id`. The canonical Job prompt contract is documented in [docs/job-trigger-context.md](docs/job-trigger-context.md). Errors consistently use `{ "error": { "code": "...", "message": "..." } }`. +Job CRUD is available at `/jobs` and `/jobs/:id`; job metadata includes `currentRuns` and `maxConcurrency`. Run collections return `{ "items": [...], "nextCursor": "..." }`; pass `nextCursor` back as the `cursor` query parameter. Runs can be filtered by `jobId`, `state`, and `contextQuery`; context queries use case-insensitive literal substring matching and matching items contain a bounded `context_excerpt`, never the full context. `GET /runs/:runId` returns the complete structured trigger `context` and invocation metadata, including the firing `trigger_id`. The canonical Job prompt contract is documented in [docs/job-trigger-context.md](docs/job-trigger-context.md). Errors consistently use `{ "error": { "code": "...", "message": "..." } }`. ## MCP clients diff --git a/packages/app/src/protected-api.ts b/packages/app/src/protected-api.ts index 9ea51e7f..0e2fa1b9 100644 --- a/packages/app/src/protected-api.ts +++ b/packages/app/src/protected-api.ts @@ -73,8 +73,8 @@ async function mcp(request: Request, service: ApiService, env: Env, ctx: Executi tool("list_runs", "List authoritative job runs by job ID, state, and an optional case-insensitive literal substring of triggered context. Automatic webhook, schedule, and lifecycle signals coalesce, so query runs and the provider API for authoritative work. Context matches include only a bounded excerpt.", listRunsSchema, (input: any) => service.listRuns(queryOf(input))); tool("get_run", "Get a run with its full triggered context, invocation metadata, execution metadata, output, and activity. For manual invocations, invocation.idempotency_key is the client-reusable value; invocation.claim_key is internal.", runIdSchema, ({ runId }: any) => service.getRun(runId)); tool("stop_run", "Stop an active run", runIdSchema, ({ runId }: any) => service.stopRun(runId)); - tool("list_jobs", "List jobs", z.object({}), () => service.listJobs()); - tool("get_job", "Get a job", jobIdSchema, ({ jobId }: any) => service.getJob(jobId)); + tool("list_jobs", "List jobs with their current run count and maximum concurrency", z.object({}), () => service.listJobs()); + tool("get_job", "Get a job with its current run count and maximum concurrency", jobIdSchema, ({ jobId }: any) => service.getJob(jobId)); tool("create_job", "Create a job using an executionTargetId returned by list_execution_targets. Credentials are never accepted or returned.", jobInputSchema, (input: any) => service.createJob(input)); tool("update_job", "Replace a job configuration. Credentials are never accepted or returned.", jobInputSchema.extend({ jobId: z.string().min(1) }), ({ jobId, ...input }: any) => service.updateJob(jobId, input)); tool("delete_job", "Delete a job and its queued invocation history", jobIdSchema, ({ jobId }: any) => service.deleteJob(jobId)); diff --git a/packages/app/src/tenant.ts b/packages/app/src/tenant.ts index 27e1b60e..f319bdc6 100644 --- a/packages/app/src/tenant.ts +++ b/packages/app/src/tenant.ts @@ -469,6 +469,8 @@ export class TenantV2 extends DurableObject { promptTemplate: await decrypt(String(row.encrypted_prompt_template), this.env.CREDENTIAL_ENCRYPTION_KEY), concurrencyLimit: Number(row.concurrency_limit), runningCount: Number(runSummary?.running_count ?? 0), + maxConcurrency: Number(row.concurrency_limit), + currentRuns: Number(runSummary?.running_count ?? 0), lastRunState: runSummary?.last_run_state ?? null, executionTargetId: `${executionTarget.backendKind === "amp" ? "amp:" : ""}${String(executionTarget.connectionId ?? "")}`, triggers: publicTriggers, diff --git a/packages/app/test/fresh-namespace.e2e.test.ts b/packages/app/test/fresh-namespace.e2e.test.ts index 74cdab69..3fba57a8 100644 --- a/packages/app/test/fresh-namespace.e2e.test.ts +++ b/packages/app/test/fresh-namespace.e2e.test.ts @@ -43,6 +43,8 @@ describe("fresh TenantV2 namespace", () => { promptTemplate: "{{trigger-1.prompt}}", executionTargetId: "amp:execution-1", runningCount: 0, + currentRuns: 0, + maxConcurrency: 1, lastRunState: null, triggers: [{ kind: "manual", slug: "trigger-1" }], });