@agent-native/core 0.11.3 → 0.11.4
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/index.d.ts +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/production-agent.d.ts +29 -0
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +57 -2
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +10 -6
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +1 -1
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/ConnectBuilderCard.d.ts +3 -3
- package/dist/client/ConnectBuilderCard.d.ts.map +1 -1
- package/dist/client/ConnectBuilderCard.js +5 -6
- package/dist/client/ConnectBuilderCard.js.map +1 -1
- package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +8 -6
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/NewWorkspaceAppFlow.d.ts.map +1 -1
- package/dist/client/NewWorkspaceAppFlow.js +2 -0
- package/dist/client/NewWorkspaceAppFlow.js.map +1 -1
- package/dist/client/composer/TiptapComposer.js +2 -2
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/extensions/ExtensionsListPage.d.ts.map +1 -1
- package/dist/client/extensions/ExtensionsListPage.js +36 -4
- package/dist/client/extensions/ExtensionsListPage.js.map +1 -1
- package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
- package/dist/client/settings/SettingsPanel.js +2 -1
- package/dist/client/settings/SettingsPanel.js.map +1 -1
- package/dist/client/settings/useBuilderStatus.d.ts +5 -3
- package/dist/client/settings/useBuilderStatus.d.ts.map +1 -1
- package/dist/client/settings/useBuilderStatus.js.map +1 -1
- package/dist/extensions/actions.js +1 -1
- package/dist/extensions/actions.js.map +1 -1
- package/dist/extensions/html-shell.d.ts.map +1 -1
- package/dist/extensions/html-shell.js +47 -1
- package/dist/extensions/html-shell.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts +6 -0
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +6 -2
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/builder-browser.d.ts +2 -0
- package/dist/server/builder-browser.d.ts.map +1 -1
- package/dist/server/builder-browser.js +24 -0
- package/dist/server/builder-browser.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +46 -29
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/request-context.d.ts +11 -0
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/request-context.js.map +1 -1
- package/dist/templates/workspace-core/AGENTS.md +19 -3
- package/dist/templates/workspace-root/AGENTS.md +20 -0
- package/dist/templates/workspace-root/README.md +6 -0
- package/docs/content/extensions.md +12 -11
- package/package.json +1 -1
- package/src/templates/workspace-core/AGENTS.md +19 -3
- package/src/templates/workspace-root/AGENTS.md +20 -0
- package/src/templates/workspace-root/README.md +6 -0
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createProductionAgentHandler, type ActionEntry, type ScriptEntry, type ProductionAgentOptions, } from "./production-agent.js";
|
|
1
|
+
export { createProductionAgentHandler, type ActionEntry, type ScriptEntry, type ProductionAgentOptions, type AgentLoopFinalResponseGuard, type AgentLoopFinalResponseGuardContext, type AgentLoopFinalResponseGuardResult, type AgentLoopToolCallSummary, type AgentLoopToolResultSummary, } from "./production-agent.js";
|
|
2
2
|
export { type ActionTool, type ScriptTool, type AgentMessage, type AgentChatRequest, type AgentChatEvent, type AgentChatReference, type MentionProvider, type MentionProviderItem, } from "./types.js";
|
|
3
3
|
export { DEFAULT_MODEL } from "./default-model.js";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,sBAAsB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,kCAAkC,EACvC,KAAK,iCAAiC,EACtC,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/agent/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,GAS7B,MAAM,uBAAuB,CAAC;AAW/B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export {\n createProductionAgentHandler,\n type ActionEntry,\n type ScriptEntry,\n type ProductionAgentOptions,\n type AgentLoopFinalResponseGuard,\n type AgentLoopFinalResponseGuardContext,\n type AgentLoopFinalResponseGuardResult,\n type AgentLoopToolCallSummary,\n type AgentLoopToolResultSummary,\n} from \"./production-agent.js\";\nexport {\n type ActionTool,\n type ScriptTool,\n type AgentMessage,\n type AgentChatRequest,\n type AgentChatEvent,\n type AgentChatReference,\n type MentionProvider,\n type MentionProviderItem,\n} from \"./types.js\";\nexport { DEFAULT_MODEL } from \"./default-model.js\";\n"]}
|
|
@@ -109,6 +109,12 @@ export interface ProductionAgentOptions {
|
|
|
109
109
|
onEngineResolved?: (engine: AgentEngine, model: string) => void;
|
|
110
110
|
/** Resolve the owner email from the H3 event (for usage tracking) */
|
|
111
111
|
resolveOwnerEmail?: (event: any) => string | Promise<string>;
|
|
112
|
+
/**
|
|
113
|
+
* Optional final-answer guard. If it returns a message after a text-only
|
|
114
|
+
* assistant turn, the loop clears that draft once and asks the model to
|
|
115
|
+
* continue with the returned corrective instruction before allowing a final.
|
|
116
|
+
*/
|
|
117
|
+
finalResponseGuard?: AgentLoopFinalResponseGuard;
|
|
112
118
|
/**
|
|
113
119
|
* Skip auto-injecting the workspace files/skills/agents inventory on the
|
|
114
120
|
* first message of a conversation. Useful for minimal/voice apps where
|
|
@@ -129,6 +135,28 @@ export interface AgentLoopUsage {
|
|
|
129
135
|
cacheWriteTokens: number;
|
|
130
136
|
model: string;
|
|
131
137
|
}
|
|
138
|
+
export interface AgentLoopToolCallSummary {
|
|
139
|
+
name: string;
|
|
140
|
+
input: unknown;
|
|
141
|
+
}
|
|
142
|
+
export interface AgentLoopToolResultSummary {
|
|
143
|
+
name: string;
|
|
144
|
+
content: string;
|
|
145
|
+
isError: boolean;
|
|
146
|
+
}
|
|
147
|
+
export interface AgentLoopFinalResponseGuardContext {
|
|
148
|
+
messages: EngineMessage[];
|
|
149
|
+
assistantContent: EngineContentPart[];
|
|
150
|
+
text: string;
|
|
151
|
+
toolCalls: AgentLoopToolCallSummary[];
|
|
152
|
+
toolResults: AgentLoopToolResultSummary[];
|
|
153
|
+
retryCount: number;
|
|
154
|
+
}
|
|
155
|
+
export type AgentLoopFinalResponseGuardResult = string | {
|
|
156
|
+
retryMessage: string;
|
|
157
|
+
fallbackMessage?: string;
|
|
158
|
+
};
|
|
159
|
+
export type AgentLoopFinalResponseGuard = (context: AgentLoopFinalResponseGuardContext) => AgentLoopFinalResponseGuardResult | null | undefined | Promise<AgentLoopFinalResponseGuardResult | null | undefined>;
|
|
132
160
|
export declare const AGENT_INTERNAL_CONTINUE_PROMPT = "Continue from where you left off and finish the user's original request. Do not repeat completed work, do not mention internal reconnects, time limits, or step limits, and continue as if this is the same uninterrupted run.";
|
|
133
161
|
export declare function appendAgentLoopContinuation(messages: EngineMessage[], reason: "run_timeout" | "loop_limit" | "stream_ended"): void;
|
|
134
162
|
/**
|
|
@@ -155,6 +183,7 @@ export declare function runAgentLoop(opts: {
|
|
|
155
183
|
providerOptions?: any;
|
|
156
184
|
executionMode?: AgentExecutionMode;
|
|
157
185
|
maxIterations?: number;
|
|
186
|
+
finalResponseGuard?: AgentLoopFinalResponseGuard;
|
|
158
187
|
}): Promise<AgentLoopUsage>;
|
|
159
188
|
export declare function createProductionAgentHandler(options: ProductionAgentOptions): H3EventHandler;
|
|
160
189
|
export { getActiveRunForThread, getActiveRunForThreadAsync, getRun, abortRun, subscribeToRun, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"production-agent.d.ts","sourceRoot":"","sources":["../../src/agent/production-agent.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EAEnB,cAAc,EAEf,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,aAAa,EACb,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B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,oBAAoB,CAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GACnC,UAAU,EAAE,CAiBd;AAiDD;;;;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,CAoY1B;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,sBAAsB,GAC9B,cAAc,CAmyBhB;AAED,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,MAAM,EACN,QAAQ,EACR,cAAc,GACf,CAAC"}
|
|
@@ -8,7 +8,7 @@ import { PROVIDER_TO_ENV } from "./engine/provider-env-vars.js";
|
|
|
8
8
|
import { readAppState } from "../application-state/script-helpers.js";
|
|
9
9
|
import { startRun, subscribeToRun, getActiveRunForThread, getActiveRunForThreadAsync, getRun, abortRun, } from "./run-manager.js";
|
|
10
10
|
import { readBody } from "../server/h3-helpers.js";
|
|
11
|
-
import { getRequestOrgId, getRequestUserEmail, } from "../server/request-context.js";
|
|
11
|
+
import { getRequestRunContext, getRequestOrgId, getRequestUserEmail, } from "../server/request-context.js";
|
|
12
12
|
import { isMcpToolAllowedForRequest } from "../mcp-client/visibility.js";
|
|
13
13
|
import { createToolSearchEntry, TOOL_SEARCH_ACTION_NAME, } from "./tool-search.js";
|
|
14
14
|
import { getDefaultMaxIterations, normalizeMaxIterations, readAgentLoopSettings, } from "./loop-settings.js";
|
|
@@ -464,6 +464,12 @@ function enrichMessage(message, references) {
|
|
|
464
464
|
}
|
|
465
465
|
return `${parts.join("\n\n")}\n\n${message}`;
|
|
466
466
|
}
|
|
467
|
+
function collectTextParts(parts) {
|
|
468
|
+
return parts
|
|
469
|
+
.filter((part) => part.type === "text")
|
|
470
|
+
.map((part) => part.text)
|
|
471
|
+
.join("");
|
|
472
|
+
}
|
|
467
473
|
export const AGENT_INTERNAL_CONTINUE_PROMPT = "Continue from where you left off and finish the user's original request. Do not repeat completed work, do not mention internal reconnects, time limits, or step limits, and continue as if this is the same uninterrupted run.";
|
|
468
474
|
export function appendAgentLoopContinuation(messages, reason) {
|
|
469
475
|
const note = reason === "loop_limit"
|
|
@@ -551,6 +557,14 @@ export async function runAgentLoop(opts) {
|
|
|
551
557
|
model,
|
|
552
558
|
};
|
|
553
559
|
const maxIterations = normalizeMaxIterations(opts.maxIterations, getDefaultMaxIterations());
|
|
560
|
+
const toolCallHistory = [];
|
|
561
|
+
const toolResultHistory = [];
|
|
562
|
+
const runCtx = getRequestRunContext();
|
|
563
|
+
if (runCtx) {
|
|
564
|
+
runCtx.toolCalls = toolCallHistory;
|
|
565
|
+
runCtx.toolResults = toolResultHistory;
|
|
566
|
+
}
|
|
567
|
+
let finalGuardRetries = 0;
|
|
554
568
|
let iterations = 0;
|
|
555
569
|
while (true) {
|
|
556
570
|
if (signal.aborted)
|
|
@@ -662,10 +676,46 @@ export async function runAgentLoop(opts) {
|
|
|
662
676
|
: part);
|
|
663
677
|
messages.push({ role: "assistant", content: assistantContentForHistory });
|
|
664
678
|
const toolCallParts = assistantContent.filter((p) => p.type === "tool-call");
|
|
665
|
-
if (toolCallParts.length === 0)
|
|
679
|
+
if (toolCallParts.length === 0) {
|
|
680
|
+
const guard = opts.finalResponseGuard
|
|
681
|
+
? await opts.finalResponseGuard({
|
|
682
|
+
messages,
|
|
683
|
+
assistantContent: assistantContentForHistory,
|
|
684
|
+
text: collectTextParts(assistantContentForHistory),
|
|
685
|
+
toolCalls: [...toolCallHistory],
|
|
686
|
+
toolResults: [...toolResultHistory],
|
|
687
|
+
retryCount: finalGuardRetries,
|
|
688
|
+
})
|
|
689
|
+
: null;
|
|
690
|
+
if (guard) {
|
|
691
|
+
const retryMessage = typeof guard === "string" ? guard : guard.retryMessage;
|
|
692
|
+
const fallbackMessage = typeof guard === "string" ? guard : guard.fallbackMessage;
|
|
693
|
+
send({ type: "clear" });
|
|
694
|
+
if (finalGuardRetries < 1) {
|
|
695
|
+
finalGuardRetries += 1;
|
|
696
|
+
messages.push({
|
|
697
|
+
role: "user",
|
|
698
|
+
content: [{ type: "text", text: retryMessage }],
|
|
699
|
+
});
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
send({ type: "text", text: fallbackMessage ?? retryMessage });
|
|
703
|
+
}
|
|
666
704
|
break;
|
|
705
|
+
}
|
|
667
706
|
let requestedActionStop = null;
|
|
668
707
|
const runToolCall = async (toolCall) => {
|
|
708
|
+
toolCallHistory.push({
|
|
709
|
+
name: toolCall.name,
|
|
710
|
+
input: normalizeToolCallInputForHistory(toolCall.input),
|
|
711
|
+
});
|
|
712
|
+
const recordToolResult = (content, isError) => {
|
|
713
|
+
toolResultHistory.push({
|
|
714
|
+
name: toolCall.name,
|
|
715
|
+
content,
|
|
716
|
+
isError,
|
|
717
|
+
});
|
|
718
|
+
};
|
|
669
719
|
const actionEntry = actions[toolCall.name];
|
|
670
720
|
if (!actionEntry) {
|
|
671
721
|
const result = `Error: Unknown tool "${toolCall.name}"`;
|
|
@@ -675,6 +725,7 @@ export async function runAgentLoop(opts) {
|
|
|
675
725
|
input: toolCall.input,
|
|
676
726
|
});
|
|
677
727
|
send({ type: "tool_done", tool: toolCall.name, result });
|
|
728
|
+
recordToolResult(result, true);
|
|
678
729
|
return {
|
|
679
730
|
type: "tool-result",
|
|
680
731
|
toolCallId: toolCall.id,
|
|
@@ -692,6 +743,7 @@ export async function runAgentLoop(opts) {
|
|
|
692
743
|
if (toolCallSchemaError) {
|
|
693
744
|
const result = toolInputSchemaErrorResult(toolCall.name, toolCallSchemaError.input, toolCallSchemaError.error);
|
|
694
745
|
send({ type: "tool_done", tool: toolCall.name, result });
|
|
746
|
+
recordToolResult(result, true);
|
|
695
747
|
return {
|
|
696
748
|
type: "tool-result",
|
|
697
749
|
toolCallId: toolCall.id,
|
|
@@ -704,6 +756,7 @@ export async function runAgentLoop(opts) {
|
|
|
704
756
|
!isPlanModeToolCallAllowed(toolCall.name, toolCall.input, actionEntry)) {
|
|
705
757
|
const result = planModeBlockedMessage(toolCall.name);
|
|
706
758
|
send({ type: "tool_done", tool: toolCall.name, result });
|
|
759
|
+
recordToolResult(result, true);
|
|
707
760
|
return {
|
|
708
761
|
type: "tool-result",
|
|
709
762
|
toolCallId: toolCall.id,
|
|
@@ -769,6 +822,7 @@ export async function runAgentLoop(opts) {
|
|
|
769
822
|
}
|
|
770
823
|
}
|
|
771
824
|
send({ type: "tool_done", tool: toolCall.name, result });
|
|
825
|
+
recordToolResult(result, isError);
|
|
772
826
|
return {
|
|
773
827
|
type: "tool-result",
|
|
774
828
|
toolCallId: toolCall.id,
|
|
@@ -1422,6 +1476,7 @@ export function createProductionAgentHandler(options) {
|
|
|
1422
1476
|
providerOptions: options.providerOptions,
|
|
1423
1477
|
executionMode: requestMode,
|
|
1424
1478
|
maxIterations: loopSettings.maxIterations,
|
|
1479
|
+
finalResponseGuard: options.finalResponseGuard,
|
|
1425
1480
|
};
|
|
1426
1481
|
let loopUsage;
|
|
1427
1482
|
let instrumented = false;
|