UNPKG

@microsoft/agents-copilotstudio-client

Version:

Microsoft Copilot Studio Client for JavaScript. Copilot Studio Client.

173 lines 8.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CopilotStudioClientTraceDefinitions = void 0; const agents_activity_1 = require("@microsoft/agents-activity"); const agents_telemetry_1 = require("@microsoft/agents-telemetry"); const metrics_1 = require("./metrics"); exports.CopilotStudioClientTraceDefinitions = { createConnection: agents_telemetry_1.trace.define({ name: agents_telemetry_1.SpanNames.COPILOT_CREATE_CONNECTION, record: { showTyping: false, }, actions: ({ span }) => ({ receivedFromCopilot(activity) { var _a, _b, _c; span.addEvent('activity.received.from.copilot.studio', { 'copilot.webchat.activity.type': (_a = activity.type) !== null && _a !== void 0 ? _a : 'unknown', 'copilot.webchat.activity.conversation_id': (_c = (_b = activity.conversation) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : 'unknown' }); }, sentToWebChat(activity) { var _a, _b, _c; span.addEvent('activity.sent.to.webchat', { 'copilot.webchat.activity.type': (_a = activity.type) !== null && _a !== void 0 ? _a : 'unknown', 'copilot.webchat.activity.conversation_id': (_c = (_b = activity.conversation) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : 'unknown' }); }, }), end({ span, record }) { var _a; const attributes = { 'copilot.webchat.show_typing': (_a = record.showTyping) !== null && _a !== void 0 ? _a : 'unknown' }; span.setAttributes(attributes); metrics_1.CopilotStudioClientMetrics.webchatConnectionsCounter.add(1, attributes); } }), postRequest: agents_telemetry_1.trace.define({ name: agents_telemetry_1.SpanNames.COPILOT_POST_REQUEST, record: { url: '', method: '' }, actions: ({ span }) => ({ receivedFromCopilot(activity) { var _a, _b, _c; const attributes = { 'copilot.activity.type': (_a = activity.type) !== null && _a !== void 0 ? _a : 'unknown', 'copilot.activity.conversation_id': (_c = (_b = activity.conversation) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : 'unknown' }; span.addEvent('activity.received', { 'copilot.post_request.activity.type': attributes['copilot.activity.type'], 'copilot.post_request.activity.conversation_id': attributes['copilot.activity.conversation_id'] }); metrics_1.CopilotStudioClientMetrics.activitiesReceivedCounter.add(1, attributes); } }), end({ span, record, duration, error }) { var _a, _b; const attributes = { 'copilot.post_request.url': (_a = record.url) !== null && _a !== void 0 ? _a : 'unknown', 'copilot.post_request.method': (_b = record.method) !== null && _b !== void 0 ? _b : 'unknown' }; const metricAttributes = { operation: 'postRequestAsync', 'copilot.post_request.url': attributes['copilot.post_request.url'], 'copilot.post_request.method': attributes['copilot.post_request.method'] }; span.setAttributes(attributes); metrics_1.CopilotStudioClientMetrics.requestsCounter.add(1, metricAttributes); metrics_1.CopilotStudioClientMetrics.streamDuration.record(duration, metricAttributes); if (error) { metrics_1.CopilotStudioClientMetrics.requestsErrorCounter.add(1, { ...metricAttributes, 'error.type': error instanceof Error ? error.name : typeof error, }); } } }), startConversation: agents_telemetry_1.trace.define({ name: agents_telemetry_1.SpanNames.COPILOT_START_CONVERSATION, record: { shouldEmitStartEvent: false, }, end({ span, record, duration }) { const attributes = record.shouldEmitStartEvent ? { 'copilot.emit_start_event': true } : { 'copilot.request': true }; const metricAttributes = { operation: 'startConversationStreaming', ...attributes, }; span.setAttributes(attributes); metrics_1.CopilotStudioClientMetrics.conversationsStartedCounter.add(1, metricAttributes); metrics_1.CopilotStudioClientMetrics.requestDuration.record(duration, metricAttributes); } }), sendActivity: agents_telemetry_1.trace.define({ name: agents_telemetry_1.SpanNames.COPILOT_SEND_ACTIVITY, record: { activity: agents_activity_1.Activity.fromObject({ type: 'unknown' }), }, end({ span, record, duration }) { var _a, _b, _c; const attributes = { 'copilot.activity.type': (_a = record.activity.type) !== null && _a !== void 0 ? _a : 'unknown', 'copilot.activity.conversation_id': (_c = (_b = record.activity.conversation) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : 'unknown' }; const metricAttributes = { operation: 'sendActivityStreaming', ...attributes, }; span.setAttributes(attributes); metrics_1.CopilotStudioClientMetrics.activitiesSentCounter.add(1, attributes); metrics_1.CopilotStudioClientMetrics.requestDuration.record(duration, metricAttributes); } }), executeStreaming: agents_telemetry_1.trace.define({ name: agents_telemetry_1.SpanNames.COPILOT_EXECUTE_STREAMING, record: { activity: agents_activity_1.Activity.fromObject({ type: 'unknown' }), conversationId: 'unknown' }, end({ span, record, duration }) { var _a, _b; const attributes = { 'copilot.activity.type': (_a = record.activity.type) !== null && _a !== void 0 ? _a : 'unknown', 'copilot.activity.conversation_id': (_b = record.conversationId) !== null && _b !== void 0 ? _b : 'unknown' }; const metricAttributes = { operation: 'executeStreaming', ...attributes, }; span.setAttributes(attributes); metrics_1.CopilotStudioClientMetrics.executeStreamingCounter.add(1, attributes); metrics_1.CopilotStudioClientMetrics.requestDuration.record(duration, metricAttributes); } }), subscribeAsync: agents_telemetry_1.trace.define({ name: agents_telemetry_1.SpanNames.COPILOT_SUBSCRIBE_ASYNC, record: { conversationId: 'unknown', lastReceivedEventId: 'unknown' }, actions: ({ span }) => ({ eventReceivedFromCopilot(event) { var _a, _b; const attributes = { 'copilot.subscribe_async.event.id': (_a = event.eventId) !== null && _a !== void 0 ? _a : 'unknown', 'copilot.subscribe_async.event.activity.type': (_b = event.activity.type) !== null && _b !== void 0 ? _b : 'unknown', }; span.addEvent('event.received', attributes); metrics_1.CopilotStudioClientMetrics.subscribeEventCounter.add(1, attributes); } }), end({ span, record, duration }) { var _a, _b; const attributes = { 'copilot.subscribe_async.conversation_id': (_a = record.conversationId) !== null && _a !== void 0 ? _a : 'unknown', 'copilot.subscribe_async.last_received_event_id': (_b = record.lastReceivedEventId) !== null && _b !== void 0 ? _b : 'unknown' }; const metricAttributes = { operation: 'subscribeAsync', 'copilot.conversation_id': attributes['copilot.subscribe_async.conversation_id'], 'copilot.last_received_event_id': attributes['copilot.subscribe_async.last_received_event_id'] }; span.setAttributes(attributes); metrics_1.CopilotStudioClientMetrics.subscribeAsyncCounter.add(1, metricAttributes); metrics_1.CopilotStudioClientMetrics.streamDuration.record(duration, metricAttributes); } }) }; //# sourceMappingURL=traces.js.map