@terreno/ai 57.11.0 → 57.13.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.
Files changed (69) hide show
  1. package/dist/aiApp.d.ts +5 -0
  2. package/dist/aiApp.js +4 -2
  3. package/dist/harness/commit.d.ts +17 -1
  4. package/dist/harness/commit.js +86 -2
  5. package/dist/harness/routes/approvals.js +2 -2
  6. package/dist/harness/routes/conversations.js +1 -1
  7. package/dist/harness/routes/tasks.js +85 -3
  8. package/dist/harness/runtime.js +7 -1
  9. package/dist/harness/subagent.d.ts +17 -2
  10. package/dist/harness/subagent.js +26 -2
  11. package/dist/index.d.ts +5 -1
  12. package/dist/index.js +11 -2
  13. package/dist/models/project.d.ts +13 -0
  14. package/dist/models/project.js +32 -2
  15. package/dist/observability/local/models/obsTrace.js +16 -2
  16. package/dist/observability/local/traceStore.d.ts +5 -0
  17. package/dist/observability/local/traceStore.js +5 -0
  18. package/dist/observability/routes/traces.js +2 -0
  19. package/dist/routes/gptActions.js +15 -2
  20. package/dist/routes/projects.js +3 -3
  21. package/dist/service/agentBlocks.d.ts +20 -0
  22. package/dist/service/agentBlocks.js +92 -0
  23. package/dist/service/chatTurn.d.ts +3 -1
  24. package/dist/service/chatTurn.js +34 -9
  25. package/dist/service/prompts.d.ts +12 -2
  26. package/dist/service/prompts.js +20 -4
  27. package/dist/service/scaleStepper.d.ts +8 -0
  28. package/dist/service/scaleStepper.js +29 -0
  29. package/dist/service/toggleChecklist.d.ts +9 -0
  30. package/dist/service/toggleChecklist.js +37 -0
  31. package/dist/types/harness.d.ts +28 -2
  32. package/dist/types/index.d.ts +19 -4
  33. package/dist/types/observability.d.ts +3 -0
  34. package/package.json +56 -8
  35. package/src/aiApp.test.ts +15 -0
  36. package/src/aiApp.ts +9 -1
  37. package/src/harness/commit.ts +103 -1
  38. package/src/harness/routes/approvals.ts +2 -2
  39. package/src/harness/routes/conversations.ts +1 -1
  40. package/src/harness/routes/tasks.test.ts +34 -0
  41. package/src/harness/routes/tasks.ts +98 -3
  42. package/src/harness/runtime.ts +8 -1
  43. package/src/harness/subagent.test.ts +124 -3
  44. package/src/harness/subagent.ts +43 -1
  45. package/src/index.test.ts +4 -0
  46. package/src/index.ts +5 -1
  47. package/src/isolated/lazyProjectModel.isolated.ts +25 -0
  48. package/src/models/project.ts +31 -1
  49. package/src/observability/local/models/obsTrace.ts +22 -5
  50. package/src/observability/local/traceStore.test.ts +7 -0
  51. package/src/observability/local/traceStore.ts +12 -0
  52. package/src/observability/routes/traces.test.ts +15 -0
  53. package/src/observability/routes/traces.ts +2 -0
  54. package/src/routes/gpt.test.ts +90 -1
  55. package/src/routes/gptActions.test.ts +282 -1
  56. package/src/routes/gptActions.ts +16 -2
  57. package/src/routes/projects.ts +4 -4
  58. package/src/service/agentBlocks.test.ts +95 -0
  59. package/src/service/agentBlocks.ts +114 -0
  60. package/src/service/chatTurn.ts +44 -15
  61. package/src/service/prompts.test.ts +21 -0
  62. package/src/service/prompts.ts +34 -7
  63. package/src/service/scaleStepper.test.ts +105 -0
  64. package/src/service/scaleStepper.ts +29 -0
  65. package/src/service/toggleChecklist.test.ts +126 -0
  66. package/src/service/toggleChecklist.ts +44 -0
  67. package/src/types/harness.ts +31 -2
  68. package/src/types/index.ts +22 -9
  69. package/src/types/observability.ts +3 -0
@@ -72,10 +72,13 @@ export interface ObsTraceDocument extends mongoose.Document<mongoose.Types.Objec
72
72
  name: string;
73
73
  output?: unknown;
74
74
  prompts: ObsPromptRef[];
75
+ /** App-defined scope (tenant, workspace) set by `harness.createTask({trace: {scope}})`. */
76
+ scope?: string;
75
77
  sensitive: boolean;
76
78
  sessionId?: string;
77
79
  startedAt: Date;
78
80
  status: "error" | "ok";
81
+ tags: string[];
79
82
  updated: Date;
80
83
  usage?: ObsPromptUsage;
81
84
  userId?: mongoose.Types.ObjectId;
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "@langfuse/otel": "^5.0.1",
11
11
  "@opentelemetry/api": "^1.9.0",
12
12
  "@opentelemetry/sdk-node": "0.217.0",
13
- "@terreno/blocks": "57.11.0",
13
+ "@terreno/blocks": "57.13.0",
14
14
  "ai": "^6.0.97",
15
15
  "ajv": "8.20.0",
16
16
  "csv-parse": "^6.1.0",
@@ -22,10 +22,10 @@
22
22
  "description": "Provider-agnostic AI service with streaming chat, request logging, and admin tools — part of Terreno, the batteries-included TypeScript framework for universal apps.",
23
23
  "devDependencies": {
24
24
  "@biomejs/biome": "^2.3.6",
25
- "@terreno/admin-backend": "57.11.0",
26
- "@terreno/api": "57.11.0",
27
- "@terreno/jobs": "57.11.0",
28
- "@terreno/test": "57.11.0",
25
+ "@terreno/admin-backend": "57.13.0",
26
+ "@terreno/api": "57.13.0",
27
+ "@terreno/jobs": "57.13.0",
28
+ "@terreno/test": "57.13.0",
29
29
  "@types/bun": "^1.4.0",
30
30
  "@types/express": "^5.0.6",
31
31
  "@types/luxon": "^3.7.1",
@@ -45,12 +45,42 @@
45
45
  "require": "./dist/index.js",
46
46
  "types": "./dist/index.d.ts"
47
47
  },
48
+ "./admin": {
49
+ "default": "./dist/aiAdminApp.js",
50
+ "import": "./dist/aiAdminApp.js",
51
+ "require": "./dist/aiAdminApp.js",
52
+ "types": "./dist/aiAdminApp.d.ts"
53
+ },
48
54
  "./harness": {
49
55
  "default": "./dist/harness/harness.js",
50
56
  "import": "./dist/harness/harness.js",
51
57
  "require": "./dist/harness/harness.js",
52
58
  "types": "./dist/harness/harness.d.ts"
53
59
  },
60
+ "./harness/agentLoop": {
61
+ "default": "./dist/harness/agentLoop.js",
62
+ "import": "./dist/harness/agentLoop.js",
63
+ "require": "./dist/harness/agentLoop.js",
64
+ "types": "./dist/harness/agentLoop.d.ts"
65
+ },
66
+ "./harness/commit": {
67
+ "default": "./dist/harness/commit.js",
68
+ "import": "./dist/harness/commit.js",
69
+ "require": "./dist/harness/commit.js",
70
+ "types": "./dist/harness/commit.d.ts"
71
+ },
72
+ "./harness/events": {
73
+ "default": "./dist/harness/events.js",
74
+ "import": "./dist/harness/events.js",
75
+ "require": "./dist/harness/events.js",
76
+ "types": "./dist/harness/events.d.ts"
77
+ },
78
+ "./harness/internalRuntime": {
79
+ "default": "./dist/harness/internalRuntime.js",
80
+ "import": "./dist/harness/internalRuntime.js",
81
+ "require": "./dist/harness/internalRuntime.js",
82
+ "types": "./dist/harness/internalRuntime.d.ts"
83
+ },
54
84
  "./harness/jobsRunner": {
55
85
  "default": "./dist/harness/runners/jobsRunner.js",
56
86
  "import": "./dist/harness/runners/jobsRunner.js",
@@ -69,6 +99,24 @@
69
99
  "require": "./dist/langfuseClient.js",
70
100
  "types": "./dist/langfuseClient.d.ts"
71
101
  },
102
+ "./observability/localPlugin": {
103
+ "default": "./dist/observability/local/localPlugin.js",
104
+ "import": "./dist/observability/local/localPlugin.js",
105
+ "require": "./dist/observability/local/localPlugin.js",
106
+ "types": "./dist/observability/local/localPlugin.d.ts"
107
+ },
108
+ "./observability/observabilityApp": {
109
+ "default": "./dist/observability/observabilityApp.js",
110
+ "import": "./dist/observability/observabilityApp.js",
111
+ "require": "./dist/observability/observabilityApp.js",
112
+ "types": "./dist/observability/observabilityApp.d.ts"
113
+ },
114
+ "./observability/promptStore": {
115
+ "default": "./dist/observability/local/promptStore.js",
116
+ "import": "./dist/observability/local/promptStore.js",
117
+ "require": "./dist/observability/local/promptStore.js",
118
+ "types": "./dist/observability/local/promptStore.d.ts"
119
+ },
72
120
  "./parseAiJson": {
73
121
  "default": "./dist/service/parseAiJson.js",
74
122
  "import": "./dist/service/parseAiJson.js",
@@ -88,8 +136,8 @@
88
136
  "name": "@terreno/ai",
89
137
  "peerDependencies": {
90
138
  "@ai-sdk/google-vertex": "^4.0.142",
91
- "@terreno/api": "57.11.0",
92
- "@terreno/jobs": "57.11.0",
139
+ "@terreno/api": "57.13.0",
140
+ "@terreno/jobs": "57.13.0",
93
141
  "mongoose": "^8.0.0 || ^9.0.0"
94
142
  },
95
143
  "peerDependenciesMeta": {
@@ -120,5 +168,5 @@
120
168
  "test:coverage": "bun run ../scripts/check-coverage.ts"
121
169
  },
122
170
  "types": "dist/index.d.ts",
123
- "version": "57.11.0"
171
+ "version": "57.13.0"
124
172
  }
package/src/aiApp.test.ts CHANGED
@@ -79,6 +79,21 @@ describe("AiApp", () => {
79
79
  expect(projects.status).toBe(200);
80
80
  });
81
81
 
82
+ it("skips the project routes with projects: false", async () => {
83
+ const {AIService} = await import("./service/aiService");
84
+ const aiService = new AIService({model: createMockModel() as unknown as LanguageModel});
85
+ const plugin = new AiApp({aiService, projects: false});
86
+ const app = new TerrenoApp({
87
+ configureApp: (router) => plugin.register(router as unknown as express.Application),
88
+ skipListen: true,
89
+ userModel: UserModel,
90
+ }).build();
91
+
92
+ const agent = await authAsUser(app);
93
+ expect((await agent.get("/gpt/histories")).status).toBe(200);
94
+ expect((await agent.get("/gpt/projects")).status).toBe(404);
95
+ });
96
+
82
97
  it("passes asks to the gpt routes, so the model is offered the ask tools", async () => {
83
98
  const {AIService} = await import("./service/aiService");
84
99
  const model = createMockModel();
package/src/aiApp.ts CHANGED
@@ -42,6 +42,11 @@ export interface AiAppOptions {
42
42
  mcpService?: MCPService;
43
43
  /** OpenAPI options passed through to route builders for spec generation. */
44
44
  openApiOptions?: Record<string, unknown>;
45
+ /**
46
+ * Mount the `/gpt/projects` routes, which register the `Project` model. Defaults to `true`;
47
+ * pass `false` when the app owns a model named `Project`.
48
+ */
49
+ projects?: boolean;
45
50
  /** Tool choice strategy for chat requests. Defaults to "auto" when tools are present. */
46
51
  toolChoice?: "auto" | "none" | "required";
47
52
  /** Cheap model ID used for generating conversation titles (e.g. "gemini-3.5-flash-lite"). Falls back to the main model if not set. */
@@ -97,6 +102,7 @@ export class AiApp implements TerrenoPlugin {
97
102
  maxSteps,
98
103
  mcpService,
99
104
  openApiOptions,
105
+ projects,
100
106
  titleModelId,
101
107
  toolChoice,
102
108
  tools,
@@ -122,7 +128,9 @@ export class AiApp implements TerrenoPlugin {
122
128
  addGptHistoryRoutes(router, {chat, openApiOptions});
123
129
  addGptRoutes(router, chat);
124
130
  addAiRequestsExplorerRoutes(router, {openApiOptions});
125
- addProjectRoutes(router, {openApiOptions});
131
+ if (projects !== false) {
132
+ addProjectRoutes(router, {openApiOptions});
133
+ }
126
134
 
127
135
  if (fileStorageService && gcsBucket) {
128
136
  addFileRoutes(router, {
@@ -17,6 +17,7 @@ import type {
17
17
  HarnessMessageModel,
18
18
  HarnessOwnerModel,
19
19
  HarnessOwnership,
20
+ HarnessPromptRef,
20
21
  HarnessReplayPolicy,
21
22
  HarnessResolveInterruptedOptions,
22
23
  HarnessTaskDefinition,
@@ -150,6 +151,94 @@ const findByRequestId = async ({
150
151
  return existing;
151
152
  };
152
153
 
154
+ /**
155
+ * Prompt refs as stored on `ObsTrace.prompts` (`{label?, name, version}`; a registry
156
+ * `body` is dropped), once each. Throws `invalidRequest` for a ref without a name, with a
157
+ * non-string label, or without a positive integer version.
158
+ */
159
+ export const tracePromptRefs = (refs: HarnessPromptRef[] | undefined): HarnessPromptRef[] => {
160
+ if (refs === undefined) {
161
+ return [];
162
+ }
163
+ if (!Array.isArray(refs)) {
164
+ throw harnessError({detail: "prompts must be an array", kind: "invalidRequest"});
165
+ }
166
+ const unique = new Map<string, HarnessPromptRef>();
167
+ for (const ref of refs) {
168
+ if (typeof ref?.name !== "string" || !ref.name.trim()) {
169
+ throw harnessError({detail: "Each prompt ref needs a name", kind: "invalidRequest"});
170
+ }
171
+ if (!Number.isInteger(ref.version) || ref.version < 1) {
172
+ throw harnessError({
173
+ detail: `Prompt ref "${ref.name}" needs a positive integer version`,
174
+ kind: "invalidRequest",
175
+ });
176
+ }
177
+ if (ref.label !== undefined && typeof ref.label !== "string") {
178
+ throw harnessError({
179
+ detail: `Prompt ref "${ref.name}" label must be a string`,
180
+ kind: "invalidRequest",
181
+ });
182
+ }
183
+ const normalized = {
184
+ ...(ref.label !== undefined ? {label: ref.label} : {}),
185
+ name: ref.name,
186
+ version: ref.version,
187
+ };
188
+ unique.set(JSON.stringify(normalized), normalized);
189
+ }
190
+ return [...unique.values()];
191
+ };
192
+
193
+ /** The `scope` and `tags` written onto a root task's `ObsTrace`. */
194
+ const traceFields = (
195
+ trace: HarnessCreateTaskOptions["trace"]
196
+ ): {scope?: string; tags?: string[]} => {
197
+ if (trace === undefined) {
198
+ return {};
199
+ }
200
+ const {scope, tags} = trace;
201
+ if (scope !== undefined && (typeof scope !== "string" || !scope.trim())) {
202
+ throw harnessError({detail: "trace.scope must be a non-empty string", kind: "invalidRequest"});
203
+ }
204
+ const isBlankTag = (tag: unknown): boolean => typeof tag !== "string" || !tag.trim();
205
+ if (tags !== undefined && (!Array.isArray(tags) || tags.some(isBlankTag))) {
206
+ throw harnessError({
207
+ detail: "trace.tags must be an array of non-empty strings",
208
+ kind: "invalidRequest",
209
+ });
210
+ }
211
+ return {
212
+ ...(scope !== undefined ? {scope} : {}),
213
+ ...(tags !== undefined ? {tags: [...new Set(tags)]} : {}),
214
+ };
215
+ };
216
+
217
+ /**
218
+ * Record `refs` on `traceId`'s `ObsTrace.prompts`, once each. Pass `session` to write
219
+ * inside a commit's transaction.
220
+ */
221
+ export const addTracePrompts = async ({
222
+ models,
223
+ refs,
224
+ session,
225
+ traceId,
226
+ }: {
227
+ models: HarnessModels;
228
+ refs: HarnessPromptRef[];
229
+ session?: ClientSession;
230
+ traceId: mongoose.Types.ObjectId;
231
+ }): Promise<void> => {
232
+ if (refs.length === 0) {
233
+ return;
234
+ }
235
+ await models.trace.updateOne(
236
+ {_id: traceId},
237
+ {$addToSet: {prompts: {$each: refs}}},
238
+ session ? {session} : {}
239
+ );
240
+ };
241
+
153
242
  /**
154
243
  * Insert a root task with its `ObsTrace` and root `CHAIN` span in one transaction.
155
244
  * A repeated `requestId` hits the unique index, rolls the whole transaction back (so no
@@ -185,11 +274,24 @@ export const createTaskRecords = async ({
185
274
  const startedAt = traceStartedAt.toJSDate();
186
275
  const userId = toObjectId(options.userId);
187
276
  const spanIdentity = taskSpanIdentity(definition, input);
277
+ const prompts = tracePromptRefs(options.prompts);
278
+ const traceExtras = traceFields(options.trace);
188
279
 
189
280
  try {
190
281
  return await inTransaction(async (session) => {
191
282
  await models.trace.create(
192
- [{_id: traceId, input, name: definition.key, startedAt, status: "ok", userId}],
283
+ [
284
+ {
285
+ _id: traceId,
286
+ input,
287
+ name: definition.key,
288
+ prompts,
289
+ startedAt,
290
+ status: "ok",
291
+ userId,
292
+ ...traceExtras,
293
+ },
294
+ ],
193
295
  {session}
194
296
  );
195
297
  await models.span.create(
@@ -73,7 +73,7 @@ export const addHarnessApprovalRoutes = (
73
73
  method: "POST",
74
74
  permissions: [Permissions.IsAuthenticated, canApprove as PermissionMethod<unknown>],
75
75
  summary: "Approve a harness approval",
76
- tag: "harness",
76
+ tag: "harnessapprovals",
77
77
  },
78
78
  reject: {
79
79
  body: rejectBody,
@@ -82,7 +82,7 @@ export const addHarnessApprovalRoutes = (
82
82
  method: "POST",
83
83
  permissions: [Permissions.IsAuthenticated, canApprove as PermissionMethod<unknown>],
84
84
  summary: "Reject a harness approval",
85
- tag: "harness",
85
+ tag: "harnessapprovals",
86
86
  },
87
87
  },
88
88
  permissions: {
@@ -84,7 +84,7 @@ export const addHarnessConversationRoutes = (
84
84
  method: "POST",
85
85
  permissions: [Permissions.IsAuthenticated, ownerOnly as PermissionMethod<unknown>],
86
86
  summary: "Submit a message to a harness conversation",
87
- tag: "harness",
87
+ tag: "harnessconversations",
88
88
  },
89
89
  },
90
90
  permissions: {
@@ -102,6 +102,40 @@ describe("Harness task routes", () => {
102
102
  await owner.patch(`/harness/tasks/${task._id}`).send({name: "x"}).expect(405);
103
103
  });
104
104
 
105
+ it("omits the lease from the task read and tags mutations with the task collection", async () => {
106
+ const {app, harness, login, ownerId} = await setup();
107
+ const task = await harness.createTask(parked, {}, {userId: ownerId});
108
+ await TaskModel.updateOne(
109
+ {_id: task._id},
110
+ {
111
+ $set: {
112
+ lease: {
113
+ owner: "runner-1",
114
+ token: "fence-secret",
115
+ },
116
+ },
117
+ }
118
+ );
119
+ const owner = await login(OWNER);
120
+ const read = await owner.get(`/harness/tasks/${task._id}`).expect(200);
121
+ expect(read.body.data.lease).toBeUndefined();
122
+ expect(read.body.data.name).toBe("test.parked");
123
+ expect((await TaskModel.findExactlyOne({_id: task._id})).lease?.token).toBe("fence-secret");
124
+
125
+ const spec = await supertest(app).get("/openapi.json").expect(200);
126
+ const taskRead = spec.body.paths["/harness/tasks/{id}"].get;
127
+ const taskSchema = taskRead.responses["200"].content["application/json"].schema;
128
+ expect(taskSchema.properties.lease).toBeUndefined();
129
+ expect(taskRead.tags).toEqual(["harnesstasks"]);
130
+ expect(spec.body.paths["/harness/tasks/{id}/abort"].post.tags).toEqual(["harnesstasks"]);
131
+ expect(spec.body.paths["/harness/approvals/{id}/approve"].post.tags).toEqual([
132
+ "harnessapprovals",
133
+ ]);
134
+ expect(spec.body.paths["/harness/conversations/{id}/submit"].post.tags).toEqual([
135
+ "harnessconversations",
136
+ ]);
137
+ });
138
+
105
139
  it("abort: the owner or an admin aborts with a reason; others get 403; ended tasks 409", async () => {
106
140
  const {harness, login, ownerId} = await setup({start: true});
107
141
  const first = await harness.createTask(parked, {}, {userId: ownerId});
@@ -8,6 +8,9 @@ import {
8
8
  } from "@terreno/api";
9
9
  import type express from "express";
10
10
 
11
+ /** OpenAPI tag shared with the task read query, so mutations refresh that cache. */
12
+ const TASK_OPENAPI_TAG = "harnesstasks";
13
+
11
14
  import type {HarnessTaskDocument} from "../../types/harness";
12
15
  import {
13
16
  HARNESS_RESOLVE_ACTIONS,
@@ -48,6 +51,91 @@ const adminOnly: PermissionMethod<HarnessTaskDocument> = (_method, user, task) =
48
51
 
49
52
  const isCommitConflict = (error: unknown): boolean => error instanceof HarnessCommitConflictError;
50
53
 
54
+ const withoutLease = (value: unknown): Record<string, unknown> => {
55
+ const doc = value as {toObject?: () => Record<string, unknown>};
56
+ const json =
57
+ typeof doc.toObject === "function" ? doc.toObject() : {...(value as Record<string, unknown>)};
58
+ const {lease: _lease, ...rest} = json;
59
+ return rest;
60
+ };
61
+
62
+ /** HTTP task reads omit the lease. The fencing token is a runner secret, not a client field. */
63
+ const taskResponseHandler: NonNullable<
64
+ ModelRouterOptions<HarnessTaskDocument>["responseHandler"]
65
+ > = async (value) => {
66
+ if (Array.isArray(value)) {
67
+ return value.map((doc) => withoutLease(doc)) as never;
68
+ }
69
+ return withoutLease(value) as never;
70
+ };
71
+
72
+ const stripLeaseFromOpenApiSpec = (spec: unknown): unknown => {
73
+ if (!spec || typeof spec !== "object" || !("responses" in spec)) {
74
+ return spec;
75
+ }
76
+ const responses = (spec as {responses?: unknown}).responses;
77
+ if (!responses || typeof responses !== "object") {
78
+ return spec;
79
+ }
80
+ const nextResponses: Record<string, unknown> = {};
81
+ for (const [status, response] of Object.entries(responses as Record<string, unknown>)) {
82
+ const content =
83
+ response && typeof response === "object"
84
+ ? (response as {content?: Record<string, unknown>}).content
85
+ : undefined;
86
+ const json = content?.["application/json"] as {schema?: Record<string, unknown>} | undefined;
87
+ const properties = json?.schema?.properties as Record<string, unknown> | undefined;
88
+ if (!properties || !("lease" in properties)) {
89
+ nextResponses[status] = response;
90
+ continue;
91
+ }
92
+ const {lease: _lease, ...rest} = properties;
93
+ const required = json?.schema?.required;
94
+ nextResponses[status] = {
95
+ ...(response as Record<string, unknown>),
96
+ content: {
97
+ ...content,
98
+ "application/json": {
99
+ ...json,
100
+ schema: {
101
+ ...json?.schema,
102
+ properties: rest,
103
+ ...(Array.isArray(required)
104
+ ? {required: required.filter((field) => field !== "lease")}
105
+ : {}),
106
+ },
107
+ },
108
+ },
109
+ };
110
+ }
111
+ return {...(spec as Record<string, unknown>), responses: nextResponses};
112
+ };
113
+
114
+ /** Task OpenAPI schemas must not publish `lease`, including its fencing token. */
115
+ const openApiWithoutTaskLease = (openApi: unknown): unknown => {
116
+ // The registrar is a middleware function with a `path` property, not a plain object.
117
+ if (
118
+ !openApi ||
119
+ (typeof openApi !== "object" && typeof openApi !== "function") ||
120
+ !("path" in openApi)
121
+ ) {
122
+ return openApi;
123
+ }
124
+ const registrar = openApi as {path: (spec: unknown) => unknown};
125
+ return new Proxy(registrar, {
126
+ get(target, prop, receiver) {
127
+ if (prop === "path") {
128
+ return (spec: unknown): unknown => target.path(stripLeaseFromOpenApiSpec(spec));
129
+ }
130
+ const value = Reflect.get(target, prop, receiver);
131
+ if (typeof value === "function") {
132
+ return value.bind(target);
133
+ }
134
+ return value;
135
+ },
136
+ });
137
+ };
138
+
51
139
  /**
52
140
  * Mount `{basePath}/tasks`: read (owner or admin), plus the `abort` (owner or admin) and
53
141
  * `resolveInterrupted` (admin) instance actions. Tasks are not listed or edited over HTTP.
@@ -111,7 +199,13 @@ export const addHarnessTaskRoutes = (
111
199
  router.use(
112
200
  `${basePath}/tasks`,
113
201
  modelRouter(model, {
114
- ...(openApi ? {openApi: openApi as ModelRouterOptions<HarnessTaskDocument>["openApi"]} : {}),
202
+ ...(openApi
203
+ ? {
204
+ openApi: openApiWithoutTaskLease(
205
+ openApi
206
+ ) as ModelRouterOptions<HarnessTaskDocument>["openApi"],
207
+ }
208
+ : {}),
115
209
  instanceActions: {
116
210
  abort: {
117
211
  body: abortBody,
@@ -121,7 +215,7 @@ export const addHarnessTaskRoutes = (
121
215
  method: "POST",
122
216
  permissions: [Permissions.IsAuthenticated, ownerOrAdmin as PermissionMethod<unknown>],
123
217
  summary: "Abort a harness task",
124
- tag: "harness",
218
+ tag: TASK_OPENAPI_TAG,
125
219
  },
126
220
  resolveInterrupted: {
127
221
  body: resolveBody,
@@ -131,7 +225,7 @@ export const addHarnessTaskRoutes = (
131
225
  method: "POST",
132
226
  permissions: [Permissions.IsAuthenticated, adminOnly as PermissionMethod<unknown>],
133
227
  summary: "Resolve an interrupted harness task",
134
- tag: "harness",
228
+ tag: TASK_OPENAPI_TAG,
135
229
  },
136
230
  },
137
231
  permissions: {
@@ -141,6 +235,7 @@ export const addHarnessTaskRoutes = (
141
235
  read: [Permissions.IsAuthenticated, ownerOrAdmin],
142
236
  update: [],
143
237
  },
238
+ responseHandler: taskResponseHandler,
144
239
  })
145
240
  );
146
241
  };
@@ -63,6 +63,7 @@ import {
63
63
  serializeOutputSchema,
64
64
  startSubagentTurn,
65
65
  subagentContent,
66
+ subagentPrompts,
66
67
  subagentResult,
67
68
  } from "./subagent";
68
69
  import {HarnessSuspendSignal} from "./suspend";
@@ -632,16 +633,22 @@ const runPhase = async ({
632
633
  );
633
634
  }
634
635
  }
636
+ const {instructions, prompts} = subagentPrompts({
637
+ instructions: options.instructions,
638
+ prompts: options.prompts,
639
+ where: `${definition.key}: rt.runAgent`,
640
+ });
635
641
  const {conversationId, turnTask} = await startSubagentTurn({
636
642
  agent,
637
643
  callIndex,
638
644
  content,
639
645
  extensions: engine.extensions,
640
- instructions: options.instructions,
646
+ instructions,
641
647
  lease,
642
648
  models,
643
649
  outputSchema,
644
650
  parent: task,
651
+ prompts,
645
652
  turn,
646
653
  });
647
654
  engine.wake();