linkque-cli-v2 1.4.4 → 1.4.6

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/worker.js CHANGED
@@ -45,6 +45,7 @@ var init_types = __esm({
45
45
  EDebugLogScope2["LLM"] = "LLM";
46
46
  EDebugLogScope2["PI_EVENT"] = "PI_EVENT";
47
47
  EDebugLogScope2["MCP"] = "MCP";
48
+ EDebugLogScope2["SKILL"] = "SKILL";
48
49
  EDebugLogScope2["HTTP"] = "HTTP";
49
50
  EDebugLogScope2["HOOK"] = "HOOK";
50
51
  })(EDebugLogScope || (EDebugLogScope = {}));
@@ -4361,13 +4362,14 @@ var require_fast_uri = __commonJS({
4361
4362
  if (!malformedIPLiteral) {
4362
4363
  malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP2);
4363
4364
  }
4364
- if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
4365
- if (uri.indexOf("%") !== -1) {
4366
- if (parsed.host !== void 0 && !malformedIPLiteral) {
4367
- const host = isIP2 ? parsed.host : normalizePercentEncoding(parsed.host, true);
4368
- parsed.host = reescapeHostDelimiters(host, isIP2);
4369
- }
4365
+ if (uri.indexOf("%") !== -1 && parsed.host !== void 0 && !malformedIPLiteral) {
4366
+ let host = isIP2 ? parsed.host : normalizePercentEncoding(parsed.host, true);
4367
+ if (!isIP2) {
4368
+ host = normalizePercentEncoding(host.toLowerCase());
4370
4369
  }
4370
+ parsed.host = reescapeHostDelimiters(host, isIP2);
4371
+ }
4372
+ if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
4371
4373
  if (parsed.path) {
4372
4374
  parsed.path = normalizePathEncoding(parsed.path);
4373
4375
  }
@@ -11886,6 +11888,380 @@ var init_mcpAggregator = __esm({
11886
11888
  }
11887
11889
  });
11888
11890
 
11891
+ // ../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js
11892
+ var CONTENT_VALUE_MAX_LENGTH, ETelemetryAttribute, ETelemetryEventPrefix, ETelemetryEventPhase, ETelemetryEventName, ETelemetryContentSection, ETelemetryOperationName, ETelemetryOutcome, ETelemetrySignal, ETelemetryLossReason, ETelemetryAdvanceOutcome, ETelemetryStreamTermination, ETelemetryCancelSource, ETelemetryObservationBoundary, ETelemetryRemoteCompletion, ETelemetryCommitStatus, ETelemetryHookMode, ETelemetryHookResult, ETelemetrySource, ETelemetryEvidence, ETelemetryCompleteness, ETelemetryCoverage, ETelemetryUsageSource, ETelemetryAttemptVisibility, ETelemetryLinkRelation, ETelemetryToolFailureStage, ETelemetryTerminalEvidence, ETelemetryTerminalSource, ETelemetryModelPurpose, ETelemetryErrorType, ETelemetrySpanKind, ETelemetryGenAiOperation, ETelemetryVersion;
11893
+ var init_telemetryEnums = __esm({
11894
+ "../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js"() {
11895
+ "use strict";
11896
+ CONTENT_VALUE_MAX_LENGTH = 16 * 1024;
11897
+ (function(ETelemetryAttribute2) {
11898
+ ETelemetryAttribute2["HARNESS_TELEMETRY_SCHEMA_VERSION"] = "harness.telemetry.schema.version";
11899
+ ETelemetryAttribute2["LINKQUE_TELEMETRY_SCHEMA_VERSION"] = "linkque.telemetry.schema.version";
11900
+ ETelemetryAttribute2["LINKQUE_TELEMETRY_ADAPTER_VERSION"] = "linkque.telemetry.adapter.version";
11901
+ ETelemetryAttribute2["HARNESS_TELEMETRY_SOURCE"] = "harness.telemetry.source";
11902
+ ETelemetryAttribute2["HARNESS_TELEMETRY_EVIDENCE"] = "harness.telemetry.evidence";
11903
+ ETelemetryAttribute2["HARNESS_TELEMETRY_COMPLETENESS"] = "harness.telemetry.completeness";
11904
+ ETelemetryAttribute2["LINKQUE_RUNTIME_KIND"] = "linkque.runtime.kind";
11905
+ ETelemetryAttribute2["LINKQUE_RUN_ID"] = "linkque.run.id";
11906
+ ETelemetryAttribute2["LINKQUE_AGENT_ID"] = "linkque.agent.id";
11907
+ ETelemetryAttribute2["HARNESS_SESSION_ID"] = "harness.session.id";
11908
+ ETelemetryAttribute2["LINKQUE_CONVERSATION_ID"] = "linkque.conversation.id";
11909
+ ETelemetryAttribute2["LINKQUE_REQUEST_ID"] = "linkque.request.id";
11910
+ ETelemetryAttribute2["LINKQUE_TURN_ID"] = "linkque.turn.id";
11911
+ ETelemetryAttribute2["LINKQUE_ACCOUNT_ID"] = "linkque.account.id";
11912
+ ETelemetryAttribute2["LINKQUE_CHANNEL"] = "linkque.channel";
11913
+ ETelemetryAttribute2["LINKQUE_USER_KEY"] = "linkque.user.key";
11914
+ ETelemetryAttribute2["HARNESS_ADVANCE_ID"] = "harness.advance.id";
11915
+ ETelemetryAttribute2["HARNESS_CALL_ID"] = "harness.call.id";
11916
+ ETelemetryAttribute2["HARNESS_INVOCATION_ID"] = "harness.invocation.id";
11917
+ ETelemetryAttribute2["HARNESS_ATTEMPT_ID"] = "harness.attempt.id";
11918
+ ETelemetryAttribute2["HARNESS_ATTEMPT_VISIBILITY"] = "harness.attempt.visibility";
11919
+ ETelemetryAttribute2["HARNESS_ADVANCE_OUTCOME"] = "harness.advance.outcome";
11920
+ ETelemetryAttribute2["HARNESS_OPERATION_OUTCOME"] = "harness.operation.outcome";
11921
+ ETelemetryAttribute2["HARNESS_REMOTE_COMPLETION"] = "harness.remote.completion";
11922
+ ETelemetryAttribute2["HARNESS_STATE_COMMIT_STATUS"] = "harness.state.commit.status";
11923
+ ETelemetryAttribute2["LINKQUE_OPERATION_ID"] = "linkque.operation.id";
11924
+ ETelemetryAttribute2["LINKQUE_OPERATION_NAME"] = "linkque.operation.name";
11925
+ ETelemetryAttribute2["LINKQUE_OPERATION_PARENT_ID"] = "linkque.operation.parent_id";
11926
+ ETelemetryAttribute2["LINKQUE_SPAN_PARENT_ID"] = "linkque.span.parent_id";
11927
+ ETelemetryAttribute2["HARNESS_RECORD_ID"] = "harness.record.id";
11928
+ ETelemetryAttribute2["HARNESS_EVENT_SEQUENCE"] = "harness.event.sequence";
11929
+ ETelemetryAttribute2["ERROR_TYPE"] = "error.type";
11930
+ ETelemetryAttribute2["LINKQUE_STREAM_TERMINATION"] = "linkque.stream.termination";
11931
+ ETelemetryAttribute2["LINKQUE_STREAM_CANCEL_SOURCE"] = "linkque.stream.cancel_source";
11932
+ ETelemetryAttribute2["LINKQUE_TERMINAL_EVIDENCE"] = "linkque.terminal.evidence";
11933
+ ETelemetryAttribute2["LINKQUE_RUNTIME_CLEANUP_OUTCOME"] = "linkque.runtime.cleanup_outcome";
11934
+ ETelemetryAttribute2["LINKQUE_OBSERVATION_BOUNDARY"] = "linkque.observation.boundary";
11935
+ ETelemetryAttribute2["LINKQUE_LOOP_ITERATION_ID"] = "linkque.loop.iteration.id";
11936
+ ETelemetryAttribute2["LINKQUE_LOOP_ITERATION_INDEX"] = "linkque.loop.iteration.index";
11937
+ ETelemetryAttribute2["LINKQUE_STREAM_TERMINAL_SOURCE"] = "linkque.stream.terminal_source";
11938
+ ETelemetryAttribute2["LINKQUE_STREAM_PUBLIC_TEXT_DELTA_COUNT"] = "linkque.stream.public_text_delta_count";
11939
+ ETelemetryAttribute2["LINKQUE_STREAM_THINKING_DELTA_COUNT"] = "linkque.stream.thinking_delta_count";
11940
+ ETelemetryAttribute2["LINKQUE_MODEL_FIRST_CHUNK_MS"] = "linkque.model.first_chunk_ms";
11941
+ ETelemetryAttribute2["LINKQUE_MODEL_FIRST_TEXT_MS"] = "linkque.model.first_text_ms";
11942
+ ETelemetryAttribute2["LINKQUE_LOOP_FIRST_PUBLIC_TEXT_MS"] = "linkque.loop.first_public_text_ms";
11943
+ ETelemetryAttribute2["LINKQUE_MODEL_CHUNK_COUNT"] = "linkque.model.chunk_count";
11944
+ ETelemetryAttribute2["LINKQUE_MODEL_TEXT_CHARS"] = "linkque.model.text_chars";
11945
+ ETelemetryAttribute2["LINKQUE_MODEL_THINKING_CHARS"] = "linkque.model.thinking_chars";
11946
+ ETelemetryAttribute2["GEN_AI_OPERATION_NAME"] = "gen_ai.operation.name";
11947
+ ETelemetryAttribute2["GEN_AI_AGENT_NAME"] = "gen_ai.agent.name";
11948
+ ETelemetryAttribute2["GEN_AI_PROVIDER_NAME"] = "gen_ai.provider.name";
11949
+ ETelemetryAttribute2["GEN_AI_REQUEST_MODEL"] = "gen_ai.request.model";
11950
+ ETelemetryAttribute2["GEN_AI_RESPONSE_MODEL"] = "gen_ai.response.model";
11951
+ ETelemetryAttribute2["GEN_AI_RESPONSE_ID"] = "gen_ai.response.id";
11952
+ ETelemetryAttribute2["LINKQUE_CONTENT_VALUE_TRUNCATED"] = "linkque.content.value.truncated";
11953
+ ETelemetryAttribute2["GEN_AI_RESPONSE_FINISH_REASONS"] = "gen_ai.response.finish_reasons";
11954
+ ETelemetryAttribute2["GEN_AI_USAGE_INPUT_TOKENS"] = "gen_ai.usage.input_tokens";
11955
+ ETelemetryAttribute2["GEN_AI_USAGE_OUTPUT_TOKENS"] = "gen_ai.usage.output_tokens";
11956
+ ETelemetryAttribute2["GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS"] = "gen_ai.usage.cache_read.input_tokens";
11957
+ ETelemetryAttribute2["GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS"] = "gen_ai.usage.cache_creation.input_tokens";
11958
+ ETelemetryAttribute2["GEN_AI_USAGE_REASONING_OUTPUT_TOKENS"] = "gen_ai.usage.reasoning.output_tokens";
11959
+ ETelemetryAttribute2["HARNESS_USAGE_SOURCE"] = "harness.usage.source";
11960
+ ETelemetryAttribute2["HARNESS_USAGE_ATTEMPT_COVERAGE"] = "harness.usage.attempt_coverage";
11961
+ ETelemetryAttribute2["HARNESS_MODEL_PURPOSE"] = "harness.model.purpose";
11962
+ ETelemetryAttribute2["HARNESS_MODEL_INVOCATION_COUNT"] = "harness.model.invocation_count";
11963
+ ETelemetryAttribute2["GEN_AI_TOOL_NAME"] = "gen_ai.tool.name";
11964
+ ETelemetryAttribute2["LINKQUE_TOOL_DISPLAY_NAME"] = "linkque.tool.display_name";
11965
+ ETelemetryAttribute2["LINKQUE_CARD_EXECUTION_ID"] = "linkque.card.execution_id";
11966
+ ETelemetryAttribute2["LINKQUE_CARD_REF"] = "linkque.card.ref";
11967
+ ETelemetryAttribute2["LINKQUE_CARD_REVISION"] = "linkque.card.revision";
11968
+ ETelemetryAttribute2["LINKQUE_CARD_DISPLAY_NAME"] = "linkque.card.display_name";
11969
+ ETelemetryAttribute2["LINKQUE_CARD_PHASE"] = "linkque.card.phase";
11970
+ ETelemetryAttribute2["LINKQUE_CARD_SOURCE_ID"] = "linkque.card.source_id";
11971
+ ETelemetryAttribute2["LINKQUE_CARD_DELIVERY"] = "linkque.card.delivery";
11972
+ ETelemetryAttribute2["GEN_AI_TOOL_CALL_ID"] = "gen_ai.tool.call.id";
11973
+ ETelemetryAttribute2["HARNESS_TOOL_RESULT_STATUS"] = "harness.tool.result.status";
11974
+ ETelemetryAttribute2["LINKQUE_TOOL_FAILURE_STAGE"] = "linkque.tool.failure_stage";
11975
+ ETelemetryAttribute2["HARNESS_HOOK_NAME"] = "harness.hook.name";
11976
+ ETelemetryAttribute2["LINKQUE_HOOK_STAGE"] = "linkque.hook.stage";
11977
+ ETelemetryAttribute2["LINKQUE_HOOK_RESOURCE_ID"] = "linkque.hook.resource_id";
11978
+ ETelemetryAttribute2["LINKQUE_HOOK_EVENT_ID"] = "linkque.hook.event_id";
11979
+ ETelemetryAttribute2["LINKQUE_HOOK_MATCHED_COUNT"] = "linkque.hook.matched_count";
11980
+ ETelemetryAttribute2["LINKQUE_HOOK_PENDING_COUNT"] = "linkque.hook.pending_count";
11981
+ ETelemetryAttribute2["LINKQUE_HOOK_SCHEDULED_COUNT"] = "linkque.hook.scheduled_count";
11982
+ ETelemetryAttribute2["LINKQUE_HOOK_HAS_SIDE_EFFECTS"] = "linkque.hook.has_side_effects";
11983
+ ETelemetryAttribute2["LINKQUE_HOOK_MODE"] = "linkque.hook.mode";
11984
+ ETelemetryAttribute2["LINKQUE_HOOK_TIMEOUT_MS"] = "linkque.hook.timeout_ms";
11985
+ ETelemetryAttribute2["LINKQUE_HOOK_RESULT"] = "linkque.hook.result";
11986
+ ETelemetryAttribute2["HARNESS_MIDDLEWARE_NAME"] = "harness.middleware.name";
11987
+ ETelemetryAttribute2["HARNESS_MIDDLEWARE_INVOCATION_ID"] = "harness.middleware.invocation.id";
11988
+ ETelemetryAttribute2["LINKQUE_HOOK_EXECUTOR_SETTLED"] = "linkque.hook.executor_settled";
11989
+ ETelemetryAttribute2["LINKQUE_HISTORY_MESSAGE_COUNT"] = "linkque.history.message_count";
11990
+ ETelemetryAttribute2["LINKQUE_TELEMETRY_COVERAGE"] = "linkque.telemetry.coverage";
11991
+ ETelemetryAttribute2["LINKQUE_TELEMETRY_LOSS_REASON"] = "linkque.telemetry.loss_reason";
11992
+ ETelemetryAttribute2["LINKQUE_OPERATION_DURATION_MS"] = "linkque.operation.duration_ms";
11993
+ ETelemetryAttribute2["HTTP_RESPONSE_STATUS_CODE"] = "http.response.status_code";
11994
+ ETelemetryAttribute2["SERVICE_NAME"] = "service.name";
11995
+ ETelemetryAttribute2["SERVICE_NAMESPACE"] = "service.namespace";
11996
+ ETelemetryAttribute2["SERVICE_VERSION"] = "service.version";
11997
+ ETelemetryAttribute2["SERVICE_INSTANCE_ID"] = "service.instance.id";
11998
+ ETelemetryAttribute2["DEPLOYMENT_ENVIRONMENT_NAME"] = "deployment.environment.name";
11999
+ ETelemetryAttribute2["LINKQUE_LINK_RELATION"] = "linkque.link.relation";
12000
+ })(ETelemetryAttribute || (ETelemetryAttribute = {}));
12001
+ (function(ETelemetryEventPrefix2) {
12002
+ ETelemetryEventPrefix2["OPERATION"] = "linkque.operation";
12003
+ ETelemetryEventPrefix2["ADVANCE"] = "harness.advance";
12004
+ ETelemetryEventPrefix2["MODEL_INVOKE"] = "harness.model.invoke";
12005
+ ETelemetryEventPrefix2["MODEL_ATTEMPT"] = "harness.model.attempt";
12006
+ ETelemetryEventPrefix2["TOOL_INVOKE"] = "harness.tool.invoke";
12007
+ ETelemetryEventPrefix2["TOOL_ATTEMPT"] = "harness.tool.attempt";
12008
+ ETelemetryEventPrefix2["HOOK_CHAIN"] = "harness.hook.chain";
12009
+ ETelemetryEventPrefix2["MIDDLEWARE"] = "harness.middleware";
12010
+ ETelemetryEventPrefix2["LOOP"] = "linkque.loop";
12011
+ ETelemetryEventPrefix2["LOOP_ITERATION"] = "linkque.loop.iteration";
12012
+ ETelemetryEventPrefix2["HISTORY_APPEND"] = "linkque.history.append";
12013
+ ETelemetryEventPrefix2["HOOK_DRAIN"] = "linkque.hook.drain";
12014
+ })(ETelemetryEventPrefix || (ETelemetryEventPrefix = {}));
12015
+ (function(ETelemetryEventPhase2) {
12016
+ ETelemetryEventPhase2["STARTED"] = "started";
12017
+ ETelemetryEventPhase2["FINISHED"] = "finished";
12018
+ ETelemetryEventPhase2["OBSERVATION_LOST"] = "observation_lost";
12019
+ })(ETelemetryEventPhase || (ETelemetryEventPhase = {}));
12020
+ (function(ETelemetryEventName2) {
12021
+ ETelemetryEventName2["TOOL_EXECUTION_FAILED"] = "linkque.tool.execution.failed";
12022
+ ETelemetryEventName2["TELEMETRY_COVERAGE"] = "linkque.telemetry.coverage";
12023
+ ETelemetryEventName2["HOOK_MATCHED"] = "linkque.hook.matched";
12024
+ ETelemetryEventName2["HOOK_SCHEDULED"] = "linkque.hook.scheduled";
12025
+ ETelemetryEventName2["HOOK_CANCEL_REQUESTED"] = "linkque.hook.cancel_requested";
12026
+ ETelemetryEventName2["HOOK_TIMEOUT_REQUESTED"] = "linkque.hook.timeout_requested";
12027
+ ETelemetryEventName2["HOOK_EXECUTOR_SETTLED"] = "linkque.hook.executor_settled";
12028
+ ETelemetryEventName2["HOOK_WAIT_FINISHED"] = "linkque.hook.wait_finished";
12029
+ ETelemetryEventName2["LOOP_FIRST_PUBLIC_TEXT"] = "linkque.loop.first_public_text";
12030
+ ETelemetryEventName2["STREAM_TERMINAL_OBSERVED"] = "linkque.stream.terminal_observed";
12031
+ ETelemetryEventName2["MODEL_FIRST_CHUNK"] = "harness.model.first_chunk";
12032
+ ETelemetryEventName2["MODEL_FIRST_TEXT"] = "harness.model.first_text";
12033
+ ETelemetryEventName2["MODEL_USAGE_RECORDED"] = "linkque.model.usage.recorded";
12034
+ ETelemetryEventName2["MODEL_RESPONSE_HEADERS"] = "linkque.model.response_headers";
12035
+ ETelemetryEventName2["OPERATION_OBSERVATION_LOST"] = "linkque.operation.observation_lost";
12036
+ ETelemetryEventName2["RUNTIME_UNCAUGHT_ERROR"] = "linkque.runtime.uncaught_error";
12037
+ ETelemetryEventName2["OPERATION_STARTED"] = "linkque.operation.started";
12038
+ ETelemetryEventName2["OPERATION_FINISHED"] = "linkque.operation.finished";
12039
+ ETelemetryEventName2["ADVANCE_STARTED"] = "harness.advance.started";
12040
+ ETelemetryEventName2["ADVANCE_FINISHED"] = "harness.advance.finished";
12041
+ ETelemetryEventName2["MODEL_INVOKE_STARTED"] = "harness.model.invoke.started";
12042
+ ETelemetryEventName2["MODEL_INVOKE_FINISHED"] = "harness.model.invoke.finished";
12043
+ ETelemetryEventName2["MODEL_ATTEMPT_STARTED"] = "harness.model.attempt.started";
12044
+ ETelemetryEventName2["MODEL_ATTEMPT_FINISHED"] = "harness.model.attempt.finished";
12045
+ ETelemetryEventName2["TOOL_INVOKE_STARTED"] = "harness.tool.invoke.started";
12046
+ ETelemetryEventName2["TOOL_INVOKE_FINISHED"] = "harness.tool.invoke.finished";
12047
+ ETelemetryEventName2["TOOL_ATTEMPT_STARTED"] = "harness.tool.attempt.started";
12048
+ ETelemetryEventName2["TOOL_ATTEMPT_FINISHED"] = "harness.tool.attempt.finished";
12049
+ ETelemetryEventName2["HOOK_CHAIN_STARTED"] = "harness.hook.chain.started";
12050
+ ETelemetryEventName2["HOOK_CHAIN_FINISHED"] = "harness.hook.chain.finished";
12051
+ ETelemetryEventName2["MIDDLEWARE_STARTED"] = "harness.middleware.started";
12052
+ ETelemetryEventName2["MIDDLEWARE_FINISHED"] = "harness.middleware.finished";
12053
+ ETelemetryEventName2["LOOP_STARTED"] = "linkque.loop.started";
12054
+ ETelemetryEventName2["LOOP_FINISHED"] = "linkque.loop.finished";
12055
+ ETelemetryEventName2["LOOP_ITERATION_STARTED"] = "linkque.loop.iteration.started";
12056
+ ETelemetryEventName2["LOOP_ITERATION_FINISHED"] = "linkque.loop.iteration.finished";
12057
+ ETelemetryEventName2["HISTORY_APPEND_STARTED"] = "linkque.history.append.started";
12058
+ ETelemetryEventName2["HISTORY_APPEND_FINISHED"] = "linkque.history.append.finished";
12059
+ ETelemetryEventName2["HOOK_DRAIN_STARTED"] = "linkque.hook.drain.started";
12060
+ ETelemetryEventName2["HOOK_DRAIN_FINISHED"] = "linkque.hook.drain.finished";
12061
+ ETelemetryEventName2["CONTENT_RECORDED"] = "linkque.content.recorded";
12062
+ ETelemetryEventName2["TOOL_CONTEXT"] = "linkque.tool.context";
12063
+ })(ETelemetryEventName || (ETelemetryEventName = {}));
12064
+ (function(ETelemetryContentSection2) {
12065
+ ETelemetryContentSection2["QUERY_INPUT"] = "query.input";
12066
+ ETelemetryContentSection2["MODEL_OUTPUT"] = "model.output";
12067
+ ETelemetryContentSection2["MCP_ACTION_OUTPUT"] = "mcp_action.output";
12068
+ ETelemetryContentSection2["TOOL_INPUT"] = "tool.input";
12069
+ ETelemetryContentSection2["TOOL_OUTPUT"] = "tool.output";
12070
+ ETelemetryContentSection2["MCP_REQUESTED_INPUT"] = "mcp.requested_input";
12071
+ ETelemetryContentSection2["MCP_INPUT"] = "mcp.input";
12072
+ ETelemetryContentSection2["MCP_OUTPUT"] = "mcp.output";
12073
+ ETelemetryContentSection2["SKILL_INPUT"] = "skill.input";
12074
+ ETelemetryContentSection2["SKILL_OUTPUT"] = "skill.output";
12075
+ ETelemetryContentSection2["KNOWLEDGE_INPUT"] = "knowledge.input";
12076
+ ETelemetryContentSection2["KNOWLEDGE_OUTPUT"] = "knowledge.output";
12077
+ })(ETelemetryContentSection || (ETelemetryContentSection = {}));
12078
+ (function(ETelemetryOperationName2) {
12079
+ ETelemetryOperationName2["OPERATION"] = "linkque.operation";
12080
+ ETelemetryOperationName2["TOOL_INVOKE"] = "harness.tool.invoke";
12081
+ ETelemetryOperationName2["ADVANCE"] = "harness.advance";
12082
+ ETelemetryOperationName2["MODEL_INVOKE"] = "harness.model.invoke";
12083
+ ETelemetryOperationName2["MODEL_ATTEMPT"] = "harness.model.attempt";
12084
+ ETelemetryOperationName2["TOOL_ATTEMPT"] = "harness.tool.attempt";
12085
+ ETelemetryOperationName2["HOOK_CHAIN"] = "harness.hook.chain";
12086
+ ETelemetryOperationName2["MIDDLEWARE"] = "harness.middleware";
12087
+ ETelemetryOperationName2["LOOP"] = "linkque.agent.loop";
12088
+ ETelemetryOperationName2["ITERATION"] = "linkque.agent.iteration";
12089
+ ETelemetryOperationName2["SESSION_LOAD"] = "harness.session.load";
12090
+ ETelemetryOperationName2["HISTORY_APPEND"] = "linkque.history.append";
12091
+ ETelemetryOperationName2["CLEANUP"] = "linkque.runtime.cleanup";
12092
+ ETelemetryOperationName2["HOOK_DRAIN"] = "linkque.hook.drain";
12093
+ })(ETelemetryOperationName || (ETelemetryOperationName = {}));
12094
+ (function(ETelemetryOutcome2) {
12095
+ ETelemetryOutcome2["SUCCESS"] = "success";
12096
+ ETelemetryOutcome2["ERROR"] = "error";
12097
+ ETelemetryOutcome2["CANCELLED"] = "cancelled";
12098
+ ETelemetryOutcome2["TIMEOUT"] = "timeout";
12099
+ ETelemetryOutcome2["REJECTED"] = "rejected";
12100
+ ETelemetryOutcome2["UNKNOWN"] = "unknown";
12101
+ })(ETelemetryOutcome || (ETelemetryOutcome = {}));
12102
+ (function(ETelemetrySignal2) {
12103
+ ETelemetrySignal2["LOGS"] = "logs";
12104
+ ETelemetrySignal2["TRACES"] = "traces";
12105
+ })(ETelemetrySignal || (ETelemetrySignal = {}));
12106
+ (function(ETelemetryLossReason2) {
12107
+ ETelemetryLossReason2["UNCAUGHT_ERROR"] = "uncaught_error";
12108
+ ETelemetryLossReason2["ACTIVE_LIMIT"] = "active_limit";
12109
+ ETelemetryLossReason2["ACTIVE_EXPIRED"] = "active_expired";
12110
+ ETelemetryLossReason2["SHUTDOWN"] = "shutdown";
12111
+ })(ETelemetryLossReason || (ETelemetryLossReason = {}));
12112
+ (function(ETelemetryAdvanceOutcome2) {
12113
+ ETelemetryAdvanceOutcome2["FAILED"] = "failed";
12114
+ ETelemetryAdvanceOutcome2["COMPLETED"] = "completed";
12115
+ ETelemetryAdvanceOutcome2["UNKNOWN"] = "unknown";
12116
+ })(ETelemetryAdvanceOutcome || (ETelemetryAdvanceOutcome = {}));
12117
+ (function(ETelemetryStreamTermination2) {
12118
+ ETelemetryStreamTermination2["CANCEL"] = "cancel";
12119
+ ETelemetryStreamTermination2["ERROR"] = "error";
12120
+ ETelemetryStreamTermination2["COMPLETE"] = "complete";
12121
+ ETelemetryStreamTermination2["EXHAUSTED"] = "exhausted";
12122
+ })(ETelemetryStreamTermination || (ETelemetryStreamTermination = {}));
12123
+ (function(ETelemetryCancelSource2) {
12124
+ ETelemetryCancelSource2["HOST_SIGNAL"] = "host_signal";
12125
+ ETelemetryCancelSource2["CONSUMER_RETURN"] = "consumer_return";
12126
+ })(ETelemetryCancelSource || (ETelemetryCancelSource = {}));
12127
+ (function(ETelemetryObservationBoundary2) {
12128
+ ETelemetryObservationBoundary2["LOCAL_WAIT"] = "local_wait";
12129
+ ETelemetryObservationBoundary2["EXECUTOR_SETTLED"] = "executor_settled";
12130
+ ETelemetryObservationBoundary2["GENERATOR_WITH_SETUP_AND_CLEANUP"] = "generator_with_setup_and_cleanup";
12131
+ })(ETelemetryObservationBoundary || (ETelemetryObservationBoundary = {}));
12132
+ (function(ETelemetryRemoteCompletion2) {
12133
+ ETelemetryRemoteCompletion2["UNKNOWN"] = "unknown";
12134
+ ETelemetryRemoteCompletion2["NOT_DISPATCHED"] = "not_dispatched";
12135
+ ETelemetryRemoteCompletion2["CONFIRMED"] = "confirmed";
12136
+ })(ETelemetryRemoteCompletion || (ETelemetryRemoteCompletion = {}));
12137
+ (function(ETelemetryCommitStatus2) {
12138
+ ETelemetryCommitStatus2["COMMITTED"] = "committed";
12139
+ ETelemetryCommitStatus2["FAILED"] = "failed";
12140
+ })(ETelemetryCommitStatus || (ETelemetryCommitStatus = {}));
12141
+ (function(ETelemetryHookMode2) {
12142
+ ETelemetryHookMode2["AWAITED"] = "awaited";
12143
+ ETelemetryHookMode2["DETACHED"] = "detached";
12144
+ })(ETelemetryHookMode || (ETelemetryHookMode = {}));
12145
+ (function(ETelemetryHookResult2) {
12146
+ ETelemetryHookResult2["OK"] = "ok";
12147
+ ETelemetryHookResult2["TIMEOUT"] = "timeout";
12148
+ ETelemetryHookResult2["SKIPPED"] = "skipped";
12149
+ ETelemetryHookResult2["SUCCESS"] = "success";
12150
+ ETelemetryHookResult2["ERROR"] = "error";
12151
+ })(ETelemetryHookResult || (ETelemetryHookResult = {}));
12152
+ (function(ETelemetrySource2) {
12153
+ ETelemetrySource2["KERNEL"] = "kernel";
12154
+ ETelemetrySource2["PROVIDER"] = "provider";
12155
+ })(ETelemetrySource || (ETelemetrySource = {}));
12156
+ (function(ETelemetryEvidence2) {
12157
+ ETelemetryEvidence2["OBSERVED"] = "observed";
12158
+ })(ETelemetryEvidence || (ETelemetryEvidence = {}));
12159
+ (function(ETelemetryCompleteness2) {
12160
+ ETelemetryCompleteness2["COMPLETE"] = "complete";
12161
+ ETelemetryCompleteness2["PARTIAL"] = "partial";
12162
+ })(ETelemetryCompleteness || (ETelemetryCompleteness = {}));
12163
+ (function(ETelemetryCoverage2) {
12164
+ ETelemetryCoverage2["PI_MODEL_TOOL_HOOK"] = "pi_model_tool_hook";
12165
+ ETelemetryCoverage2["CORE_ONLY"] = "core_only";
12166
+ })(ETelemetryCoverage || (ETelemetryCoverage = {}));
12167
+ (function(ETelemetryUsageSource2) {
12168
+ ETelemetryUsageSource2["UNKNOWN"] = "unknown";
12169
+ ETelemetryUsageSource2["PROVIDER_NORMALIZED"] = "provider_normalized";
12170
+ })(ETelemetryUsageSource || (ETelemetryUsageSource = {}));
12171
+ (function(ETelemetryAttemptVisibility2) {
12172
+ ETelemetryAttemptVisibility2["PROVIDER_INVOCATION"] = "provider_invocation";
12173
+ ETelemetryAttemptVisibility2["TOOL_PROVIDER_INVOCATION"] = "tool_provider_invocation";
12174
+ })(ETelemetryAttemptVisibility || (ETelemetryAttemptVisibility = {}));
12175
+ (function(ETelemetryLinkRelation2) {
12176
+ ETelemetryLinkRelation2["GENERATED_BY"] = "generated_by";
12177
+ ETelemetryLinkRelation2["SCHEDULED_BY"] = "scheduled_by";
12178
+ })(ETelemetryLinkRelation || (ETelemetryLinkRelation = {}));
12179
+ (function(ETelemetryToolFailureStage2) {
12180
+ ETelemetryToolFailureStage2["BEFORE_HOOK"] = "before_hook";
12181
+ ETelemetryToolFailureStage2["EXECUTION"] = "execution";
12182
+ ETelemetryToolFailureStage2["AFTER_HOOK"] = "after_hook";
12183
+ })(ETelemetryToolFailureStage || (ETelemetryToolFailureStage = {}));
12184
+ (function(ETelemetryTerminalEvidence2) {
12185
+ ETelemetryTerminalEvidence2["EXPLICIT_DONE_HISTORY_COMMITTED"] = "explicit_done_history_committed";
12186
+ ETelemetryTerminalEvidence2["EXPLICIT_DONE"] = "explicit_done";
12187
+ ETelemetryTerminalEvidence2["STREAM_ERROR"] = "stream_error";
12188
+ ETelemetryTerminalEvidence2["CONSUMER_CANCEL"] = "consumer_cancel";
12189
+ ETelemetryTerminalEvidence2["NATURAL_EXHAUSTION"] = "natural_exhaustion";
12190
+ })(ETelemetryTerminalEvidence || (ETelemetryTerminalEvidence = {}));
12191
+ (function(ETelemetryTerminalSource2) {
12192
+ ETelemetryTerminalSource2["NATIVE_AGENT_END"] = "native_agent_end";
12193
+ ETelemetryTerminalSource2["PROMPT_RESOLVED_FALLBACK"] = "prompt_resolved_fallback";
12194
+ })(ETelemetryTerminalSource || (ETelemetryTerminalSource = {}));
12195
+ (function(ETelemetryModelPurpose2) {
12196
+ ETelemetryModelPurpose2["AGENT_LOOP"] = "agent_loop";
12197
+ })(ETelemetryModelPurpose || (ETelemetryModelPurpose = {}));
12198
+ (function(ETelemetryErrorType2) {
12199
+ ETelemetryErrorType2["PROVIDER_STREAM_ERROR"] = "ProviderStreamError";
12200
+ ETelemetryErrorType2["TOOL_EXECUTION_ERROR"] = "ToolExecutionError";
12201
+ ETelemetryErrorType2["HOOK_DISPATCH_ERROR"] = "HookDispatchError";
12202
+ ETelemetryErrorType2["HOOK_DRAIN_ERROR"] = "HookDrainError";
12203
+ })(ETelemetryErrorType || (ETelemetryErrorType = {}));
12204
+ (function(ETelemetrySpanKind2) {
12205
+ ETelemetrySpanKind2["INTERNAL"] = "internal";
12206
+ ETelemetrySpanKind2["CLIENT"] = "client";
12207
+ })(ETelemetrySpanKind || (ETelemetrySpanKind = {}));
12208
+ (function(ETelemetryGenAiOperation2) {
12209
+ ETelemetryGenAiOperation2["CHAT"] = "chat";
12210
+ ETelemetryGenAiOperation2["EXECUTE_TOOL"] = "execute_tool";
12211
+ ETelemetryGenAiOperation2["INVOKE_AGENT"] = "invoke_agent";
12212
+ })(ETelemetryGenAiOperation || (ETelemetryGenAiOperation = {}));
12213
+ (function(ETelemetryVersion2) {
12214
+ ETelemetryVersion2["V0_2"] = "0.2";
12215
+ ETelemetryVersion2["V1_0"] = "1.0";
12216
+ })(ETelemetryVersion || (ETelemetryVersion = {}));
12217
+ }
12218
+ });
12219
+
12220
+ // ../linkque-agent-protocol/dist/esm/telemetry.js
12221
+ var init_telemetry = __esm({
12222
+ "../linkque-agent-protocol/dist/esm/telemetry.js"() {
12223
+ "use strict";
12224
+ init_telemetryEnums();
12225
+ }
12226
+ });
12227
+
12228
+ // ../linkque-agent-runtime/dist/esm/core/telemetry/contentRecording.js
12229
+ function recordContentSection(observation, section, value, availability = "available") {
12230
+ observation?.record(ETelemetryEventName.CONTENT_RECORDED, {}, { section, value, availability });
12231
+ }
12232
+ function recordMcpContentSection(observation, section, value, schema) {
12233
+ if (!observation)
12234
+ return;
12235
+ const fieldTitles = {};
12236
+ const visit = (node, path9) => {
12237
+ if (!node || typeof node !== "object" || Array.isArray(node))
12238
+ return;
12239
+ const definition = node;
12240
+ if (path9 && typeof definition.title === "string" && definition.title.trim())
12241
+ fieldTitles[path9] = definition.title;
12242
+ const properties = definition.properties;
12243
+ if (properties && typeof properties === "object" && !Array.isArray(properties)) {
12244
+ for (const [key, child] of Object.entries(properties))
12245
+ visit(child, `${path9}/${key.replaceAll("~", "~0").replaceAll("/", "~1")}`);
12246
+ }
12247
+ if (definition.items)
12248
+ visit(definition.items, `${path9}/*`);
12249
+ };
12250
+ visit(schema, section === ETelemetryContentSection.MCP_OUTPUT ? "/structuredContent" : "");
12251
+ observation.record(ETelemetryEventName.CONTENT_RECORDED, {}, {
12252
+ section,
12253
+ value,
12254
+ availability: "available",
12255
+ ...Object.keys(fieldTitles).length ? { fieldTitles } : {}
12256
+ });
12257
+ }
12258
+ var init_contentRecording = __esm({
12259
+ "../linkque-agent-runtime/dist/esm/core/telemetry/contentRecording.js"() {
12260
+ "use strict";
12261
+ init_telemetry();
12262
+ }
12263
+ });
12264
+
11889
12265
  // ../linkque-agent-runtime/dist/esm/core/mcpProxyTool.js
11890
12266
  function resourceIdsForTool(spec, toolName) {
11891
12267
  if (!spec.allToolResourceIds && !spec.resourceIdsByTool)
@@ -11955,6 +12331,8 @@ var MCP_PROXY_TOOL_NAME, McpProxyTool, MCP_BATCH_SEARCH_MAX_ITEMS, MCP_PROXY_DES
11955
12331
  var init_mcpProxyTool = __esm({
11956
12332
  "../linkque-agent-runtime/dist/esm/core/mcpProxyTool.js"() {
11957
12333
  "use strict";
12334
+ init_telemetry();
12335
+ init_contentRecording();
11958
12336
  init_esm();
11959
12337
  init_types();
11960
12338
  MCP_PROXY_TOOL_NAME = "mcp";
@@ -12015,6 +12393,10 @@ var init_mcpProxyTool = __esm({
12015
12393
  context: context2
12016
12394
  });
12017
12395
  return entry.server.callTool(tool.name, args, sig, {
12396
+ toolSchema: {
12397
+ inputSchema: tool.inputSchema,
12398
+ outputSchema: tool.outputSchema
12399
+ },
12018
12400
  ...headers ? { headers } : {},
12019
12401
  ...context2 ? { context: context2 } : {}
12020
12402
  });
@@ -12108,27 +12490,33 @@ var init_mcpProxyTool = __esm({
12108
12490
  async dispatch(args, signal, context2) {
12109
12491
  const params = parseProxyArgs(args);
12110
12492
  if (params.connect !== void 0) {
12111
- return this.executeConnect(params.connect, signal);
12493
+ return this.executeConnect(params.connect, signal, context2);
12112
12494
  }
12113
12495
  if (params.describe !== void 0) {
12114
- return this.executeDescribe(params.describe, params.server, signal);
12496
+ return this.executeDescribe(params.describe, params.server, signal, context2);
12115
12497
  }
12116
12498
  if (params.searches !== void 0) {
12117
- return this.executeBatchSearch(params.searches, params.server);
12499
+ return this.executeBatchSearch(params.searches, params.server, context2);
12118
12500
  }
12119
12501
  if (params.search !== void 0) {
12120
- return this.executeSearch(params.search, params.server);
12502
+ const result = await this.executeSearch(params.search, params.server);
12503
+ this.recordAction(context2, "search", result.tools.length ? "matched" : "no_hits", { query: result.query, tools: result.tools });
12504
+ return result.text;
12121
12505
  }
12122
12506
  if (params.tool !== void 0) {
12123
12507
  return this.executeCall(params.tool, params.args, params.server, signal, context2);
12124
12508
  }
12125
12509
  if (params.server !== void 0) {
12126
- return this.executeList(params.server, signal);
12510
+ return this.executeList(params.server, signal, context2);
12127
12511
  }
12128
- return this.executeStatus();
12512
+ return this.executeStatus(context2);
12513
+ }
12514
+ /** 保留代理动作事实,不改变供模型消费的原始返回值。 */
12515
+ recordAction(context2, action, status, data = {}) {
12516
+ recordContentSection(context2?.observation, ETelemetryContentSection.MCP_ACTION_OUTPUT, { action, status, ...data });
12129
12517
  }
12130
12518
  /** `mcp({})` / `mcp({ status: true })`:列各 server 连接状态 + 工具数。 */
12131
- executeStatus() {
12519
+ executeStatus(context2) {
12132
12520
  const lines = [];
12133
12521
  let connected = 0;
12134
12522
  let totalTools = 0;
@@ -12147,6 +12535,13 @@ var init_mcpProxyTool = __esm({
12147
12535
  lines.push(`\u2717 ${label} (failed${entry.error ? ": " + entry.error : ""})`);
12148
12536
  }
12149
12537
  }
12538
+ this.recordAction(context2, "status", "completed", {
12539
+ servers: this.specs.map((spec) => ({
12540
+ name: spec.serverName,
12541
+ status: this.entries.get(spec.serverName)?.status ?? "not_connected",
12542
+ toolCount: this.entries.get(spec.serverName)?.tools.length ?? 0
12543
+ }))
12544
+ });
12150
12545
  const header = `MCP: ${connected}/${this.specs.length} servers, ${totalTools} tools`;
12151
12546
  const hint = this.specs.length > 0 ? '\nmcp({ server: "name" }) to list tools, mcp({ search: "..." }) to search, mcp({ tool: "...", args: {...} }) to call' : "\n(no MCP resources configured)";
12152
12547
  return `${header}
@@ -12154,35 +12549,57 @@ var init_mcpProxyTool = __esm({
12154
12549
  ${lines.join("\n")}${hint}`.trim();
12155
12550
  }
12156
12551
  /** `mcp({ connect: "server" })`:显式连接并刷元数据,返回该 server 工具列表。 */
12157
- async executeConnect(server, signal) {
12552
+ async executeConnect(server, signal, context2) {
12158
12553
  const spec = this.findSpec(server);
12159
- if (!spec)
12554
+ if (!spec) {
12555
+ this.recordAction(context2, "connect", "not_found", { server });
12160
12556
  return `Server "${server}" not found. Use mcp({}) to see available servers.`;
12557
+ }
12161
12558
  this.entries.delete(spec.serverName);
12162
12559
  const entry = await this.ensureEntry(spec.serverName, signal);
12163
12560
  if (!entry) {
12561
+ this.recordAction(context2, "connect", "failed", {
12562
+ server: spec.serverName
12563
+ });
12164
12564
  const failed = this.entries.get(spec.serverName);
12165
12565
  const detail = failed?.error ? `: ${failed.error}` : "";
12166
12566
  return `Failed to connect to "${spec.serverName}"${detail}.`;
12167
12567
  }
12568
+ this.recordAction(context2, "connect", "matched", {
12569
+ server: spec.serverName,
12570
+ tools: entry.tools.map((tool) => ({
12571
+ name: tool.name,
12572
+ description: tool.description
12573
+ }))
12574
+ });
12168
12575
  return this.formatToolList(spec.serverName, entry.tools);
12169
12576
  }
12170
12577
  /** `mcp({ server: "name" })`:列该 server 工具名 + 截断 description。 */
12171
- async executeList(server, signal) {
12578
+ async executeList(server, signal, context2) {
12172
12579
  const spec = this.findSpec(server);
12173
- if (!spec)
12580
+ if (!spec) {
12581
+ this.recordAction(context2, "list", "not_found", { server });
12174
12582
  return `Server "${server}" not found. Use mcp({}) to see available servers.`;
12583
+ }
12175
12584
  const entry = await this.ensureEntry(spec.serverName, signal);
12176
12585
  if (!entry) {
12586
+ this.recordAction(context2, "list", "failed", { server: spec.serverName });
12177
12587
  return `Server "${spec.serverName}" is not connected. Use mcp({ connect: "${spec.serverName}" }) to retry.`;
12178
12588
  }
12589
+ this.recordAction(context2, "list", "matched", {
12590
+ server: spec.serverName,
12591
+ tools: entry.tools.map((tool) => ({
12592
+ name: tool.name,
12593
+ description: tool.description
12594
+ }))
12595
+ });
12179
12596
  return this.formatToolList(spec.serverName, entry.tools);
12180
12597
  }
12181
12598
  /** `mcp({ search: "query" })`:空格分词 OR 子串匹配 name/description(跨所有 server)。 */
12182
12599
  async executeSearch(query, serverHint) {
12183
12600
  const terms = query.trim().split(/\s+/u).filter((t2) => t2.length > 0);
12184
12601
  if (terms.length === 0)
12185
- return "Search query cannot be empty.";
12602
+ return { query, text: "Search query cannot be empty.", tools: [] };
12186
12603
  const pattern = new RegExp(terms.map(escapeRegExp).join("|"), "iu");
12187
12604
  const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
12188
12605
  await Promise.all(specs.map((s2) => this.ensureEntry(s2.serverName)));
@@ -12197,8 +12614,18 @@ ${lines.join("\n")}${hint}`.trim();
12197
12614
  }
12198
12615
  }
12199
12616
  }
12617
+ const tools = matches.map(({ server, tool }) => ({
12618
+ server,
12619
+ name: tool.name,
12620
+ description: tool.description,
12621
+ inputSchema: tool.inputSchema
12622
+ }));
12200
12623
  if (matches.length === 0) {
12201
- return serverHint ? `No tools matching "${query}" in "${serverHint}"` : `No tools matching "${query}"`;
12624
+ return {
12625
+ query,
12626
+ tools,
12627
+ text: serverHint ? `No tools matching "${query}" in "${serverHint}"` : `No tools matching "${query}"`
12628
+ };
12202
12629
  }
12203
12630
  const lines = [`Found ${matches.length} tool(s) matching "${query}":`, ""];
12204
12631
  for (const { server, tool } of matches) {
@@ -12210,10 +12637,10 @@ ${formatSchema(tool.inputSchema, " ")}`);
12210
12637
  }
12211
12638
  lines.push("");
12212
12639
  }
12213
- return lines.join("\n").trim();
12640
+ return { query, tools, text: lines.join("\n").trim() };
12214
12641
  }
12215
12642
  /** `mcp({ searches: [...] })`:一次连接元数据并按 query 分组执行多组搜索。 */
12216
- async executeBatchSearch(queries, serverHint) {
12643
+ async executeBatchSearch(queries, serverHint, context2) {
12217
12644
  const normalized = [
12218
12645
  ...new Set(queries.map((query) => query.trim()).filter(Boolean))
12219
12646
  ].slice(0, MCP_BATCH_SEARCH_MAX_ITEMS);
@@ -12223,16 +12650,23 @@ ${formatSchema(tool.inputSchema, " ")}`);
12223
12650
  const specs = serverHint ? this.specsMatching(serverHint) : this.specs;
12224
12651
  await Promise.all(specs.map((spec) => this.ensureEntry(spec.serverName)));
12225
12652
  const results = await Promise.all(normalized.map((query) => this.executeSearch(query, serverHint)));
12653
+ this.recordAction(context2, "search", results.some((result) => result.tools.length) ? "matched" : "no_hits", { results: results.map(({ query, tools }) => ({ query, tools })) });
12226
12654
  return results.map((result, index2) => `Query ${index2 + 1}: "${normalized[index2]}"
12227
- ${result}`).join("\n\n");
12655
+ ${result.text}`).join("\n\n");
12228
12656
  }
12229
12657
  /** `mcp({ describe: "tool" })`:输出工具所属 server + 参数 schema。 */
12230
- async executeDescribe(toolName, serverHint, signal) {
12658
+ async executeDescribe(toolName, serverHint, signal, context2) {
12231
12659
  const found = await this.findTool(toolName, serverHint, signal);
12232
12660
  if (!found) {
12661
+ this.recordAction(context2, "describe", "not_found", { name: toolName });
12233
12662
  return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
12234
12663
  }
12235
12664
  const { server, tool } = found;
12665
+ this.recordAction(context2, "describe", "matched", {
12666
+ server,
12667
+ name: tool.name,
12668
+ inputSchema: tool.inputSchema
12669
+ });
12236
12670
  const lines = [
12237
12671
  `${tool.name}`,
12238
12672
  `Server: ${server}`,
@@ -12251,6 +12685,7 @@ ${formatSchema(tool.inputSchema)}`);
12251
12685
  async executeCall(toolName, args, serverHint, signal, context2) {
12252
12686
  const found = await this.findTool(toolName, serverHint, signal);
12253
12687
  if (!found) {
12688
+ this.recordAction(context2, "call", "not_found", { name: toolName });
12254
12689
  return `Tool "${toolName}" not found. Use mcp({ search: "..." }) to search.`;
12255
12690
  }
12256
12691
  const { entry, tool, spec } = found;
@@ -12262,11 +12697,17 @@ ${formatSchema(tool.inputSchema)}`);
12262
12697
  context: context2
12263
12698
  });
12264
12699
  const result = await entry.server.callTool(tool.name, args, signal, {
12700
+ toolSchema: {
12701
+ inputSchema: tool.inputSchema,
12702
+ outputSchema: tool.outputSchema
12703
+ },
12265
12704
  ...headers ? { headers } : {},
12266
12705
  ...context2 ? { context: context2 } : {}
12267
12706
  });
12707
+ this.recordAction(context2, "call", result && typeof result === "object" && "isError" in result && result.isError === true ? "failed" : "completed", { name: tool.name, server: spec.serverName });
12268
12708
  return serializeToolResult(result);
12269
12709
  } catch (error40) {
12710
+ this.recordAction(context2, "call", signal?.aborted ? "cancelled" : "failed", { name: tool.name, server: spec.serverName });
12270
12711
  const message = error40 instanceof Error ? error40.message : String(error40);
12271
12712
  return `Tool "${toolName}" call failed: ${message}`;
12272
12713
  }
@@ -12626,317 +13067,6 @@ var init_hookRegistry = __esm({
12626
13067
  }
12627
13068
  });
12628
13069
 
12629
- // ../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js
12630
- var ETelemetryAttribute, ETelemetryEventPrefix, ETelemetryEventPhase, ETelemetryEventName, ETelemetryOperationName, ETelemetryOutcome, ETelemetrySignal, ETelemetryLossReason, ETelemetryAdvanceOutcome, ETelemetryStreamTermination, ETelemetryCancelSource, ETelemetryObservationBoundary, ETelemetryRemoteCompletion, ETelemetryCommitStatus, ETelemetryHookMode, ETelemetryHookResult, ETelemetrySource, ETelemetryEvidence, ETelemetryCompleteness, ETelemetryCoverage, ETelemetryUsageSource, ETelemetryAttemptVisibility, ETelemetryLinkRelation, ETelemetryToolFailureStage, ETelemetryTerminalEvidence, ETelemetryTerminalSource, ETelemetryModelPurpose, ETelemetryErrorType, ETelemetrySpanKind, ETelemetryGenAiOperation, ETelemetryVersion;
12631
- var init_telemetryEnums = __esm({
12632
- "../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js"() {
12633
- "use strict";
12634
- (function(ETelemetryAttribute2) {
12635
- ETelemetryAttribute2["HARNESS_TELEMETRY_SCHEMA_VERSION"] = "harness.telemetry.schema.version";
12636
- ETelemetryAttribute2["LINKQUE_TELEMETRY_SCHEMA_VERSION"] = "linkque.telemetry.schema.version";
12637
- ETelemetryAttribute2["LINKQUE_TELEMETRY_ADAPTER_VERSION"] = "linkque.telemetry.adapter.version";
12638
- ETelemetryAttribute2["HARNESS_TELEMETRY_SOURCE"] = "harness.telemetry.source";
12639
- ETelemetryAttribute2["HARNESS_TELEMETRY_EVIDENCE"] = "harness.telemetry.evidence";
12640
- ETelemetryAttribute2["HARNESS_TELEMETRY_COMPLETENESS"] = "harness.telemetry.completeness";
12641
- ETelemetryAttribute2["LINKQUE_RUNTIME_KIND"] = "linkque.runtime.kind";
12642
- ETelemetryAttribute2["LINKQUE_RUN_ID"] = "linkque.run.id";
12643
- ETelemetryAttribute2["LINKQUE_AGENT_ID"] = "linkque.agent.id";
12644
- ETelemetryAttribute2["HARNESS_SESSION_ID"] = "harness.session.id";
12645
- ETelemetryAttribute2["LINKQUE_CONVERSATION_ID"] = "linkque.conversation.id";
12646
- ETelemetryAttribute2["LINKQUE_REQUEST_ID"] = "linkque.request.id";
12647
- ETelemetryAttribute2["LINKQUE_TURN_ID"] = "linkque.turn.id";
12648
- ETelemetryAttribute2["LINKQUE_ACCOUNT_ID"] = "linkque.account.id";
12649
- ETelemetryAttribute2["LINKQUE_CHANNEL"] = "linkque.channel";
12650
- ETelemetryAttribute2["LINKQUE_USER_KEY"] = "linkque.user.key";
12651
- ETelemetryAttribute2["HARNESS_ADVANCE_ID"] = "harness.advance.id";
12652
- ETelemetryAttribute2["HARNESS_CALL_ID"] = "harness.call.id";
12653
- ETelemetryAttribute2["HARNESS_INVOCATION_ID"] = "harness.invocation.id";
12654
- ETelemetryAttribute2["HARNESS_ATTEMPT_ID"] = "harness.attempt.id";
12655
- ETelemetryAttribute2["HARNESS_ATTEMPT_VISIBILITY"] = "harness.attempt.visibility";
12656
- ETelemetryAttribute2["HARNESS_ADVANCE_OUTCOME"] = "harness.advance.outcome";
12657
- ETelemetryAttribute2["HARNESS_OPERATION_OUTCOME"] = "harness.operation.outcome";
12658
- ETelemetryAttribute2["HARNESS_REMOTE_COMPLETION"] = "harness.remote.completion";
12659
- ETelemetryAttribute2["HARNESS_STATE_COMMIT_STATUS"] = "harness.state.commit.status";
12660
- ETelemetryAttribute2["LINKQUE_OPERATION_ID"] = "linkque.operation.id";
12661
- ETelemetryAttribute2["LINKQUE_OPERATION_NAME"] = "linkque.operation.name";
12662
- ETelemetryAttribute2["LINKQUE_OPERATION_PARENT_ID"] = "linkque.operation.parent_id";
12663
- ETelemetryAttribute2["LINKQUE_SPAN_PARENT_ID"] = "linkque.span.parent_id";
12664
- ETelemetryAttribute2["HARNESS_RECORD_ID"] = "harness.record.id";
12665
- ETelemetryAttribute2["HARNESS_EVENT_SEQUENCE"] = "harness.event.sequence";
12666
- ETelemetryAttribute2["ERROR_TYPE"] = "error.type";
12667
- ETelemetryAttribute2["LINKQUE_STREAM_TERMINATION"] = "linkque.stream.termination";
12668
- ETelemetryAttribute2["LINKQUE_STREAM_CANCEL_SOURCE"] = "linkque.stream.cancel_source";
12669
- ETelemetryAttribute2["LINKQUE_TERMINAL_EVIDENCE"] = "linkque.terminal.evidence";
12670
- ETelemetryAttribute2["LINKQUE_RUNTIME_CLEANUP_OUTCOME"] = "linkque.runtime.cleanup_outcome";
12671
- ETelemetryAttribute2["LINKQUE_OBSERVATION_BOUNDARY"] = "linkque.observation.boundary";
12672
- ETelemetryAttribute2["LINKQUE_LOOP_ITERATION_ID"] = "linkque.loop.iteration.id";
12673
- ETelemetryAttribute2["LINKQUE_LOOP_ITERATION_INDEX"] = "linkque.loop.iteration.index";
12674
- ETelemetryAttribute2["LINKQUE_STREAM_TERMINAL_SOURCE"] = "linkque.stream.terminal_source";
12675
- ETelemetryAttribute2["LINKQUE_STREAM_PUBLIC_TEXT_DELTA_COUNT"] = "linkque.stream.public_text_delta_count";
12676
- ETelemetryAttribute2["LINKQUE_STREAM_THINKING_DELTA_COUNT"] = "linkque.stream.thinking_delta_count";
12677
- ETelemetryAttribute2["LINKQUE_MODEL_FIRST_CHUNK_MS"] = "linkque.model.first_chunk_ms";
12678
- ETelemetryAttribute2["LINKQUE_MODEL_FIRST_TEXT_MS"] = "linkque.model.first_text_ms";
12679
- ETelemetryAttribute2["LINKQUE_LOOP_FIRST_PUBLIC_TEXT_MS"] = "linkque.loop.first_public_text_ms";
12680
- ETelemetryAttribute2["LINKQUE_MODEL_CHUNK_COUNT"] = "linkque.model.chunk_count";
12681
- ETelemetryAttribute2["LINKQUE_MODEL_TEXT_CHARS"] = "linkque.model.text_chars";
12682
- ETelemetryAttribute2["LINKQUE_MODEL_THINKING_CHARS"] = "linkque.model.thinking_chars";
12683
- ETelemetryAttribute2["GEN_AI_OPERATION_NAME"] = "gen_ai.operation.name";
12684
- ETelemetryAttribute2["GEN_AI_AGENT_NAME"] = "gen_ai.agent.name";
12685
- ETelemetryAttribute2["GEN_AI_PROVIDER_NAME"] = "gen_ai.provider.name";
12686
- ETelemetryAttribute2["GEN_AI_REQUEST_MODEL"] = "gen_ai.request.model";
12687
- ETelemetryAttribute2["GEN_AI_RESPONSE_MODEL"] = "gen_ai.response.model";
12688
- ETelemetryAttribute2["GEN_AI_RESPONSE_ID"] = "gen_ai.response.id";
12689
- ETelemetryAttribute2["GEN_AI_RESPONSE_FINISH_REASONS"] = "gen_ai.response.finish_reasons";
12690
- ETelemetryAttribute2["GEN_AI_USAGE_INPUT_TOKENS"] = "gen_ai.usage.input_tokens";
12691
- ETelemetryAttribute2["GEN_AI_USAGE_OUTPUT_TOKENS"] = "gen_ai.usage.output_tokens";
12692
- ETelemetryAttribute2["GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS"] = "gen_ai.usage.cache_read.input_tokens";
12693
- ETelemetryAttribute2["GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS"] = "gen_ai.usage.cache_creation.input_tokens";
12694
- ETelemetryAttribute2["GEN_AI_USAGE_REASONING_OUTPUT_TOKENS"] = "gen_ai.usage.reasoning.output_tokens";
12695
- ETelemetryAttribute2["HARNESS_USAGE_SOURCE"] = "harness.usage.source";
12696
- ETelemetryAttribute2["HARNESS_USAGE_ATTEMPT_COVERAGE"] = "harness.usage.attempt_coverage";
12697
- ETelemetryAttribute2["HARNESS_MODEL_PURPOSE"] = "harness.model.purpose";
12698
- ETelemetryAttribute2["HARNESS_MODEL_INVOCATION_COUNT"] = "harness.model.invocation_count";
12699
- ETelemetryAttribute2["GEN_AI_TOOL_NAME"] = "gen_ai.tool.name";
12700
- ETelemetryAttribute2["GEN_AI_TOOL_CALL_ID"] = "gen_ai.tool.call.id";
12701
- ETelemetryAttribute2["HARNESS_TOOL_RESULT_STATUS"] = "harness.tool.result.status";
12702
- ETelemetryAttribute2["LINKQUE_TOOL_FAILURE_STAGE"] = "linkque.tool.failure_stage";
12703
- ETelemetryAttribute2["HARNESS_HOOK_NAME"] = "harness.hook.name";
12704
- ETelemetryAttribute2["LINKQUE_HOOK_STAGE"] = "linkque.hook.stage";
12705
- ETelemetryAttribute2["LINKQUE_HOOK_RESOURCE_ID"] = "linkque.hook.resource_id";
12706
- ETelemetryAttribute2["LINKQUE_HOOK_EVENT_ID"] = "linkque.hook.event_id";
12707
- ETelemetryAttribute2["LINKQUE_HOOK_MATCHED_COUNT"] = "linkque.hook.matched_count";
12708
- ETelemetryAttribute2["LINKQUE_HOOK_PENDING_COUNT"] = "linkque.hook.pending_count";
12709
- ETelemetryAttribute2["LINKQUE_HOOK_SCHEDULED_COUNT"] = "linkque.hook.scheduled_count";
12710
- ETelemetryAttribute2["LINKQUE_HOOK_HAS_SIDE_EFFECTS"] = "linkque.hook.has_side_effects";
12711
- ETelemetryAttribute2["LINKQUE_HOOK_MODE"] = "linkque.hook.mode";
12712
- ETelemetryAttribute2["LINKQUE_HOOK_TIMEOUT_MS"] = "linkque.hook.timeout_ms";
12713
- ETelemetryAttribute2["LINKQUE_HOOK_RESULT"] = "linkque.hook.result";
12714
- ETelemetryAttribute2["HARNESS_MIDDLEWARE_NAME"] = "harness.middleware.name";
12715
- ETelemetryAttribute2["HARNESS_MIDDLEWARE_INVOCATION_ID"] = "harness.middleware.invocation.id";
12716
- ETelemetryAttribute2["LINKQUE_HOOK_EXECUTOR_SETTLED"] = "linkque.hook.executor_settled";
12717
- ETelemetryAttribute2["LINKQUE_HISTORY_MESSAGE_COUNT"] = "linkque.history.message_count";
12718
- ETelemetryAttribute2["LINKQUE_TELEMETRY_COVERAGE"] = "linkque.telemetry.coverage";
12719
- ETelemetryAttribute2["LINKQUE_TELEMETRY_LOSS_REASON"] = "linkque.telemetry.loss_reason";
12720
- ETelemetryAttribute2["LINKQUE_OPERATION_DURATION_MS"] = "linkque.operation.duration_ms";
12721
- ETelemetryAttribute2["HTTP_RESPONSE_STATUS_CODE"] = "http.response.status_code";
12722
- ETelemetryAttribute2["SERVICE_NAME"] = "service.name";
12723
- ETelemetryAttribute2["SERVICE_NAMESPACE"] = "service.namespace";
12724
- ETelemetryAttribute2["SERVICE_VERSION"] = "service.version";
12725
- ETelemetryAttribute2["SERVICE_INSTANCE_ID"] = "service.instance.id";
12726
- ETelemetryAttribute2["DEPLOYMENT_ENVIRONMENT_NAME"] = "deployment.environment.name";
12727
- ETelemetryAttribute2["LINKQUE_LINK_RELATION"] = "linkque.link.relation";
12728
- })(ETelemetryAttribute || (ETelemetryAttribute = {}));
12729
- (function(ETelemetryEventPrefix2) {
12730
- ETelemetryEventPrefix2["OPERATION"] = "linkque.operation";
12731
- ETelemetryEventPrefix2["ADVANCE"] = "harness.advance";
12732
- ETelemetryEventPrefix2["MODEL_INVOKE"] = "harness.model.invoke";
12733
- ETelemetryEventPrefix2["MODEL_ATTEMPT"] = "harness.model.attempt";
12734
- ETelemetryEventPrefix2["TOOL_INVOKE"] = "harness.tool.invoke";
12735
- ETelemetryEventPrefix2["TOOL_ATTEMPT"] = "harness.tool.attempt";
12736
- ETelemetryEventPrefix2["HOOK_CHAIN"] = "harness.hook.chain";
12737
- ETelemetryEventPrefix2["MIDDLEWARE"] = "harness.middleware";
12738
- ETelemetryEventPrefix2["LOOP"] = "linkque.loop";
12739
- ETelemetryEventPrefix2["LOOP_ITERATION"] = "linkque.loop.iteration";
12740
- ETelemetryEventPrefix2["HISTORY_APPEND"] = "linkque.history.append";
12741
- ETelemetryEventPrefix2["HOOK_DRAIN"] = "linkque.hook.drain";
12742
- })(ETelemetryEventPrefix || (ETelemetryEventPrefix = {}));
12743
- (function(ETelemetryEventPhase2) {
12744
- ETelemetryEventPhase2["STARTED"] = "started";
12745
- ETelemetryEventPhase2["FINISHED"] = "finished";
12746
- ETelemetryEventPhase2["OBSERVATION_LOST"] = "observation_lost";
12747
- })(ETelemetryEventPhase || (ETelemetryEventPhase = {}));
12748
- (function(ETelemetryEventName2) {
12749
- ETelemetryEventName2["TOOL_EXECUTION_FAILED"] = "linkque.tool.execution.failed";
12750
- ETelemetryEventName2["TELEMETRY_COVERAGE"] = "linkque.telemetry.coverage";
12751
- ETelemetryEventName2["HOOK_MATCHED"] = "linkque.hook.matched";
12752
- ETelemetryEventName2["HOOK_SCHEDULED"] = "linkque.hook.scheduled";
12753
- ETelemetryEventName2["HOOK_CANCEL_REQUESTED"] = "linkque.hook.cancel_requested";
12754
- ETelemetryEventName2["HOOK_TIMEOUT_REQUESTED"] = "linkque.hook.timeout_requested";
12755
- ETelemetryEventName2["HOOK_EXECUTOR_SETTLED"] = "linkque.hook.executor_settled";
12756
- ETelemetryEventName2["HOOK_WAIT_FINISHED"] = "linkque.hook.wait_finished";
12757
- ETelemetryEventName2["LOOP_FIRST_PUBLIC_TEXT"] = "linkque.loop.first_public_text";
12758
- ETelemetryEventName2["STREAM_TERMINAL_OBSERVED"] = "linkque.stream.terminal_observed";
12759
- ETelemetryEventName2["MODEL_FIRST_CHUNK"] = "harness.model.first_chunk";
12760
- ETelemetryEventName2["MODEL_FIRST_TEXT"] = "harness.model.first_text";
12761
- ETelemetryEventName2["MODEL_USAGE_RECORDED"] = "linkque.model.usage.recorded";
12762
- ETelemetryEventName2["MODEL_RESPONSE_HEADERS"] = "linkque.model.response_headers";
12763
- ETelemetryEventName2["OPERATION_OBSERVATION_LOST"] = "linkque.operation.observation_lost";
12764
- ETelemetryEventName2["RUNTIME_UNCAUGHT_ERROR"] = "linkque.runtime.uncaught_error";
12765
- ETelemetryEventName2["OPERATION_STARTED"] = "linkque.operation.started";
12766
- ETelemetryEventName2["OPERATION_FINISHED"] = "linkque.operation.finished";
12767
- ETelemetryEventName2["ADVANCE_STARTED"] = "harness.advance.started";
12768
- ETelemetryEventName2["ADVANCE_FINISHED"] = "harness.advance.finished";
12769
- ETelemetryEventName2["MODEL_INVOKE_STARTED"] = "harness.model.invoke.started";
12770
- ETelemetryEventName2["MODEL_INVOKE_FINISHED"] = "harness.model.invoke.finished";
12771
- ETelemetryEventName2["MODEL_ATTEMPT_STARTED"] = "harness.model.attempt.started";
12772
- ETelemetryEventName2["MODEL_ATTEMPT_FINISHED"] = "harness.model.attempt.finished";
12773
- ETelemetryEventName2["TOOL_INVOKE_STARTED"] = "harness.tool.invoke.started";
12774
- ETelemetryEventName2["TOOL_INVOKE_FINISHED"] = "harness.tool.invoke.finished";
12775
- ETelemetryEventName2["TOOL_ATTEMPT_STARTED"] = "harness.tool.attempt.started";
12776
- ETelemetryEventName2["TOOL_ATTEMPT_FINISHED"] = "harness.tool.attempt.finished";
12777
- ETelemetryEventName2["HOOK_CHAIN_STARTED"] = "harness.hook.chain.started";
12778
- ETelemetryEventName2["HOOK_CHAIN_FINISHED"] = "harness.hook.chain.finished";
12779
- ETelemetryEventName2["MIDDLEWARE_STARTED"] = "harness.middleware.started";
12780
- ETelemetryEventName2["MIDDLEWARE_FINISHED"] = "harness.middleware.finished";
12781
- ETelemetryEventName2["LOOP_STARTED"] = "linkque.loop.started";
12782
- ETelemetryEventName2["LOOP_FINISHED"] = "linkque.loop.finished";
12783
- ETelemetryEventName2["LOOP_ITERATION_STARTED"] = "linkque.loop.iteration.started";
12784
- ETelemetryEventName2["LOOP_ITERATION_FINISHED"] = "linkque.loop.iteration.finished";
12785
- ETelemetryEventName2["HISTORY_APPEND_STARTED"] = "linkque.history.append.started";
12786
- ETelemetryEventName2["HISTORY_APPEND_FINISHED"] = "linkque.history.append.finished";
12787
- ETelemetryEventName2["HOOK_DRAIN_STARTED"] = "linkque.hook.drain.started";
12788
- ETelemetryEventName2["HOOK_DRAIN_FINISHED"] = "linkque.hook.drain.finished";
12789
- })(ETelemetryEventName || (ETelemetryEventName = {}));
12790
- (function(ETelemetryOperationName2) {
12791
- ETelemetryOperationName2["OPERATION"] = "linkque.operation";
12792
- ETelemetryOperationName2["TOOL_INVOKE"] = "harness.tool.invoke";
12793
- ETelemetryOperationName2["ADVANCE"] = "harness.advance";
12794
- ETelemetryOperationName2["MODEL_INVOKE"] = "harness.model.invoke";
12795
- ETelemetryOperationName2["MODEL_ATTEMPT"] = "harness.model.attempt";
12796
- ETelemetryOperationName2["TOOL_ATTEMPT"] = "harness.tool.attempt";
12797
- ETelemetryOperationName2["HOOK_CHAIN"] = "harness.hook.chain";
12798
- ETelemetryOperationName2["MIDDLEWARE"] = "harness.middleware";
12799
- ETelemetryOperationName2["LOOP"] = "linkque.agent.loop";
12800
- ETelemetryOperationName2["ITERATION"] = "linkque.agent.iteration";
12801
- ETelemetryOperationName2["SESSION_LOAD"] = "harness.session.load";
12802
- ETelemetryOperationName2["HISTORY_APPEND"] = "linkque.history.append";
12803
- ETelemetryOperationName2["CLEANUP"] = "linkque.runtime.cleanup";
12804
- ETelemetryOperationName2["HOOK_DRAIN"] = "linkque.hook.drain";
12805
- })(ETelemetryOperationName || (ETelemetryOperationName = {}));
12806
- (function(ETelemetryOutcome2) {
12807
- ETelemetryOutcome2["SUCCESS"] = "success";
12808
- ETelemetryOutcome2["ERROR"] = "error";
12809
- ETelemetryOutcome2["CANCELLED"] = "cancelled";
12810
- ETelemetryOutcome2["TIMEOUT"] = "timeout";
12811
- ETelemetryOutcome2["REJECTED"] = "rejected";
12812
- ETelemetryOutcome2["UNKNOWN"] = "unknown";
12813
- })(ETelemetryOutcome || (ETelemetryOutcome = {}));
12814
- (function(ETelemetrySignal2) {
12815
- ETelemetrySignal2["LOGS"] = "logs";
12816
- ETelemetrySignal2["TRACES"] = "traces";
12817
- })(ETelemetrySignal || (ETelemetrySignal = {}));
12818
- (function(ETelemetryLossReason2) {
12819
- ETelemetryLossReason2["UNCAUGHT_ERROR"] = "uncaught_error";
12820
- ETelemetryLossReason2["ACTIVE_LIMIT"] = "active_limit";
12821
- ETelemetryLossReason2["ACTIVE_EXPIRED"] = "active_expired";
12822
- ETelemetryLossReason2["SHUTDOWN"] = "shutdown";
12823
- })(ETelemetryLossReason || (ETelemetryLossReason = {}));
12824
- (function(ETelemetryAdvanceOutcome2) {
12825
- ETelemetryAdvanceOutcome2["FAILED"] = "failed";
12826
- ETelemetryAdvanceOutcome2["COMPLETED"] = "completed";
12827
- ETelemetryAdvanceOutcome2["UNKNOWN"] = "unknown";
12828
- })(ETelemetryAdvanceOutcome || (ETelemetryAdvanceOutcome = {}));
12829
- (function(ETelemetryStreamTermination2) {
12830
- ETelemetryStreamTermination2["CANCEL"] = "cancel";
12831
- ETelemetryStreamTermination2["ERROR"] = "error";
12832
- ETelemetryStreamTermination2["COMPLETE"] = "complete";
12833
- ETelemetryStreamTermination2["EXHAUSTED"] = "exhausted";
12834
- })(ETelemetryStreamTermination || (ETelemetryStreamTermination = {}));
12835
- (function(ETelemetryCancelSource2) {
12836
- ETelemetryCancelSource2["HOST_SIGNAL"] = "host_signal";
12837
- ETelemetryCancelSource2["CONSUMER_RETURN"] = "consumer_return";
12838
- })(ETelemetryCancelSource || (ETelemetryCancelSource = {}));
12839
- (function(ETelemetryObservationBoundary2) {
12840
- ETelemetryObservationBoundary2["LOCAL_WAIT"] = "local_wait";
12841
- ETelemetryObservationBoundary2["EXECUTOR_SETTLED"] = "executor_settled";
12842
- ETelemetryObservationBoundary2["GENERATOR_WITH_SETUP_AND_CLEANUP"] = "generator_with_setup_and_cleanup";
12843
- })(ETelemetryObservationBoundary || (ETelemetryObservationBoundary = {}));
12844
- (function(ETelemetryRemoteCompletion2) {
12845
- ETelemetryRemoteCompletion2["UNKNOWN"] = "unknown";
12846
- ETelemetryRemoteCompletion2["NOT_DISPATCHED"] = "not_dispatched";
12847
- ETelemetryRemoteCompletion2["CONFIRMED"] = "confirmed";
12848
- })(ETelemetryRemoteCompletion || (ETelemetryRemoteCompletion = {}));
12849
- (function(ETelemetryCommitStatus2) {
12850
- ETelemetryCommitStatus2["COMMITTED"] = "committed";
12851
- ETelemetryCommitStatus2["FAILED"] = "failed";
12852
- })(ETelemetryCommitStatus || (ETelemetryCommitStatus = {}));
12853
- (function(ETelemetryHookMode2) {
12854
- ETelemetryHookMode2["AWAITED"] = "awaited";
12855
- ETelemetryHookMode2["DETACHED"] = "detached";
12856
- })(ETelemetryHookMode || (ETelemetryHookMode = {}));
12857
- (function(ETelemetryHookResult2) {
12858
- ETelemetryHookResult2["OK"] = "ok";
12859
- ETelemetryHookResult2["TIMEOUT"] = "timeout";
12860
- ETelemetryHookResult2["SKIPPED"] = "skipped";
12861
- ETelemetryHookResult2["SUCCESS"] = "success";
12862
- ETelemetryHookResult2["ERROR"] = "error";
12863
- })(ETelemetryHookResult || (ETelemetryHookResult = {}));
12864
- (function(ETelemetrySource2) {
12865
- ETelemetrySource2["KERNEL"] = "kernel";
12866
- ETelemetrySource2["PROVIDER"] = "provider";
12867
- })(ETelemetrySource || (ETelemetrySource = {}));
12868
- (function(ETelemetryEvidence2) {
12869
- ETelemetryEvidence2["OBSERVED"] = "observed";
12870
- })(ETelemetryEvidence || (ETelemetryEvidence = {}));
12871
- (function(ETelemetryCompleteness2) {
12872
- ETelemetryCompleteness2["COMPLETE"] = "complete";
12873
- ETelemetryCompleteness2["PARTIAL"] = "partial";
12874
- })(ETelemetryCompleteness || (ETelemetryCompleteness = {}));
12875
- (function(ETelemetryCoverage2) {
12876
- ETelemetryCoverage2["PI_MODEL_TOOL_HOOK"] = "pi_model_tool_hook";
12877
- ETelemetryCoverage2["CORE_ONLY"] = "core_only";
12878
- })(ETelemetryCoverage || (ETelemetryCoverage = {}));
12879
- (function(ETelemetryUsageSource2) {
12880
- ETelemetryUsageSource2["UNKNOWN"] = "unknown";
12881
- ETelemetryUsageSource2["PROVIDER_NORMALIZED"] = "provider_normalized";
12882
- })(ETelemetryUsageSource || (ETelemetryUsageSource = {}));
12883
- (function(ETelemetryAttemptVisibility2) {
12884
- ETelemetryAttemptVisibility2["PROVIDER_INVOCATION"] = "provider_invocation";
12885
- ETelemetryAttemptVisibility2["TOOL_PROVIDER_INVOCATION"] = "tool_provider_invocation";
12886
- })(ETelemetryAttemptVisibility || (ETelemetryAttemptVisibility = {}));
12887
- (function(ETelemetryLinkRelation2) {
12888
- ETelemetryLinkRelation2["GENERATED_BY"] = "generated_by";
12889
- ETelemetryLinkRelation2["SCHEDULED_BY"] = "scheduled_by";
12890
- })(ETelemetryLinkRelation || (ETelemetryLinkRelation = {}));
12891
- (function(ETelemetryToolFailureStage2) {
12892
- ETelemetryToolFailureStage2["BEFORE_HOOK"] = "before_hook";
12893
- ETelemetryToolFailureStage2["EXECUTION"] = "execution";
12894
- ETelemetryToolFailureStage2["AFTER_HOOK"] = "after_hook";
12895
- })(ETelemetryToolFailureStage || (ETelemetryToolFailureStage = {}));
12896
- (function(ETelemetryTerminalEvidence2) {
12897
- ETelemetryTerminalEvidence2["EXPLICIT_DONE_HISTORY_COMMITTED"] = "explicit_done_history_committed";
12898
- ETelemetryTerminalEvidence2["EXPLICIT_DONE"] = "explicit_done";
12899
- ETelemetryTerminalEvidence2["STREAM_ERROR"] = "stream_error";
12900
- ETelemetryTerminalEvidence2["CONSUMER_CANCEL"] = "consumer_cancel";
12901
- ETelemetryTerminalEvidence2["NATURAL_EXHAUSTION"] = "natural_exhaustion";
12902
- })(ETelemetryTerminalEvidence || (ETelemetryTerminalEvidence = {}));
12903
- (function(ETelemetryTerminalSource2) {
12904
- ETelemetryTerminalSource2["NATIVE_AGENT_END"] = "native_agent_end";
12905
- ETelemetryTerminalSource2["PROMPT_RESOLVED_FALLBACK"] = "prompt_resolved_fallback";
12906
- })(ETelemetryTerminalSource || (ETelemetryTerminalSource = {}));
12907
- (function(ETelemetryModelPurpose2) {
12908
- ETelemetryModelPurpose2["AGENT_LOOP"] = "agent_loop";
12909
- })(ETelemetryModelPurpose || (ETelemetryModelPurpose = {}));
12910
- (function(ETelemetryErrorType2) {
12911
- ETelemetryErrorType2["PROVIDER_STREAM_ERROR"] = "ProviderStreamError";
12912
- ETelemetryErrorType2["TOOL_EXECUTION_ERROR"] = "ToolExecutionError";
12913
- ETelemetryErrorType2["HOOK_DISPATCH_ERROR"] = "HookDispatchError";
12914
- ETelemetryErrorType2["HOOK_DRAIN_ERROR"] = "HookDrainError";
12915
- })(ETelemetryErrorType || (ETelemetryErrorType = {}));
12916
- (function(ETelemetrySpanKind2) {
12917
- ETelemetrySpanKind2["INTERNAL"] = "internal";
12918
- ETelemetrySpanKind2["CLIENT"] = "client";
12919
- })(ETelemetrySpanKind || (ETelemetrySpanKind = {}));
12920
- (function(ETelemetryGenAiOperation2) {
12921
- ETelemetryGenAiOperation2["CHAT"] = "chat";
12922
- ETelemetryGenAiOperation2["EXECUTE_TOOL"] = "execute_tool";
12923
- ETelemetryGenAiOperation2["INVOKE_AGENT"] = "invoke_agent";
12924
- })(ETelemetryGenAiOperation || (ETelemetryGenAiOperation = {}));
12925
- (function(ETelemetryVersion2) {
12926
- ETelemetryVersion2["V0_2"] = "0.2";
12927
- ETelemetryVersion2["V1_0"] = "1.0";
12928
- })(ETelemetryVersion || (ETelemetryVersion = {}));
12929
- }
12930
- });
12931
-
12932
- // ../linkque-agent-protocol/dist/esm/telemetry.js
12933
- var init_telemetry = __esm({
12934
- "../linkque-agent-protocol/dist/esm/telemetry.js"() {
12935
- "use strict";
12936
- init_telemetryEnums();
12937
- }
12938
- });
12939
-
12940
13070
  // ../linkque-agent-runtime/dist/esm/core/logFailure.js
12941
13071
  function warnLogFailure(stage, error40) {
12942
13072
  (0, import_node_process.emitWarning)(`[${stage}] errorType=${error40 instanceof Error ? error40.name : typeof error40}`, { code: "LINKQUE_RUNTIME_DIAGNOSTIC_FAILURE" });
@@ -14252,18 +14382,45 @@ function createActivateSkillTool(records) {
14252
14382
  required: ["name"],
14253
14383
  additionalProperties: false
14254
14384
  },
14255
- execute: async (args) => {
14385
+ execute: async (args, _signal, context2) => {
14256
14386
  const name = extractName(args);
14257
- if (!name)
14387
+ const startedAt = Date.now();
14388
+ const obs = context2?.observation;
14389
+ recordContentSection(obs, ETelemetryContentSection.SKILL_INPUT, {
14390
+ name: name ?? null
14391
+ });
14392
+ if (!name) {
14393
+ recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
14394
+ status: "failed",
14395
+ error: "\u7F3A\u5C11 name \u53C2\u6570",
14396
+ durationMs: Date.now() - startedAt
14397
+ });
14258
14398
  return "\u6FC0\u6D3B\u6280\u80FD\u5931\u8D25:\u7F3A\u5C11 name \u53C2\u6570\u3002";
14399
+ }
14259
14400
  if (!bodyByName.has(name)) {
14401
+ recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
14402
+ name,
14403
+ status: "failed",
14404
+ error: `\u672A\u627E\u5230\u6280\u80FD "${name}"`,
14405
+ durationMs: Date.now() - startedAt
14406
+ });
14260
14407
  return `\u6FC0\u6D3B\u6280\u80FD\u5931\u8D25:\u672A\u627E\u5230\u6280\u80FD "${name}"\u3002\u53EF\u7528:${[...bodyByName.keys()].join(", ")}`;
14261
14408
  }
14262
14409
  if (activated.has(name)) {
14410
+ recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
14411
+ name,
14412
+ status: "already_loaded",
14413
+ durationMs: Date.now() - startedAt
14414
+ });
14263
14415
  return `\u6280\u80FD "${name}" \u5DF2\u5728\u672C\u8F6E\u52A0\u8F7D,\u65E0\u9700\u91CD\u590D\u6FC0\u6D3B\u3002`;
14264
14416
  }
14265
14417
  activated.add(name);
14266
14418
  const body = bodyByName.get(name) ?? "";
14419
+ recordContentSection(obs, ETelemetryContentSection.SKILL_OUTPUT, {
14420
+ name,
14421
+ status: "loaded",
14422
+ durationMs: Date.now() - startedAt
14423
+ });
14267
14424
  return `<skill name="${escapeXml(name)}">
14268
14425
  ${body}
14269
14426
  </skill>`;
@@ -14321,6 +14478,8 @@ var ACTIVATE_SKILL_TOOL_NAME, AVAILABLE_SKILLS_OPEN, AVAILABLE_SKILLS_CLOSE;
14321
14478
  var init_skillTools = __esm({
14322
14479
  "../linkque-agent-runtime/dist/esm/core/skillTools.js"() {
14323
14480
  "use strict";
14481
+ init_telemetry();
14482
+ init_contentRecording();
14324
14483
  ACTIVATE_SKILL_TOOL_NAME = "activate_skill";
14325
14484
  AVAILABLE_SKILLS_OPEN = "<available_skills>";
14326
14485
  AVAILABLE_SKILLS_CLOSE = "</available_skills>";
@@ -14548,7 +14707,7 @@ function createKnowledgeTools(resources, searchPort, agentId) {
14548
14707
  additionalProperties: false
14549
14708
  },
14550
14709
  annotations: { readOnlyHint: true },
14551
- execute: () => listKnowledge()
14710
+ execute: (_args, _signal, context2) => listKnowledge(context2)
14552
14711
  },
14553
14712
  {
14554
14713
  name: KNOWLEDGE_RECALL_TOOL_NAME,
@@ -14575,24 +14734,48 @@ function createKnowledgeTools(resources, searchPort, agentId) {
14575
14734
  additionalProperties: false
14576
14735
  },
14577
14736
  annotations: { readOnlyHint: true },
14578
- execute: (args, signal) => recallKnowledge(args, signal)
14737
+ execute: (args, signal, context2) => recallKnowledge(args, signal, context2)
14579
14738
  }
14580
14739
  ];
14581
- async function listKnowledge() {
14582
- return { knowledgeBases: await getKnowledgeBases() };
14740
+ async function listKnowledge(context2) {
14741
+ const result = { knowledgeBases: await getKnowledgeBases() };
14742
+ recordContentSection(context2?.observation, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
14743
+ knowledgeBases: result.knowledgeBases.map((kb) => ({
14744
+ knowledgeBaseId: kb.knowledgeBaseId,
14745
+ knowledgeDesc: kb.knowledgeDesc
14746
+ }))
14747
+ });
14748
+ return result;
14583
14749
  }
14584
- async function recallKnowledge(args, signal) {
14750
+ async function recallKnowledge(args, signal, context2) {
14585
14751
  const parsed = parseRecallArgs(args);
14752
+ const obs = context2?.observation;
14586
14753
  if ("error" in parsed) {
14754
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_INPUT, {
14755
+ error: parsed.error
14756
+ });
14757
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
14758
+ status: "failed",
14759
+ hits: [],
14760
+ error: parsed.error
14761
+ });
14587
14762
  return { hits: [], error: parsed.error };
14588
14763
  }
14764
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_INPUT, {
14765
+ knowledgeBaseId: parsed.knowledgeBaseId,
14766
+ query: parsed.query,
14767
+ topK: parsed.topK
14768
+ });
14589
14769
  const knowledgeBases = await getKnowledgeBases();
14590
14770
  const bound = knowledgeBases.some((info) => info.knowledgeBaseId === parsed.knowledgeBaseId);
14591
14771
  if (!bound) {
14592
- return {
14772
+ const error40 = `knowledgeBaseId \u672A\u7ED1\u5B9A: ${parsed.knowledgeBaseId}\u3002\u8BF7\u5148\u8C03\u7528 knowledge_list \u67E5\u770B\u53EF\u7528\u77E5\u8BC6\u5E93\u3002`;
14773
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
14774
+ status: "failed",
14593
14775
  hits: [],
14594
- error: `knowledgeBaseId \u672A\u7ED1\u5B9A: ${parsed.knowledgeBaseId}\u3002\u8BF7\u5148\u8C03\u7528 knowledge_list \u67E5\u770B\u53EF\u7528\u77E5\u8BC6\u5E93\u3002`
14595
- };
14776
+ error: error40
14777
+ });
14778
+ return { hits: [], error: error40 };
14596
14779
  }
14597
14780
  try {
14598
14781
  const result = await searchPort.search({
@@ -14601,10 +14784,20 @@ function createKnowledgeTools(resources, searchPort, agentId) {
14601
14784
  agentId,
14602
14785
  topK: parsed.topK
14603
14786
  }, signal);
14787
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
14788
+ status: result.hits.length ? "matched" : "no_hits",
14789
+ hits: result.hits
14790
+ });
14604
14791
  return { hits: result.hits };
14605
14792
  } catch (e2) {
14606
14793
  const msg = e2 instanceof Error ? e2.message : String(e2);
14607
- return { hits: [], error: `\u77E5\u8BC6\u5E93\u68C0\u7D22\u5931\u8D25: ${msg}` };
14794
+ const error40 = `\u77E5\u8BC6\u5E93\u68C0\u7D22\u5931\u8D25: ${msg}`;
14795
+ recordContentSection(obs, ETelemetryContentSection.KNOWLEDGE_OUTPUT, {
14796
+ status: "failed",
14797
+ hits: [],
14798
+ error: error40
14799
+ });
14800
+ return { hits: [], error: error40 };
14608
14801
  }
14609
14802
  }
14610
14803
  async function getKnowledgeBases() {
@@ -14618,6 +14811,8 @@ var init_createKnowledgeTools = __esm({
14618
14811
  "../linkque-agent-runtime/dist/esm/core/createKnowledgeTools.js"() {
14619
14812
  "use strict";
14620
14813
  init_knowledgeTools();
14814
+ init_telemetry();
14815
+ init_contentRecording();
14621
14816
  }
14622
14817
  });
14623
14818
 
@@ -14648,7 +14843,7 @@ var init_noopRuntimeTelemetry = __esm({
14648
14843
  startOperation(_operation) {
14649
14844
  return this;
14650
14845
  }
14651
- record(_name, _attributes) {
14846
+ record(_name, _attributes, _body) {
14652
14847
  }
14653
14848
  finish(_outcome, _attributes) {
14654
14849
  }
@@ -14746,7 +14941,7 @@ var init_runtimeObservation = __esm({
14746
14941
  find(key) {
14747
14942
  return this.associations.get(key);
14748
14943
  }
14749
- record(name, attributes) {
14944
+ record(name, attributes, body) {
14750
14945
  if (this.abandoned)
14751
14946
  return;
14752
14947
  try {
@@ -14754,7 +14949,7 @@ var init_runtimeObservation = __esm({
14754
14949
  this.resultAttributes = {
14755
14950
  [ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]: attributes[ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE]
14756
14951
  };
14757
- this.sink.record(name, attributes);
14952
+ this.sink.record(name, attributes, body);
14758
14953
  } catch {
14759
14954
  }
14760
14955
  }
@@ -49054,9 +49249,9 @@ function toolResultOutcome(result) {
49054
49249
  return ETelemetryOutcome.UNKNOWN;
49055
49250
  }
49056
49251
  const record4 = result;
49057
- if (record4.isError === true || record4.ok === false || record4.success === false)
49252
+ if (record4.isError === true)
49058
49253
  return ETelemetryOutcome.ERROR;
49059
- if (record4.isError === false || record4.ok === true || record4.success === true || record4.type === "linkque.presentation-tool-result")
49254
+ if (record4.isError === false || record4.type === "linkque.presentation-tool-result")
49060
49255
  return ETelemetryOutcome.SUCCESS;
49061
49256
  } catch {
49062
49257
  }
@@ -49074,6 +49269,7 @@ function observeTool(tool, observation) {
49074
49269
  eventPrefix: ETelemetryEventPrefix.TOOL_ATTEMPT,
49075
49270
  attributes: {
49076
49271
  [ETelemetryAttribute.GEN_AI_TOOL_NAME]: tool.modelName ?? tool.name,
49272
+ [ETelemetryAttribute.LINKQUE_TOOL_DISPLAY_NAME]: tool.label ?? tool.name,
49077
49273
  [ETelemetryAttribute.GEN_AI_TOOL_CALL_ID]: context2?.toolCallId ?? "",
49078
49274
  [ETelemetryAttribute.HARNESS_ATTEMPT_ID]: (0, import_node_crypto6.randomUUID)(),
49079
49275
  [ETelemetryAttribute.HARNESS_ATTEMPT_VISIBILITY]: ETelemetryAttemptVisibility.TOOL_PROVIDER_INVOCATION
@@ -49081,8 +49277,19 @@ function observeTool(tool, observation) {
49081
49277
  detached: false,
49082
49278
  links: []
49083
49279
  });
49280
+ const captureBody = !isSkillTool(tool);
49084
49281
  try {
49085
- const result = await tool.execute(args, signal, context2);
49282
+ if (captureBody) {
49283
+ recordContentSection(operation, ETelemetryContentSection.TOOL_INPUT, args);
49284
+ }
49285
+ const execContext = {
49286
+ ...context2 ?? { toolCallId: "", emit: () => void 0 },
49287
+ observation: operation
49288
+ };
49289
+ const result = await tool.execute(args, signal, execContext);
49290
+ if (captureBody) {
49291
+ recordContentSection(operation, ETelemetryContentSection.TOOL_OUTPUT, result);
49292
+ }
49086
49293
  operation.finish(toolResultOutcome(result), {
49087
49294
  [ETelemetryAttribute.HARNESS_TOOL_RESULT_STATUS]: toolResultOutcome(result)
49088
49295
  });
@@ -49100,13 +49307,16 @@ function observeTool(tool, observation) {
49100
49307
  }
49101
49308
  };
49102
49309
  }
49103
- var import_node_crypto6;
49310
+ var import_node_crypto6, isSkillTool;
49104
49311
  var init_toolObservation = __esm({
49105
49312
  "../linkque-agent-runtime/dist/esm/core/telemetry/toolObservation.js"() {
49106
49313
  "use strict";
49107
49314
  init_telemetry();
49108
49315
  init_telemetryEnums2();
49316
+ init_skillTools();
49109
49317
  import_node_crypto6 = require("node:crypto");
49318
+ init_contentRecording();
49319
+ isSkillTool = (tool) => (tool.modelName ?? tool.name) === ACTIVATE_SKILL_TOOL_NAME;
49110
49320
  }
49111
49321
  });
49112
49322
 
@@ -49214,8 +49424,6 @@ var init_piTelemetry = __esm({
49214
49424
  proposed = /* @__PURE__ */ new Map();
49215
49425
  loop;
49216
49426
  lastProvider = null;
49217
- publicTextSeen = false;
49218
- started = performance.now();
49219
49427
  terminal = ETelemetryStreamTermination.EXHAUSTED;
49220
49428
  constructor(root) {
49221
49429
  this.root = root;
@@ -49230,6 +49438,9 @@ var init_piTelemetry = __esm({
49230
49438
  [ETelemetryAttribute.LINKQUE_TELEMETRY_COVERAGE]: ETelemetryCoverage.PI_MODEL_TOOL_HOOK
49231
49439
  });
49232
49440
  }
49441
+ get currentModel() {
49442
+ return this.root.find(ETelemetryAssociation.MODEL);
49443
+ }
49233
49444
  startModel(model) {
49234
49445
  const parent = this.root.find(ETelemetryAssociation.ITERATION) ?? this.loop;
49235
49446
  return parent.startOperation({
@@ -49326,12 +49537,6 @@ var init_piTelemetry = __esm({
49326
49537
  break;
49327
49538
  case "message_update": {
49328
49539
  const update = event.assistantMessageEvent;
49329
- if (update.type === "text_delta" && update.delta && !this.publicTextSeen) {
49330
- this.publicTextSeen = true;
49331
- this.loop.record(ETelemetryEventName.LOOP_FIRST_PUBLIC_TEXT, {
49332
- [ETelemetryAttribute.LINKQUE_LOOP_FIRST_PUBLIC_TEXT_MS]: performance.now() - this.started
49333
- });
49334
- }
49335
49540
  if (update.type === "error")
49336
49541
  this.terminal = update.reason === "aborted" ? ETelemetryStreamTermination.CANCEL : ETelemetryStreamTermination.ERROR;
49337
49542
  break;
@@ -205823,6 +206028,9 @@ var init_agentService = __esm({
205823
206028
  this.unsubscribe = this.session.subscribe((event) => {
205824
206029
  if (this.aborted)
205825
206030
  return;
206031
+ if (event.type === "message_end" && event.message.role === "assistant") {
206032
+ this.options.publicOutput?.completeSource(this.telemetry?.currentModel, event.message.stopReason !== "error" && event.message.stopReason !== "aborted");
206033
+ }
205826
206034
  this.telemetry?.onEvent(event);
205827
206035
  this.logDebug(`[pi-event] ${this.safeStringify(event)}`);
205828
206036
  for (const translated of translateEvents(event, this.uiStatusToolNames)) {
@@ -205831,6 +206039,7 @@ var init_agentService = __esm({
205831
206039
  return;
205832
206040
  this.settled = true;
205833
206041
  }
206042
+ this.options.publicOutput?.associate(translated, this.telemetry?.currentModel);
205834
206043
  this.enqueue(translated);
205835
206044
  }
205836
206045
  });
@@ -206138,6 +206347,7 @@ var init_piAgentLoop = __esm({
206138
206347
  },
206139
206348
  ...req.debugLog && { debugLog: req.debugLog },
206140
206349
  ...req.observation && { observation: req.observation },
206350
+ ...req.publicOutput && { publicOutput: req.publicOutput },
206141
206351
  // agentId 透传:agentService 在 LINKQUE provider 时注入 x-agent-id 请求头,供网关计费归因。
206142
206352
  ...req.agentId !== void 0 && { agentId: req.agentId },
206143
206353
  // runId 透传:注入 x-run-id 请求头,供网关用量上报归因(落库 run_id)。
@@ -206169,6 +206379,92 @@ var init_pi = __esm({
206169
206379
  }
206170
206380
  });
206171
206381
 
206382
+ // ../linkque-agent-runtime/dist/esm/core/telemetry/publicOutputObservation.js
206383
+ var PublicOutputObservation;
206384
+ var init_publicOutputObservation = __esm({
206385
+ "../linkque-agent-runtime/dist/esm/core/telemetry/publicOutputObservation.js"() {
206386
+ "use strict";
206387
+ init_telemetry();
206388
+ PublicOutputObservation = class {
206389
+ root;
206390
+ sources = /* @__PURE__ */ new WeakMap();
206391
+ completedSources = /* @__PURE__ */ new WeakMap();
206392
+ source;
206393
+ text = "";
206394
+ bytes = 0;
206395
+ index = 0;
206396
+ truncated = false;
206397
+ firstText = false;
206398
+ startedAt = performance.now();
206399
+ constructor(root) {
206400
+ this.root = root;
206401
+ }
206402
+ associate(event, source) {
206403
+ if (source)
206404
+ this.sources.set(event, source);
206405
+ }
206406
+ /** 来源终态可能早于队列中的正文到达,不能在此提前刷空缓冲。 */
206407
+ completeSource(source, complete) {
206408
+ if (source)
206409
+ this.completedSources.set(source, complete);
206410
+ }
206411
+ accept(event) {
206412
+ if (event.type === "done" || event.type === "error") {
206413
+ const completed = this.source ? this.completedSources.get(this.source) : void 0;
206414
+ this.finish(completed ?? event.type === "done");
206415
+ return;
206416
+ }
206417
+ if (event.type !== "delta" || !event.content)
206418
+ return;
206419
+ if (!this.firstText) {
206420
+ this.firstText = true;
206421
+ this.root.record(ETelemetryEventName.LOOP_FIRST_PUBLIC_TEXT, {
206422
+ [ETelemetryAttribute.LINKQUE_LOOP_FIRST_PUBLIC_TEXT_MS]: performance.now() - this.startedAt
206423
+ });
206424
+ }
206425
+ const source = this.sources.get(event);
206426
+ if (!source)
206427
+ return;
206428
+ if (source !== this.source) {
206429
+ this.finish(true);
206430
+ this.source = source;
206431
+ }
206432
+ if (this.truncated)
206433
+ return;
206434
+ for (const character of event.content) {
206435
+ const size = Buffer.byteLength(character, "utf8");
206436
+ if (this.bytes + size > 512 * 1024) {
206437
+ this.truncated = true;
206438
+ break;
206439
+ }
206440
+ this.bytes += size;
206441
+ this.text += character;
206442
+ if (this.text.length >= 16 * 1024)
206443
+ this.flush(false, false);
206444
+ }
206445
+ }
206446
+ finish(complete) {
206447
+ if (this.bytes)
206448
+ this.flush(true, complete && (this.source ? this.completedSources.get(this.source) ?? true : true));
206449
+ this.source = void 0;
206450
+ this.bytes = 0;
206451
+ this.index = 0;
206452
+ this.truncated = false;
206453
+ }
206454
+ flush(final, complete) {
206455
+ this.source?.record(ETelemetryEventName.CONTENT_RECORDED, {}, {
206456
+ section: ETelemetryContentSection.MODEL_OUTPUT,
206457
+ value: this.text,
206458
+ chunkIndex: this.index++,
206459
+ final,
206460
+ availability: final && complete && !this.truncated ? "available" : "partial"
206461
+ });
206462
+ this.text = "";
206463
+ }
206464
+ };
206465
+ }
206466
+ });
206467
+
206172
206468
  // ../linkque-agent-runtime/dist/esm/core/telemetry/runtimeErrorBoundary.js
206173
206469
  async function* withRuntimeErrorBoundary(telemetry, input, run, signal) {
206174
206470
  const observation = startRuntimeObservation(telemetry, input);
@@ -206215,6 +206511,103 @@ var init_runtimeErrorBoundary = __esm({
206215
206511
  }
206216
206512
  });
206217
206513
 
206514
+ // ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
206515
+ function assertAgentConfigRoot(value, pluginName) {
206516
+ if (typeof value !== "object" || value === null || !("agent" in value)) {
206517
+ throw new Error(`Agent runtime \u63D2\u4EF6 ${pluginName} \u7684 modifyAgentConfig \u8FD4\u56DE\u4E86\u65E0\u6548\u914D\u7F6E`);
206518
+ }
206519
+ }
206520
+ var validatePlugins, applyAgentRuntimePluginConfig, MergedHookExecutorHandler, resolveAgentRuntimeHookExecutor;
206521
+ var init_agentRuntimePlugin = __esm({
206522
+ "../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js"() {
206523
+ "use strict";
206524
+ init_types();
206525
+ validatePlugins = (plugins) => {
206526
+ const names = /* @__PURE__ */ new Set();
206527
+ for (const plugin of plugins) {
206528
+ const name = plugin.name.trim();
206529
+ if (!name) {
206530
+ throw new Error("Agent runtime \u63D2\u4EF6 name \u4E0D\u80FD\u4E3A\u7A7A");
206531
+ }
206532
+ if (names.has(name)) {
206533
+ throw new Error(`Agent runtime \u63D2\u4EF6 name \u91CD\u590D: ${name}`);
206534
+ }
206535
+ names.add(name);
206536
+ }
206537
+ return plugins;
206538
+ };
206539
+ applyAgentRuntimePluginConfig = (agentConfig, plugins = []) => {
206540
+ const validatedPlugins = validatePlugins(plugins);
206541
+ const modifiers = validatedPlugins.filter((plugin) => plugin.modifyAgentConfig !== void 0);
206542
+ if (modifiers.length === 0)
206543
+ return agentConfig;
206544
+ let current = structuredClone(agentConfig);
206545
+ for (const plugin of modifiers) {
206546
+ try {
206547
+ const modified = plugin.modifyAgentConfig?.(current);
206548
+ if (modified !== void 0) {
206549
+ assertAgentConfigRoot(modified, plugin.name);
206550
+ current = modified;
206551
+ }
206552
+ current = structuredClone(current);
206553
+ } catch (error40) {
206554
+ throw new Error(`Agent runtime \u63D2\u4EF6 ${plugin.name} \u4FEE\u6539 Agent Config \u5931\u8D25`, { cause: error40 });
206555
+ }
206556
+ }
206557
+ return current;
206558
+ };
206559
+ MergedHookExecutorHandler = class {
206560
+ executorByName;
206561
+ constructor(executorByName) {
206562
+ this.executorByName = executorByName;
206563
+ }
206564
+ matches(resource, stage, subject) {
206565
+ const executor = this.executorByName.get(resource.config.executorName);
206566
+ return executor?.matches?.(resource, stage, subject) ?? true;
206567
+ }
206568
+ async execute(resource, context2, options) {
206569
+ const executor = this.executorByName.get(resource.config.executorName);
206570
+ if (executor)
206571
+ return executor.execute(resource, context2, options);
206572
+ return {
206573
+ ok: true,
206574
+ skipped: true,
206575
+ code: "PLUGIN_EXECUTOR_NOT_FOUND",
206576
+ message: `\u672A\u627E\u5230 name=${resource.config.executorName} \u7684 hook executor`
206577
+ };
206578
+ }
206579
+ };
206580
+ resolveAgentRuntimeHookExecutor = (plugins = [], portHookExecutorList = [], debugLog) => {
206581
+ const entries = validatePlugins(plugins).flatMap((plugin) => (plugin.hookExecutorList ?? []).map((executor, index2) => ({
206582
+ executor,
206583
+ source: `plugin:${plugin.name}[${index2}]`
206584
+ })));
206585
+ entries.push(...portHookExecutorList.map((executor, index2) => ({
206586
+ executor,
206587
+ source: `ports.hookExecutorList[${index2}]`
206588
+ })));
206589
+ if (entries.length === 0)
206590
+ return void 0;
206591
+ const merged = /* @__PURE__ */ new Map();
206592
+ for (const entry of entries) {
206593
+ const name = entry.executor.name;
206594
+ if (!name.trim())
206595
+ throw new Error(`Hook executor name \u4E0D\u80FD\u4E3A\u7A7A: ${entry.source}`);
206596
+ const previous = merged.get(name);
206597
+ if (previous) {
206598
+ try {
206599
+ debugLog?.(`[hook-executor-merge] name=${name} \u51B2\u7A81: ${previous.source} \u88AB ${entry.source} \u8986\u76D6`, EDebugLogScope.HOOK);
206600
+ } catch {
206601
+ }
206602
+ }
206603
+ merged.set(name, entry);
206604
+ }
206605
+ const executorByName = new Map([...merged].map(([name, entry]) => [name, entry.executor]));
206606
+ return new MergedHookExecutorHandler(executorByName);
206607
+ };
206608
+ }
206609
+ });
206610
+
206218
206611
  // ../linkque-agent-runtime/dist/esm/core/cardSourceResult.js
206219
206612
  async function createCardSourceReceipt(input) {
206220
206613
  const resultRef = `card-source-result-${(0, import_node_crypto8.randomUUID)()}`;
@@ -206681,6 +207074,7 @@ var CARD_SEQUENCE, AFTER_CARD_DESCRIPTION, RESPONSE_MODE_DESCRIPTION, CardRender
206681
207074
  var init_cardRenderMcpServer = __esm({
206682
207075
  "../linkque-agent-runtime/dist/esm/core/cardRenderMcpServer.js"() {
206683
207076
  "use strict";
207077
+ init_telemetry();
206684
207078
  init_cardSourceResult();
206685
207079
  init_cardTools();
206686
207080
  init_mcpNaming();
@@ -206711,6 +207105,7 @@ var init_cardRenderMcpServer = __esm({
206711
207105
  toolByName = /* @__PURE__ */ new Map();
206712
207106
  sourceResultByRef = /* @__PURE__ */ new Map();
206713
207107
  activeCardId;
207108
+ deliveries = /* @__PURE__ */ new WeakMap();
206714
207109
  closed = false;
206715
207110
  invalidCards = [];
206716
207111
  /** 只信任本实例实际执行成功的结果,普通 MCP JSON 无权控制文字输出。 */
@@ -206747,7 +207142,11 @@ var init_cardRenderMcpServer = __esm({
206747
207142
  });
206748
207143
  continue;
206749
207144
  }
206750
- const state2 = { selected: false, results: /* @__PURE__ */ new Map() };
207145
+ const state2 = {
207146
+ selected: false,
207147
+ results: /* @__PURE__ */ new Map(),
207148
+ executionId: void 0
207149
+ };
206751
207150
  this.states.set(resource.resourceId, state2);
206752
207151
  const finishName = createCardFinishToolName(resource.resourceId);
206753
207152
  const readName = createCardSourceReadToolName(resource.resourceId);
@@ -206763,7 +207162,9 @@ var init_cardRenderMcpServer = __esm({
206763
207162
  properties: {},
206764
207163
  additionalProperties: false
206765
207164
  },
206766
- execute: async () => {
207165
+ execute: async (_args, _signal, context2) => {
207166
+ state2.executionId = context2?.toolCallId;
207167
+ this.observeCard(context2, resource, config2, "prepare", state2.executionId);
206767
207168
  for (const candidate of this.states.values())
206768
207169
  candidate.selected = false;
206769
207170
  this.activeCardId = resource.resourceId;
@@ -206801,6 +207202,8 @@ var init_cardRenderMcpServer = __esm({
206801
207202
  inputSchema: normalizeMcpInputSchema(discoveredHandle?.inputSchema),
206802
207203
  outputSchema: CARD_SOURCE_RECEIPT_SCHEMA,
206803
207204
  execute: async (args, signal, context2) => {
207205
+ const executionId = state2.executionId;
207206
+ this.observeCard(context2, resource, config2, "source", executionId, source.sourceId);
206804
207207
  if (!state2.selected || this.activeCardId !== resource.resourceId)
206805
207208
  throw new Error(`\u8C03\u7528\u6570\u636E\u6E90\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
206806
207209
  const missingDependencies = (source.dependsOn ?? []).filter((dependency) => !state2.results.has(dependency));
@@ -206844,7 +207247,10 @@ var init_cardRenderMcpServer = __esm({
206844
207247
  signal?.throwIfAborted();
206845
207248
  if (this.closed)
206846
207249
  throw new Error("\u5361\u7247\u8FD0\u884C\u5DF2\u7ED3\u675F");
206847
- this.sourceResultByRef.set(cacheEntry.resultRef, cacheEntry);
207250
+ this.sourceResultByRef.set(cacheEntry.resultRef, {
207251
+ ...cacheEntry,
207252
+ executionId
207253
+ });
206848
207254
  this.logMetric(() => `source=${source.sourceId} mcpMs=${projectionStartedAt - mcpStartedAt} projectionMs=${Date.now() - projectionStartedAt} rawBytes=${byteLength(structured)} receiptBytes=${byteLength(receipt)}`);
206849
207255
  return receipt;
206850
207256
  }
@@ -206858,17 +207264,18 @@ var init_cardRenderMcpServer = __esm({
206858
207264
  description: "\u8BFB\u53D6\u672C\u8F6E\u5DF2\u6210\u529F\u6267\u884C\u7684\u6570\u636E\u6E90\u7F13\u5B58\uFF0C\u4E0D\u4F1A\u518D\u6B21\u8C03\u7528 MCP\u3002\u4EC5\u5F53\u6570\u636E\u6E90\u56DE\u6267\u7F3A\u5C11\u51B3\u7B56\u6240\u9700\u5B57\u6BB5\u3001\u6807\u8BB0\u4E3A\u4E0D\u5B8C\u6574\uFF0C\u6216\u540E\u7EED\u5DE5\u5177\u9700\u8981\u672A\u7ED1\u5B9A\u5B57\u6BB5\u65F6\u8C03\u7528\u3002\u4F18\u5148\u8BFB\u53D6 bound \u89C6\u56FE\uFF1B\u8BFB\u53D6\u96C6\u5408\u540E\u7EED\u6761\u76EE\u65F6\uFF0C\u628A\u56DE\u6267 fields.path \u4F5C\u4E3A path \u5E76\u8BBE\u7F6E offset/limit\uFF1B\u53EA\u6709\u672A\u7ED1\u5B9A\u5B57\u6BB5\u624D\u4F7F\u7528 raw\u3002\u4E0D\u8981\u628A\u5206\u9875\u6216\u622A\u65AD\u7ED3\u679C\u5F53\u4F5C\u5168\u96C6\u3002",
206859
207265
  inputSchema: CARD_SOURCE_READ_INPUT_SCHEMA,
206860
207266
  outputSchema: CARD_SOURCE_READ_OUTPUT_SCHEMA,
206861
- execute: async (args) => {
207267
+ execute: async (args, _signal, context2) => {
206862
207268
  const resultRef = readResultRef(args);
207269
+ const entry = this.sourceResultByRef.get(resultRef);
207270
+ const matchingEntry = entry?.cardId === resource.resourceId ? entry : void 0;
207271
+ this.observeCard(context2, resource, config2, "read", matchingEntry?.executionId);
206863
207272
  if (this.closed)
206864
207273
  throw new Error(`\u7F13\u5B58\u5DF2\u5931\u6548: ${resultRef}`);
206865
- const entry = this.sourceResultByRef.get(resultRef);
206866
- if (!entry || entry.cardId !== resource.resourceId) {
207274
+ if (!matchingEntry)
206867
207275
  throw new Error(`\u672A\u77E5\u7ED3\u679C\u5F15\u7528: ${resultRef}`);
206868
- }
206869
207276
  const startedAt = Date.now();
206870
- const receipt = readCardSourceResult(entry, args);
206871
- this.logMetric(() => `source=${entry.sourceId} cacheReadMs=${Date.now() - startedAt} receiptBytes=${byteLength(receipt)}`);
207277
+ const receipt = readCardSourceResult(matchingEntry, args);
207278
+ this.logMetric(() => `source=${matchingEntry.sourceId} cacheReadMs=${Date.now() - startedAt} receiptBytes=${byteLength(receipt)}`);
206872
207279
  return receipt;
206873
207280
  }
206874
207281
  });
@@ -206896,12 +207303,15 @@ ${AFTER_CARD_DESCRIPTION}`,
206896
207303
  },
206897
207304
  additionalProperties: false
206898
207305
  },
206899
- execute: async (args, signal) => {
207306
+ execute: async (args, signal, context2) => {
207307
+ this.observeCard(context2, resource, config2, "finish", state2.executionId);
206900
207308
  if (!state2.selected || this.activeCardId !== resource.resourceId)
206901
207309
  throw new Error(`\u5B8C\u6210\u5C55\u793A\u524D\uFF0C\u8BF7\u5148\u9009\u62E9\u5361\u7247 ${name}`);
206902
207310
  const afterCard = readAfterCard(args);
206903
207311
  const finishStartedAt = Date.now();
206904
207312
  const result = await executeCardPresentationFromSources(resource, this.runtimeContext, state2.results, signal);
207313
+ if (context2?.observation)
207314
+ this.deliveries.set(result.card, context2.observation);
206905
207315
  if (afterCard !== void 0) {
206906
207316
  this.companions.set(result, afterCard);
206907
207317
  result.modelText += `
@@ -206933,7 +207343,11 @@ ${AFTER_CARD_DESCRIPTION}`,
206933
207343
  throw new Error(`\u672A\u77E5\u5361\u7247\u5DE5\u5177: ${name}`);
206934
207344
  return descriptor.execute(args, signal, options?.context);
206935
207345
  }
206936
- return executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal, options?.context);
207346
+ this.observeCard(options?.context, resource, config2, "finish", options?.context?.toolCallId);
207347
+ const result = await executeCardPresentation(resource, this.registry, this.runtimeContext, args, signal, options?.context);
207348
+ if (options?.context?.observation)
207349
+ this.deliveries.set(result.card, options.context.observation);
207350
+ return result;
206937
207351
  }
206938
207352
  async close() {
206939
207353
  this.closed = true;
@@ -206943,6 +207357,17 @@ ${AFTER_CARD_DESCRIPTION}`,
206943
207357
  this.toolByName.clear();
206944
207358
  this.companions = /* @__PURE__ */ new WeakMap();
206945
207359
  }
207360
+ /** 记录执行时配置和显式关联,不从工具名称反推业务身份。 */
207361
+ observeCard(context2, resource, config2, phase, executionId, sourceId) {
207362
+ context2?.observation?.record(ETelemetryEventName.TOOL_CONTEXT, {
207363
+ [ETelemetryAttribute.LINKQUE_CARD_REF]: resource.resourceId,
207364
+ [ETelemetryAttribute.LINKQUE_CARD_REVISION]: config2.revision,
207365
+ [ETelemetryAttribute.LINKQUE_CARD_DISPLAY_NAME]: config2.displayName,
207366
+ [ETelemetryAttribute.LINKQUE_CARD_PHASE]: phase,
207367
+ ...executionId ? { [ETelemetryAttribute.LINKQUE_CARD_EXECUTION_ID]: executionId } : {},
207368
+ ...sourceId ? { [ETelemetryAttribute.LINKQUE_CARD_SOURCE_ID]: sourceId } : {}
207369
+ });
207370
+ }
206946
207371
  logMetric(message) {
206947
207372
  try {
206948
207373
  if (!this.debugLog)
@@ -206952,7 +207377,7 @@ ${AFTER_CARD_DESCRIPTION}`,
206952
207377
  }
206953
207378
  }
206954
207379
  /** 卡片与伴随文字的共享输出边界,不参与模型循环或工具调度。 */
206955
- async *projectConversation(events) {
207380
+ async *projectConversation(events, publicOutput) {
206956
207381
  const pending = /* @__PURE__ */ new WeakMap();
206957
207382
  let cardOwnsText = false;
206958
207383
  for await (const event of events) {
@@ -206969,13 +207394,24 @@ ${AFTER_CARD_DESCRIPTION}`,
206969
207394
  if (event.type === "a2ui_card" && pending.has(event)) {
206970
207395
  this.logMetric(`phase=card-event-emitted atMs=${Date.now()}`);
206971
207396
  }
207397
+ if (event.type === "a2ui_card") {
207398
+ this.deliveries.get(event)?.record(ETelemetryEventName.TOOL_CONTEXT, {
207399
+ [ETelemetryAttribute.LINKQUE_CARD_DELIVERY]: "emitted"
207400
+ });
207401
+ }
206972
207402
  yield event;
206973
207403
  if (event.type === "a2ui_card" && pending.has(event)) {
206974
207404
  const text2 = pending.get(event);
206975
207405
  pending.delete(event);
206976
207406
  cardOwnsText = true;
206977
- if (text2)
206978
- yield { type: "delta", content: text2 };
207407
+ if (text2) {
207408
+ const companion = { type: "delta", content: text2 };
207409
+ const source = this.deliveries.get(event);
207410
+ publicOutput?.associate(companion, source);
207411
+ publicOutput?.completeSource(source, true);
207412
+ yield companion;
207413
+ }
207414
+ this.deliveries.delete(event);
206979
207415
  }
206980
207416
  }
206981
207417
  }
@@ -207098,103 +207534,6 @@ var init_noopKnowledgeSearchPort = __esm({
207098
207534
  }
207099
207535
  });
207100
207536
 
207101
- // ../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js
207102
- function assertAgentConfigRoot(value, pluginName) {
207103
- if (typeof value !== "object" || value === null || !("agent" in value)) {
207104
- throw new Error(`Agent runtime \u63D2\u4EF6 ${pluginName} \u7684 modifyAgentConfig \u8FD4\u56DE\u4E86\u65E0\u6548\u914D\u7F6E`);
207105
- }
207106
- }
207107
- var validatePlugins, applyAgentRuntimePluginConfig, MergedHookExecutorHandler, resolveAgentRuntimeHookExecutor;
207108
- var init_agentRuntimePlugin = __esm({
207109
- "../linkque-agent-runtime/dist/esm/core/agentRuntimePlugin.js"() {
207110
- "use strict";
207111
- init_types();
207112
- validatePlugins = (plugins) => {
207113
- const names = /* @__PURE__ */ new Set();
207114
- for (const plugin of plugins) {
207115
- const name = plugin.name.trim();
207116
- if (!name) {
207117
- throw new Error("Agent runtime \u63D2\u4EF6 name \u4E0D\u80FD\u4E3A\u7A7A");
207118
- }
207119
- if (names.has(name)) {
207120
- throw new Error(`Agent runtime \u63D2\u4EF6 name \u91CD\u590D: ${name}`);
207121
- }
207122
- names.add(name);
207123
- }
207124
- return plugins;
207125
- };
207126
- applyAgentRuntimePluginConfig = (agentConfig, plugins = []) => {
207127
- const validatedPlugins = validatePlugins(plugins);
207128
- const modifiers = validatedPlugins.filter((plugin) => plugin.modifyAgentConfig !== void 0);
207129
- if (modifiers.length === 0)
207130
- return agentConfig;
207131
- let current = structuredClone(agentConfig);
207132
- for (const plugin of modifiers) {
207133
- try {
207134
- const modified = plugin.modifyAgentConfig?.(current);
207135
- if (modified !== void 0) {
207136
- assertAgentConfigRoot(modified, plugin.name);
207137
- current = modified;
207138
- }
207139
- current = structuredClone(current);
207140
- } catch (error40) {
207141
- throw new Error(`Agent runtime \u63D2\u4EF6 ${plugin.name} \u4FEE\u6539 Agent Config \u5931\u8D25`, { cause: error40 });
207142
- }
207143
- }
207144
- return current;
207145
- };
207146
- MergedHookExecutorHandler = class {
207147
- executorByName;
207148
- constructor(executorByName) {
207149
- this.executorByName = executorByName;
207150
- }
207151
- matches(resource, stage, subject) {
207152
- const executor = this.executorByName.get(resource.config.executorName);
207153
- return executor?.matches?.(resource, stage, subject) ?? true;
207154
- }
207155
- async execute(resource, context2, options) {
207156
- const executor = this.executorByName.get(resource.config.executorName);
207157
- if (executor)
207158
- return executor.execute(resource, context2, options);
207159
- return {
207160
- ok: true,
207161
- skipped: true,
207162
- code: "PLUGIN_EXECUTOR_NOT_FOUND",
207163
- message: `\u672A\u627E\u5230 name=${resource.config.executorName} \u7684 hook executor`
207164
- };
207165
- }
207166
- };
207167
- resolveAgentRuntimeHookExecutor = (plugins = [], portHookExecutorList = [], debugLog) => {
207168
- const entries = validatePlugins(plugins).flatMap((plugin) => (plugin.hookExecutorList ?? []).map((executor, index2) => ({
207169
- executor,
207170
- source: `plugin:${plugin.name}[${index2}]`
207171
- })));
207172
- entries.push(...portHookExecutorList.map((executor, index2) => ({
207173
- executor,
207174
- source: `ports.hookExecutorList[${index2}]`
207175
- })));
207176
- if (entries.length === 0)
207177
- return void 0;
207178
- const merged = /* @__PURE__ */ new Map();
207179
- for (const entry of entries) {
207180
- const name = entry.executor.name;
207181
- if (!name.trim())
207182
- throw new Error(`Hook executor name \u4E0D\u80FD\u4E3A\u7A7A: ${entry.source}`);
207183
- const previous = merged.get(name);
207184
- if (previous) {
207185
- try {
207186
- debugLog?.(`[hook-executor-merge] name=${name} \u51B2\u7A81: ${previous.source} \u88AB ${entry.source} \u8986\u76D6`, EDebugLogScope.HOOK);
207187
- } catch {
207188
- }
207189
- }
207190
- merged.set(name, entry);
207191
- }
207192
- const executorByName = new Map([...merged].map(([name, entry]) => [name, entry.executor]));
207193
- return new MergedHookExecutorHandler(executorByName);
207194
- };
207195
- }
207196
- });
207197
-
207198
207537
  // ../linkque-agent-runtime/dist/esm/core/agentRuntime.js
207199
207538
  function composeSystemPrompt(harnessPrompt, systemPrompt, skillcatalog = "", runtimePatchSuffix = "") {
207200
207539
  const parts = [];
@@ -207231,34 +207570,35 @@ var init_agentRuntime = __esm({
207231
207570
  "use strict";
207232
207571
  init_telemetry();
207233
207572
  init_noopRuntimeTelemetry();
207573
+ init_publicOutputObservation();
207234
207574
  init_runtimeErrorBoundary();
207235
207575
  init_toolObservation();
207236
- init_types();
207237
207576
  init_esm();
207238
- init_piAgentLoop();
207577
+ init_types();
207239
207578
  init_followUpQuestionGenerator();
207240
- init_inMemorySessionManager();
207241
- init_noopSkillLoader();
207242
- init_noopMcpServerProvider();
207243
- init_mcpProxyTool();
207244
- init_mcpAggregator();
207579
+ init_piAgentLoop();
207580
+ init_agentRuntimePlugin();
207245
207581
  init_cardRenderMcpServer();
207246
- init_cardTools();
207247
207582
  init_cardRenderMcpServerProvider();
207583
+ init_cardTools();
207248
207584
  init_createKnowledgeTools();
207249
- init_noopKnowledgeSearchPort();
207250
207585
  init_createWebSearchTool();
207251
- init_noopWebSearchPort();
207252
- init_webSearchResource();
207253
- init_skillTools();
207254
207586
  init_followUpQuestions();
207255
207587
  init_hookContext();
207256
207588
  init_hookDispatcher();
207257
207589
  init_hookRegistry();
207590
+ init_hookToolWrapper();
207258
207591
  init_noopHookExecutor();
207259
207592
  init_sideEffectRunner();
207260
- init_hookToolWrapper();
207261
- init_agentRuntimePlugin();
207593
+ init_inMemorySessionManager();
207594
+ init_mcpAggregator();
207595
+ init_mcpProxyTool();
207596
+ init_noopKnowledgeSearchPort();
207597
+ init_noopMcpServerProvider();
207598
+ init_noopSkillLoader();
207599
+ init_noopWebSearchPort();
207600
+ init_skillTools();
207601
+ init_webSearchResource();
207262
207602
  DEFAULT_HARNESS_PROMPT = `# Harness \u8FD0\u884C\u89C4\u7EA6
207263
207603
 
207264
207604
  \u4F60\u662F\u8FD0\u884C\u5728 LinkQue harness \u4E4B\u4E0B\u7684\u667A\u80FD\u4F53\u3002\u8BF7\u9075\u5B88\u4EE5\u4E0B\u7A33\u5B9A\u8FD0\u884C\u89C4\u7EA6:
@@ -207422,11 +207762,38 @@ var init_agentRuntime = __esm({
207422
207762
  }
207423
207763
  }, (observation) => this.runObservedAdvance(request, auth2, options, observation), options.signal);
207424
207764
  }
207765
+ /**
207766
+ * 记录本次用户输入(RFC §4.1):取进入 Runtime 的本次新消息中最后一条 user message
207767
+ * 的 content,作为 `linkque.content.recorded` 的 body 走 record 链路落入
207768
+ * OTLP logs(body 含 section/value/availability)。不以模型 messages 上下文为输入;
207769
+ * 无 user 文本(卡片交互等)时按可用性如实标记,不伪造自然语言 Query。
207770
+ */
207771
+ recordCurrentQuery(observation, request) {
207772
+ let lastUser;
207773
+ for (const message of request.messages) {
207774
+ if (message.role === "user")
207775
+ lastUser = message;
207776
+ }
207777
+ const content = lastUser?.content;
207778
+ const text2 = typeof content === "string" && content ? content : void 0;
207779
+ const value = text2?.slice(0, CONTENT_VALUE_MAX_LENGTH);
207780
+ const truncated = text2 !== void 0 && text2.length > CONTENT_VALUE_MAX_LENGTH;
207781
+ const card = content && typeof content === "object" && "type" in content && content.type === "a2ui.event" ? content : void 0;
207782
+ const displayText = card && "displayText" in card && typeof card.displayText === "string" && card.displayText ? card.displayText : void 0;
207783
+ const body = {
207784
+ section: ETelemetryContentSection.QUERY_INPUT,
207785
+ ...value !== void 0 ? { value } : {},
207786
+ ...card ? { inputType: "card", ...displayText ? { displayText } : {} } : {},
207787
+ availability: text2 !== void 0 || card ? "available" : "not_recorded"
207788
+ };
207789
+ observation.record(ETelemetryEventName.CONTENT_RECORDED, { [ETelemetryAttribute.LINKQUE_CONTENT_VALUE_TRUNCATED]: truncated }, body);
207790
+ }
207425
207791
  async *runObservedAdvance(request, auth2, options, observation) {
207426
207792
  observation.record(ETelemetryEventName.TELEMETRY_COVERAGE, {
207427
207793
  [ETelemetryAttribute.LINKQUE_TELEMETRY_COVERAGE]: this.agentLoop instanceof PiAgentLoop ? ETelemetryCoverage.PI_MODEL_TOOL_HOOK : ETelemetryCoverage.CORE_ONLY,
207428
207794
  [ETelemetryAttribute.HARNESS_TELEMETRY_COMPLETENESS]: this.agentLoop instanceof PiAgentLoop ? ETelemetryCompleteness.COMPLETE : ETelemetryCompleteness.PARTIAL
207429
207795
  });
207796
+ this.recordCurrentQuery(observation, request);
207430
207797
  const cleanup = [];
207431
207798
  let termination = ETelemetryStreamTermination.CANCEL;
207432
207799
  let failed = false;
@@ -207697,8 +208064,11 @@ var init_agentRuntime = __esm({
207697
208064
  ...assistantText !== "" && { messageContent: assistantText }
207698
208065
  });
207699
208066
  };
208067
+ const publicOutput = new PublicOutputObservation(observation);
208068
+ agentReq.publicOutput = publicOutput;
207700
208069
  try {
207701
- for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq))) {
208070
+ for await (const ev of cardServer.projectConversation(this.agentLoop.run(agentReq), publicOutput)) {
208071
+ publicOutput.accept(ev);
207702
208072
  if (ev.type === "delta")
207703
208073
  assistantText += ev.content;
207704
208074
  if (ev.type === "tool_end" && !ev.isError) {
@@ -207760,6 +208130,7 @@ var init_agentRuntime = __esm({
207760
208130
  await dispatchTerminalHook();
207761
208131
  yield ev;
207762
208132
  }
208133
+ publicOutput.finish(true);
207763
208134
  await dispatchTerminalHook();
207764
208135
  } catch (error40) {
207765
208136
  if (!terminalHookDispatched) {
@@ -207770,6 +208141,8 @@ var init_agentRuntime = __esm({
207770
208141
  await dispatchTerminalHook();
207771
208142
  }
207772
208143
  throw error40;
208144
+ } finally {
208145
+ publicOutput.finish(false);
207773
208146
  }
207774
208147
  }
207775
208148
  };
@@ -208531,6 +208904,22 @@ var EModelRequestSource;
208531
208904
 
208532
208905
  // ../linkque-agent-runtime/dist/esm/core/index.js
208533
208906
  init_types();
208907
+
208908
+ // ../linkque-agent-runtime/dist/esm/core/debugLog.js
208909
+ init_types();
208910
+ function isDebugLoggingEnabled(level) {
208911
+ return level?.trim().toLowerCase() === "debug";
208912
+ }
208913
+ function createRuntimeDebugLog(level, sink) {
208914
+ const debug = isDebugLoggingEnabled(level);
208915
+ return (line, scope) => {
208916
+ if (!debug && (scope === EDebugLogScope.PI_EVENT || scope === EDebugLogScope.HTTP || scope === EDebugLogScope.MCP || scope === EDebugLogScope.SKILL))
208917
+ return;
208918
+ sink(line, scope);
208919
+ };
208920
+ }
208921
+
208922
+ // ../linkque-agent-runtime/dist/esm/core/index.js
208534
208923
  init_esm();
208535
208924
  init_cardTools();
208536
208925
  init_mcpNaming();
@@ -214525,6 +214914,10 @@ init_esm();
214525
214914
 
214526
214915
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
214527
214916
  var import_node_async_hooks2 = require("node:async_hooks");
214917
+ init_telemetry();
214918
+ init_logFailure();
214919
+ init_contentRecording();
214920
+ init_types();
214528
214921
 
214529
214922
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/linkquegwTokenVerifier.js
214530
214923
  init_config();
@@ -214571,8 +214964,6 @@ var LinkquegwTokenVerifier = class {
214571
214964
  };
214572
214965
 
214573
214966
  // ../linkque-agent-runtime/dist/esm/impl/mcp/alipay/remoteGatewayMcpServer.js
214574
- init_types();
214575
- init_logFailure();
214576
214967
  var defaultCreateSigner = (config2, getAuthorizationHeader, debugLog) => new RemoteSignatureSigner({
214577
214968
  agentId: config2.agentId,
214578
214969
  signEndpoint: config2.signEndpoint,
@@ -214623,7 +215014,14 @@ var RemoteGatewayMcpServerProvider = class {
214623
215014
  if (!this.debugLog)
214624
215015
  return;
214625
215016
  try {
214626
- this.debugLog(`[mcp-client] ${JSON.stringify({ serverName, resourceId: resource.resourceId, requestId, method, phase, payload: this.invocationContext.current()?.auth ? { redacted: true } : payload })}`, EDebugLogScope.MCP);
215017
+ this.debugLog(`[mcp-client] ${JSON.stringify({
215018
+ serverName,
215019
+ resourceId: resource.resourceId,
215020
+ requestId,
215021
+ method,
215022
+ phase,
215023
+ payload: this.invocationContext.current()?.auth ? { redacted: true } : payload
215024
+ })}`, EDebugLogScope.MCP);
214627
215025
  } catch (error40) {
214628
215026
  warnLogFailure("remoteGatewayMcpServer.log", error40);
214629
215027
  }
@@ -214643,6 +215041,8 @@ var RemoteGatewayMcpServerProvider = class {
214643
215041
  callTool: (params, resultSchema, requestOptions) => request("tools/call", params, () => client.callTool(params, resultSchema, requestOptions))
214644
215042
  };
214645
215043
  const callTool = (name, args, signal, options) => callHeaders.run(options?.headers ?? {}, () => this.invocationContext.run(timeoutMs, signal, async (invocation) => {
215044
+ const observation = options?.context?.observation;
215045
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_REQUESTED_INPUT, args, options?.toolSchema?.inputSchema);
214646
215046
  const plan = createArgsMappingPlan(name, args, argsMappingRules);
214647
215047
  if (plan.requiresUserId) {
214648
215048
  if (config2.signEndpoint !== void 0 && config2.signEndpoint !== DEFAULT_SIGN_ENDPOINT && !config2.verifyTokenEndpoint?.trim())
@@ -214665,19 +215065,22 @@ var RemoteGatewayMcpServerProvider = class {
214665
215065
  };
214666
215066
  }
214667
215067
  const mapped = resolveArgsMappingPlan(plan, invocation.auth);
215068
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_INPUT, mapped, options?.toolSchema?.inputSchema);
214668
215069
  invocation.signal.throwIfAborted();
214669
215070
  const remaining = Math.max(1, invocation.deadline - performance.now());
214670
215071
  try {
214671
- return await loggedClient.callTool({ name, arguments: mapped }, void 0, {
215072
+ const result = await loggedClient.callTool({ name, arguments: mapped }, void 0, {
214672
215073
  signal: invocation.signal,
214673
215074
  timeout: remaining,
214674
215075
  maxTotalTimeout: remaining,
214675
215076
  resetTimeoutOnProgress: false
214676
215077
  });
215078
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_OUTPUT, result, options?.toolSchema?.outputSchema);
215079
+ return result;
214677
215080
  } catch (error40) {
214678
215081
  invocation.signal.throwIfAborted();
214679
215082
  if (invocation.auth && !(error40 instanceof McpInvocationError))
214680
- throw new Error("MCP \u7528\u6237\u5DE5\u5177\u8C03\u7528\u5931\u8D25");
215083
+ throw new Error("MCP \u7528\u6237\u5DE5\u5177\u8C03\u7528\u5931\u8D25", { cause: error40 });
214681
215084
  throw error40;
214682
215085
  }
214683
215086
  }));
@@ -214702,7 +215105,13 @@ async function listToolsFromClient(client, resourceId, callTool) {
214702
215105
  const descriptor = {
214703
215106
  name: tool.name,
214704
215107
  resourceId,
214705
- execute: (args, signal) => callTool(tool.name, args, signal)
215108
+ execute: (args, signal, context2) => callTool(tool.name, args, signal, {
215109
+ context: context2,
215110
+ toolSchema: {
215111
+ inputSchema: tool.inputSchema,
215112
+ outputSchema: tool.outputSchema
215113
+ }
215114
+ })
214706
215115
  };
214707
215116
  if (tool.description !== void 0)
214708
215117
  descriptor.description = tool.description;
@@ -215053,6 +215462,8 @@ function parseResponse(body, query, topK) {
215053
215462
  }
215054
215463
 
215055
215464
  // ../linkque-agent-runtime/dist/esm/impl/mcp/localHttpMcpServerProvider.js
215465
+ init_telemetry();
215466
+ init_contentRecording();
215056
215467
  init_httpLoggingFetch();
215057
215468
  var LocalHttpMcpServerProvider = class {
215058
215469
  baseUrl;
@@ -215081,7 +215492,7 @@ var LocalHttpMcpServerProvider = class {
215081
215492
  }
215082
215493
  return body.tools.map((value) => this.createDescriptor(resource.resourceId, value));
215083
215494
  },
215084
- callTool: (name, args, signal) => this.callTool(resource.resourceId, name, args, signal)
215495
+ callTool: (name, args, signal, options) => this.callTool(resource.resourceId, name, args, signal, options)
215085
215496
  };
215086
215497
  }
215087
215498
  createDescriptor(resourceId, value) {
@@ -215095,17 +215506,28 @@ var LocalHttpMcpServerProvider = class {
215095
215506
  ...isRecord2(value.inputSchema) ? { inputSchema: value.inputSchema } : {},
215096
215507
  ...isRecord2(value.outputSchema) ? { outputSchema: value.outputSchema } : {},
215097
215508
  ...isRecord2(value.annotations) ? { annotations: value.annotations } : {},
215098
- execute: (args, signal) => this.callTool(resourceId, value.name, args, signal)
215509
+ execute: (args, signal, context2) => this.callTool(resourceId, value.name, args, signal, {
215510
+ context: context2,
215511
+ toolSchema: {
215512
+ inputSchema: value.inputSchema,
215513
+ outputSchema: value.outputSchema
215514
+ }
215515
+ })
215099
215516
  };
215100
215517
  }
215101
- async callTool(resourceId, toolName, args, signal) {
215518
+ async callTool(resourceId, toolName, args, signal, options) {
215519
+ const observation = options?.context?.observation;
215520
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_REQUESTED_INPUT, args, options?.toolSchema?.inputSchema);
215521
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_INPUT, args, options?.toolSchema?.inputSchema);
215102
215522
  const response = await this.fetchImpl(this.resourceUrl(resourceId, `tools/${encodeURIComponent(toolName)}/call`), {
215103
215523
  method: "POST",
215104
215524
  headers: { "content-type": "application/json" },
215105
215525
  body: JSON.stringify({ arguments: args }),
215106
215526
  signal
215107
215527
  });
215108
- return readJsonResponse(response);
215528
+ const result = await readJsonResponse(response);
215529
+ recordMcpContentSection(observation, ETelemetryContentSection.MCP_OUTPUT, result, options?.toolSchema?.outputSchema);
215530
+ return result;
215109
215531
  }
215110
215532
  resourceUrl(resourceId, suffix) {
215111
215533
  return new URL(`resources/${encodeURIComponent(resourceId)}/${suffix}`, ensureTrailingSlash(this.baseUrl));
@@ -215784,6 +216206,7 @@ function unzip(data, opts, cb) {
215784
216206
  }
215785
216207
 
215786
216208
  // ../linkque-agent-runtime/dist/esm/impl/webSkillLoader.js
216209
+ init_types();
215787
216210
  init_skillTools();
215788
216211
  init_httpLoggingFetch();
215789
216212
  var ESkillUrlScheme;
@@ -215821,7 +216244,7 @@ var WebSkillLoader = class {
215821
216244
  return records.filter((record4, idx) => {
215822
216245
  if (record4 !== void 0)
215823
216246
  return true;
215824
- this.debugLog?.(`[skill] \u8DF3\u8FC7\u8D44\u6E90 ${resources[idx]?.resourceId ?? "?"}:SKILL.md \u7F3A description(\u524D\u7F6E\u65E0\u6548),\u6309 spec \u4E0D\u52A0\u8F7D`);
216247
+ this.debugLog?.(`[skill] \u8DF3\u8FC7\u8D44\u6E90 ${resources[idx]?.resourceId ?? "?"}:SKILL.md \u7F3A description(\u524D\u7F6E\u65E0\u6548),\u6309 spec \u4E0D\u52A0\u8F7D`, EDebugLogScope.SKILL);
215825
216248
  return false;
215826
216249
  });
215827
216250
  }
@@ -216324,6 +216747,7 @@ var allowedAttributeKeys = /* @__PURE__ */ new Set([
216324
216747
  ETelemetryAttribute.GEN_AI_REQUEST_MODEL,
216325
216748
  ETelemetryAttribute.GEN_AI_RESPONSE_MODEL,
216326
216749
  ETelemetryAttribute.GEN_AI_RESPONSE_ID,
216750
+ ETelemetryAttribute.LINKQUE_CONTENT_VALUE_TRUNCATED,
216327
216751
  ETelemetryAttribute.GEN_AI_RESPONSE_FINISH_REASONS,
216328
216752
  ETelemetryAttribute.GEN_AI_USAGE_INPUT_TOKENS,
216329
216753
  ETelemetryAttribute.GEN_AI_USAGE_OUTPUT_TOKENS,
@@ -216335,6 +216759,14 @@ var allowedAttributeKeys = /* @__PURE__ */ new Set([
216335
216759
  ETelemetryAttribute.HARNESS_MODEL_PURPOSE,
216336
216760
  ETelemetryAttribute.HARNESS_MODEL_INVOCATION_COUNT,
216337
216761
  ETelemetryAttribute.GEN_AI_TOOL_NAME,
216762
+ ETelemetryAttribute.LINKQUE_TOOL_DISPLAY_NAME,
216763
+ ETelemetryAttribute.LINKQUE_CARD_EXECUTION_ID,
216764
+ ETelemetryAttribute.LINKQUE_CARD_REF,
216765
+ ETelemetryAttribute.LINKQUE_CARD_REVISION,
216766
+ ETelemetryAttribute.LINKQUE_CARD_DISPLAY_NAME,
216767
+ ETelemetryAttribute.LINKQUE_CARD_PHASE,
216768
+ ETelemetryAttribute.LINKQUE_CARD_SOURCE_ID,
216769
+ ETelemetryAttribute.LINKQUE_CARD_DELIVERY,
216338
216770
  ETelemetryAttribute.GEN_AI_TOOL_CALL_ID,
216339
216771
  ETelemetryAttribute.HARNESS_TOOL_RESULT_STATUS,
216340
216772
  ETelemetryAttribute.LINKQUE_TOOL_FAILURE_STAGE,
@@ -216482,7 +216914,7 @@ var OtelRuntimeTelemetry = class {
216482
216914
  {
216483
216915
  onEmit: (record4, ctx) => {
216484
216916
  const route = ctx?.getValue(this.routeKey);
216485
- this.output(ETelemetrySignal.LOGS, import_otlp_transformer.JsonLogsSerializer.serializeRequest([record4]), route?.route, route?.critical ?? false);
216917
+ this.output(ETelemetrySignal.LOGS, import_otlp_transformer.JsonLogsSerializer.serializeRequest([record4]), route?.route, route?.critical ?? false, route?.localOnly ?? false);
216486
216918
  },
216487
216919
  forceFlush: async () => void 0,
216488
216920
  shutdown: async () => void 0
@@ -216490,12 +216922,13 @@ var OtelRuntimeTelemetry = class {
216490
216922
  ]
216491
216923
  });
216492
216924
  }
216493
- output(signal, encoded, route, critical) {
216925
+ output(signal, encoded, route, critical, localOnly = false) {
216494
216926
  if (!encoded || this.outputActive || this.disposed)
216495
216927
  return;
216496
216928
  this.outputActive = true;
216497
216929
  try {
216498
- this.queue.enqueue(route, signal, encoded, critical);
216930
+ if (!localOnly)
216931
+ this.queue.enqueue(route, signal, encoded, critical);
216499
216932
  if (this.options.localSink) {
216500
216933
  try {
216501
216934
  const payload = JSON.parse(new TextDecoder().decode(encoded));
@@ -216520,7 +216953,6 @@ var OtelRuntimeTelemetry = class {
216520
216953
  return new NoopRuntimeObservation();
216521
216954
  }
216522
216955
  const state2 = {
216523
- agentId: input.agentId,
216524
216956
  sequence: 0,
216525
216957
  route: auth2 ? this.queue.authorize(auth2) : void 0,
216526
216958
  attributes: sanitizeTelemetryAttributes({
@@ -216576,7 +217008,6 @@ var OtelRuntimeTelemetry = class {
216576
217008
  isRemote: upstream !== null,
216577
217009
  traceState: parentContext.traceState ? createTraceState(parentContext.traceState) : void 0
216578
217010
  });
216579
- const spanName = spec.name === ETelemetryOperationName.MODEL_ATTEMPT ? `${ETelemetryGenAiOperation.CHAT} ${spec.attributes[ETelemetryAttribute.GEN_AI_REQUEST_MODEL]}` : spec.name === ETelemetryOperationName.TOOL_INVOKE ? `${ETelemetryGenAiOperation.EXECUTE_TOOL} ${spec.attributes[ETelemetryAttribute.GEN_AI_TOOL_NAME]}` : spec.name === ETelemetryOperationName.ADVANCE && state2.agentId ? `${ETelemetryGenAiOperation.INVOKE_AGENT} ${state2.agentId}` : spec.name;
216580
217011
  const attributes = sanitizeTelemetryAttributes({
216581
217012
  ...state2.attributes,
216582
217013
  ...parent?.attributes,
@@ -216594,11 +217025,11 @@ var OtelRuntimeTelemetry = class {
216594
217025
  ETelemetryAttribute.LINKQUE_CONVERSATION_ID
216595
217026
  ].some((attribute) => attribute === key))),
216596
217027
  [ETelemetryAttribute.LINKQUE_OPERATION_ID]: (0, import_node_crypto5.randomUUID)(),
216597
- [ETelemetryAttribute.LINKQUE_OPERATION_NAME]: spanName,
217028
+ [ETelemetryAttribute.LINKQUE_OPERATION_NAME]: spec.name,
216598
217029
  [ETelemetryAttribute.LINKQUE_OPERATION_PARENT_ID]: spec.detached ? "" : parent?.operationId ?? "",
216599
217030
  [ETelemetryAttribute.LINKQUE_SPAN_PARENT_ID]: spec.detached ? "" : parentContext?.spanId ?? ""
216600
217031
  });
216601
- const span = this.tracerProvider.getTracer(ETelemetryMetadata.SCOPE_NAME, ETelemetryVersion.V1_0).startSpan(spanName.slice(0, 256), {
217032
+ const span = this.tracerProvider.getTracer(ETelemetryMetadata.SCOPE_NAME, ETelemetryVersion.V1_0).startSpan(spec.name, {
216602
217033
  kind: spec.name === ETelemetryOperationName.MODEL_ATTEMPT ? SpanKind.CLIENT : SpanKind.INTERNAL,
216603
217034
  attributes,
216604
217035
  links: spec.links.filter((link) => validContext(link.context)).slice(0, 16).map((link) => ({
@@ -216626,7 +217057,7 @@ var OtelRuntimeTelemetry = class {
216626
217057
  operation.record(`${spec.eventPrefix}.${ETelemetryEventPhase.STARTED}`, {});
216627
217058
  return operation;
216628
217059
  }
216629
- emit(operation, name, attributes, critical) {
217060
+ emit(operation, name, attributes, critical, body) {
216630
217061
  if (this.disposed || this.queue.isExporting)
216631
217062
  return;
216632
217063
  const contextAttributes = operation.attributes;
@@ -216653,18 +217084,33 @@ var OtelRuntimeTelemetry = class {
216653
217084
  Math.floor(now / 1e3),
216654
217085
  now % 1e3 * 1e6
216655
217086
  ];
216656
- if (operation.span.isRecording())
217087
+ const localOnly = name === ETelemetryEventName.CONTENT_RECORDED;
217088
+ if (localOnly && body && typeof body === "object" && "value" in body) {
217089
+ const { value, ...metadata } = body;
217090
+ try {
217091
+ const valueJson = JSON.stringify(value);
217092
+ body = valueJson !== void 0 && Buffer.byteLength(JSON.stringify(valueJson), "utf8") <= 512 * 1024 ? { ...metadata, valueJson } : { ...metadata, availability: "unavailable", reason: "content_limit" };
217093
+ } catch {
217094
+ body = { ...metadata, availability: "unavailable" };
217095
+ }
217096
+ }
217097
+ if (!localOnly && operation.span.isRecording())
216657
217098
  operation.span.addEvent(
216658
217099
  name,
216659
217100
  // 复用已投影的属性;Span 已持有上下文,事件只保留本次事实及去重字段。
216660
217101
  Object.fromEntries(Object.entries(record4).filter(([key]) => Object.hasOwn(attributes, key) || key === ETelemetryAttribute.HARNESS_RECORD_ID || key === ETelemetryAttribute.HARNESS_EVENT_SEQUENCE)),
216661
217102
  time3
216662
217103
  );
216663
- const ctx = trace.setSpan(ROOT_CONTEXT, operation.span).setValue(this.routeKey, { route: operation.state.route, critical });
217104
+ const ctx = trace.setSpan(ROOT_CONTEXT, operation.span).setValue(this.routeKey, {
217105
+ route: operation.state.route,
217106
+ critical,
217107
+ localOnly
217108
+ });
216664
217109
  this.loggerProvider.getLogger(ETelemetryMetadata.SCOPE_NAME, ETelemetryVersion.V1_0).emit({
216665
217110
  eventName: name,
216666
217111
  timestamp: time3,
216667
217112
  observedTimestamp: time3,
217113
+ ...body !== void 0 ? { body } : {},
216668
217114
  severityNumber: record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.ERROR || record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.TIMEOUT ? import_api_logs.SeverityNumber.ERROR : import_api_logs.SeverityNumber.INFO,
216669
217115
  severityText: record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.ERROR || record4[ETelemetryAttribute.HARNESS_OPERATION_OUTCOME] === ETelemetryOutcome.TIMEOUT ? import_api_logs.SeverityNumber[import_api_logs.SeverityNumber.ERROR] : import_api_logs.SeverityNumber[import_api_logs.SeverityNumber.INFO],
216670
217116
  attributes: record4,
@@ -216735,10 +217181,11 @@ var OtelObservation = class {
216735
217181
  return new NoopRuntimeObservation();
216736
217182
  return this.owner.createOperation(this.state, spec, this);
216737
217183
  }
216738
- record(name, attributes) {
217184
+ record(name, attributes, body) {
216739
217185
  if (this.lost || !/^(harness|linkque)\.[a-z0-9_.]{1,128}$/.test(name))
216740
217186
  return;
216741
- this.owner.emit(this, name, attributes, name.endsWith(`.${ETelemetryEventPhase.FINISHED}`) || name === ETelemetryEventName.MODEL_USAGE_RECORDED || name === ETelemetryEventName.RUNTIME_UNCAUGHT_ERROR || name.endsWith(`.${ETelemetryEventPhase.OBSERVATION_LOST}`));
217187
+ const critical = name.endsWith(`.${ETelemetryEventPhase.FINISHED}`) || name === ETelemetryEventName.MODEL_USAGE_RECORDED || name === ETelemetryEventName.RUNTIME_UNCAUGHT_ERROR || name.endsWith(`.${ETelemetryEventPhase.OBSERVATION_LOST}`);
217188
+ this.owner.emit(this, name, attributes, critical, body);
216742
217189
  }
216743
217190
  finish(outcome, attributes) {
216744
217191
  if (this.ended)
@@ -216978,6 +217425,7 @@ var OtlpFileSink = class {
216978
217425
  // src/commands/agentdev/sandboxIntegrate/sandboxRuntimeConfigProvider.ts
216979
217426
  var SANDBOX_RUNTIME_CONFIG_DEFAULTS = Object.freeze({
216980
217427
  ...RUNTIME_CONFIG_DEFAULTS,
217428
+ LOG_LEVEL: "DEBUG",
216981
217429
  LINKQUE_MCP_SIGN_ENDPOINT: RUNTIME_CONFIG_DEFAULTS.LINKQUEGW_MCP_SIGN_ENDPOINT,
216982
217430
  LINKQUE_OPEN_MCP_BASE_URL: "https://opengw.alipay.com",
216983
217431
  LINKQUEGW_TELEMETRY_LOGS_ENDPOINT: `${LINKQUE_ENDPOINT_PROD}/api/telemetry/v1/logs`,
@@ -217435,6 +217883,7 @@ var fileSize = async (filePath) => {
217435
217883
  };
217436
217884
  var maskSecret = (raw) => raw ? "<set>" : "<unset>";
217437
217885
  var AGENT_ENV_SNAPSHOT = [
217886
+ ["LOG_LEVEL", false],
217438
217887
  ["LINKQUE_AGENT_API_KEY", true],
217439
217888
  ["LINKQUE_AGENT_ACCESS_KEY", true],
217440
217889
  ["LINKQUE_USER_TOKEN", true],
@@ -217671,11 +218120,15 @@ var main = async () => {
217671
218120
  `[${(/* @__PURE__ */ new Date()).toISOString()}] agent worker loading agent runtime
217672
218121
  `
217673
218122
  );
217674
- const debugLog = (line, scope) => {
217675
- const prefix = scope ? `[${scope}] ` : "";
217676
- log.write(`[${(/* @__PURE__ */ new Date()).toISOString()}]${prefix}${line}
218123
+ const config2 = new SandboxRuntimeConfigProvider();
218124
+ const debugLog = createRuntimeDebugLog(
218125
+ config2.get("LOG_LEVEL"),
218126
+ (line, scope) => {
218127
+ const prefix = scope ? `[${scope}] ` : "";
218128
+ log.write(`[${(/* @__PURE__ */ new Date()).toISOString()}]${prefix}${line}
217677
218129
  `);
217678
- };
218130
+ }
218131
+ );
217679
218132
  agentDevTelemetry = await createAgentDevTelemetry(
217680
218133
  input.agentId,
217681
218134
  input.logPath,
@@ -217689,7 +218142,6 @@ var main = async () => {
217689
218142
  executeHomeData2 = executeHomeData;
217690
218143
  executeCardAction2 = executeCardAction;
217691
218144
  executeFunctionActionMcp2 = executeFunctionActionMcp;
217692
- const config2 = new SandboxRuntimeConfigProvider();
217693
218145
  const localMcpUrl = config2.get("LINKQUE_AGENT_MCP_FIXTURE_URL");
217694
218146
  const gatewayAuthorization = resolveSandboxGatewayAuthorization(process.env);
217695
218147
  const remoteAuthorizationHeader = gatewayAuthorization ? async () => gatewayAuthorization : void 0;
@@ -217764,9 +218216,9 @@ var main = async () => {
217764
218216
  // opengw 响应头 alipay-trace-id 下沉到 agent.log(同 SSE 会话级复用,
217765
218217
  // 每会话首个 POST 上报一次有效值),供 MCP 调用链路归因排查。
217766
218218
  onTraceId: (info) => {
217767
- log.write(
217768
- `[${(/* @__PURE__ */ new Date()).toISOString()}] [mcp-trace] ${info.httpMethod} ${info.requestUrl} alipay-trace-id=${info.traceId}
217769
- `
218219
+ debugLog(
218220
+ `[mcp-trace] ${info.httpMethod} ${info.requestUrl} alipay-trace-id=${info.traceId}`,
218221
+ EDebugLogScope.MCP
217770
218222
  );
217771
218223
  },
217772
218224
  // HTTP 出站日志下沉(scope=http):tag=mcp-sign(签名服务)+ mcp-call(SSE GET/POST 工具调用)→ agent.log。