@truefoundry/trueforge 0.183.0 → 0.183.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/dist/controller-main.js +1023 -56
- package/dist/controller-main.js.map +1 -1
- package/dist/main.js +625 -113
- package/dist/main.js.map +1 -1
- package/dist/postgres/migrations/20260727_000001_init.js +45 -1
- package/dist/postgres/migrations/20260727_000001_init.js.map +1 -1
- package/dist/postgres/migrations/20261030_000001_memory_ingest_cursor.js +15 -0
- package/dist/postgres/migrations/20261030_000001_memory_ingest_cursor.js.map +1 -0
- package/dist/sqlite/migrations/20261030_000001_memory_ingest_cursor.js +25 -0
- package/dist/sqlite/migrations/20261030_000001_memory_ingest_cursor.js.map +1 -0
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -359,6 +359,16 @@ function parsePublicBaseUrl(raw) {
|
|
|
359
359
|
const path7 = segments.length === 0 ? "" : `/${segments.join("/")}`;
|
|
360
360
|
return `${parsed.origin}${path7}`;
|
|
361
361
|
}
|
|
362
|
+
function parseTrueFoundryMemoryProvider(raw) {
|
|
363
|
+
if (raw === void 0 || raw.trim() === "") {
|
|
364
|
+
return void 0;
|
|
365
|
+
}
|
|
366
|
+
const value = raw.trim();
|
|
367
|
+
if (value === "zep") {
|
|
368
|
+
return value;
|
|
369
|
+
}
|
|
370
|
+
throw new Error(`Environment variable TRUEFOUNDRY_MEMORY_PROVIDER must be "zep", got ${JSON.stringify(raw)}`);
|
|
371
|
+
}
|
|
362
372
|
function parseTrueFoundrySandboxProvider(raw) {
|
|
363
373
|
if (raw === void 0 || raw.trim() === "") {
|
|
364
374
|
return void 0;
|
|
@@ -979,7 +989,22 @@ var init_config = __esm({
|
|
|
979
989
|
getEnv("TRUEFOUNDRY_WEB_SEARCH_PROVIDER", { required: false })
|
|
980
990
|
),
|
|
981
991
|
TRUEFOUNDRY_AUTH_SERVER_URL: getEnv("TRUEFOUNDRY_AUTH_SERVER_URL", { required: false }),
|
|
982
|
-
TRUEFOUNDRY_TENANT_NAME: getEnv("TRUEFOUNDRY_TENANT_NAME", { required: false })
|
|
992
|
+
TRUEFOUNDRY_TENANT_NAME: getEnv("TRUEFOUNDRY_TENANT_NAME", { required: false }),
|
|
993
|
+
TRUEFOUNDRY_MEMORY_ENABLED: parseBoolean({
|
|
994
|
+
envKey: "TRUEFOUNDRY_MEMORY_ENABLED",
|
|
995
|
+
raw: getEnv("TRUEFOUNDRY_MEMORY_ENABLED"),
|
|
996
|
+
defaultValue: false
|
|
997
|
+
}),
|
|
998
|
+
TRUEFOUNDRY_MEMORY_PROVIDER: parseTrueFoundryMemoryProvider(
|
|
999
|
+
getEnv("TRUEFOUNDRY_MEMORY_PROVIDER", { required: false })
|
|
1000
|
+
),
|
|
1001
|
+
TRUEFOUNDRY_MEMORY_API_KEY: getEnv("TRUEFOUNDRY_MEMORY_API_KEY", { required: false }),
|
|
1002
|
+
TRUEFOUNDRY_MEMORY_SERVER_URL: getEnv("TRUEFOUNDRY_MEMORY_SERVER_URL", { required: false }),
|
|
1003
|
+
TRUEFOUNDRY_MEMORY_TENANT_ALLOWLIST: parseJsonStringArrayEnv({
|
|
1004
|
+
envKey: "TRUEFOUNDRY_MEMORY_TENANT_ALLOWLIST",
|
|
1005
|
+
raw: getEnv("TRUEFOUNDRY_MEMORY_TENANT_ALLOWLIST")
|
|
1006
|
+
}),
|
|
1007
|
+
TRUEFOUNDRY_MEMORY_SETTINGS: getEnv("TRUEFOUNDRY_MEMORY_SETTINGS", { required: false })
|
|
983
1008
|
};
|
|
984
1009
|
TrueForgeAuthMode = /* @__PURE__ */ ((TrueForgeAuthMode3) => {
|
|
985
1010
|
TrueForgeAuthMode3["Standalone"] = "standalone";
|
|
@@ -1023,6 +1048,25 @@ var init_config = __esm({
|
|
|
1023
1048
|
);
|
|
1024
1049
|
}
|
|
1025
1050
|
}
|
|
1051
|
+
if (configuration.TRUEFOUNDRY_MEMORY_ENABLED) {
|
|
1052
|
+
if (configuration.TRUEFOUNDRY_MEMORY_PROVIDER === void 0) {
|
|
1053
|
+
throw new Error(
|
|
1054
|
+
'TRUEFOUNDRY_MEMORY_ENABLED is true but TRUEFOUNDRY_MEMORY_PROVIDER is not set. Set TRUEFOUNDRY_MEMORY_PROVIDER to "zep", or set TRUEFOUNDRY_MEMORY_ENABLED=false.'
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
if (configuration.TRUEFOUNDRY_MEMORY_API_KEY === void 0) {
|
|
1058
|
+
throw new Error(
|
|
1059
|
+
"TRUEFOUNDRY_MEMORY_PROVIDER=zep requires TRUEFOUNDRY_MEMORY_API_KEY, or set TRUEFOUNDRY_MEMORY_ENABLED=false."
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
if (configuration.TRUEFOUNDRY_MEMORY_SETTINGS !== void 0) {
|
|
1063
|
+
try {
|
|
1064
|
+
JSON.parse(configuration.TRUEFOUNDRY_MEMORY_SETTINGS);
|
|
1065
|
+
} catch (error) {
|
|
1066
|
+
throw new Error("TRUEFOUNDRY_MEMORY_SETTINGS must be valid JSON", { cause: error });
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1026
1070
|
}
|
|
1027
1071
|
if (!configuration.STANDALONE && configuration.TRUEFORGE_API_KEY.trim() === "") {
|
|
1028
1072
|
throw new Error("TRUEFORGE_API_KEY must not be empty when STANDALONE=false.");
|
|
@@ -21615,6 +21659,473 @@ var Controller = class {
|
|
|
21615
21659
|
}
|
|
21616
21660
|
};
|
|
21617
21661
|
|
|
21662
|
+
// src/memory/zep/ZepMemoryProvider.ts
|
|
21663
|
+
import { z as z45 } from "zod";
|
|
21664
|
+
|
|
21665
|
+
// src/memory/MemoryProvider.ts
|
|
21666
|
+
var MemoryIngestError = class extends Error {
|
|
21667
|
+
externalThreadId;
|
|
21668
|
+
constructor({
|
|
21669
|
+
message,
|
|
21670
|
+
externalThreadId,
|
|
21671
|
+
cause
|
|
21672
|
+
}) {
|
|
21673
|
+
super(message, { cause });
|
|
21674
|
+
this.name = "MemoryIngestError";
|
|
21675
|
+
this.externalThreadId = externalThreadId;
|
|
21676
|
+
}
|
|
21677
|
+
};
|
|
21678
|
+
|
|
21679
|
+
// src/memory/scope.ts
|
|
21680
|
+
import { createHash as createHash2 } from "crypto";
|
|
21681
|
+
var DEFAULT_MEMORY_AGENT_KEY = "trueforge";
|
|
21682
|
+
var UI_SESSION_SOURCE = "ui";
|
|
21683
|
+
function memoryScopeKey({
|
|
21684
|
+
tenantId,
|
|
21685
|
+
agentKey,
|
|
21686
|
+
subjectId
|
|
21687
|
+
}) {
|
|
21688
|
+
const digest = createHash2("sha256").update(JSON.stringify([tenantId, agentKey, subjectId])).digest("hex");
|
|
21689
|
+
return `tfg-${digest}`;
|
|
21690
|
+
}
|
|
21691
|
+
function resolveMemoryScope(session) {
|
|
21692
|
+
if (session.createAgentSession) {
|
|
21693
|
+
return void 0;
|
|
21694
|
+
}
|
|
21695
|
+
const tenantId = session.tenantId;
|
|
21696
|
+
const subjectId = session.createdBySubject.subject_id;
|
|
21697
|
+
if (session.agentId !== null) {
|
|
21698
|
+
if (!session.agentMemoryEnabled) {
|
|
21699
|
+
return void 0;
|
|
21700
|
+
}
|
|
21701
|
+
return {
|
|
21702
|
+
type: "agent",
|
|
21703
|
+
tenantId,
|
|
21704
|
+
subjectId,
|
|
21705
|
+
agentId: session.agentId,
|
|
21706
|
+
key: memoryScopeKey({ tenantId, agentKey: session.agentId, subjectId })
|
|
21707
|
+
};
|
|
21708
|
+
}
|
|
21709
|
+
if (session.tfgSource !== UI_SESSION_SOURCE) {
|
|
21710
|
+
return void 0;
|
|
21711
|
+
}
|
|
21712
|
+
return {
|
|
21713
|
+
type: "default",
|
|
21714
|
+
tenantId,
|
|
21715
|
+
subjectId,
|
|
21716
|
+
agentId: null,
|
|
21717
|
+
key: memoryScopeKey({ tenantId, agentKey: DEFAULT_MEMORY_AGENT_KEY, subjectId })
|
|
21718
|
+
};
|
|
21719
|
+
}
|
|
21720
|
+
|
|
21721
|
+
// src/memory/zep/ZepMemoryProvider.ts
|
|
21722
|
+
var ZepUuidResponseSchema = z45.object({ uuid: z45.string().min(1) });
|
|
21723
|
+
var ZepMessagesResponseSchema = z45.object({
|
|
21724
|
+
items: z45.array(z45.object({ metadata: z45.record(z45.string(), z45.unknown()).nullish() }))
|
|
21725
|
+
});
|
|
21726
|
+
|
|
21727
|
+
// src/memory/exchanges.ts
|
|
21728
|
+
import { ASK_USER_QUESTION_TOOL_NAME } from "@truefoundry/trueforge-core/core";
|
|
21729
|
+
var MAX_MEMORY_MESSAGE_CHARS = 4e3;
|
|
21730
|
+
var TRUNCATION_MARKER = " [truncated]";
|
|
21731
|
+
function hasUserMessage(turn) {
|
|
21732
|
+
return turn.input.some((item) => item.type === "user.message");
|
|
21733
|
+
}
|
|
21734
|
+
function statusAfter(state) {
|
|
21735
|
+
switch (state.status) {
|
|
21736
|
+
case "running":
|
|
21737
|
+
case "paused":
|
|
21738
|
+
return "running";
|
|
21739
|
+
case "done":
|
|
21740
|
+
return state.required_actions.length === 0 ? "closed" : "paused";
|
|
21741
|
+
case "error":
|
|
21742
|
+
case "cancelled":
|
|
21743
|
+
return "closed";
|
|
21744
|
+
}
|
|
21745
|
+
}
|
|
21746
|
+
function activePath({
|
|
21747
|
+
turns,
|
|
21748
|
+
tipTurnId
|
|
21749
|
+
}) {
|
|
21750
|
+
const byId = new Map(turns.map((turn) => [turn.turn_id, turn]));
|
|
21751
|
+
const path7 = [];
|
|
21752
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21753
|
+
let current = byId.get(tipTurnId);
|
|
21754
|
+
while (current !== void 0 && !seen.has(current.turn_id)) {
|
|
21755
|
+
seen.add(current.turn_id);
|
|
21756
|
+
path7.push(current);
|
|
21757
|
+
current = current.previous_turn_id === null ? void 0 : byId.get(current.previous_turn_id);
|
|
21758
|
+
}
|
|
21759
|
+
return path7.reverse();
|
|
21760
|
+
}
|
|
21761
|
+
function buildExchanges(turns) {
|
|
21762
|
+
const exchanges = [];
|
|
21763
|
+
let current;
|
|
21764
|
+
for (const turn of turns) {
|
|
21765
|
+
if (current !== void 0 && hasUserMessage(turn)) {
|
|
21766
|
+
current.status = "closed";
|
|
21767
|
+
current.completedAt ??= turn.created_at;
|
|
21768
|
+
current = void 0;
|
|
21769
|
+
}
|
|
21770
|
+
if (current === void 0) {
|
|
21771
|
+
current = {
|
|
21772
|
+
turns: [turn],
|
|
21773
|
+
status: statusAfter(turn.state),
|
|
21774
|
+
completedAt: completedAt(turn.state),
|
|
21775
|
+
continuation: !hasUserMessage(turn)
|
|
21776
|
+
};
|
|
21777
|
+
exchanges.push(current);
|
|
21778
|
+
} else {
|
|
21779
|
+
current.turns.push(turn);
|
|
21780
|
+
current.status = statusAfter(turn.state);
|
|
21781
|
+
current.completedAt = completedAt(turn.state);
|
|
21782
|
+
}
|
|
21783
|
+
if (current.status === "closed") {
|
|
21784
|
+
current = void 0;
|
|
21785
|
+
}
|
|
21786
|
+
}
|
|
21787
|
+
return exchanges;
|
|
21788
|
+
}
|
|
21789
|
+
function resumePoint({
|
|
21790
|
+
path: path7,
|
|
21791
|
+
turns,
|
|
21792
|
+
lastIngestedTurnId
|
|
21793
|
+
}) {
|
|
21794
|
+
if (lastIngestedTurnId === null) {
|
|
21795
|
+
return { startIndex: 0, forked: false };
|
|
21796
|
+
}
|
|
21797
|
+
const pathIndex = new Map(path7.map((turn, index) => [turn.turn_id, index]));
|
|
21798
|
+
const ingestedIndex = pathIndex.get(lastIngestedTurnId);
|
|
21799
|
+
if (ingestedIndex !== void 0) {
|
|
21800
|
+
return { startIndex: ingestedIndex + 1, forked: false };
|
|
21801
|
+
}
|
|
21802
|
+
const byId = new Map(turns.map((turn) => [turn.turn_id, turn]));
|
|
21803
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21804
|
+
let forkIndex;
|
|
21805
|
+
let current = byId.get(lastIngestedTurnId);
|
|
21806
|
+
while (current !== void 0 && !seen.has(current.turn_id) && forkIndex === void 0) {
|
|
21807
|
+
seen.add(current.turn_id);
|
|
21808
|
+
current = current.previous_turn_id === null ? void 0 : byId.get(current.previous_turn_id);
|
|
21809
|
+
forkIndex = current === void 0 ? void 0 : pathIndex.get(current.turn_id);
|
|
21810
|
+
}
|
|
21811
|
+
return { startIndex: forkIndex === void 0 ? 0 : forkIndex + 1, forked: true };
|
|
21812
|
+
}
|
|
21813
|
+
function completedAt(state) {
|
|
21814
|
+
return state.status === "done" || state.status === "error" || state.status === "cancelled" ? state.completed_at : null;
|
|
21815
|
+
}
|
|
21816
|
+
function exchangeReadiness({
|
|
21817
|
+
exchange,
|
|
21818
|
+
now: now2,
|
|
21819
|
+
pauseTimeoutMs
|
|
21820
|
+
}) {
|
|
21821
|
+
const finishedAt = exchange.completedAt;
|
|
21822
|
+
if (exchange.status === "running" || finishedAt === null) {
|
|
21823
|
+
return { ready: false };
|
|
21824
|
+
}
|
|
21825
|
+
if (exchange.status === "closed") {
|
|
21826
|
+
return { ready: true, partial: false };
|
|
21827
|
+
}
|
|
21828
|
+
return now2.getTime() - Date.parse(finishedAt) >= pauseTimeoutMs ? { ready: true, partial: true } : { ready: false };
|
|
21829
|
+
}
|
|
21830
|
+
function askUserQuestionsByToolCallId(messages) {
|
|
21831
|
+
const questions = /* @__PURE__ */ new Map();
|
|
21832
|
+
for (const message of messages) {
|
|
21833
|
+
for (const call of message.tool_calls ?? []) {
|
|
21834
|
+
if (call.function.name !== ASK_USER_QUESTION_TOOL_NAME) {
|
|
21835
|
+
continue;
|
|
21836
|
+
}
|
|
21837
|
+
const question = parseQuestion(call.function.arguments);
|
|
21838
|
+
if (question !== void 0) {
|
|
21839
|
+
questions.set(call.id, question);
|
|
21840
|
+
}
|
|
21841
|
+
}
|
|
21842
|
+
}
|
|
21843
|
+
return questions;
|
|
21844
|
+
}
|
|
21845
|
+
function parseQuestion(rawArguments) {
|
|
21846
|
+
try {
|
|
21847
|
+
const parsed = JSON.parse(rawArguments);
|
|
21848
|
+
if (typeof parsed === "object" && parsed !== null && "question" in parsed && typeof parsed.question === "string") {
|
|
21849
|
+
const question = parsed.question.trim();
|
|
21850
|
+
return question === "" ? void 0 : question;
|
|
21851
|
+
}
|
|
21852
|
+
} catch {
|
|
21853
|
+
}
|
|
21854
|
+
return void 0;
|
|
21855
|
+
}
|
|
21856
|
+
function modelMessageText(content) {
|
|
21857
|
+
if (content === void 0 || content === null) {
|
|
21858
|
+
return "";
|
|
21859
|
+
}
|
|
21860
|
+
if (typeof content === "string") {
|
|
21861
|
+
return content.trim();
|
|
21862
|
+
}
|
|
21863
|
+
return content.map((part) => part.type === "text" ? part.text : part.refusal).join("").trim();
|
|
21864
|
+
}
|
|
21865
|
+
function capped(text) {
|
|
21866
|
+
return text.length <= MAX_MEMORY_MESSAGE_CHARS ? text : text.slice(0, MAX_MEMORY_MESSAGE_CHARS - TRUNCATION_MARKER.length) + TRUNCATION_MARKER;
|
|
21867
|
+
}
|
|
21868
|
+
function renderExchange({
|
|
21869
|
+
exchange,
|
|
21870
|
+
questions
|
|
21871
|
+
}) {
|
|
21872
|
+
const messages = [];
|
|
21873
|
+
const user = (content, createdAt) => {
|
|
21874
|
+
if (content !== "") {
|
|
21875
|
+
messages.push({ role: "user", content: capped(content), createdAt, extract: true });
|
|
21876
|
+
}
|
|
21877
|
+
};
|
|
21878
|
+
for (const turn of exchange.turns) {
|
|
21879
|
+
for (const item of turn.input) {
|
|
21880
|
+
if (item.type === "user.message") {
|
|
21881
|
+
const text = typeof item.content === "string" ? item.content : item.content.flatMap((part) => part.type === "text" ? [part.text] : []).join("\n");
|
|
21882
|
+
user(text.trim(), turn.created_at);
|
|
21883
|
+
} else if (item.type === "user.tool_response") {
|
|
21884
|
+
const question = questions.get(item.tool_call_id);
|
|
21885
|
+
const answer = item.content.trim();
|
|
21886
|
+
if (question !== void 0 && answer !== "") {
|
|
21887
|
+
user(`(Answering "${question}") ${answer}`, turn.created_at);
|
|
21888
|
+
}
|
|
21889
|
+
}
|
|
21890
|
+
}
|
|
21891
|
+
}
|
|
21892
|
+
const last = exchange.turns[exchange.turns.length - 1];
|
|
21893
|
+
if (exchange.status === "closed" && last?.state.status === "done" && last.state.output !== null) {
|
|
21894
|
+
const reply = modelMessageText(last.state.output.content);
|
|
21895
|
+
if (reply !== "") {
|
|
21896
|
+
messages.push({
|
|
21897
|
+
role: "assistant",
|
|
21898
|
+
content: capped(reply),
|
|
21899
|
+
createdAt: last.state.completed_at,
|
|
21900
|
+
extract: false
|
|
21901
|
+
});
|
|
21902
|
+
}
|
|
21903
|
+
}
|
|
21904
|
+
return messages;
|
|
21905
|
+
}
|
|
21906
|
+
|
|
21907
|
+
// src/truefoundry/resolveTrueFoundryMemoryProviderConfig.ts
|
|
21908
|
+
import { z as z46 } from "zod";
|
|
21909
|
+
var TrueFoundryMemorySettingsSchema = z46.object({
|
|
21910
|
+
/** Gap between ingest runs. */
|
|
21911
|
+
interval_ms: z46.number().int().positive().default(5 * 60 * 1e3),
|
|
21912
|
+
/** Sessions processed per run. */
|
|
21913
|
+
max_sessions_per_run: z46.number().int().positive().default(50),
|
|
21914
|
+
/** Exchanges sent per session per run. */
|
|
21915
|
+
max_exchanges_per_session: z46.number().int().positive().default(20),
|
|
21916
|
+
/** How far back a session's latest turn is picked up; sessions not ingested by then are dropped. */
|
|
21917
|
+
lookback_ms: z46.number().int().positive().default(2 * 60 * 60 * 1e3),
|
|
21918
|
+
/**
|
|
21919
|
+
* An exchange paused on the user (a question, approval or auth) is sent as-is after this long.
|
|
21920
|
+
* Paused sessions are looked up again in a lookback-wide range this far back.
|
|
21921
|
+
*/
|
|
21922
|
+
pause_timeout_ms: z46.number().int().positive().default(12 * 60 * 60 * 1e3)
|
|
21923
|
+
}).strict();
|
|
21924
|
+
|
|
21925
|
+
// src/controller/memoryIngest.ts
|
|
21926
|
+
var MEMORY_INGEST_LOOP_NAME = "memory-ingest";
|
|
21927
|
+
function errorMessage(error) {
|
|
21928
|
+
return error instanceof Error ? error.message : String(error);
|
|
21929
|
+
}
|
|
21930
|
+
function readyExchanges({
|
|
21931
|
+
exchanges,
|
|
21932
|
+
now: now2,
|
|
21933
|
+
config
|
|
21934
|
+
}) {
|
|
21935
|
+
const ready = [];
|
|
21936
|
+
for (const exchange of exchanges) {
|
|
21937
|
+
if (ready.length === config.maxExchangesPerSession || !exchangeReadiness({ exchange, now: now2, pauseTimeoutMs: config.pauseTimeoutMs }).ready) {
|
|
21938
|
+
break;
|
|
21939
|
+
}
|
|
21940
|
+
ready.push(exchange);
|
|
21941
|
+
}
|
|
21942
|
+
return ready;
|
|
21943
|
+
}
|
|
21944
|
+
async function ingestSession({
|
|
21945
|
+
candidate,
|
|
21946
|
+
scope,
|
|
21947
|
+
deps,
|
|
21948
|
+
signal
|
|
21949
|
+
}) {
|
|
21950
|
+
const { store, provider, logger: logger2, config, now: now2 } = deps;
|
|
21951
|
+
const { cursor } = candidate;
|
|
21952
|
+
const logFields = {
|
|
21953
|
+
session_id: candidate.session_id,
|
|
21954
|
+
tenant_id: candidate.tenant_id,
|
|
21955
|
+
scope_type: scope.type,
|
|
21956
|
+
agent_id: candidate.agent_id
|
|
21957
|
+
};
|
|
21958
|
+
let threadId = cursor?.external_thread_id ?? null;
|
|
21959
|
+
let lastIngestedTurnId = cursor?.last_ingested_turn_id ?? null;
|
|
21960
|
+
const turns = await store.listSessionTurns({ session_id: candidate.session_id });
|
|
21961
|
+
const path7 = activePath({ turns, tipTurnId: candidate.tip_turn_id });
|
|
21962
|
+
const { startIndex, forked } = resumePoint({ path: path7, turns, lastIngestedTurnId });
|
|
21963
|
+
if (forked) {
|
|
21964
|
+
logger2.warn("Memory checkpoint is off the active path; resuming after the fork point", {
|
|
21965
|
+
...logFields,
|
|
21966
|
+
last_ingested_turn_id: lastIngestedTurnId
|
|
21967
|
+
});
|
|
21968
|
+
}
|
|
21969
|
+
const ready = readyExchanges({ exchanges: buildExchanges(path7.slice(startIndex)), now: now2(), config });
|
|
21970
|
+
if (ready.length === 0) {
|
|
21971
|
+
return { outcome: "not_ready", exchangesSent: 0, exchangesFailed: 0 };
|
|
21972
|
+
}
|
|
21973
|
+
const previous = path7[startIndex - 1];
|
|
21974
|
+
const turnIds = [
|
|
21975
|
+
...previous === void 0 ? [] : [previous.turn_id],
|
|
21976
|
+
...ready.flatMap((e) => e.turns.map((t) => t.turn_id))
|
|
21977
|
+
];
|
|
21978
|
+
const modelMessages = await store.listMainThreadModelMessages({
|
|
21979
|
+
session_id: candidate.session_id,
|
|
21980
|
+
turn_ids: turnIds
|
|
21981
|
+
});
|
|
21982
|
+
const questions = askUserQuestionsByToolCallId(modelMessages.map((entry) => entry.message));
|
|
21983
|
+
let exchangesSent = 0;
|
|
21984
|
+
let mayAlreadyBeStored = cursor !== null && cursor.last_error !== null;
|
|
21985
|
+
for (const exchange of ready) {
|
|
21986
|
+
if (signal.aborted) {
|
|
21987
|
+
break;
|
|
21988
|
+
}
|
|
21989
|
+
const firstTurnId = exchange.turns[0].turn_id;
|
|
21990
|
+
const lastTurnId = exchange.turns[exchange.turns.length - 1]?.turn_id ?? firstTurnId;
|
|
21991
|
+
const messages = renderExchange({ exchange, questions });
|
|
21992
|
+
try {
|
|
21993
|
+
if (messages.length > 0) {
|
|
21994
|
+
const sent = await provider.ingestExchange({
|
|
21995
|
+
scope,
|
|
21996
|
+
exchange: { sessionId: candidate.session_id, lastTurnId, messages },
|
|
21997
|
+
externalThreadId: threadId,
|
|
21998
|
+
mayAlreadyBeStored
|
|
21999
|
+
});
|
|
22000
|
+
threadId = sent.externalThreadId;
|
|
22001
|
+
mayAlreadyBeStored = false;
|
|
22002
|
+
exchangesSent += 1;
|
|
22003
|
+
}
|
|
22004
|
+
} catch (error) {
|
|
22005
|
+
if (error instanceof MemoryIngestError && error.externalThreadId !== null) {
|
|
22006
|
+
threadId = error.externalThreadId;
|
|
22007
|
+
}
|
|
22008
|
+
const lastError = errorMessage(error);
|
|
22009
|
+
logger2.error("Memory ingest failed for session", {
|
|
22010
|
+
...logFields,
|
|
22011
|
+
exchanges_sent: exchangesSent,
|
|
22012
|
+
last_error: lastError,
|
|
22013
|
+
reportable_error: { error, extra: { ...logFields, first_turn_id: firstTurnId, last_turn_id: lastTurnId } }
|
|
22014
|
+
});
|
|
22015
|
+
await store.upsertCursor({
|
|
22016
|
+
session_id: candidate.session_id,
|
|
22017
|
+
last_ingested_turn_id: lastIngestedTurnId,
|
|
22018
|
+
external_thread_id: threadId,
|
|
22019
|
+
last_error: lastError.slice(0, 1e3)
|
|
22020
|
+
});
|
|
22021
|
+
return { outcome: "failed", exchangesSent, exchangesFailed: 1 };
|
|
22022
|
+
}
|
|
22023
|
+
lastIngestedTurnId = lastTurnId;
|
|
22024
|
+
await store.upsertCursor({
|
|
22025
|
+
session_id: candidate.session_id,
|
|
22026
|
+
last_ingested_turn_id: lastIngestedTurnId,
|
|
22027
|
+
external_thread_id: threadId,
|
|
22028
|
+
last_error: null
|
|
22029
|
+
});
|
|
22030
|
+
}
|
|
22031
|
+
logger2.debug("Memory ingest session finished", { ...logFields, exchanges_sent: exchangesSent });
|
|
22032
|
+
return { outcome: "ingested", exchangesSent, exchangesFailed: 0 };
|
|
22033
|
+
}
|
|
22034
|
+
async function runMemoryIngestPass({
|
|
22035
|
+
deps,
|
|
22036
|
+
signal
|
|
22037
|
+
}) {
|
|
22038
|
+
const { store, settings, logger: logger2, config, now: now2 } = deps;
|
|
22039
|
+
const startedAt = now2();
|
|
22040
|
+
const startedMs = startedAt.getTime();
|
|
22041
|
+
const tenantIds = await settings.listEnabledTenantIds();
|
|
22042
|
+
const listed = tenantIds?.length === 0 ? [] : await store.listCandidateSessions({
|
|
22043
|
+
tenant_ids: tenantIds,
|
|
22044
|
+
recent_since: new Date(startedMs - config.lookbackMs),
|
|
22045
|
+
paused_from: new Date(startedMs - config.pauseTimeoutMs - config.lookbackMs),
|
|
22046
|
+
paused_until: new Date(startedMs - config.pauseTimeoutMs),
|
|
22047
|
+
limit: config.maxSessionsPerRun + 1
|
|
22048
|
+
});
|
|
22049
|
+
const backlog = listed.length > config.maxSessionsPerRun;
|
|
22050
|
+
const candidates = listed.slice(0, config.maxSessionsPerRun);
|
|
22051
|
+
const outcomes = {};
|
|
22052
|
+
let exchangesSent = 0;
|
|
22053
|
+
let exchangesFailed = 0;
|
|
22054
|
+
let sessionsProcessed = 0;
|
|
22055
|
+
for (const candidate of candidates) {
|
|
22056
|
+
if (signal.aborted) {
|
|
22057
|
+
break;
|
|
22058
|
+
}
|
|
22059
|
+
sessionsProcessed += 1;
|
|
22060
|
+
const result = await processCandidate({ candidate, deps, signal });
|
|
22061
|
+
outcomes[result.outcome] = (outcomes[result.outcome] ?? 0) + 1;
|
|
22062
|
+
exchangesSent += result.exchangesSent;
|
|
22063
|
+
exchangesFailed += result.exchangesFailed;
|
|
22064
|
+
}
|
|
22065
|
+
const summary = {
|
|
22066
|
+
sessions: sessionsProcessed,
|
|
22067
|
+
backlog,
|
|
22068
|
+
sessions_by_outcome: outcomes,
|
|
22069
|
+
exchanges_sent: exchangesSent,
|
|
22070
|
+
exchanges_failed: exchangesFailed,
|
|
22071
|
+
duration_ms: now2().getTime() - startedAt.getTime()
|
|
22072
|
+
};
|
|
22073
|
+
if (exchangesSent > 0 || exchangesFailed > 0 || backlog) {
|
|
22074
|
+
logger2.info("Memory ingest run finished", summary);
|
|
22075
|
+
} else {
|
|
22076
|
+
logger2.debug("Memory ingest run finished", summary);
|
|
22077
|
+
}
|
|
22078
|
+
return summary;
|
|
22079
|
+
}
|
|
22080
|
+
async function processCandidate({
|
|
22081
|
+
candidate,
|
|
22082
|
+
deps,
|
|
22083
|
+
signal
|
|
22084
|
+
}) {
|
|
22085
|
+
const { logger: logger2 } = deps;
|
|
22086
|
+
const skipped = (outcome) => ({
|
|
22087
|
+
outcome,
|
|
22088
|
+
exchangesSent: 0,
|
|
22089
|
+
exchangesFailed: 0
|
|
22090
|
+
});
|
|
22091
|
+
const scope = resolveMemoryScope({
|
|
22092
|
+
tenantId: candidate.tenant_id,
|
|
22093
|
+
createdBySubject: candidate.created_by_subject,
|
|
22094
|
+
agentId: candidate.agent_id,
|
|
22095
|
+
agentMemoryEnabled: candidate.agent_memory_enabled,
|
|
22096
|
+
tfgSource: candidate.tfg_source,
|
|
22097
|
+
createAgentSession: candidate.create_agent_session
|
|
22098
|
+
});
|
|
22099
|
+
if (scope === void 0) {
|
|
22100
|
+
return skipped("memory_disabled");
|
|
22101
|
+
}
|
|
22102
|
+
try {
|
|
22103
|
+
return await ingestSession({ candidate, scope, deps, signal });
|
|
22104
|
+
} catch (error) {
|
|
22105
|
+
logger2.error("Memory ingest failed for session", {
|
|
22106
|
+
session_id: candidate.session_id,
|
|
22107
|
+
tenant_id: candidate.tenant_id,
|
|
22108
|
+
scope_type: scope.type,
|
|
22109
|
+
agent_id: candidate.agent_id,
|
|
22110
|
+
last_error: errorMessage(error),
|
|
22111
|
+
reportable_error: { error, extra: { session_id: candidate.session_id, tenant_id: candidate.tenant_id } }
|
|
22112
|
+
});
|
|
22113
|
+
return skipped("failed");
|
|
22114
|
+
}
|
|
22115
|
+
}
|
|
22116
|
+
function memoryIngestLoop(deps) {
|
|
22117
|
+
return {
|
|
22118
|
+
name: MEMORY_INGEST_LOOP_NAME,
|
|
22119
|
+
intervalMs: deps.config.intervalMs,
|
|
22120
|
+
async tick(signal) {
|
|
22121
|
+
if (signal.aborted) {
|
|
22122
|
+
return;
|
|
22123
|
+
}
|
|
22124
|
+
await runMemoryIngestPass({ deps, signal });
|
|
22125
|
+
}
|
|
22126
|
+
};
|
|
22127
|
+
}
|
|
22128
|
+
|
|
21618
22129
|
// src/controller/sandboxEnvBuild.ts
|
|
21619
22130
|
import { TrueForgeApi, TrueForgeError } from "@truefoundry/trueforge-sdk";
|
|
21620
22131
|
var SANDBOX_ENV_BUILD_INTERVAL_MS = 5e3;
|
|
@@ -21665,17 +22176,18 @@ function sandboxEnvBuildLoop(params) {
|
|
|
21665
22176
|
|
|
21666
22177
|
// src/controller.ts
|
|
21667
22178
|
function createController(params) {
|
|
21668
|
-
|
|
21669
|
-
|
|
21670
|
-
|
|
21671
|
-
|
|
21672
|
-
|
|
21673
|
-
|
|
21674
|
-
|
|
21675
|
-
|
|
21676
|
-
|
|
21677
|
-
logger: params.logger
|
|
21678
|
-
}
|
|
22179
|
+
const loops = [
|
|
22180
|
+
scheduleDispatchLoop({
|
|
22181
|
+
scheduleStore: params.scheduleStore,
|
|
22182
|
+
withTransaction: params.withTransaction,
|
|
22183
|
+
logger: params.logger
|
|
22184
|
+
}),
|
|
22185
|
+
sandboxEnvBuildLoop({ logger: params.logger })
|
|
22186
|
+
];
|
|
22187
|
+
if (params.memory !== void 0) {
|
|
22188
|
+
loops.push(memoryIngestLoop({ ...params.memory, logger: params.logger, now: () => /* @__PURE__ */ new Date() }));
|
|
22189
|
+
}
|
|
22190
|
+
return new Controller({ loops, logger: params.logger });
|
|
21679
22191
|
}
|
|
21680
22192
|
|
|
21681
22193
|
// src/db/McpServerWithAuthStore.ts
|
|
@@ -22960,11 +23472,11 @@ import {
|
|
|
22960
23472
|
toolResultResponse
|
|
22961
23473
|
} from "@truefoundry/trueforge-core/core";
|
|
22962
23474
|
import { HTTPException as HTTPException25 } from "hono/http-exception";
|
|
22963
|
-
import { z as
|
|
23475
|
+
import { z as z47 } from "zod";
|
|
22964
23476
|
var X_TFG_TOOLS = "x-tfg-tools";
|
|
22965
23477
|
var MAX_TFG_TOOLS = 16;
|
|
22966
23478
|
var MAX_TFG_TOOLS_HEADER_LENGTH = 16e3;
|
|
22967
|
-
var InlineToolsHeaderSchema =
|
|
23479
|
+
var InlineToolsHeaderSchema = z47.array(McpToolSchema);
|
|
22968
23480
|
function assertTfgToolsHeaderAllowed(input) {
|
|
22969
23481
|
if (!input.isTrueFoundryMode) {
|
|
22970
23482
|
throw new HTTPException25(400, { message: `${X_TFG_TOOLS} requires TrueFoundry mode` });
|
|
@@ -23061,9 +23573,9 @@ var InlineClientSideTools = class extends ClientSideTool {
|
|
|
23061
23573
|
|
|
23062
23574
|
// src/truefoundry/perServerMcpHeaders.ts
|
|
23063
23575
|
import { HTTPException as HTTPException26 } from "hono/http-exception";
|
|
23064
|
-
import { z as
|
|
23576
|
+
import { z as z48 } from "zod";
|
|
23065
23577
|
var X_TFG_MCP_HEADERS = "x-tfg-mcp-headers";
|
|
23066
|
-
var PerServerMcpHeadersSchema =
|
|
23578
|
+
var PerServerMcpHeadersSchema = z48.record(z48.string().min(1), z48.record(z48.string().min(1), z48.string()));
|
|
23067
23579
|
function parsePerServerMcpHeaders(raw) {
|
|
23068
23580
|
let decoded;
|
|
23069
23581
|
try {
|
|
@@ -23096,7 +23608,7 @@ import {
|
|
|
23096
23608
|
import { HTTPException as HTTPException27 } from "hono/http-exception";
|
|
23097
23609
|
import { LRUCache } from "lru-cache";
|
|
23098
23610
|
import { fetch as undiciFetch3 } from "undici";
|
|
23099
|
-
import { z as
|
|
23611
|
+
import { z as z51 } from "zod";
|
|
23100
23612
|
|
|
23101
23613
|
// src/truefoundry/internalTls.ts
|
|
23102
23614
|
function normalizeInternalTlsUrl(input) {
|
|
@@ -23110,20 +23622,20 @@ function createInternalTlsDispatcher(options) {
|
|
|
23110
23622
|
}
|
|
23111
23623
|
|
|
23112
23624
|
// src/truefoundry/mapSfyAgentSkills.ts
|
|
23113
|
-
import { z as
|
|
23114
|
-
var SfyRegistryManifestSchema =
|
|
23625
|
+
import { z as z49 } from "zod";
|
|
23626
|
+
var SfyRegistryManifestSchema = z49.object({
|
|
23115
23627
|
// Display label only — not TF ResourceName / DNS-label rules.
|
|
23116
|
-
name:
|
|
23117
|
-
version:
|
|
23628
|
+
name: z49.string().min(1),
|
|
23629
|
+
version: z49.number().int().positive(),
|
|
23118
23630
|
// SFY field is `ml_repo`; TrueForge wire is `repository_name`.
|
|
23119
|
-
ml_repo:
|
|
23120
|
-
source:
|
|
23121
|
-
description:
|
|
23631
|
+
ml_repo: z49.string().min(1),
|
|
23632
|
+
source: z49.object({
|
|
23633
|
+
description: z49.string().min(1).optional()
|
|
23122
23634
|
}).optional()
|
|
23123
23635
|
});
|
|
23124
|
-
var SfyRegistrySkillSchema =
|
|
23125
|
-
latest_version:
|
|
23126
|
-
fqn:
|
|
23636
|
+
var SfyRegistrySkillSchema = z49.object({
|
|
23637
|
+
latest_version: z49.object({
|
|
23638
|
+
fqn: z49.string().min(1),
|
|
23127
23639
|
manifest: SfyRegistryManifestSchema
|
|
23128
23640
|
})
|
|
23129
23641
|
}).transform(({ latest_version }) => ({
|
|
@@ -23134,20 +23646,20 @@ var SfyRegistrySkillSchema = z47.object({
|
|
|
23134
23646
|
repository_name: latest_version.manifest.ml_repo,
|
|
23135
23647
|
version: latest_version.manifest.version
|
|
23136
23648
|
}));
|
|
23137
|
-
var SfyRegistrySkillVersionSchema =
|
|
23138
|
-
agent_skill_id:
|
|
23139
|
-
fqn:
|
|
23649
|
+
var SfyRegistrySkillVersionSchema = z49.object({
|
|
23650
|
+
agent_skill_id: z49.string().min(1),
|
|
23651
|
+
fqn: z49.string().min(1),
|
|
23140
23652
|
manifest: SfyRegistryManifestSchema
|
|
23141
23653
|
});
|
|
23142
|
-
var ResolvedAgentSkillVersionSchema =
|
|
23143
|
-
fqn:
|
|
23144
|
-
name:
|
|
23145
|
-
description:
|
|
23146
|
-
skill_md_content:
|
|
23147
|
-
presigned_url:
|
|
23654
|
+
var ResolvedAgentSkillVersionSchema = z49.object({
|
|
23655
|
+
fqn: z49.string().min(1),
|
|
23656
|
+
name: z49.string().min(1),
|
|
23657
|
+
description: z49.string().min(1),
|
|
23658
|
+
skill_md_content: z49.string().nullable().optional(),
|
|
23659
|
+
presigned_url: z49.string().min(1).optional()
|
|
23148
23660
|
});
|
|
23149
|
-
var ResolveAgentSkillVersionsResponseSchema =
|
|
23150
|
-
skills:
|
|
23661
|
+
var ResolveAgentSkillVersionsResponseSchema = z49.object({
|
|
23662
|
+
skills: z49.array(ResolvedAgentSkillVersionSchema)
|
|
23151
23663
|
});
|
|
23152
23664
|
function mapSfyRegistrySkills(rows) {
|
|
23153
23665
|
return rows.map((row) => SfyRegistrySkillSchema.parse(row));
|
|
@@ -23171,48 +23683,48 @@ function mapResolvedAgentSkillVersions(payload) {
|
|
|
23171
23683
|
}
|
|
23172
23684
|
|
|
23173
23685
|
// src/truefoundry/mapSfyMcpServers.ts
|
|
23174
|
-
import { z as
|
|
23686
|
+
import { z as z50 } from "zod";
|
|
23175
23687
|
var MCP_PROXY_BASE_URL_TEMPLATE = "{{mcpProxyBaseURL}}";
|
|
23176
|
-
var IsoInstantSchema =
|
|
23688
|
+
var IsoInstantSchema = z50.union([z50.string().min(1), z50.date()]).transform((value, ctx) => {
|
|
23177
23689
|
if (value instanceof Date) {
|
|
23178
23690
|
if (!Number.isFinite(value.getTime())) {
|
|
23179
23691
|
ctx.addIssue({ code: "custom", message: "Invalid Date" });
|
|
23180
|
-
return
|
|
23692
|
+
return z50.NEVER;
|
|
23181
23693
|
}
|
|
23182
23694
|
return value.toISOString();
|
|
23183
23695
|
}
|
|
23184
23696
|
const ms = Date.parse(value);
|
|
23185
23697
|
if (!Number.isFinite(ms)) {
|
|
23186
23698
|
ctx.addIssue({ code: "custom", message: "Invalid ISO timestamp" });
|
|
23187
|
-
return
|
|
23699
|
+
return z50.NEVER;
|
|
23188
23700
|
}
|
|
23189
23701
|
return new Date(ms).toISOString();
|
|
23190
23702
|
});
|
|
23191
|
-
var SfyMcpServerRowSchema =
|
|
23192
|
-
id:
|
|
23193
|
-
name:
|
|
23194
|
-
proxyUrl:
|
|
23703
|
+
var SfyMcpServerRowSchema = z50.object({
|
|
23704
|
+
id: z50.string().min(1),
|
|
23705
|
+
name: z50.string().min(1),
|
|
23706
|
+
proxyUrl: z50.string().min(1),
|
|
23195
23707
|
createdAt: IsoInstantSchema,
|
|
23196
23708
|
updatedAt: IsoInstantSchema,
|
|
23197
|
-
manifest:
|
|
23198
|
-
description:
|
|
23199
|
-
auth_data:
|
|
23200
|
-
type:
|
|
23709
|
+
manifest: z50.object({
|
|
23710
|
+
description: z50.string().min(1).optional(),
|
|
23711
|
+
auth_data: z50.object({
|
|
23712
|
+
type: z50.string().min(1).optional()
|
|
23201
23713
|
}).optional()
|
|
23202
23714
|
}).optional()
|
|
23203
23715
|
});
|
|
23204
|
-
var SfyMcpAuthStatusAuthenticatedSchema =
|
|
23205
|
-
var SfyMcpAuthStatusNotRequiredSchema =
|
|
23206
|
-
var SfyMcpAuthStatusRequiredSchema =
|
|
23716
|
+
var SfyMcpAuthStatusAuthenticatedSchema = z50.object({ status: z50.literal("authenticated") });
|
|
23717
|
+
var SfyMcpAuthStatusNotRequiredSchema = z50.object({ status: z50.literal("authentication_not_required") });
|
|
23718
|
+
var SfyMcpAuthStatusRequiredSchema = z50.object({ status: z50.literal("authentication_required") });
|
|
23207
23719
|
var SfyMcpAuthorizeRequiredSchema = SfyMcpAuthStatusRequiredSchema.extend({
|
|
23208
|
-
authorization_endpoint:
|
|
23720
|
+
authorization_endpoint: z50.url()
|
|
23209
23721
|
});
|
|
23210
|
-
var SfyMcpAuthStatusSchema =
|
|
23722
|
+
var SfyMcpAuthStatusSchema = z50.discriminatedUnion("status", [
|
|
23211
23723
|
SfyMcpAuthStatusAuthenticatedSchema,
|
|
23212
23724
|
SfyMcpAuthStatusRequiredSchema,
|
|
23213
23725
|
SfyMcpAuthStatusNotRequiredSchema
|
|
23214
23726
|
]);
|
|
23215
|
-
var SfyMcpAuthorizeResultSchema =
|
|
23727
|
+
var SfyMcpAuthorizeResultSchema = z50.discriminatedUnion("status", [
|
|
23216
23728
|
SfyMcpAuthStatusAuthenticatedSchema,
|
|
23217
23729
|
SfyMcpAuthorizeRequiredSchema,
|
|
23218
23730
|
SfyMcpAuthStatusNotRequiredSchema
|
|
@@ -23286,32 +23798,32 @@ var VEND_TOKEN_PATH = "internal/vend-token";
|
|
|
23286
23798
|
var SUBJECTS_PEEK_PATH = "v1/subjects/peek";
|
|
23287
23799
|
var AGENT_SKILLS_PAGE_SIZE = 100;
|
|
23288
23800
|
var AGENT_SKILL_RESOLVE_CHUNK_SIZE = 50;
|
|
23289
|
-
var SessionSubjectSchema =
|
|
23290
|
-
subjectId:
|
|
23291
|
-
subjectType:
|
|
23292
|
-
subjectDisplayName:
|
|
23293
|
-
subjectSlug:
|
|
23801
|
+
var SessionSubjectSchema = z51.object({
|
|
23802
|
+
subjectId: z51.string().min(1),
|
|
23803
|
+
subjectType: z51.string().min(1),
|
|
23804
|
+
subjectDisplayName: z51.string().nullable().optional(),
|
|
23805
|
+
subjectSlug: z51.string().nullable().optional()
|
|
23294
23806
|
});
|
|
23295
|
-
var GetSessionUserSchema =
|
|
23296
|
-
tenantName:
|
|
23297
|
-
roles:
|
|
23807
|
+
var GetSessionUserSchema = z51.object({
|
|
23808
|
+
tenantName: z51.string().min(1),
|
|
23809
|
+
roles: z51.array(z51.string()),
|
|
23298
23810
|
subject: SessionSubjectSchema
|
|
23299
23811
|
});
|
|
23300
|
-
var GetSessionUnauthenticatedSchema =
|
|
23301
|
-
user:
|
|
23812
|
+
var GetSessionUnauthenticatedSchema = z51.object({
|
|
23813
|
+
user: z51.null()
|
|
23302
23814
|
});
|
|
23303
|
-
var GetSessionAuthenticatedSchema =
|
|
23815
|
+
var GetSessionAuthenticatedSchema = z51.object({
|
|
23304
23816
|
user: GetSessionUserSchema
|
|
23305
23817
|
});
|
|
23306
|
-
var GetSessionWireSchema =
|
|
23307
|
-
var TenantControlPlaneUrlSchema =
|
|
23308
|
-
controlPlaneURL:
|
|
23818
|
+
var GetSessionWireSchema = z51.union([GetSessionUnauthenticatedSchema, GetSessionAuthenticatedSchema]);
|
|
23819
|
+
var TenantControlPlaneUrlSchema = z51.object({
|
|
23820
|
+
controlPlaneURL: z51.url()
|
|
23309
23821
|
});
|
|
23310
|
-
var ListResponseSchema =
|
|
23311
|
-
|
|
23312
|
-
|
|
23313
|
-
data:
|
|
23314
|
-
pagination:
|
|
23822
|
+
var ListResponseSchema = z51.union([
|
|
23823
|
+
z51.array(z51.unknown()),
|
|
23824
|
+
z51.object({
|
|
23825
|
+
data: z51.array(z51.unknown()).catch([]),
|
|
23826
|
+
pagination: z51.object({ total: z51.number().optional() }).optional()
|
|
23315
23827
|
})
|
|
23316
23828
|
]);
|
|
23317
23829
|
var SERVICE_FOUNDRY_OPERATIONS = {
|
|
@@ -23334,34 +23846,34 @@ var SERVICE_FOUNDRY_OPERATIONS = {
|
|
|
23334
23846
|
vendToken: "vend_token",
|
|
23335
23847
|
peekUsers: "users"
|
|
23336
23848
|
};
|
|
23337
|
-
var ServiceFoundryErrorSchema =
|
|
23338
|
-
message:
|
|
23849
|
+
var ServiceFoundryErrorSchema = z51.object({
|
|
23850
|
+
message: z51.union([z51.string(), z51.array(z51.string())]).optional()
|
|
23339
23851
|
});
|
|
23340
|
-
var PutRemoteAgentResponseSchema =
|
|
23341
|
-
agentId:
|
|
23852
|
+
var PutRemoteAgentResponseSchema = z51.object({
|
|
23853
|
+
agentId: z51.string().min(1)
|
|
23342
23854
|
});
|
|
23343
|
-
var AgentPermissionSchema =
|
|
23344
|
-
var AgentPermissionsSchema =
|
|
23345
|
-
|
|
23346
|
-
|
|
23855
|
+
var AgentPermissionSchema = z51.enum(["READ_AGENT", "USE_AGENT", "MANAGE_AGENT", "DELETE_AGENT"]);
|
|
23856
|
+
var AgentPermissionsSchema = z51.record(
|
|
23857
|
+
z51.string(),
|
|
23858
|
+
z51.array(z51.string()).transform(
|
|
23347
23859
|
(permissions) => permissions.flatMap((permission) => {
|
|
23348
23860
|
const parsed = AgentPermissionSchema.safeParse(permission);
|
|
23349
23861
|
return parsed.success ? [parsed.data] : [];
|
|
23350
23862
|
})
|
|
23351
23863
|
)
|
|
23352
23864
|
);
|
|
23353
|
-
var VendTokenResponseSchema =
|
|
23354
|
-
subjectToken:
|
|
23355
|
-
actorToken:
|
|
23865
|
+
var VendTokenResponseSchema = z51.object({
|
|
23866
|
+
subjectToken: z51.string().min(1),
|
|
23867
|
+
actorToken: z51.string().min(1)
|
|
23356
23868
|
});
|
|
23357
|
-
var PeekUserSchema =
|
|
23358
|
-
id:
|
|
23359
|
-
name:
|
|
23360
|
-
email:
|
|
23869
|
+
var PeekUserSchema = z51.object({
|
|
23870
|
+
id: z51.string().min(1),
|
|
23871
|
+
name: z51.string().nullish(),
|
|
23872
|
+
email: z51.string().min(1)
|
|
23361
23873
|
});
|
|
23362
|
-
var PeekUsersResponseSchema =
|
|
23363
|
-
users:
|
|
23364
|
-
totalUsers:
|
|
23874
|
+
var PeekUsersResponseSchema = z51.object({
|
|
23875
|
+
users: z51.array(PeekUserSchema),
|
|
23876
|
+
totalUsers: z51.number().int().nonnegative()
|
|
23365
23877
|
});
|
|
23366
23878
|
async function readServiceFoundryErrorMessage(response) {
|
|
23367
23879
|
const body = await response.json().catch(() => void 0);
|
|
@@ -23766,7 +24278,7 @@ var TrueFoundryServiceFoundryServerClient = class {
|
|
|
23766
24278
|
accessToken: input.accessToken,
|
|
23767
24279
|
method: "GET"
|
|
23768
24280
|
});
|
|
23769
|
-
const parsed =
|
|
24281
|
+
const parsed = z51.array(z51.string()).safeParse(payload);
|
|
23770
24282
|
if (!parsed.success) {
|
|
23771
24283
|
this.#logger.error("TrueFoundry ServiceFoundry tenant permissions response was malformed", {
|
|
23772
24284
|
...extractErrorLogFields8(parsed.error),
|
|
@@ -24273,24 +24785,24 @@ init_mcpServerStore();
|
|
|
24273
24785
|
init_config();
|
|
24274
24786
|
import { SUPPORTED_REASONING_EFFORTS as SUPPORTED_REASONING_EFFORTS3 } from "@truefoundry/trueforge-core/core";
|
|
24275
24787
|
import { HTTPException as HTTPException29 } from "hono/http-exception";
|
|
24276
|
-
import { z as
|
|
24277
|
-
var ModelParamSchema =
|
|
24278
|
-
key:
|
|
24279
|
-
supportedValues:
|
|
24788
|
+
import { z as z52 } from "zod";
|
|
24789
|
+
var ModelParamSchema = z52.object({
|
|
24790
|
+
key: z52.string(),
|
|
24791
|
+
supportedValues: z52.array(z52.string()).optional()
|
|
24280
24792
|
});
|
|
24281
|
-
var MetadataSchema =
|
|
24282
|
-
limits:
|
|
24283
|
-
context_window:
|
|
24284
|
-
max_input_tokens:
|
|
24285
|
-
max_output_tokens:
|
|
24286
|
-
max_tokens:
|
|
24793
|
+
var MetadataSchema = z52.object({
|
|
24794
|
+
limits: z52.object({
|
|
24795
|
+
context_window: z52.number().optional(),
|
|
24796
|
+
max_input_tokens: z52.number().optional(),
|
|
24797
|
+
max_output_tokens: z52.number().optional(),
|
|
24798
|
+
max_tokens: z52.number().optional()
|
|
24287
24799
|
}).optional(),
|
|
24288
|
-
params:
|
|
24800
|
+
params: z52.array(ModelParamSchema).optional()
|
|
24289
24801
|
});
|
|
24290
|
-
var IntegrationSchema =
|
|
24291
|
-
name:
|
|
24292
|
-
manifest:
|
|
24293
|
-
providerAccount:
|
|
24802
|
+
var IntegrationSchema = z52.object({
|
|
24803
|
+
name: z52.string().min(1),
|
|
24804
|
+
manifest: z52.object({ model_types: z52.array(z52.string()).optional() }),
|
|
24805
|
+
providerAccount: z52.object({ name: z52.string().min(1) }),
|
|
24294
24806
|
metadata: MetadataSchema.optional()
|
|
24295
24807
|
});
|
|
24296
24808
|
function toReasoningEfforts(params) {
|
|
@@ -24348,11 +24860,11 @@ function filterEnvModels(input) {
|
|
|
24348
24860
|
const allowed = new Set(allowedAccounts);
|
|
24349
24861
|
return input.models.filter((model) => allowed.has(model.accountName));
|
|
24350
24862
|
}
|
|
24351
|
-
var InstallationSchema =
|
|
24352
|
-
isDefault:
|
|
24353
|
-
manifest:
|
|
24863
|
+
var InstallationSchema = z52.object({
|
|
24864
|
+
isDefault: z52.boolean().optional(),
|
|
24865
|
+
manifest: z52.object({ url: z52.string().min(1) })
|
|
24354
24866
|
});
|
|
24355
|
-
var InstallationsEnvelopeSchema =
|
|
24867
|
+
var InstallationsEnvelopeSchema = z52.union([z52.array(z52.unknown()), z52.object({ data: z52.array(z52.unknown()) })]);
|
|
24356
24868
|
function resolveDefaultGatewayUrl(payload) {
|
|
24357
24869
|
const envelope = InstallationsEnvelopeSchema.parse(payload);
|
|
24358
24870
|
const rows = Array.isArray(envelope) ? envelope : envelope.data;
|