@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.
- package/AGENTS.md +20 -18
- package/CHANGELOG.md +93 -0
- package/biome.jsonc +3 -2
- package/dist/aiApp.d.ts +5 -2
- package/dist/aiApp.js +3 -2
- package/dist/harness/agentLoop.js +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -2
- package/dist/migrations/gptHistoryStringIds.d.ts +41 -0
- package/dist/migrations/gptHistoryStringIds.js +94 -0
- package/dist/models/aiDataset.js +2 -2
- package/dist/models/gptHistory.js +11 -0
- package/dist/observability/local/experimentRunner.d.ts +2 -5
- package/dist/routes/files.d.ts +7 -1
- package/dist/routes/files.js +62 -13
- package/dist/routes/gptActions.js +0 -7
- package/dist/routes/gptHistories.js +8 -2
- package/dist/service/aiDatasets.js +2 -1
- package/dist/service/chatTurn.js +4 -0
- package/dist/service/vertex.d.ts +5 -2
- package/dist/types/harness.d.ts +5 -2
- package/dist/types/index.d.ts +5 -2
- package/e2e/smoke.ts +227 -0
- package/package.json +19 -16
- package/src/aiApp.test.ts +43 -18
- package/src/aiApp.ts +6 -3
- package/src/harness/agentLoop.test.ts +1 -1
- package/src/harness/agentLoop.ts +2 -1
- package/src/harness/agentRecovery.test.ts +31 -28
- package/src/harness/approvals.test.ts +11 -9
- package/src/harness/events.test.ts +10 -6
- package/src/harness/extensions.test.ts +7 -6
- package/src/harness/ownership.test.ts +20 -9
- package/src/harness/retries.test.ts +6 -3
- package/src/harness/routes/conversations.test.ts +2 -2
- package/src/harness/routes/tasks.test.ts +2 -2
- package/src/harness/runners/jobsRunner.test.ts +1 -1
- package/src/harness/subagent.test.ts +3 -2
- package/src/harness/waits.test.ts +6 -4
- package/src/index.test.ts +3 -3
- package/src/index.ts +7 -1
- package/src/isolated/gptStream.isolated.ts +35 -30
- package/src/isolated/langfuseClient.isolated.ts +9 -3
- package/src/isolated/lazyProjectModel.isolated.ts +2 -2
- package/src/langfuseApp.test.ts +4 -20
- package/src/langfuseRoutes.test.ts +20 -15
- package/src/langfuseTracing.test.ts +6 -2
- package/src/langfuseVercelAi.test.ts +12 -9
- package/src/migrations/gptHistoryStringIds.test.ts +231 -0
- package/src/migrations/gptHistoryStringIds.ts +150 -0
- package/src/models/aiDataset.test.ts +1 -1
- package/src/models/aiDataset.ts +2 -2
- package/src/models/gptHistory.test.ts +22 -11
- package/src/models/gptHistory.ts +19 -1
- package/src/observability/evaluate.test.ts +12 -10
- package/src/observability/local/experimentRunner.test.ts +9 -12
- package/src/observability/local/experimentRunner.ts +2 -2
- package/src/observability/local/promptStore.test.ts +4 -3
- package/src/observability/routes/datasets.test.ts +2 -2
- package/src/observability/routes/evaluators.test.ts +2 -2
- package/src/observability/routes/experiments.test.ts +2 -2
- package/src/observability/routes/prompts.test.ts +3 -3
- package/src/observability/routes/review.test.ts +2 -2
- package/src/observability/routes/status.test.ts +4 -4
- package/src/observability/routes/testMultiStage.test.ts +6 -6
- package/src/observability/routes/traces.test.ts +2 -2
- package/src/routes/files.test.ts +126 -3
- package/src/routes/files.ts +90 -15
- package/src/routes/gpt.test.ts +23 -16
- package/src/routes/gptActions.test.ts +15 -15
- package/src/routes/gptActions.ts +1 -4
- package/src/routes/gptApprovals.test.ts +1 -1
- package/src/routes/gptDatasets.test.ts +1 -1
- package/src/routes/gptFiles.test.ts +2 -2
- package/src/routes/gptHistories.test.ts +17 -11
- package/src/routes/gptHistories.ts +59 -55
- package/src/routes/gptHistoriesSync.test.ts +141 -0
- package/src/routes/mcp.test.ts +3 -3
- package/src/routes/projects.test.ts +5 -3
- package/src/routes/routes.test.ts +64 -47
- package/src/service/aiDatasets.ts +2 -1
- package/src/service/aiService.test.ts +1 -1
- package/src/service/asks.test.ts +14 -6
- package/src/service/chatTurn.ts +4 -0
- package/src/service/fileStorage.test.ts +5 -2
- package/src/service/getMCPTools.test.ts +9 -5
- package/src/service/mcpService.test.ts +6 -3
- package/src/service/vertex.test.ts +1 -1
- package/src/service/vertex.ts +7 -4
- package/src/tests/bunSetup.ts +1 -1
- package/src/tests/chatHarness.ts +4 -4
- package/src/tests/fakeJudge.ts +8 -0
- package/src/tests/fakeLangfusePrompt.ts +10 -0
- package/src/tests/helpers.ts +26 -4
- package/src/types/harness.ts +6 -2
- package/src/types/index.ts +5 -2
- 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
|
+
}
|
package/src/tests/helpers.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
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,
|
package/src/types/harness.ts
CHANGED
|
@@ -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
|
|
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`. */
|
package/src/types/index.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
+
}
|