@agent-native/core 0.12.24 → 0.12.27
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/agent/production-agent.d.ts +9 -2
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +56 -37
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/thread-data-builder.d.ts +16 -1
- package/dist/agent/thread-data-builder.d.ts.map +1 -1
- package/dist/agent/thread-data-builder.js +132 -0
- package/dist/agent/thread-data-builder.js.map +1 -1
- package/dist/client/AgentTaskCard.d.ts.map +1 -1
- package/dist/client/AgentTaskCard.js +16 -3
- package/dist/client/AgentTaskCard.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +22 -12
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/IframeEmbed.d.ts.map +1 -1
- package/dist/client/IframeEmbed.js +2 -2
- package/dist/client/IframeEmbed.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +77 -12
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/composer/ComposerPlusMenu.d.ts.map +1 -1
- package/dist/client/composer/ComposerPlusMenu.js +1 -1
- package/dist/client/composer/ComposerPlusMenu.js.map +1 -1
- package/dist/client/composer/PromptComposer.d.ts.map +1 -1
- package/dist/client/composer/PromptComposer.js +8 -7
- package/dist/client/composer/PromptComposer.js.map +1 -1
- package/dist/client/composer/attachment-accept.d.ts +7 -0
- package/dist/client/composer/attachment-accept.d.ts.map +1 -0
- package/dist/client/composer/attachment-accept.js +36 -0
- package/dist/client/composer/attachment-accept.js.map +1 -0
- package/dist/client/progress/RunsTray.d.ts.map +1 -1
- package/dist/client/progress/RunsTray.js +3 -1
- package/dist/client/progress/RunsTray.js.map +1 -1
- package/dist/client/sse-event-processor.d.ts.map +1 -1
- package/dist/client/sse-event-processor.js +12 -1
- package/dist/client/sse-event-processor.js.map +1 -1
- package/dist/db/client.d.ts +3 -0
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +70 -34
- package/dist/db/client.js.map +1 -1
- package/dist/db/create-get-db.d.ts.map +1 -1
- package/dist/db/create-get-db.js +30 -7
- package/dist/db/create-get-db.js.map +1 -1
- package/dist/deploy/build.js +64 -0
- package/dist/deploy/build.js.map +1 -1
- package/dist/onboarding/default-steps.d.ts.map +1 -1
- package/dist/onboarding/default-steps.js +8 -1
- package/dist/onboarding/default-steps.js.map +1 -1
- package/dist/scripts/db/exec.d.ts.map +1 -1
- package/dist/scripts/db/exec.js +3 -6
- package/dist/scripts/db/exec.js.map +1 -1
- package/dist/scripts/db/patch.d.ts.map +1 -1
- package/dist/scripts/db/patch.js +3 -6
- package/dist/scripts/db/patch.js.map +1 -1
- package/dist/scripts/db/query.d.ts.map +1 -1
- package/dist/scripts/db/query.js +3 -6
- package/dist/scripts/db/query.js.map +1 -1
- package/dist/scripts/db/schema.d.ts.map +1 -1
- package/dist/scripts/db/schema.js +3 -6
- package/dist/scripts/db/schema.js.map +1 -1
- package/dist/scripts/db/sqlite-client.d.ts +15 -0
- package/dist/scripts/db/sqlite-client.d.ts.map +1 -0
- package/dist/scripts/db/sqlite-client.js +51 -0
- package/dist/scripts/db/sqlite-client.js.map +1 -0
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +53 -2
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/better-auth-instance.js +4 -3
- package/dist/server/better-auth-instance.js.map +1 -1
- package/dist/server/credential-provider.d.ts +2 -2
- package/dist/server/credential-provider.d.ts.map +1 -1
- package/dist/server/credential-provider.js +22 -1
- package/dist/server/credential-provider.js.map +1 -1
- package/dist/server/google-oauth.js +1 -1
- package/dist/server/google-oauth.js.map +1 -1
- package/package.json +1 -1
|
@@ -25,8 +25,8 @@ export declare function engineToProvider(engineName: string): string;
|
|
|
25
25
|
/**
|
|
26
26
|
* Resolve the active engine's provider and look up the user's API key for it.
|
|
27
27
|
*
|
|
28
|
-
* In
|
|
29
|
-
*
|
|
28
|
+
* In shared hosted deploys we deliberately refuse the deploy-level fallback
|
|
29
|
+
* for authenticated users. Without that gate any
|
|
30
30
|
* signed-in user who hasn't configured their own provider key would silently
|
|
31
31
|
* inherit the deployment's key (uncapped billing on the owner's account,
|
|
32
32
|
* prompt logging tied to the deployment owner) — exactly the prior-incident
|
|
@@ -94,6 +94,13 @@ export interface ProductionAgentOptions {
|
|
|
94
94
|
providerOptions?: EngineMessage extends never ? never : any;
|
|
95
95
|
/** Called when a run completes (for server-side thread persistence) */
|
|
96
96
|
onRunComplete?: (run: ActiveRun, threadId: string | undefined) => void;
|
|
97
|
+
/** Called after request validation but before a run is started. */
|
|
98
|
+
onRunPrepared?: (details: {
|
|
99
|
+
runId: string;
|
|
100
|
+
threadId: string | undefined;
|
|
101
|
+
message: string;
|
|
102
|
+
attachments?: AgentChatAttachment[];
|
|
103
|
+
}) => void | Promise<void>;
|
|
97
104
|
/** Optional per-app agent run chunk budget in milliseconds. Defaults to
|
|
98
105
|
* AGENT_RUN_SOFT_TIMEOUT_MS when set, otherwise no framework-imposed
|
|
99
106
|
* timeout. When reached, the client receives an internal auto-continuation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"production-agent.d.ts","sourceRoot":"","sources":["../../src/agent/production-agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"production-agent.d.ts","sourceRoot":"","sources":["../../src/agent/production-agent.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EAEnB,cAAc,EAEd,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAQ3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GAAG,YAAY,GAAG,cAAc,QAiBtD;AAwDD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GACnC,UAAU,EAAE,CAiBd;AAmED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE;IACvC,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACrC,IAAI,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IACtC,MAAM,EAAE,WAAW,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,eAAe,CAAC,EAAE,GAAG,CAAC;IACtB,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,2BAA2B,CAAC;CAClD,GAAG,OAAO,CAAC,cAAc,CAAC,CAie1B;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,sBAAsB,GAC9B,cAAc,CAszBhB;AAED,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,MAAM,EACN,QAAQ,EACR,cAAc,GACf,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { defineEventHandler, setResponseHeader, setResponseStatus, getMethod, } from "h3";
|
|
2
|
-
import {
|
|
3
|
-
import { readDeployCredentialEnv } from "../server/credential-provider.js";
|
|
2
|
+
import { isDeployCredentialFallbackAllowed, readDeployCredentialEnv, } from "../server/credential-provider.js";
|
|
4
3
|
import { EngineError } from "./engine/types.js";
|
|
5
4
|
import { resolveEngine, registerBuiltinEngines, getStoredModelForEngine, } from "./engine/index.js";
|
|
6
5
|
import { userFacingLlmCredentialError } from "./engine/credential-errors.js";
|
|
@@ -79,31 +78,20 @@ export function engineToProvider(engineName) {
|
|
|
79
78
|
return engineName.startsWith("ai-sdk:") ? engineName.slice(7) : engineName;
|
|
80
79
|
}
|
|
81
80
|
/**
|
|
82
|
-
* Returns true when this process
|
|
83
|
-
*
|
|
84
|
-
* silently substituted with the deploy-level API key.
|
|
81
|
+
* Returns true when this process should block generic deploy-level provider
|
|
82
|
+
* credentials for signed-in chat requests.
|
|
85
83
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* Heuristic:
|
|
89
|
-
* - `NODE_ENV === "production"`, AND
|
|
90
|
-
* - The DB is not a local file (i.e. it's Neon/Postgres/Turso/D1 — any
|
|
91
|
-
* backend that could be shared across multiple users).
|
|
92
|
-
*
|
|
93
|
-
* Self-hosted single-tenant deployments (a local sqlite file, or NODE_ENV
|
|
94
|
-
* unset/development) keep the env-var fallback so the original BYO-server
|
|
95
|
-
* UX continues to work without a per-user key.
|
|
84
|
+
* Self-hosted single-tenant deployments keep the env-var fallback so the
|
|
85
|
+
* original BYO-server UX continues to work without a per-user key.
|
|
96
86
|
*/
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
return false;
|
|
100
|
-
return !isLocalDatabase();
|
|
87
|
+
function shouldBlockDeployCredentialFallback() {
|
|
88
|
+
return !isDeployCredentialFallbackAllowed();
|
|
101
89
|
}
|
|
102
90
|
/**
|
|
103
91
|
* Resolve the active engine's provider and look up the user's API key for it.
|
|
104
92
|
*
|
|
105
|
-
* In
|
|
106
|
-
*
|
|
93
|
+
* In shared hosted deploys we deliberately refuse the deploy-level fallback
|
|
94
|
+
* for authenticated users. Without that gate any
|
|
107
95
|
* signed-in user who hasn't configured their own provider key would silently
|
|
108
96
|
* inherit the deployment's key (uncapped billing on the owner's account,
|
|
109
97
|
* prompt logging tied to the deployment owner) — exactly the prior-incident
|
|
@@ -124,11 +112,12 @@ export async function getOwnerActiveApiKey(ownerEmail) {
|
|
|
124
112
|
const userKey = await getOwnerApiKey(provider, ownerEmail);
|
|
125
113
|
if (userKey)
|
|
126
114
|
return userKey;
|
|
127
|
-
if (
|
|
128
|
-
//
|
|
129
|
-
// background context with no owner) gets undefined
|
|
130
|
-
// no user to bill, and the call site must surface a
|
|
131
|
-
// error to the requester rather than silently using
|
|
115
|
+
if (shouldBlockDeployCredentialFallback()) {
|
|
116
|
+
// Shared hosted default: refuse the env fallback. A null user
|
|
117
|
+
// (unauthenticated / background context with no owner) gets undefined
|
|
118
|
+
// here too — there's no user to bill, and the call site must surface a
|
|
119
|
+
// "configure a key" error to the requester rather than silently using
|
|
120
|
+
// the deploy key.
|
|
132
121
|
return undefined;
|
|
133
122
|
}
|
|
134
123
|
const envVar = PROVIDER_TO_ENV[provider];
|
|
@@ -722,6 +711,7 @@ export async function runAgentLoop(opts) {
|
|
|
722
711
|
}
|
|
723
712
|
const readOnlyToolResultCache = seedReadOnlyToolResultsFromHistory(messages, actions);
|
|
724
713
|
const duplicateReadOnlyToolCalls = new Map();
|
|
714
|
+
const bufferTextUntilFinalGuard = Boolean(opts.finalResponseGuard);
|
|
725
715
|
let finalGuardRetries = 0;
|
|
726
716
|
let iterations = 0;
|
|
727
717
|
while (true) {
|
|
@@ -732,9 +722,11 @@ export async function runAgentLoop(opts) {
|
|
|
732
722
|
iterations = 1;
|
|
733
723
|
}
|
|
734
724
|
let assistantContent;
|
|
725
|
+
let bufferedAssistantText = "";
|
|
735
726
|
const toolCallErrors = new Map();
|
|
736
727
|
for (let retry = 0;; retry++) {
|
|
737
728
|
assistantContent = undefined;
|
|
729
|
+
bufferedAssistantText = "";
|
|
738
730
|
toolCallErrors.clear();
|
|
739
731
|
try {
|
|
740
732
|
const streamOpts = {
|
|
@@ -765,7 +757,12 @@ export async function runAgentLoop(opts) {
|
|
|
765
757
|
};
|
|
766
758
|
for await (const event of eventStream) {
|
|
767
759
|
if (event.type === "text-delta") {
|
|
768
|
-
|
|
760
|
+
if (bufferTextUntilFinalGuard) {
|
|
761
|
+
bufferedAssistantText += event.text;
|
|
762
|
+
}
|
|
763
|
+
else {
|
|
764
|
+
send({ type: "text", text: event.text });
|
|
765
|
+
}
|
|
769
766
|
}
|
|
770
767
|
else if (event.type === "thinking-delta") {
|
|
771
768
|
thinkingBuffer += event.text;
|
|
@@ -860,6 +857,13 @@ export async function runAgentLoop(opts) {
|
|
|
860
857
|
: part);
|
|
861
858
|
messages.push({ role: "assistant", content: assistantContentForHistory });
|
|
862
859
|
const toolCallParts = assistantContent.filter((p) => p.type === "tool-call");
|
|
860
|
+
const flushBufferedAssistantText = () => {
|
|
861
|
+
if (!bufferTextUntilFinalGuard)
|
|
862
|
+
return;
|
|
863
|
+
const text = bufferedAssistantText || collectTextParts(assistantContentForHistory);
|
|
864
|
+
if (text)
|
|
865
|
+
send({ type: "text", text });
|
|
866
|
+
};
|
|
863
867
|
if (toolCallParts.length === 0) {
|
|
864
868
|
const guard = opts.finalResponseGuard
|
|
865
869
|
? await opts.finalResponseGuard({
|
|
@@ -874,7 +878,6 @@ export async function runAgentLoop(opts) {
|
|
|
874
878
|
if (guard) {
|
|
875
879
|
const retryMessage = typeof guard === "string" ? guard : guard.retryMessage;
|
|
876
880
|
const fallbackMessage = typeof guard === "string" ? guard : guard.fallbackMessage;
|
|
877
|
-
send({ type: "clear" });
|
|
878
881
|
if (finalGuardRetries < 1) {
|
|
879
882
|
finalGuardRetries += 1;
|
|
880
883
|
messages.push({
|
|
@@ -885,8 +888,12 @@ export async function runAgentLoop(opts) {
|
|
|
885
888
|
}
|
|
886
889
|
send({ type: "text", text: fallbackMessage ?? retryMessage });
|
|
887
890
|
}
|
|
891
|
+
else {
|
|
892
|
+
flushBufferedAssistantText();
|
|
893
|
+
}
|
|
888
894
|
break;
|
|
889
895
|
}
|
|
896
|
+
flushBufferedAssistantText();
|
|
890
897
|
let requestedActionStop = null;
|
|
891
898
|
const runToolCall = async (toolCall) => {
|
|
892
899
|
toolCallHistory.push({
|
|
@@ -1136,7 +1143,7 @@ export function createProductionAgentHandler(options) {
|
|
|
1136
1143
|
setResponseStatus(event, 400);
|
|
1137
1144
|
return { error: "Invalid request body" };
|
|
1138
1145
|
}
|
|
1139
|
-
const { message, history = [], structuredHistory, references = [], threadId, attachments, model: requestModel, engine: requestEngine, effort: requestEffort, } = body;
|
|
1146
|
+
const { message, history = [], structuredHistory, references = [], threadId, attachments, displayMessage, internalContinuation, model: requestModel, engine: requestEngine, effort: requestEffort, } = body;
|
|
1140
1147
|
const requestMode = body.mode === "plan" ? "plan" : "act";
|
|
1141
1148
|
const hasMessageText = typeof message === "string" && message.trim().length > 0;
|
|
1142
1149
|
const hasAttachments = Array.isArray(attachments) && attachments.length > 0;
|
|
@@ -1157,11 +1164,11 @@ export function createProductionAgentHandler(options) {
|
|
|
1157
1164
|
if (requestEngine) {
|
|
1158
1165
|
const provider = engineToProvider(requestEngine);
|
|
1159
1166
|
userApiKey = await getOwnerApiKey(provider, ownerEmail);
|
|
1160
|
-
if (!userApiKey && !
|
|
1161
|
-
// Single-tenant only: env fallback for the requested provider.
|
|
1162
|
-
//
|
|
1163
|
-
//
|
|
1164
|
-
//
|
|
1167
|
+
if (!userApiKey && !shouldBlockDeployCredentialFallback()) {
|
|
1168
|
+
// Single-tenant only: env fallback for the requested provider. Shared
|
|
1169
|
+
// hosted deploys never silently substitute the deploy-level key for
|
|
1170
|
+
// an authenticated user (see getOwnerActiveApiKey for the full
|
|
1171
|
+
// rationale).
|
|
1165
1172
|
const envVar = PROVIDER_TO_ENV[provider];
|
|
1166
1173
|
userApiKey = envVar ? readDeployCredentialEnv(envVar) : undefined;
|
|
1167
1174
|
}
|
|
@@ -1170,11 +1177,12 @@ export function createProductionAgentHandler(options) {
|
|
|
1170
1177
|
userApiKey = await getOwnerActiveApiKey(ownerEmail);
|
|
1171
1178
|
}
|
|
1172
1179
|
// `options.apiKey` is the value the template constructed the plugin with
|
|
1173
|
-
// (e.g. wired from a deployment env var). On a
|
|
1180
|
+
// (e.g. wired from a deployment env var). On a shared hosted deploy this
|
|
1174
1181
|
// is the same cross-tenant hazard as any deploy-level provider key:
|
|
1175
1182
|
// accepting it as the final fallback would silently bill every key-less
|
|
1176
|
-
// user to the deployment's account.
|
|
1177
|
-
|
|
1183
|
+
// user to the deployment's account. Honour it only when the generic
|
|
1184
|
+
// deploy fallback policy allows it.
|
|
1185
|
+
const effectiveApiKey = shouldBlockDeployCredentialFallback()
|
|
1178
1186
|
? userApiKey
|
|
1179
1187
|
: (userApiKey ??
|
|
1180
1188
|
options.apiKey ??
|
|
@@ -1453,6 +1461,17 @@ export function createProductionAgentHandler(options) {
|
|
|
1453
1461
|
}
|
|
1454
1462
|
// Start agent loop in background via run-manager
|
|
1455
1463
|
const runId = generateRunId();
|
|
1464
|
+
if (options.onRunPrepared && !internalContinuation) {
|
|
1465
|
+
const messageToPersist = typeof displayMessage === "string" && displayMessage.trim().length > 0
|
|
1466
|
+
? displayMessage
|
|
1467
|
+
: requestMessage;
|
|
1468
|
+
await options.onRunPrepared({
|
|
1469
|
+
runId,
|
|
1470
|
+
threadId,
|
|
1471
|
+
message: messageToPersist,
|
|
1472
|
+
attachments: Array.isArray(attachments) ? attachments : [],
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1456
1475
|
startRun(runId, threadId ?? runId, async (send, signal) => {
|
|
1457
1476
|
// Notify listeners that a run has started (used by agent teams)
|
|
1458
1477
|
if (options.onRunStart) {
|