@myagentroam/agent 0.10.19 → 0.10.21
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/index.d.ts +1 -1
- package/dist/shared/model-text.d.ts +12 -5
- package/dist/shared/model-text.js +28 -10
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { testMarAgentModelTransport } from './agent-core/model/transport-test.js
|
|
|
11
11
|
export type { AccessMode, ExecutionMode, ExecutionResult, MarAgentImageMetadata, RolloutBudgetOptions, RunInput, RunInputImage } from './agent-core/runtime/contracts.js';
|
|
12
12
|
export type { MarAgentEvent } from './agent-core/runtime/events.js';
|
|
13
13
|
export { createMarAgent } from './agent-core/sdk/agent.js';
|
|
14
|
-
export { generateModelText, type GenerateModelTextInput } from './shared/model-text.js';
|
|
14
|
+
export { generateModelText, type GenerateModelTextInput, type GenerateModelTextResult } from './shared/model-text.js';
|
|
15
15
|
export type { CoreAgentExtensionContext, CoreSessionExtensionContext, CoreRuntimeExtension, CoreExtensionSnapshot, CoreExtensionSource, CoreExtensionDiagnostic, CoreDomainOperations, CoreDomainFacts, CoreHookRegistrar, CoreCapabilitySnapshot, CoreCommandSpec, CorePromptSection, CoreServiceDeclaration, CoreServiceDependency } from './agent-core/extensions/contracts.js';
|
|
16
16
|
export type { CoreDisposer, CoreResourceRegistration, CoreResourceScope } from './agent-core/extensions/resources.js';
|
|
17
17
|
export type { CoreHookOptions, CoreInterceptor } from './agent-core/extensions/hooks.js';
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { type MarAgentModelConfiguration, type MarAgentReasoningEffort } from '../agent-core/model/configuration.js';
|
|
2
2
|
import type { ModelAttemptDiagnostic, ModelUsage } from '../agent-core/model/contracts.js';
|
|
3
3
|
import type { CoreCompactMessage } from '../agent-core/extensions/compaction.js';
|
|
4
|
+
import type { ClientToolDefinition, ToolCall } from '../agent-core/tools/contracts.js';
|
|
4
5
|
export interface GenerateModelTextInput {
|
|
5
6
|
readonly onModelUsage?: (usage: import('../agent-core/model/usage-observer.js').ModelRequestUsage) => Promise<void> | void;
|
|
6
7
|
readonly onModelUsageFailure?: () => void;
|
|
7
8
|
readonly model: MarAgentModelConfiguration;
|
|
8
9
|
readonly system: string;
|
|
9
10
|
readonly messages: readonly CoreCompactMessage[];
|
|
11
|
+
/** Declarative client tools only. Returned calls are never executed or continued here. */
|
|
12
|
+
readonly tools?: readonly ClientToolDefinition[];
|
|
13
|
+
readonly promptCacheKey?: string;
|
|
14
|
+
readonly cachePrefixMessages?: number;
|
|
10
15
|
readonly reasoningEffort?: MarAgentReasoningEffort;
|
|
11
16
|
readonly outputLimit?: number;
|
|
12
17
|
readonly signal: AbortSignal;
|
|
13
18
|
readonly onAttemptDiagnostic?: (diagnostic: ModelAttemptDiagnostic) => Promise<void> | void;
|
|
14
19
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
usage?: ModelUsage;
|
|
19
|
-
}
|
|
20
|
+
export interface GenerateModelTextResult {
|
|
21
|
+
readonly text: string;
|
|
22
|
+
readonly toolCalls?: readonly ToolCall[];
|
|
23
|
+
readonly usage?: ModelUsage;
|
|
24
|
+
}
|
|
25
|
+
/** One request using the SDK transports, without tool execution or a Session. */
|
|
26
|
+
export declare function generateModelText(input: GenerateModelTextInput): Promise<GenerateModelTextResult | undefined>;
|
|
@@ -3,16 +3,20 @@ import { MarAgentError } from '../agent-core/error.js';
|
|
|
3
3
|
import { AnthropicMessagesAdapter } from '../agent-core/model/anthropic-messages.js';
|
|
4
4
|
import { OpenAiResponsesAdapter } from '../agent-core/model/openai-responses.js';
|
|
5
5
|
import { resolveModelDefaultReasoningEffort } from '../agent-core/model/configuration.js';
|
|
6
|
-
/** One
|
|
6
|
+
/** One request using the SDK transports, without tool execution or a Session. */
|
|
7
7
|
export async function generateModelText(input) {
|
|
8
8
|
input.signal.throwIfAborted();
|
|
9
9
|
if (!input.model.enabled)
|
|
10
10
|
return undefined;
|
|
11
|
+
const tools = input.tools ?? [];
|
|
12
|
+
// Standalone calls expose only the caller's declared client tools, never hosted search.
|
|
13
|
+
const model = { ...input.model, hostedWebSearch: false };
|
|
11
14
|
const adapter = input.model.protocol === 'OPENAI_RESPONSES'
|
|
12
|
-
? new OpenAiResponsesAdapter(
|
|
13
|
-
: new AnthropicMessagesAdapter(
|
|
15
|
+
? new OpenAiResponsesAdapter(model)
|
|
16
|
+
: new AnthropicMessagesAdapter(model);
|
|
14
17
|
let text = '';
|
|
15
18
|
let completed = false;
|
|
19
|
+
const toolCalls = [];
|
|
16
20
|
let usage;
|
|
17
21
|
try {
|
|
18
22
|
for await (const event of adapter.start({
|
|
@@ -23,11 +27,15 @@ export async function generateModelText(input) {
|
|
|
23
27
|
? {}
|
|
24
28
|
: { onModelUsageFailure: input.onModelUsageFailure }),
|
|
25
29
|
system: input.system,
|
|
30
|
+
...(input.cachePrefixMessages === undefined
|
|
31
|
+
? {}
|
|
32
|
+
: { cachePrefixMessages: input.cachePrefixMessages }),
|
|
26
33
|
messages: input.messages,
|
|
27
|
-
tools
|
|
28
|
-
allowTools:
|
|
29
|
-
toolChoice: 'none',
|
|
34
|
+
tools,
|
|
35
|
+
allowTools: tools.length > 0,
|
|
36
|
+
toolChoice: tools.length > 0 ? 'auto' : 'none',
|
|
30
37
|
reasoningEffort: input.reasoningEffort ?? resolveModelDefaultReasoningEffort(input.model),
|
|
38
|
+
...(input.promptCacheKey === undefined ? {} : { promptCacheKey: input.promptCacheKey }),
|
|
31
39
|
...(input.onAttemptDiagnostic ? { onAttemptDiagnostic: input.onAttemptDiagnostic } : {}),
|
|
32
40
|
...(input.outputLimit === undefined ? {} : { outputLimit: input.outputLimit })
|
|
33
41
|
}, input.signal)) {
|
|
@@ -37,12 +45,22 @@ export async function generateModelText(input) {
|
|
|
37
45
|
else if (event.type === 'usage')
|
|
38
46
|
usage = event.usage;
|
|
39
47
|
else if (event.type === 'completed')
|
|
40
|
-
completed =
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
completed =
|
|
49
|
+
event.reason === 'completed' || (event.reason === 'tool_use' && toolCalls.length > 0);
|
|
50
|
+
else if (event.type === 'client_tool.call') {
|
|
51
|
+
if (!tools.some((tool) => tool.name === event.name) || event.argumentError !== undefined)
|
|
52
|
+
throw new MarAgentError('MAR_AGENT_MODEL_PROTOCOL_ERROR', 'Standalone generation returned an undeclared tool or invalid tool arguments.');
|
|
53
|
+
toolCalls.push({ name: event.name, callId: event.callId, arguments: event.arguments });
|
|
54
|
+
}
|
|
43
55
|
}
|
|
44
56
|
input.signal.throwIfAborted();
|
|
45
|
-
return completed && text
|
|
57
|
+
return completed && (text || toolCalls.length > 0)
|
|
58
|
+
? {
|
|
59
|
+
text,
|
|
60
|
+
...(toolCalls.length > 0 ? { toolCalls } : {}),
|
|
61
|
+
...(usage === undefined ? {} : { usage })
|
|
62
|
+
}
|
|
63
|
+
: undefined;
|
|
46
64
|
}
|
|
47
65
|
finally {
|
|
48
66
|
await adapter.close?.();
|