@terreno/ai 57.20.0 → 58.0.0-beta.1

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 (97) hide show
  1. package/AGENTS.md +20 -18
  2. package/CHANGELOG.md +93 -0
  3. package/biome.jsonc +3 -2
  4. package/dist/aiApp.d.ts +5 -2
  5. package/dist/aiApp.js +3 -2
  6. package/dist/harness/agentLoop.js +1 -0
  7. package/dist/index.d.ts +2 -1
  8. package/dist/index.js +6 -2
  9. package/dist/migrations/gptHistoryStringIds.d.ts +41 -0
  10. package/dist/migrations/gptHistoryStringIds.js +94 -0
  11. package/dist/models/aiDataset.js +2 -2
  12. package/dist/models/gptHistory.js +11 -0
  13. package/dist/observability/local/experimentRunner.d.ts +2 -5
  14. package/dist/routes/files.d.ts +7 -1
  15. package/dist/routes/files.js +62 -13
  16. package/dist/routes/gptActions.js +0 -7
  17. package/dist/routes/gptHistories.js +8 -2
  18. package/dist/service/aiDatasets.js +2 -1
  19. package/dist/service/chatTurn.js +4 -0
  20. package/dist/service/vertex.d.ts +5 -2
  21. package/dist/types/harness.d.ts +5 -2
  22. package/dist/types/index.d.ts +5 -2
  23. package/e2e/smoke.ts +227 -0
  24. package/package.json +19 -16
  25. package/src/aiApp.test.ts +43 -18
  26. package/src/aiApp.ts +6 -3
  27. package/src/harness/agentLoop.test.ts +1 -1
  28. package/src/harness/agentLoop.ts +2 -1
  29. package/src/harness/agentRecovery.test.ts +31 -28
  30. package/src/harness/approvals.test.ts +11 -9
  31. package/src/harness/events.test.ts +10 -6
  32. package/src/harness/extensions.test.ts +7 -6
  33. package/src/harness/ownership.test.ts +20 -9
  34. package/src/harness/retries.test.ts +6 -3
  35. package/src/harness/routes/conversations.test.ts +2 -2
  36. package/src/harness/routes/tasks.test.ts +2 -2
  37. package/src/harness/runners/jobsRunner.test.ts +1 -1
  38. package/src/harness/subagent.test.ts +3 -2
  39. package/src/harness/waits.test.ts +6 -4
  40. package/src/index.test.ts +3 -3
  41. package/src/index.ts +7 -1
  42. package/src/isolated/gptStream.isolated.ts +35 -30
  43. package/src/isolated/langfuseClient.isolated.ts +9 -3
  44. package/src/isolated/lazyProjectModel.isolated.ts +2 -2
  45. package/src/langfuseApp.test.ts +4 -20
  46. package/src/langfuseRoutes.test.ts +20 -15
  47. package/src/langfuseTracing.test.ts +6 -2
  48. package/src/langfuseVercelAi.test.ts +12 -9
  49. package/src/migrations/gptHistoryStringIds.test.ts +231 -0
  50. package/src/migrations/gptHistoryStringIds.ts +150 -0
  51. package/src/models/aiDataset.test.ts +1 -1
  52. package/src/models/aiDataset.ts +2 -2
  53. package/src/models/gptHistory.test.ts +22 -11
  54. package/src/models/gptHistory.ts +19 -1
  55. package/src/observability/evaluate.test.ts +12 -10
  56. package/src/observability/local/experimentRunner.test.ts +9 -12
  57. package/src/observability/local/experimentRunner.ts +2 -2
  58. package/src/observability/local/promptStore.test.ts +4 -3
  59. package/src/observability/routes/datasets.test.ts +2 -2
  60. package/src/observability/routes/evaluators.test.ts +2 -2
  61. package/src/observability/routes/experiments.test.ts +2 -2
  62. package/src/observability/routes/prompts.test.ts +3 -3
  63. package/src/observability/routes/review.test.ts +2 -2
  64. package/src/observability/routes/status.test.ts +4 -4
  65. package/src/observability/routes/testMultiStage.test.ts +6 -6
  66. package/src/observability/routes/traces.test.ts +2 -2
  67. package/src/routes/files.test.ts +126 -3
  68. package/src/routes/files.ts +90 -15
  69. package/src/routes/gpt.test.ts +23 -16
  70. package/src/routes/gptActions.test.ts +15 -15
  71. package/src/routes/gptActions.ts +1 -4
  72. package/src/routes/gptApprovals.test.ts +1 -1
  73. package/src/routes/gptDatasets.test.ts +1 -1
  74. package/src/routes/gptFiles.test.ts +2 -2
  75. package/src/routes/gptHistories.test.ts +17 -11
  76. package/src/routes/gptHistories.ts +59 -55
  77. package/src/routes/gptHistoriesSync.test.ts +141 -0
  78. package/src/routes/mcp.test.ts +3 -3
  79. package/src/routes/projects.test.ts +5 -3
  80. package/src/routes/routes.test.ts +64 -47
  81. package/src/service/aiDatasets.ts +2 -1
  82. package/src/service/aiService.test.ts +1 -1
  83. package/src/service/asks.test.ts +14 -6
  84. package/src/service/chatTurn.ts +4 -0
  85. package/src/service/fileStorage.test.ts +5 -2
  86. package/src/service/getMCPTools.test.ts +9 -5
  87. package/src/service/mcpService.test.ts +6 -3
  88. package/src/service/vertex.test.ts +1 -1
  89. package/src/service/vertex.ts +7 -4
  90. package/src/tests/bunSetup.ts +1 -1
  91. package/src/tests/chatHarness.ts +4 -4
  92. package/src/tests/fakeJudge.ts +8 -0
  93. package/src/tests/fakeLangfusePrompt.ts +10 -0
  94. package/src/tests/helpers.ts +26 -4
  95. package/src/types/harness.ts +6 -2
  96. package/src/types/index.ts +5 -2
  97. package/tsconfig.typecheck.json +18 -0
@@ -0,0 +1,8 @@
1
+ /**
2
+ * A stub for `AIService.generateJsonObject` that answers every call with `answer()`, whatever
3
+ * schema the caller asks for. The real method is generic over the parsed object's type.
4
+ */
5
+ export const judgeAnswering =
6
+ (answer: () => Record<string, unknown>) =>
7
+ async <OBJECT>(): Promise<OBJECT> =>
8
+ answer() as OBJECT;
@@ -0,0 +1,10 @@
1
+ /** The fields of a Langfuse prompt that tests stub `client.prompt.get` with. */
2
+ export interface FakeLangfusePrompt {
3
+ config: Record<string, unknown>;
4
+ labels: string[];
5
+ name: string;
6
+ prompt: string | Array<{content: string; role: string}>;
7
+ tags: string[];
8
+ type: "chat" | "text";
9
+ version: number;
10
+ }
@@ -1,10 +1,16 @@
1
- import {createdUpdatedPlugin} from "@terreno/api";
1
+ import {
2
+ type UserModel as ApiUserModel,
3
+ createdUpdatedPlugin,
4
+ type ModelRouterOptions,
5
+ } from "@terreno/api";
2
6
  import {authAsUser as authAsUserWithCredentials} from "@terreno/test";
3
7
  import type express from "express";
4
- import mongoose, {type Model} from "mongoose";
8
+ import mongoose, {type HydratedDocument, type Model} from "mongoose";
5
9
  import passportLocalMongoose from "passport-local-mongoose";
6
10
  import type TestAgent from "supertest/lib/agent";
7
11
 
12
+ import type {GptHistoryDocument} from "../types/index";
13
+
8
14
  type PasswordedUser = {setPassword: (password: string) => Promise<void>};
9
15
 
10
16
  export interface AiTestUser {
@@ -43,6 +49,22 @@ const createTestUserModel = (): Model<AiTestUserDoc> => {
43
49
 
44
50
  export const UserModel = createTestUserModel();
45
51
 
52
+ /**
53
+ * `UserModel` as `TerrenoApp({userModel})` expects it. The passport-local-mongoose plugin adds
54
+ * the auth statics at runtime, and `@terreno/api`'s `User._id` uses mongoose's schema `ObjectId`
55
+ * type, which a hydrated document's `Types.ObjectId` does not satisfy.
56
+ */
57
+ export const terrenoUserModel = UserModel as unknown as ApiUserModel;
58
+
59
+ /**
60
+ * `TerrenoApp`'s `configureApp` options, typed as the GptHistory model router options tests
61
+ * spread them into. `configureApp` types them for no particular model.
62
+ */
63
+ export const historyRouterOptions = (
64
+ options: Partial<ModelRouterOptions<unknown>> | undefined
65
+ ): Partial<ModelRouterOptions<GptHistoryDocument>> =>
66
+ options as Partial<ModelRouterOptions<GptHistoryDocument>>;
67
+
46
68
  const STANDARD_AI_TEST_USERS = {
47
69
  admin: {admin: true, email: "admin@example.com", name: "Admin", password: "securePassword"},
48
70
  notAdmin: {admin: false, email: "notAdmin@example.com", name: "User", password: "password"},
@@ -52,10 +74,10 @@ export type StandardAiTestUserRole = keyof typeof STANDARD_AI_TEST_USERS;
52
74
 
53
75
  export const ensureTestUsers = async (
54
76
  users: AiTestUser[] = [STANDARD_AI_TEST_USERS.admin, STANDARD_AI_TEST_USERS.notAdmin]
55
- ): Promise<AiTestUserDoc[]> => {
77
+ ): Promise<HydratedDocument<AiTestUserDoc>[]> => {
56
78
  await UserModel.deleteMany({email: {$in: users.map((user) => user.email)}});
57
79
 
58
- const createdUsers: AiTestUserDoc[] = [];
80
+ const createdUsers: HydratedDocument<AiTestUserDoc>[] = [];
59
81
  for (const user of users) {
60
82
  const doc = await UserModel.create({
61
83
  admin: user.admin ?? false,
@@ -625,9 +625,13 @@ export interface HarnessToolDefinition<Args = unknown, Result = unknown>
625
625
 
626
626
  /**
627
627
  * Any tool, whatever its argument and result types. `execute` arguments are contravariant, so
628
- * `never` accepts every tool in heterogeneous lists without an explicit `any`.
628
+ * `never` accepts every tool in heterogeneous lists without an explicit `any`. A Zod schema's
629
+ * output is covariant, so `parameters` widens to `unknown` instead.
629
630
  */
630
- export type AnyHarnessToolDefinition = HarnessToolDefinition<never, unknown>;
631
+ export interface AnyHarnessToolDefinition
632
+ extends Omit<HarnessToolDefinition<never, unknown>, "parameters"> {
633
+ parameters: z.ZodType<unknown>;
634
+ }
631
635
 
632
636
  export interface HarnessAgentDefinitionInput {
633
637
  /** Tried in order once the primary model's retryable failures exhaust `modelRetry`. */
@@ -154,7 +154,9 @@ interface GptHistoryPendingAskState {
154
154
  /** The ask a history is waiting on. At most one per history. */
155
155
  export type GptHistoryPendingAsk = Ask & GptHistoryPendingAskState;
156
156
 
157
- export interface GptHistoryDocument extends mongoose.Document<mongoose.Types.ObjectId> {
157
+ /** Synced through @terreno/syncdb, so `_id` is a String (UUID for new rows, ObjectId hex for migrated rows). */
158
+ export interface GptHistoryDocument extends mongoose.Document<string> {
159
+ _id: string;
158
160
  created: Date;
159
161
  deleted: boolean;
160
162
  pendingAsk?: GptHistoryPendingAsk;
@@ -515,7 +517,8 @@ export interface AIDatasetDocument extends mongoose.Document<mongoose.Types.Obje
515
517
  created: Date;
516
518
  deleted: boolean;
517
519
  expiresAt?: Date;
518
- historyId: mongoose.Types.ObjectId;
520
+ /** The GptHistory String `_id`. */
521
+ historyId: string;
519
522
  rowCount: number;
520
523
  rows: AIDatasetCell[][];
521
524
  updated: Date;
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": true,
5
+ "composite": false,
6
+ "incremental": false,
7
+ "declaration": false,
8
+ "declarationMap": false,
9
+ "types": [
10
+ "node",
11
+ "bun"
12
+ ]
13
+ },
14
+ "exclude": [
15
+ "node_modules",
16
+ "dist"
17
+ ]
18
+ }