@microsoft/agents-a365-observability-hosting 0.1.0-preview.95 → 0.2.0-preview.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/cjs/caching/AgenticTokenCache.d.ts +38 -1
- package/dist/cjs/caching/AgenticTokenCache.d.ts.map +1 -1
- package/dist/cjs/caching/AgenticTokenCache.js +48 -5
- package/dist/cjs/caching/AgenticTokenCache.js.map +1 -1
- package/dist/cjs/index.d.ts +5 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +10 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/middleware/BaggageMiddleware.d.ts +9 -0
- package/dist/cjs/middleware/BaggageMiddleware.d.ts.map +1 -0
- package/dist/cjs/middleware/BaggageMiddleware.js +34 -0
- package/dist/cjs/middleware/BaggageMiddleware.js.map +1 -0
- package/dist/cjs/middleware/ObservabilityHostingManager.d.ts +30 -0
- package/dist/cjs/middleware/ObservabilityHostingManager.d.ts.map +1 -0
- package/dist/cjs/middleware/ObservabilityHostingManager.js +46 -0
- package/dist/cjs/middleware/ObservabilityHostingManager.js.map +1 -0
- package/dist/cjs/middleware/OutputLoggingMiddleware.d.ts +34 -0
- package/dist/cjs/middleware/OutputLoggingMiddleware.d.ts.map +1 -0
- package/dist/cjs/middleware/OutputLoggingMiddleware.js +95 -0
- package/dist/cjs/middleware/OutputLoggingMiddleware.js.map +1 -0
- package/dist/cjs/utils/BaggageBuilderUtils.d.ts +2 -9
- package/dist/cjs/utils/BaggageBuilderUtils.d.ts.map +1 -1
- package/dist/cjs/utils/BaggageBuilderUtils.js +4 -15
- package/dist/cjs/utils/BaggageBuilderUtils.js.map +1 -1
- package/dist/cjs/utils/ScopeUtils.d.ts +39 -26
- package/dist/cjs/utils/ScopeUtils.d.ts.map +1 -1
- package/dist/cjs/utils/ScopeUtils.js +96 -71
- package/dist/cjs/utils/ScopeUtils.js.map +1 -1
- package/dist/cjs/utils/TurnContextUtils.d.ts +18 -10
- package/dist/cjs/utils/TurnContextUtils.d.ts.map +1 -1
- package/dist/cjs/utils/TurnContextUtils.js +33 -53
- package/dist/cjs/utils/TurnContextUtils.js.map +1 -1
- package/dist/esm/caching/AgenticTokenCache.d.ts +38 -1
- package/dist/esm/caching/AgenticTokenCache.d.ts.map +1 -1
- package/dist/esm/caching/AgenticTokenCache.js +48 -6
- package/dist/esm/caching/AgenticTokenCache.js.map +1 -1
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/middleware/BaggageMiddleware.d.ts +9 -0
- package/dist/esm/middleware/BaggageMiddleware.d.ts.map +1 -0
- package/dist/esm/middleware/BaggageMiddleware.js +30 -0
- package/dist/esm/middleware/BaggageMiddleware.js.map +1 -0
- package/dist/esm/middleware/ObservabilityHostingManager.d.ts +30 -0
- package/dist/esm/middleware/ObservabilityHostingManager.d.ts.map +1 -0
- package/dist/esm/middleware/ObservabilityHostingManager.js +42 -0
- package/dist/esm/middleware/ObservabilityHostingManager.js.map +1 -0
- package/dist/esm/middleware/OutputLoggingMiddleware.d.ts +34 -0
- package/dist/esm/middleware/OutputLoggingMiddleware.d.ts.map +1 -0
- package/dist/esm/middleware/OutputLoggingMiddleware.js +91 -0
- package/dist/esm/middleware/OutputLoggingMiddleware.js.map +1 -0
- package/dist/esm/utils/BaggageBuilderUtils.d.ts +2 -9
- package/dist/esm/utils/BaggageBuilderUtils.d.ts.map +1 -1
- package/dist/esm/utils/BaggageBuilderUtils.js +5 -16
- package/dist/esm/utils/BaggageBuilderUtils.js.map +1 -1
- package/dist/esm/utils/ScopeUtils.d.ts +39 -26
- package/dist/esm/utils/ScopeUtils.d.ts.map +1 -1
- package/dist/esm/utils/ScopeUtils.js +98 -73
- package/dist/esm/utils/ScopeUtils.js.map +1 -1
- package/dist/esm/utils/TurnContextUtils.d.ts +18 -10
- package/dist/esm/utils/TurnContextUtils.d.ts.map +1 -1
- package/dist/esm/utils/TurnContextUtils.js +32 -52
- package/dist/esm/utils/TurnContextUtils.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { OutputScope, logger, isPerRequestExportEnabled, } from '@microsoft/agents-a365-observability';
|
|
4
|
+
import { ScopeUtils } from '../utils/ScopeUtils';
|
|
5
|
+
import { AgenticTokenCacheInstance } from '../caching/AgenticTokenCache';
|
|
6
|
+
/**
|
|
7
|
+
* TurnState key for the parent span reference.
|
|
8
|
+
* Set this in `turnState` to link OutputScope spans as children of an InvokeAgentScope.
|
|
9
|
+
*/
|
|
10
|
+
export const A365_PARENT_SPAN_KEY = 'A365ParentSpanId';
|
|
11
|
+
/**
|
|
12
|
+
* TurnState key for the auth token.
|
|
13
|
+
* Set this in `turnState` so middleware can resolve the agent blueprint ID
|
|
14
|
+
* from token claims (used for embodied/agentic requests).
|
|
15
|
+
*/
|
|
16
|
+
export const A365_AUTH_TOKEN_KEY = 'A365AuthToken';
|
|
17
|
+
/**
|
|
18
|
+
* Middleware that creates {@link OutputScope} spans for outgoing messages.
|
|
19
|
+
* Links to a parent span when {@link A365_PARENT_SPAN_KEY} is set in turnState.
|
|
20
|
+
*
|
|
21
|
+
* **Privacy note:** Outgoing message content is captured verbatim
|
|
22
|
+
* as span attributes and exported to the configured telemetry backend.
|
|
23
|
+
*/
|
|
24
|
+
export class OutputLoggingMiddleware {
|
|
25
|
+
async onTurn(context, next) {
|
|
26
|
+
const authToken = this.resolveAuthToken(context);
|
|
27
|
+
const agentDetails = ScopeUtils.deriveAgentDetails(context, authToken);
|
|
28
|
+
if (!agentDetails || !agentDetails.tenantId) {
|
|
29
|
+
await next();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const userDetails = ScopeUtils.deriveCallerDetails(context);
|
|
33
|
+
const conversationId = ScopeUtils.deriveConversationId(context);
|
|
34
|
+
const channel = ScopeUtils.deriveChannelObject(context);
|
|
35
|
+
const request = {
|
|
36
|
+
conversationId,
|
|
37
|
+
channel,
|
|
38
|
+
};
|
|
39
|
+
context.onSendActivities(this._createSendHandler(context, agentDetails, userDetails, request));
|
|
40
|
+
await next();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the auth token for agent identity resolution.
|
|
44
|
+
* When per-request export is enabled, reads from turnState.
|
|
45
|
+
* Otherwise, reads from the cached observability token.
|
|
46
|
+
*/
|
|
47
|
+
resolveAuthToken(context) {
|
|
48
|
+
if (isPerRequestExportEnabled()) {
|
|
49
|
+
return context.turnState.get(A365_AUTH_TOKEN_KEY) ?? '';
|
|
50
|
+
}
|
|
51
|
+
const agentId = context.activity?.getAgenticInstanceId?.() ?? '';
|
|
52
|
+
const tenantId = context.activity?.getAgenticTenantId?.() ?? '';
|
|
53
|
+
if (agentId && tenantId) {
|
|
54
|
+
return AgenticTokenCacheInstance.getObservabilityToken(agentId, tenantId) ?? '';
|
|
55
|
+
}
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a send handler that wraps outgoing messages in OutputScope spans.
|
|
60
|
+
* Reads parent span ref lazily so the agent handler can set it during `next()`.
|
|
61
|
+
*/
|
|
62
|
+
_createSendHandler(turnContext, agentDetails, userDetails, request) {
|
|
63
|
+
return async (_ctx, activities, sendNext) => {
|
|
64
|
+
const messages = activities
|
|
65
|
+
.filter((a) => a.type === 'message' && a.text)
|
|
66
|
+
.map((a) => a.text);
|
|
67
|
+
if (messages.length === 0) {
|
|
68
|
+
return await sendNext();
|
|
69
|
+
}
|
|
70
|
+
const parentSpanRef = turnContext.turnState.get(A365_PARENT_SPAN_KEY);
|
|
71
|
+
if (!parentSpanRef) {
|
|
72
|
+
logger.warn(`[OutputLoggingMiddleware] No parent span ref in turnState under '${A365_PARENT_SPAN_KEY}'. OutputScope will not be linked to a parent.`);
|
|
73
|
+
}
|
|
74
|
+
const spanDetails = parentSpanRef
|
|
75
|
+
? { parentContext: parentSpanRef }
|
|
76
|
+
: undefined;
|
|
77
|
+
const outputScope = OutputScope.start(request ?? {}, { messages }, agentDetails, userDetails, spanDetails);
|
|
78
|
+
try {
|
|
79
|
+
return await sendNext();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
outputScope.recordError(error instanceof Error ? error : new Error(typeof error === 'string' ? error : JSON.stringify(error)));
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
outputScope.dispose();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=OutputLoggingMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OutputLoggingMiddleware.js","sourceRoot":"","sources":["../../../src/middleware/OutputLoggingMiddleware.ts"],"names":[],"mappings":"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"}
|
|
@@ -18,13 +18,6 @@ export declare class BaggageBuilderUtils {
|
|
|
18
18
|
* @returns The updated BaggageBuilder instance.
|
|
19
19
|
*/
|
|
20
20
|
static setCallerBaggage(builder: BaggageBuilder, turnContext: TurnContext): BaggageBuilder;
|
|
21
|
-
/**
|
|
22
|
-
* Sets the execution type baggage value based on caller and recipient agentic status.
|
|
23
|
-
* @param builder The BaggageBuilder instance.
|
|
24
|
-
* @param turnContext The TurnContext containing activity information.
|
|
25
|
-
* @returns The updated BaggageBuilder instance.
|
|
26
|
-
*/
|
|
27
|
-
static setExecutionTypeBaggage(builder: BaggageBuilder, turnContext: TurnContext): BaggageBuilder;
|
|
28
21
|
/**
|
|
29
22
|
* Sets the target agent-related baggage values from the TurnContext.
|
|
30
23
|
* @param builder The BaggageBuilder instance.
|
|
@@ -40,12 +33,12 @@ export declare class BaggageBuilderUtils {
|
|
|
40
33
|
*/
|
|
41
34
|
static setTenantIdBaggage(builder: BaggageBuilder, turnContext: TurnContext): BaggageBuilder;
|
|
42
35
|
/**
|
|
43
|
-
* Sets the
|
|
36
|
+
* Sets the channel baggage values from the TurnContext.
|
|
44
37
|
* @param builder The BaggageBuilder instance.
|
|
45
38
|
* @param turnContext The TurnContext containing activity information.
|
|
46
39
|
* @returns The updated BaggageBuilder instance.
|
|
47
40
|
*/
|
|
48
|
-
static
|
|
41
|
+
static setChannelBaggage(builder: BaggageBuilder, turnContext: TurnContext): BaggageBuilder;
|
|
49
42
|
/**
|
|
50
43
|
* Sets the conversation ID and item link baggage values from the TurnContext.
|
|
51
44
|
* @param builder The BaggageBuilder instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaggageBuilderUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/BaggageBuilderUtils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"BaggageBuilderUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/BaggageBuilderUtils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAQxD,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAItE;;GAEG;AACH,qBAAa,mBAAmB;IAC9B;;;;;OAKG;IACH,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,GAAG,cAAc;IAYzF;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,GAAG,cAAc;IAM1F;;;;;OAKG;IACH,MAAM,CAAC,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,GAAG,cAAc;IAM/F;;;;;OAKG;IACH,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,GAAG,cAAc;IAM5F;;;;;OAKG;IACH,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,GAAG,cAAc;IAM3F;;;;;OAKG;IACH,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,GAAG,cAAc;CAInG"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
4
|
// ------------------------------------------------------------------------------
|
|
5
|
-
import { getCallerBaggagePairs,
|
|
5
|
+
import { getCallerBaggagePairs, getTargetAgentBaggagePairs, getTenantIdPair, getChannelBaggagePairs, getConversationIdAndItemLinkPairs } from './TurnContextUtils';
|
|
6
6
|
/**
|
|
7
7
|
* Utilities to populate BaggageBuilder from a TurnContext.
|
|
8
8
|
*/
|
|
@@ -18,10 +18,9 @@ export class BaggageBuilderUtils {
|
|
|
18
18
|
throw new Error('turnContext is required');
|
|
19
19
|
}
|
|
20
20
|
this.setCallerBaggage(builder, turnContext);
|
|
21
|
-
this.setExecutionTypeBaggage(builder, turnContext);
|
|
22
21
|
this.setTargetAgentBaggage(builder, turnContext);
|
|
23
22
|
this.setTenantIdBaggage(builder, turnContext);
|
|
24
|
-
this.
|
|
23
|
+
this.setChannelBaggage(builder, turnContext);
|
|
25
24
|
this.setConversationIdBaggage(builder, turnContext);
|
|
26
25
|
return builder;
|
|
27
26
|
}
|
|
@@ -35,16 +34,6 @@ export class BaggageBuilderUtils {
|
|
|
35
34
|
builder.setPairs(getCallerBaggagePairs(turnContext));
|
|
36
35
|
return builder;
|
|
37
36
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Sets the execution type baggage value based on caller and recipient agentic status.
|
|
40
|
-
* @param builder The BaggageBuilder instance.
|
|
41
|
-
* @param turnContext The TurnContext containing activity information.
|
|
42
|
-
* @returns The updated BaggageBuilder instance.
|
|
43
|
-
*/
|
|
44
|
-
static setExecutionTypeBaggage(builder, turnContext) {
|
|
45
|
-
builder.setPairs(getExecutionTypePair(turnContext));
|
|
46
|
-
return builder;
|
|
47
|
-
}
|
|
48
37
|
/**
|
|
49
38
|
* Sets the target agent-related baggage values from the TurnContext.
|
|
50
39
|
* @param builder The BaggageBuilder instance.
|
|
@@ -66,13 +55,13 @@ export class BaggageBuilderUtils {
|
|
|
66
55
|
return builder;
|
|
67
56
|
}
|
|
68
57
|
/**
|
|
69
|
-
* Sets the
|
|
58
|
+
* Sets the channel baggage values from the TurnContext.
|
|
70
59
|
* @param builder The BaggageBuilder instance.
|
|
71
60
|
* @param turnContext The TurnContext containing activity information.
|
|
72
61
|
* @returns The updated BaggageBuilder instance.
|
|
73
62
|
*/
|
|
74
|
-
static
|
|
75
|
-
builder.setPairs(
|
|
63
|
+
static setChannelBaggage(builder, turnContext) {
|
|
64
|
+
builder.setPairs(getChannelBaggagePairs(turnContext));
|
|
76
65
|
return builder;
|
|
77
66
|
}
|
|
78
67
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaggageBuilderUtils.js","sourceRoot":"","sources":["../../../src/utils/BaggageBuilderUtils.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,uCAAuC;AACvC,kCAAkC;AAClC,iFAAiF;AAGjF,OAAO,EACL,qBAAqB,EACrB,
|
|
1
|
+
{"version":3,"file":"BaggageBuilderUtils.js","sourceRoot":"","sources":["../../../src/utils/BaggageBuilderUtils.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,uCAAuC;AACvC,kCAAkC;AAClC,iFAAiF;AAGjF,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,eAAe,EACf,sBAAsB,EACtB,iCAAiC,EAClC,MAAM,oBAAoB,CAAC;AAK5B;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAC9B;;;;;OAKG;IACH,MAAM,CAAC,eAAe,CAAC,OAAuB,EAAE,WAAwB;QACtE,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC5C,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACjD,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC9C,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAC7C,IAAI,CAAC,wBAAwB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACpD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAuB,EAAE,WAAwB;QACvE,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC,CAAC;QACrD,OAAO,OAAO,CAAC;IACjB,CAAC;IAGD;;;;;OAKG;IACH,MAAM,CAAC,qBAAqB,CAAC,OAAuB,EAAE,WAAwB;QAC5E,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAC,WAAW,CAAC,CAAC,CAAC;QAC1D,OAAO,OAAO,CAAC;IACjB,CAAC;IAGD;;;;;OAKG;IACH,MAAM,CAAC,kBAAkB,CAAC,OAAuB,EAAE,WAAwB;QACzE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC;QAC/C,OAAO,OAAO,CAAC;IACjB,CAAC;IAGD;;;;;OAKG;IACH,MAAM,CAAC,iBAAiB,CAAC,OAAuB,EAAE,WAAwB;QACxE,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC,CAAC;QACtD,OAAO,OAAO,CAAC;IACjB,CAAC;IAGD;;;;;OAKG;IACH,MAAM,CAAC,wBAAwB,CAAC,OAAuB,EAAE,WAAwB;QAC/E,OAAO,CAAC,QAAQ,CAAC,iCAAiC,CAAC,WAAW,CAAC,CAAC,CAAC;QACjE,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import { TurnContext } from '@microsoft/agents-hosting';
|
|
2
|
-
import {
|
|
2
|
+
import { SpanKind, TimeInput } from '@opentelemetry/api';
|
|
3
|
+
import { InvokeAgentScope, InferenceScope, ExecuteToolScope, AgentDetails, UserDetails, InferenceDetails, ToolCallDetails, InvokeAgentScopeDetails } from '@microsoft/agents-a365-observability';
|
|
3
4
|
/**
|
|
4
5
|
* Unified utilities to populate scope tags from a TurnContext.
|
|
5
6
|
* Provides common tag population and scope-specific helpers.
|
|
6
7
|
*/
|
|
7
8
|
export declare class ScopeUtils {
|
|
8
9
|
private static setInputMessageTags;
|
|
9
|
-
/**
|
|
10
|
-
* Derive tenant details from the TurnContext.
|
|
11
|
-
* @param turnContext Activity context
|
|
12
|
-
* @returns Tenant details if a recipient tenant id is present; otherwise undefined.
|
|
13
|
-
*/
|
|
14
|
-
static deriveTenantDetails(turnContext: TurnContext): TenantDetails | undefined;
|
|
15
10
|
/**
|
|
16
11
|
* Derive target agent details from the activity recipient.
|
|
12
|
+
* Uses {@link resolveEmbodiedAgentIds} to resolve the agent ID and blueprint ID, which are only
|
|
13
|
+
* set for embodied (agentic) agents — see that function for the rationale.
|
|
17
14
|
* @param turnContext Activity context
|
|
15
|
+
* @param authToken Auth token for resolving agent identity from token claims.
|
|
18
16
|
* @returns Agent details built from recipient properties; otherwise undefined.
|
|
19
17
|
*/
|
|
20
|
-
static deriveAgentDetails(turnContext: TurnContext): AgentDetails | undefined;
|
|
18
|
+
static deriveAgentDetails(turnContext: TurnContext, authToken: string): AgentDetails | undefined;
|
|
21
19
|
/**
|
|
22
20
|
* Derive caller agent details from the activity from.
|
|
23
21
|
* @param turnContext Activity context
|
|
@@ -25,11 +23,11 @@ export declare class ScopeUtils {
|
|
|
25
23
|
*/
|
|
26
24
|
static deriveCallerAgent(turnContext: TurnContext): AgentDetails | undefined;
|
|
27
25
|
/**
|
|
28
|
-
* Derive caller identity details (id,
|
|
26
|
+
* Derive caller identity details (id, email, name, tenant) from the activity from.
|
|
29
27
|
* @param turnContext Activity context
|
|
30
|
-
* @returns
|
|
28
|
+
* @returns User details when available; otherwise undefined.
|
|
31
29
|
*/
|
|
32
|
-
static deriveCallerDetails(turnContext: TurnContext):
|
|
30
|
+
static deriveCallerDetails(turnContext: TurnContext): UserDetails | undefined;
|
|
33
31
|
/**
|
|
34
32
|
* Derive conversation id from the TurnContext.
|
|
35
33
|
* @param turnContext Activity context
|
|
@@ -37,47 +35,62 @@ export declare class ScopeUtils {
|
|
|
37
35
|
*/
|
|
38
36
|
static deriveConversationId(turnContext: TurnContext): string | undefined;
|
|
39
37
|
/**
|
|
40
|
-
* Derive
|
|
38
|
+
* Derive channel (name and description) from the TurnContext.
|
|
41
39
|
* @param turnContext Activity context
|
|
42
40
|
* @returns Object with optional name and description fields.
|
|
43
41
|
*/
|
|
44
|
-
static
|
|
42
|
+
static deriveChannelObject(turnContext: TurnContext): {
|
|
45
43
|
name?: string;
|
|
46
44
|
description?: string;
|
|
47
45
|
};
|
|
48
46
|
/**
|
|
49
47
|
* Create an `InferenceScope` using `details` and values derived from the provided `TurnContext`.
|
|
50
|
-
* Derives `
|
|
48
|
+
* Derives `conversationId` and `channel` (name/description) from context.
|
|
51
49
|
* Also records input messages from the context if present.
|
|
52
50
|
* @param details The inference call details (model, provider, tokens, etc.).
|
|
53
51
|
* @param turnContext The current activity context to derive scope parameters from.
|
|
52
|
+
* @param authToken Auth token for resolving agent identity from token claims.
|
|
53
|
+
* @param startTime Optional explicit start time (ms epoch, Date, or HrTime).
|
|
54
|
+
* @param endTime Optional explicit end time (ms epoch, Date, or HrTime).
|
|
54
55
|
* @returns A started `InferenceScope` enriched with context-derived parameters.
|
|
55
56
|
*/
|
|
56
|
-
static populateInferenceScopeFromTurnContext(details: InferenceDetails, turnContext: TurnContext): InferenceScope;
|
|
57
|
+
static populateInferenceScopeFromTurnContext(details: InferenceDetails, turnContext: TurnContext, authToken: string, startTime?: TimeInput, endTime?: TimeInput): InferenceScope;
|
|
57
58
|
/**
|
|
58
59
|
* Create an `InvokeAgentScope` using `details` and values derived from the provided `TurnContext`.
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
60
|
+
* Builds a separate `Request` with `conversationId` and `channel` from context.
|
|
61
|
+
* Merges agent identity from context into `details` via `buildInvokeAgentDetailsCore`.
|
|
62
|
+
* Derives `callerAgentDetails` (from caller) and `userDetails` (human caller).
|
|
63
|
+
* Also records input messages from the context if present.
|
|
64
|
+
* @param details The agent details to be augmented with context-derived identity.
|
|
63
65
|
* @param turnContext The current activity context to derive scope parameters from.
|
|
66
|
+
* @param authToken Auth token for resolving agent identity from token claims.
|
|
67
|
+
* @param startTime Optional explicit start time (ms epoch, Date, or HrTime).
|
|
68
|
+
* @param endTime Optional explicit end time (ms epoch, Date, or HrTime).
|
|
69
|
+
* @param spanKind Optional span kind override. Defaults to `SpanKind.CLIENT`.
|
|
64
70
|
* @returns A started `InvokeAgentScope` enriched with context-derived parameters.
|
|
65
71
|
*/
|
|
66
|
-
static populateInvokeAgentScopeFromTurnContext(details:
|
|
72
|
+
static populateInvokeAgentScopeFromTurnContext(details: AgentDetails, scopeDetails: InvokeAgentScopeDetails, turnContext: TurnContext, authToken: string, startTime?: TimeInput, endTime?: TimeInput, spanKind?: SpanKind): InvokeAgentScope;
|
|
67
73
|
/**
|
|
68
|
-
* Build
|
|
69
|
-
* @param details Base
|
|
74
|
+
* Build agent details by merging provided details with agent info from the TurnContext.
|
|
75
|
+
* @param details Base agent details to augment
|
|
70
76
|
* @param turnContext Activity context
|
|
71
|
-
* @
|
|
77
|
+
* @param authToken Auth token for resolving agent identity from token claims.
|
|
78
|
+
* @returns Merged AgentDetails with context-derived identity.
|
|
72
79
|
*/
|
|
73
|
-
static buildInvokeAgentDetails(details:
|
|
80
|
+
static buildInvokeAgentDetails(details: AgentDetails, turnContext: TurnContext, authToken: string): AgentDetails;
|
|
81
|
+
private static buildInvokeAgentDetailsCore;
|
|
74
82
|
/**
|
|
75
83
|
* Create an `ExecuteToolScope` using `details` and values derived from the provided `TurnContext`.
|
|
76
|
-
* Derives `
|
|
84
|
+
* Derives `conversationId` and `channel` (name/link) from context.
|
|
77
85
|
* @param details The tool call details (name, type, args, call id, etc.).
|
|
78
86
|
* @param turnContext The current activity context to derive scope parameters from.
|
|
87
|
+
* @param authToken Auth token for resolving agent identity from token claims.
|
|
88
|
+
* @param startTime Optional explicit start time (ms epoch, Date, or HrTime). Useful when recording a
|
|
89
|
+
* tool call after execution has already completed.
|
|
90
|
+
* @param endTime Optional explicit end time (ms epoch, Date, or HrTime).
|
|
91
|
+
* @param spanKind Optional span kind override. Defaults to `SpanKind.INTERNAL`.
|
|
79
92
|
* @returns A started `ExecuteToolScope` enriched with context-derived parameters.
|
|
80
93
|
*/
|
|
81
|
-
static populateExecuteToolScopeFromTurnContext(details: ToolCallDetails, turnContext: TurnContext): ExecuteToolScope;
|
|
94
|
+
static populateExecuteToolScopeFromTurnContext(details: ToolCallDetails, turnContext: TurnContext, authToken: string, startTime?: TimeInput, endTime?: TimeInput, spanKind?: SpanKind): ExecuteToolScope;
|
|
82
95
|
}
|
|
83
96
|
//# sourceMappingURL=ScopeUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScopeUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/ScopeUtils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"ScopeUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/ScopeUtils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,WAAW,EAEX,gBAAgB,EAChB,eAAe,EAGf,uBAAuB,EACxB,MAAM,sCAAsC,CAAC;AAG9C;;;GAGG;AACH,qBAAa,UAAU;IAGrB,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAalC;;;;;;;OAOG;WACW,kBAAkB,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAgBvG;;;;OAIG;WACW,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,YAAY,GAAG,SAAS;IAenF;;;;OAIG;WACW,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS;IAWpF;;;;OAIG;WACW,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS;IAIhF;;;;OAIG;WACW,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE;IAOpG;;;;;;;;;;OAUG;IACH,MAAM,CAAC,qCAAqC,CAC1C,OAAO,EAAE,gBAAgB,EACzB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,SAAS,EACrB,OAAO,CAAC,EAAE,SAAS,GAClB,cAAc;IAyBjB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,uCAAuC,CAC5C,OAAO,EAAE,YAAY,EACrB,YAAY,EAAE,uBAAuB,EACrC,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,SAAS,EACrB,OAAO,CAAC,EAAE,SAAS,EACnB,QAAQ,CAAC,EAAE,QAAQ,GAClB,gBAAgB;IA+BnB;;;;;;OAMG;WACW,uBAAuB,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,YAAY;IAIvH,OAAO,CAAC,MAAM,CAAC,2BAA2B;IAY1C;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,uCAAuC,CAC5C,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,SAAS,EACrB,OAAO,CAAC,EAAE,SAAS,EACnB,QAAQ,CAAC,EAAE,QAAQ,GAClB,gBAAgB;CAwBpB"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
4
|
// ------------------------------------------------------------------------------
|
|
5
|
-
import { InvokeAgentScope, InferenceScope, ExecuteToolScope } from '@microsoft/agents-a365-observability';
|
|
6
|
-
import {
|
|
5
|
+
import { InvokeAgentScope, InferenceScope, ExecuteToolScope, } from '@microsoft/agents-a365-observability';
|
|
6
|
+
import { resolveEmbodiedAgentIds } from './TurnContextUtils';
|
|
7
7
|
/**
|
|
8
8
|
* Unified utilities to populate scope tags from a TurnContext.
|
|
9
9
|
* Provides common tag population and scope-specific helpers.
|
|
@@ -18,30 +18,27 @@ export class ScopeUtils {
|
|
|
18
18
|
// ----------------------
|
|
19
19
|
// Context-derived helpers
|
|
20
20
|
// ----------------------
|
|
21
|
-
/**
|
|
22
|
-
* Derive tenant details from the TurnContext.
|
|
23
|
-
* @param turnContext Activity context
|
|
24
|
-
* @returns Tenant details if a recipient tenant id is present; otherwise undefined.
|
|
25
|
-
*/
|
|
26
|
-
static deriveTenantDetails(turnContext) {
|
|
27
|
-
const tenantId = turnContext?.activity?.recipient?.tenantId;
|
|
28
|
-
return tenantId ? { tenantId } : undefined;
|
|
29
|
-
}
|
|
30
21
|
/**
|
|
31
22
|
* Derive target agent details from the activity recipient.
|
|
23
|
+
* Uses {@link resolveEmbodiedAgentIds} to resolve the agent ID and blueprint ID, which are only
|
|
24
|
+
* set for embodied (agentic) agents — see that function for the rationale.
|
|
32
25
|
* @param turnContext Activity context
|
|
26
|
+
* @param authToken Auth token for resolving agent identity from token claims.
|
|
33
27
|
* @returns Agent details built from recipient properties; otherwise undefined.
|
|
34
28
|
*/
|
|
35
|
-
static deriveAgentDetails(turnContext) {
|
|
29
|
+
static deriveAgentDetails(turnContext, authToken) {
|
|
36
30
|
const recipient = turnContext?.activity?.recipient;
|
|
37
31
|
if (!recipient)
|
|
38
32
|
return undefined;
|
|
33
|
+
const { agentId, agentBlueprintId } = resolveEmbodiedAgentIds(turnContext, authToken);
|
|
39
34
|
return {
|
|
40
|
-
agentId
|
|
35
|
+
agentId,
|
|
41
36
|
agentName: recipient.name,
|
|
42
37
|
agentAUID: recipient.aadObjectId,
|
|
38
|
+
agentBlueprintId,
|
|
39
|
+
agentEmail: turnContext?.activity?.getAgenticUser?.(),
|
|
43
40
|
agentDescription: recipient.role,
|
|
44
|
-
tenantId:
|
|
41
|
+
tenantId: turnContext?.activity?.getAgenticTenantId?.()
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
/**
|
|
@@ -59,22 +56,23 @@ export class ScopeUtils {
|
|
|
59
56
|
agentAUID: from.aadObjectId,
|
|
60
57
|
agentDescription: from.role,
|
|
61
58
|
tenantId: from.tenantId,
|
|
62
|
-
agentId: from.agenticAppId
|
|
59
|
+
agentId: from.agenticAppId,
|
|
60
|
+
agentEmail: from.agenticUserId
|
|
63
61
|
};
|
|
64
62
|
}
|
|
65
63
|
/**
|
|
66
|
-
* Derive caller identity details (id,
|
|
64
|
+
* Derive caller identity details (id, email, name, tenant) from the activity from.
|
|
67
65
|
* @param turnContext Activity context
|
|
68
|
-
* @returns
|
|
66
|
+
* @returns User details when available; otherwise undefined.
|
|
69
67
|
*/
|
|
70
68
|
static deriveCallerDetails(turnContext) {
|
|
71
69
|
const from = turnContext?.activity?.from;
|
|
72
70
|
if (!from)
|
|
73
71
|
return undefined;
|
|
74
72
|
return {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
userId: from.aadObjectId,
|
|
74
|
+
userEmail: from.agenticUserId,
|
|
75
|
+
userName: from.name,
|
|
78
76
|
tenantId: from.tenantId,
|
|
79
77
|
};
|
|
80
78
|
}
|
|
@@ -87,11 +85,11 @@ export class ScopeUtils {
|
|
|
87
85
|
return turnContext?.activity?.conversation?.id;
|
|
88
86
|
}
|
|
89
87
|
/**
|
|
90
|
-
* Derive
|
|
88
|
+
* Derive channel (name and description) from the TurnContext.
|
|
91
89
|
* @param turnContext Activity context
|
|
92
90
|
* @returns Object with optional name and description fields.
|
|
93
91
|
*/
|
|
94
|
-
static
|
|
92
|
+
static deriveChannelObject(turnContext) {
|
|
95
93
|
return {
|
|
96
94
|
name: turnContext?.activity?.channelId,
|
|
97
95
|
description: turnContext?.activity?.channelIdSubChannel
|
|
@@ -99,95 +97,122 @@ export class ScopeUtils {
|
|
|
99
97
|
}
|
|
100
98
|
/**
|
|
101
99
|
* Create an `InferenceScope` using `details` and values derived from the provided `TurnContext`.
|
|
102
|
-
* Derives `
|
|
100
|
+
* Derives `conversationId` and `channel` (name/description) from context.
|
|
103
101
|
* Also records input messages from the context if present.
|
|
104
102
|
* @param details The inference call details (model, provider, tokens, etc.).
|
|
105
103
|
* @param turnContext The current activity context to derive scope parameters from.
|
|
104
|
+
* @param authToken Auth token for resolving agent identity from token claims.
|
|
105
|
+
* @param startTime Optional explicit start time (ms epoch, Date, or HrTime).
|
|
106
|
+
* @param endTime Optional explicit end time (ms epoch, Date, or HrTime).
|
|
106
107
|
* @returns A started `InferenceScope` enriched with context-derived parameters.
|
|
107
108
|
*/
|
|
108
|
-
static populateInferenceScopeFromTurnContext(details, turnContext) {
|
|
109
|
-
const agent = ScopeUtils.deriveAgentDetails(turnContext);
|
|
110
|
-
const
|
|
109
|
+
static populateInferenceScopeFromTurnContext(details, turnContext, authToken, startTime, endTime) {
|
|
110
|
+
const agent = ScopeUtils.deriveAgentDetails(turnContext, authToken);
|
|
111
|
+
const caller = ScopeUtils.deriveCallerDetails(turnContext);
|
|
111
112
|
const conversationId = ScopeUtils.deriveConversationId(turnContext);
|
|
112
|
-
const
|
|
113
|
+
const channel = ScopeUtils.deriveChannelObject(turnContext);
|
|
113
114
|
if (!agent) {
|
|
114
115
|
throw new Error('populateInferenceScopeFromTurnContext: Missing agent details on TurnContext (recipient)');
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
const hasChannel = channel.name !== undefined || channel.description !== undefined;
|
|
118
|
+
const request = {
|
|
119
|
+
conversationId,
|
|
120
|
+
...(hasChannel ? { channel: { name: channel.name, description: channel.description } } : {}),
|
|
121
|
+
};
|
|
122
|
+
const spanDetails = (startTime || endTime)
|
|
123
|
+
? { startTime, endTime }
|
|
124
|
+
: undefined;
|
|
125
|
+
const scope = InferenceScope.start(request, details, agent, caller, spanDetails);
|
|
120
126
|
this.setInputMessageTags(scope, turnContext);
|
|
121
127
|
return scope;
|
|
122
128
|
}
|
|
123
129
|
/**
|
|
124
130
|
* Create an `InvokeAgentScope` using `details` and values derived from the provided `TurnContext`.
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
131
|
+
* Builds a separate `Request` with `conversationId` and `channel` from context.
|
|
132
|
+
* Merges agent identity from context into `details` via `buildInvokeAgentDetailsCore`.
|
|
133
|
+
* Derives `callerAgentDetails` (from caller) and `userDetails` (human caller).
|
|
134
|
+
* Also records input messages from the context if present.
|
|
135
|
+
* @param details The agent details to be augmented with context-derived identity.
|
|
129
136
|
* @param turnContext The current activity context to derive scope parameters from.
|
|
137
|
+
* @param authToken Auth token for resolving agent identity from token claims.
|
|
138
|
+
* @param startTime Optional explicit start time (ms epoch, Date, or HrTime).
|
|
139
|
+
* @param endTime Optional explicit end time (ms epoch, Date, or HrTime).
|
|
140
|
+
* @param spanKind Optional span kind override. Defaults to `SpanKind.CLIENT`.
|
|
130
141
|
* @returns A started `InvokeAgentScope` enriched with context-derived parameters.
|
|
131
142
|
*/
|
|
132
|
-
static populateInvokeAgentScopeFromTurnContext(details, turnContext) {
|
|
133
|
-
const tenant = ScopeUtils.deriveTenantDetails(turnContext);
|
|
143
|
+
static populateInvokeAgentScopeFromTurnContext(details, scopeDetails, turnContext, authToken, startTime, endTime, spanKind) {
|
|
134
144
|
const callerAgent = ScopeUtils.deriveCallerAgent(turnContext);
|
|
135
145
|
const caller = ScopeUtils.deriveCallerDetails(turnContext);
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
const conversationId = ScopeUtils.deriveConversationId(turnContext);
|
|
147
|
+
const channel = ScopeUtils.deriveChannelObject(turnContext);
|
|
148
|
+
// Merge agent identity from TurnContext into details.details
|
|
149
|
+
const agentDetails = ScopeUtils.buildInvokeAgentDetailsCore(details, turnContext, authToken);
|
|
150
|
+
// Build the request with channel and conversationId from context
|
|
151
|
+
const hasChannel = channel.name !== undefined || channel.description !== undefined;
|
|
152
|
+
const request = {
|
|
153
|
+
conversationId,
|
|
154
|
+
...(hasChannel ? { channel: { name: channel.name, description: channel.description } } : {}),
|
|
155
|
+
};
|
|
156
|
+
// Build caller info with both human caller and caller agent details
|
|
157
|
+
const callerDetails = {
|
|
158
|
+
userDetails: caller,
|
|
159
|
+
callerAgentDetails: callerAgent,
|
|
160
|
+
};
|
|
161
|
+
const spanDetailsObj = (startTime || endTime || spanKind)
|
|
162
|
+
? { startTime, endTime, spanKind }
|
|
163
|
+
: undefined;
|
|
164
|
+
const scope = InvokeAgentScope.start(request, scopeDetails, agentDetails, callerDetails, spanDetailsObj);
|
|
141
165
|
this.setInputMessageTags(scope, turnContext);
|
|
142
166
|
return scope;
|
|
143
167
|
}
|
|
144
168
|
/**
|
|
145
|
-
* Build
|
|
146
|
-
* @param details Base
|
|
169
|
+
* Build agent details by merging provided details with agent info from the TurnContext.
|
|
170
|
+
* @param details Base agent details to augment
|
|
147
171
|
* @param turnContext Activity context
|
|
148
|
-
* @
|
|
172
|
+
* @param authToken Auth token for resolving agent identity from token claims.
|
|
173
|
+
* @returns Merged AgentDetails with context-derived identity.
|
|
149
174
|
*/
|
|
150
|
-
static buildInvokeAgentDetails(details, turnContext) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
...baseSource,
|
|
158
|
-
...(srcMetaFromContext.name !== undefined ? { name: srcMetaFromContext.name } : {}),
|
|
159
|
-
...(srcMetaFromContext.description !== undefined ? { description: srcMetaFromContext.description } : {}),
|
|
160
|
-
};
|
|
161
|
-
return {
|
|
175
|
+
static buildInvokeAgentDetails(details, turnContext, authToken) {
|
|
176
|
+
return ScopeUtils.buildInvokeAgentDetailsCore(details, turnContext, authToken);
|
|
177
|
+
}
|
|
178
|
+
static buildInvokeAgentDetailsCore(details, turnContext, authToken) {
|
|
179
|
+
const derivedAgentDetails = ScopeUtils.deriveAgentDetails(turnContext, authToken);
|
|
180
|
+
// Merge derived agent identity into details
|
|
181
|
+
const mergedAgent = {
|
|
162
182
|
...details,
|
|
163
|
-
...
|
|
164
|
-
conversationId: ScopeUtils.deriveConversationId(turnContext),
|
|
165
|
-
request: {
|
|
166
|
-
...baseRequest,
|
|
167
|
-
executionType: executionTypePair.length > 0 ? executionTypePair[0][1] : baseRequest.executionType,
|
|
168
|
-
sourceMetadata: mergedSourceMetadata
|
|
169
|
-
}
|
|
183
|
+
...(derivedAgentDetails ?? {}),
|
|
170
184
|
};
|
|
185
|
+
return mergedAgent;
|
|
171
186
|
}
|
|
172
187
|
/**
|
|
173
188
|
* Create an `ExecuteToolScope` using `details` and values derived from the provided `TurnContext`.
|
|
174
|
-
* Derives `
|
|
189
|
+
* Derives `conversationId` and `channel` (name/link) from context.
|
|
175
190
|
* @param details The tool call details (name, type, args, call id, etc.).
|
|
176
191
|
* @param turnContext The current activity context to derive scope parameters from.
|
|
192
|
+
* @param authToken Auth token for resolving agent identity from token claims.
|
|
193
|
+
* @param startTime Optional explicit start time (ms epoch, Date, or HrTime). Useful when recording a
|
|
194
|
+
* tool call after execution has already completed.
|
|
195
|
+
* @param endTime Optional explicit end time (ms epoch, Date, or HrTime).
|
|
196
|
+
* @param spanKind Optional span kind override. Defaults to `SpanKind.INTERNAL`.
|
|
177
197
|
* @returns A started `ExecuteToolScope` enriched with context-derived parameters.
|
|
178
198
|
*/
|
|
179
|
-
static populateExecuteToolScopeFromTurnContext(details, turnContext) {
|
|
180
|
-
const agent = ScopeUtils.deriveAgentDetails(turnContext);
|
|
181
|
-
const
|
|
199
|
+
static populateExecuteToolScopeFromTurnContext(details, turnContext, authToken, startTime, endTime, spanKind) {
|
|
200
|
+
const agent = ScopeUtils.deriveAgentDetails(turnContext, authToken);
|
|
201
|
+
const caller = ScopeUtils.deriveCallerDetails(turnContext);
|
|
182
202
|
const conversationId = ScopeUtils.deriveConversationId(turnContext);
|
|
183
|
-
const
|
|
203
|
+
const channel = ScopeUtils.deriveChannelObject(turnContext);
|
|
184
204
|
if (!agent) {
|
|
185
205
|
throw new Error('populateExecuteToolScopeFromTurnContext: Missing agent details on TurnContext (recipient)');
|
|
186
206
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
207
|
+
const hasChannel = channel.name !== undefined || channel.description !== undefined;
|
|
208
|
+
const request = {
|
|
209
|
+
conversationId,
|
|
210
|
+
...(hasChannel ? { channel: { name: channel.name, description: channel.description } } : {}),
|
|
211
|
+
};
|
|
212
|
+
const spanDetailsObj = (startTime || endTime || spanKind)
|
|
213
|
+
? { startTime, endTime, spanKind }
|
|
214
|
+
: undefined;
|
|
215
|
+
const scope = ExecuteToolScope.start(request, details, agent, caller, spanDetailsObj);
|
|
191
216
|
return scope;
|
|
192
217
|
}
|
|
193
218
|
}
|