@agent-native/core 0.11.1 → 0.11.2
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/thread-data-builder.d.ts +1 -0
- package/dist/agent/thread-data-builder.d.ts.map +1 -1
- package/dist/agent/thread-data-builder.js +1 -0
- package/dist/agent/thread-data-builder.js.map +1 -1
- package/dist/client/AgentPanel.js +2 -2
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +71 -6
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/components/ui/dropdown-menu.js +2 -2
- package/dist/client/components/ui/dropdown-menu.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +6 -6
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/client/settings/useBuilderStatus.d.ts.map +1 -1
- package/dist/client/settings/useBuilderStatus.js +6 -2
- package/dist/client/settings/useBuilderStatus.js.map +1 -1
- package/dist/client/sharing/ShareButton.d.ts +2 -0
- package/dist/client/sharing/ShareButton.d.ts.map +1 -1
- package/dist/client/sharing/ShareButton.js +26 -3
- package/dist/client/sharing/ShareButton.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts +14 -0
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +77 -12
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/builder-browser.d.ts +8 -6
- package/dist/server/builder-browser.d.ts.map +1 -1
- package/dist/server/builder-browser.js +54 -32
- package/dist/server/builder-browser.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts +7 -0
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +100 -74
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/package.json +1 -1
|
@@ -58,6 +58,9 @@ function wrapCliScript(tool, cliDefault, opts) {
|
|
|
58
58
|
},
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
+
function filterReadOnlyActions(actions) {
|
|
62
|
+
return Object.fromEntries(Object.entries(actions).filter(([, entry]) => entry.readOnly === true));
|
|
63
|
+
}
|
|
61
64
|
function resolveArtifactBaseUrl(event) {
|
|
62
65
|
const fromEnv = process.env.APP_URL ||
|
|
63
66
|
process.env.URL ||
|
|
@@ -2530,17 +2533,36 @@ export function createAgentChatPlugin(options) {
|
|
|
2530
2533
|
return accumulatedText || "(no response)";
|
|
2531
2534
|
},
|
|
2532
2535
|
});
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
statusMessage: "Unauthenticated",
|
|
2541
|
-
});
|
|
2536
|
+
const OWNER_CONTEXT_KEY = "__agentNativeOwnerContext";
|
|
2537
|
+
// Resolve owner from the H3 event's session, with an optional
|
|
2538
|
+
// template-provided anonymous owner for public read-only surfaces.
|
|
2539
|
+
const resolveOwnerContext = async (event) => {
|
|
2540
|
+
const eventContext = event?.context;
|
|
2541
|
+
if (eventContext?.[OWNER_CONTEXT_KEY]) {
|
|
2542
|
+
return eventContext[OWNER_CONTEXT_KEY];
|
|
2542
2543
|
}
|
|
2543
|
-
|
|
2544
|
+
const session = await getSession(event);
|
|
2545
|
+
if (session?.email) {
|
|
2546
|
+
const resolved = { owner: session.email, anonymous: false };
|
|
2547
|
+
if (eventContext)
|
|
2548
|
+
eventContext[OWNER_CONTEXT_KEY] = resolved;
|
|
2549
|
+
return resolved;
|
|
2550
|
+
}
|
|
2551
|
+
const anonymousOwner = await options?.anonymousOwner?.(event);
|
|
2552
|
+
if (anonymousOwner) {
|
|
2553
|
+
const resolved = { owner: anonymousOwner, anonymous: true };
|
|
2554
|
+
if (eventContext)
|
|
2555
|
+
eventContext[OWNER_CONTEXT_KEY] = resolved;
|
|
2556
|
+
return resolved;
|
|
2557
|
+
}
|
|
2558
|
+
const { createError } = await import("h3");
|
|
2559
|
+
throw createError({
|
|
2560
|
+
statusCode: 401,
|
|
2561
|
+
statusMessage: "Unauthenticated",
|
|
2562
|
+
});
|
|
2563
|
+
};
|
|
2564
|
+
const getOwnerFromEvent = async (event) => {
|
|
2565
|
+
return (await resolveOwnerContext(event)).owner;
|
|
2544
2566
|
};
|
|
2545
2567
|
// Auto-mount template actions as HTTP endpoints under /_agent-native/actions/
|
|
2546
2568
|
// Include engine management script so the UI can call manage-agent-engine.
|
|
@@ -2776,6 +2798,7 @@ export function createAgentChatPlugin(options) {
|
|
|
2776
2798
|
...chatScripts,
|
|
2777
2799
|
...toolActions,
|
|
2778
2800
|
});
|
|
2801
|
+
const anonymousReadOnlyActions = attachToolSearch(filterReadOnlyActions(templateScripts));
|
|
2779
2802
|
const prodActions = attachToolSearch({
|
|
2780
2803
|
...templateScripts,
|
|
2781
2804
|
...resourceScripts,
|
|
@@ -2810,6 +2833,9 @@ export function createAgentChatPlugin(options) {
|
|
|
2810
2833
|
// Skip resource loading and schema block — those add DB round-trips
|
|
2811
2834
|
// and tokens that minimal/voice apps don't need.
|
|
2812
2835
|
const leanBasePrompt = (options?.systemPrompt ?? "") + prodActionsPrompt;
|
|
2836
|
+
const anonymousReadOnlyPrompt = (options?.systemPrompt ?? PROD_FRAMEWORK_PROMPT_COMPACT) +
|
|
2837
|
+
generateActionsPrompt(filterReadOnlyActions(templateScripts), "tool") +
|
|
2838
|
+
"\n\nYou are answering from a public shared page. Treat the visible resource as read-only: do not create, edit, delete, comment on, share, or otherwise mutate app data. If the user asks for a change, describe what you would change or suggest signing in to edit.";
|
|
2813
2839
|
// Per-request preamble shared by both prod and dev handlers. Resolves
|
|
2814
2840
|
// owner + user API key onto the AsyncLocalStorage run context so
|
|
2815
2841
|
// downstream tool closures (automation, fetch, team) read the
|
|
@@ -2886,6 +2912,40 @@ export function createAgentChatPlugin(options) {
|
|
|
2886
2912
|
// Resolve owner from session for usage attribution in hosted prod
|
|
2887
2913
|
resolveOwnerEmail: isHostedProd ? getOwnerFromEvent : undefined,
|
|
2888
2914
|
});
|
|
2915
|
+
const anonymousHandler = options?.anonymousOwner && options.anonymousReadOnly !== false
|
|
2916
|
+
? createProductionAgentHandler({
|
|
2917
|
+
actions: anonymousReadOnlyActions,
|
|
2918
|
+
systemPrompt: async (event) => {
|
|
2919
|
+
const { extra } = await prepareRun(event);
|
|
2920
|
+
return setSystemPromptOnContext(anonymousReadOnlyPrompt +
|
|
2921
|
+
runtimeContextForEvent(event) +
|
|
2922
|
+
extra);
|
|
2923
|
+
},
|
|
2924
|
+
model: options?.model ?? DEFAULT_MODEL,
|
|
2925
|
+
apiKey: options?.apiKey,
|
|
2926
|
+
runSoftTimeoutMs: options?.runSoftTimeoutMs,
|
|
2927
|
+
skipFilesContext: true,
|
|
2928
|
+
onEngineResolved: (engine, model) => {
|
|
2929
|
+
const runCtx = ensureRequestRunContext();
|
|
2930
|
+
if (runCtx) {
|
|
2931
|
+
runCtx.engine = engine;
|
|
2932
|
+
runCtx.model = model;
|
|
2933
|
+
}
|
|
2934
|
+
},
|
|
2935
|
+
onRunStart: (send, threadId) => {
|
|
2936
|
+
_runSendByThread.set(threadId, send);
|
|
2937
|
+
const runCtx = ensureRequestRunContext();
|
|
2938
|
+
if (runCtx)
|
|
2939
|
+
runCtx.threadId = threadId;
|
|
2940
|
+
},
|
|
2941
|
+
onRunComplete: async (run, threadId) => {
|
|
2942
|
+
if (threadId)
|
|
2943
|
+
_runSendByThread.delete(threadId);
|
|
2944
|
+
await onRunComplete(run, threadId);
|
|
2945
|
+
},
|
|
2946
|
+
resolveOwnerEmail: getOwnerFromEvent,
|
|
2947
|
+
})
|
|
2948
|
+
: null;
|
|
2889
2949
|
// Build the dev handler (with filesystem/shell/db tools) if environment allows toggling
|
|
2890
2950
|
let devHandler = null;
|
|
2891
2951
|
if (canToggle) {
|
|
@@ -3800,7 +3860,8 @@ export function createAgentChatPlugin(options) {
|
|
|
3800
3860
|
return { error: "Not found" };
|
|
3801
3861
|
}
|
|
3802
3862
|
// Resolve per-request auth context
|
|
3803
|
-
const
|
|
3863
|
+
const ownerContext = await resolveOwnerContext(event);
|
|
3864
|
+
const owner = ownerContext.owner;
|
|
3804
3865
|
// Resolve org ID: explicit callback > session.orgId from Better Auth
|
|
3805
3866
|
let resolvedOrgId;
|
|
3806
3867
|
if (options?.resolveOrgId) {
|
|
@@ -3825,7 +3886,11 @@ export function createAgentChatPlugin(options) {
|
|
|
3825
3886
|
? tzRaw.trim()
|
|
3826
3887
|
: undefined;
|
|
3827
3888
|
return runWithRequestContext({ userEmail: owner, orgId: resolvedOrgId, timezone }, () => {
|
|
3828
|
-
const handler =
|
|
3889
|
+
const handler = ownerContext.anonymous && anonymousHandler
|
|
3890
|
+
? anonymousHandler
|
|
3891
|
+
: currentDevMode && devHandler
|
|
3892
|
+
? devHandler
|
|
3893
|
+
: prodHandler;
|
|
3829
3894
|
return handler(event);
|
|
3830
3895
|
});
|
|
3831
3896
|
}));
|