@dudousxd/nestjs-agent-core 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +31 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -1
- package/dist/index.d.ts +81 -1
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { ChannelRegistry } from '@dudousxd/nestjs-diagnostics';
|
|
2
3
|
|
|
3
4
|
/** Who is driving the turn. Roles + tenant come from the host app (nestjs-context/authz). */
|
|
4
5
|
interface Actor {
|
|
@@ -119,6 +120,11 @@ interface QuotaView {
|
|
|
119
120
|
interface Decision {
|
|
120
121
|
approved: boolean;
|
|
121
122
|
reason?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Opaque ref of WHO decided (e.g. a console admin). When absent, the run's own actor decided
|
|
125
|
+
* (the chat flow).
|
|
126
|
+
*/
|
|
127
|
+
executedByRef?: string;
|
|
122
128
|
}
|
|
123
129
|
type MessageRole = 'user' | 'assistant' | 'system';
|
|
124
130
|
/**
|
|
@@ -357,6 +363,11 @@ declare const AGENT_ACTOR_DIRECTORY: unique symbol;
|
|
|
357
363
|
* {@link import('./spi/attachment-staging.js').AttachmentStagingStore}.
|
|
358
364
|
*/
|
|
359
365
|
declare const AGENT_ATTACHMENT_STAGING: unique symbol;
|
|
366
|
+
/**
|
|
367
|
+
* Console-side HITL approve/reject for the cross-thread approvals inbox. Optional — see
|
|
368
|
+
* {@link import('./spi/approval-port.js').AgentApprovalPort}.
|
|
369
|
+
*/
|
|
370
|
+
declare const AGENT_APPROVAL_PORT: unique symbol;
|
|
360
371
|
|
|
361
372
|
/**
|
|
362
373
|
* Per-invocation context handed to a tool handler. Host-supplied bits are optional. Identity lives
|
|
@@ -578,6 +589,8 @@ interface RecordRunStartInput {
|
|
|
578
589
|
threadId: string;
|
|
579
590
|
actorRef: string;
|
|
580
591
|
agentName?: string;
|
|
592
|
+
/** sha256 hex of the run's resolved (pre-RAG) system prompt — identifies the prompt VERSION. */
|
|
593
|
+
promptHash?: string;
|
|
581
594
|
}
|
|
582
595
|
interface RecordRunEndInput {
|
|
583
596
|
runId: string;
|
|
@@ -921,6 +934,31 @@ interface RecentRunRow {
|
|
|
921
934
|
retries: number;
|
|
922
935
|
/** ISO timestamp. */
|
|
923
936
|
startedAt: string;
|
|
937
|
+
/** sha256 hex of the run's resolved (pre-RAG) system prompt; `null` for a run recorded before this shipped. */
|
|
938
|
+
promptHash: string | null;
|
|
939
|
+
}
|
|
940
|
+
/** One tool call awaiting a HITL decision, for the cross-thread approvals inbox. */
|
|
941
|
+
interface PendingApprovalRow {
|
|
942
|
+
toolCallId: string;
|
|
943
|
+
toolName: string;
|
|
944
|
+
input: unknown;
|
|
945
|
+
threadId: string;
|
|
946
|
+
threadTitle: string;
|
|
947
|
+
/** Who asked — the run's actor. */
|
|
948
|
+
actorRef: string;
|
|
949
|
+
agentName: string | null;
|
|
950
|
+
/** ISO timestamp. */
|
|
951
|
+
requestedAt: string;
|
|
952
|
+
}
|
|
953
|
+
/** Governance rollup for one tool over a range. */
|
|
954
|
+
interface ToolStatRow {
|
|
955
|
+
toolName: string;
|
|
956
|
+
toolType: string;
|
|
957
|
+
calls: number;
|
|
958
|
+
failed: number;
|
|
959
|
+
rejected: number;
|
|
960
|
+
/** p95 of executionMs across executed calls; null when none carry it. */
|
|
961
|
+
p95ExecutionMs: number | null;
|
|
924
962
|
}
|
|
925
963
|
/**
|
|
926
964
|
* The governance read-model. Cost is `inputTokens/1e6 * inputPricePer1m + outputTokens/1e6 *
|
|
@@ -940,6 +978,10 @@ interface AgentGovernanceQueries {
|
|
|
940
978
|
runErrors(range: GovernanceRange): Promise<RunErrorBreakdownRow[]>;
|
|
941
979
|
runTrend(range: GovernanceRange): Promise<RunTrendPoint[]>;
|
|
942
980
|
recentRuns(limit: number): Promise<RecentRunRow[]>;
|
|
981
|
+
/** Tool calls sitting `pending_approval`, oldest first — an inbox drains from the back. Capped at `limit`. */
|
|
982
|
+
pendingApprovals(limit: number): Promise<PendingApprovalRow[]>;
|
|
983
|
+
/** Per-tool call/failure/rejection/latency rollup over the range, highest call count first. */
|
|
984
|
+
toolStats(range: GovernanceRange): Promise<ToolStatRow[]>;
|
|
943
985
|
}
|
|
944
986
|
|
|
945
987
|
/**
|
|
@@ -981,6 +1023,21 @@ interface AttachmentStagingStore {
|
|
|
981
1023
|
stage(input: StageAttachmentInput): Promise<MessageAttachment>;
|
|
982
1024
|
}
|
|
983
1025
|
|
|
1026
|
+
/**
|
|
1027
|
+
* Console-side HITL decisions. Implemented by the agent runtime (the nestjs package binds it to
|
|
1028
|
+
* the same signal path chat approvals use); the dashboard injects it OPTIONALLY — absent = the
|
|
1029
|
+
* approvals inbox renders read-only.
|
|
1030
|
+
*/
|
|
1031
|
+
interface AgentApprovalPort {
|
|
1032
|
+
approve(toolCallId: string, opts?: {
|
|
1033
|
+
executedByRef?: string;
|
|
1034
|
+
}): Promise<void>;
|
|
1035
|
+
reject(toolCallId: string, opts?: {
|
|
1036
|
+
executedByRef?: string;
|
|
1037
|
+
reason?: string;
|
|
1038
|
+
}): Promise<void>;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
984
1041
|
/**
|
|
985
1042
|
* The pure aggregation core shared by every {@link import('../spi/governance-queries.js').AgentGovernanceQueries}
|
|
986
1043
|
* adapter (MikroORM, Drizzle, in-memory). An adapter's only job is the DB-specific row fetch; the
|
|
@@ -1283,5 +1340,28 @@ declare function publishAgentRunFinished(payload: AgentRunFinished): void;
|
|
|
1283
1340
|
declare function publishAgentRunFailed(payload: AgentRunFailed): void;
|
|
1284
1341
|
declare function publishAgentDelegated(payload: AgentDelegated): void;
|
|
1285
1342
|
declare function publishAgentRetrieved(payload: AgentRetrieved): void;
|
|
1343
|
+
/** Every event key declared on `ChannelRegistry['agent']` above — derived, not hand-copied. */
|
|
1344
|
+
type AgentDiagnosticEvent = keyof ChannelRegistry['agent'];
|
|
1345
|
+
/**
|
|
1346
|
+
* All 8 events on `ChannelRegistry['agent']`, in a stable order — handy for wiring subscribers
|
|
1347
|
+
* (mirrors nestjs-media's `MEDIA_DIAGNOSTIC_EVENTS`). A drift between this list and the registry is
|
|
1348
|
+
* a compile error in both directions: an extra/misspelled entry fails this array's own
|
|
1349
|
+
* `readonly AgentDiagnosticEvent[]` annotation immediately; a missing entry fails the
|
|
1350
|
+
* {@link AgentDiagnosticEventsCoverAllKeys} check below.
|
|
1351
|
+
*/
|
|
1352
|
+
declare const AGENT_DIAGNOSTIC_EVENTS: readonly AgentDiagnosticEvent[];
|
|
1353
|
+
/**
|
|
1354
|
+
* The telescope key for an agent diagnostics channel — `agent:<event>`. This is the key the
|
|
1355
|
+
* `@dudousxd/nestjs-diagnostics-telescope` generic bridge matches its `exclude` option against,
|
|
1356
|
+
* and the label its "Busiest events" panel shows. Distinct from the `aviary:agent:<event>` channel
|
|
1357
|
+
* name used on the wire. Mirrors `mediaDiagnosticKey`.
|
|
1358
|
+
*/
|
|
1359
|
+
type AgentDiagnosticKey = `agent:${AgentDiagnosticEvent}`;
|
|
1360
|
+
/**
|
|
1361
|
+
* Compose the telescope key for an agent event, typed against {@link AgentDiagnosticEvent} so a
|
|
1362
|
+
* misspelled event is a compile error. Feed the result to `nestjsDiagnosticsTelescope({ exclude:
|
|
1363
|
+
* [...] })` to mute a noisy channel, e.g. `agentDiagnosticKey('message')`.
|
|
1364
|
+
*/
|
|
1365
|
+
declare function agentDiagnosticKey(event: AgentDiagnosticEvent): AgentDiagnosticKey;
|
|
1286
1366
|
|
|
1287
|
-
export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_DURABLE_RUNNER, AGENT_EMBEDDING_PROVIDER, AGENT_GOVERNANCE_QUERIES, AGENT_MODEL, AGENT_OPTIONS, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_RETRIEVER, AGENT_ROLES_POLICY, AGENT_RUNNER, AGENT_SINK, AGENT_STORE, AGENT_TOOL_REGISTRY, type Actor, type ActorDirectory, type ActorResolver, type ActorSpendRow, type AgentCatalogEntry, type AgentDefinition, type AgentDelegated, type AgentGovernanceQueries, type AgentLoopDeps, type AgentLoopHooks, type AgentMessageEvent, type AgentPricingStore, type AgentQuotaExceeded, AgentRegistry, type AgentRetrieved, type AgentRunFailed, type AgentRunFinished, type AgentRunInput, type AgentRunStarted, type AgentRunner, type AgentStore, AgentStreamError, type AgentStreamEvent, type AgentToolCallEvent, type AiToolCtx, type AppendMessageInput, type AttachmentStagingStore, type CostUsage, type CreateThreadInput, type CurrentModelPrice, type Decision, DefaultRolesPolicy, type EmbeddingProvider, type GovernanceRange, type GovernanceUsageInput, type LlmStepEnvelope, type MessageAttachment, type MessageRole, type MessageUsage, type ModelMessage, type ModelPrice, type ModelPriceInput, type ModelProvider, type ModelSpendRow, type ModelTurnArgs, type ModelTurnResult, type PageContext, type Passage, type PromptBuilder, type PromptContext, type PromptContributor, QuotaExceededError, type QuotaState, type QuotaStore, type QuotaView, type RecentRunRow, type RecordRunEndInput, type RecordRunStartInput, type RecordToolCallInput, type RecordUsageInput, type RerankOptions, type Reranker, type RetrieveOptions, type Retriever, type RolesPolicy, type RunAgentBreakdownRow, type RunErrorBreakdownRow, type RunMetrics, type RunTrendPoint, type SinkWriter, type StageAttachmentInput, type StoredMessage, type StreamError, type ThreadActivityRow, type ThreadDetail, type ThreadMeta, type ThreadSpendRow, type ThreadSummary, type TokenStreamSink, type ToolCallActivityRow, type ToolCallRequest, type ToolCallStatus, type ToolDefinition, ToolForbiddenError, type ToolHandler, ToolInputInvalidError, type ToolKind, ToolNotFoundError, ToolRegistry, type ToolResult, type ToolSpec, type ToolStepCtx, type ToolStepEnvelope, type UpdateThreadInput, type UpdateToolCallInput, type UsagePurpose, type UsageTrendPoint, bucketByActor, bucketByModel, bucketByThread, bucketUsageTrend, dayBoundsUtc, encodeStreamEvent, estimateCost, filterToolsByAllowList, filterToolsByRole, publishAgentDelegated, publishAgentMessage, publishAgentQuotaExceeded, publishAgentRetrieved, publishAgentRunFailed, publishAgentRunFinished, publishAgentRunStarted, publishAgentToolCall, runAgentLoop, seedModelPrices, withToolTimeout };
|
|
1367
|
+
export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_APPROVAL_PORT, AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_DIAGNOSTIC_EVENTS, AGENT_DURABLE_RUNNER, AGENT_EMBEDDING_PROVIDER, AGENT_GOVERNANCE_QUERIES, AGENT_MODEL, AGENT_OPTIONS, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_RETRIEVER, AGENT_ROLES_POLICY, AGENT_RUNNER, AGENT_SINK, AGENT_STORE, AGENT_TOOL_REGISTRY, type Actor, type ActorDirectory, type ActorResolver, type ActorSpendRow, type AgentApprovalPort, type AgentCatalogEntry, type AgentDefinition, type AgentDelegated, type AgentDiagnosticEvent, type AgentDiagnosticKey, type AgentGovernanceQueries, type AgentLoopDeps, type AgentLoopHooks, type AgentMessageEvent, type AgentPricingStore, type AgentQuotaExceeded, AgentRegistry, type AgentRetrieved, type AgentRunFailed, type AgentRunFinished, type AgentRunInput, type AgentRunStarted, type AgentRunner, type AgentStore, AgentStreamError, type AgentStreamEvent, type AgentToolCallEvent, type AiToolCtx, type AppendMessageInput, type AttachmentStagingStore, type CostUsage, type CreateThreadInput, type CurrentModelPrice, type Decision, DefaultRolesPolicy, type EmbeddingProvider, type GovernanceRange, type GovernanceUsageInput, type LlmStepEnvelope, type MessageAttachment, type MessageRole, type MessageUsage, type ModelMessage, type ModelPrice, type ModelPriceInput, type ModelProvider, type ModelSpendRow, type ModelTurnArgs, type ModelTurnResult, type PageContext, type Passage, type PendingApprovalRow, type PromptBuilder, type PromptContext, type PromptContributor, QuotaExceededError, type QuotaState, type QuotaStore, type QuotaView, type RecentRunRow, type RecordRunEndInput, type RecordRunStartInput, type RecordToolCallInput, type RecordUsageInput, type RerankOptions, type Reranker, type RetrieveOptions, type Retriever, type RolesPolicy, type RunAgentBreakdownRow, type RunErrorBreakdownRow, type RunMetrics, type RunTrendPoint, type SinkWriter, type StageAttachmentInput, type StoredMessage, type StreamError, type ThreadActivityRow, type ThreadDetail, type ThreadMeta, type ThreadSpendRow, type ThreadSummary, type TokenStreamSink, type ToolCallActivityRow, type ToolCallRequest, type ToolCallStatus, type ToolDefinition, ToolForbiddenError, type ToolHandler, ToolInputInvalidError, type ToolKind, ToolNotFoundError, ToolRegistry, type ToolResult, type ToolSpec, type ToolStatRow, type ToolStepCtx, type ToolStepEnvelope, type UpdateThreadInput, type UpdateToolCallInput, type UsagePurpose, type UsageTrendPoint, agentDiagnosticKey, bucketByActor, bucketByModel, bucketByThread, bucketUsageTrend, dayBoundsUtc, encodeStreamEvent, estimateCost, filterToolsByAllowList, filterToolsByRole, publishAgentDelegated, publishAgentMessage, publishAgentQuotaExceeded, publishAgentRetrieved, publishAgentRunFailed, publishAgentRunFinished, publishAgentRunStarted, publishAgentToolCall, runAgentLoop, seedModelPrices, withToolTimeout };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { ChannelRegistry } from '@dudousxd/nestjs-diagnostics';
|
|
2
3
|
|
|
3
4
|
/** Who is driving the turn. Roles + tenant come from the host app (nestjs-context/authz). */
|
|
4
5
|
interface Actor {
|
|
@@ -119,6 +120,11 @@ interface QuotaView {
|
|
|
119
120
|
interface Decision {
|
|
120
121
|
approved: boolean;
|
|
121
122
|
reason?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Opaque ref of WHO decided (e.g. a console admin). When absent, the run's own actor decided
|
|
125
|
+
* (the chat flow).
|
|
126
|
+
*/
|
|
127
|
+
executedByRef?: string;
|
|
122
128
|
}
|
|
123
129
|
type MessageRole = 'user' | 'assistant' | 'system';
|
|
124
130
|
/**
|
|
@@ -357,6 +363,11 @@ declare const AGENT_ACTOR_DIRECTORY: unique symbol;
|
|
|
357
363
|
* {@link import('./spi/attachment-staging.js').AttachmentStagingStore}.
|
|
358
364
|
*/
|
|
359
365
|
declare const AGENT_ATTACHMENT_STAGING: unique symbol;
|
|
366
|
+
/**
|
|
367
|
+
* Console-side HITL approve/reject for the cross-thread approvals inbox. Optional — see
|
|
368
|
+
* {@link import('./spi/approval-port.js').AgentApprovalPort}.
|
|
369
|
+
*/
|
|
370
|
+
declare const AGENT_APPROVAL_PORT: unique symbol;
|
|
360
371
|
|
|
361
372
|
/**
|
|
362
373
|
* Per-invocation context handed to a tool handler. Host-supplied bits are optional. Identity lives
|
|
@@ -578,6 +589,8 @@ interface RecordRunStartInput {
|
|
|
578
589
|
threadId: string;
|
|
579
590
|
actorRef: string;
|
|
580
591
|
agentName?: string;
|
|
592
|
+
/** sha256 hex of the run's resolved (pre-RAG) system prompt — identifies the prompt VERSION. */
|
|
593
|
+
promptHash?: string;
|
|
581
594
|
}
|
|
582
595
|
interface RecordRunEndInput {
|
|
583
596
|
runId: string;
|
|
@@ -921,6 +934,31 @@ interface RecentRunRow {
|
|
|
921
934
|
retries: number;
|
|
922
935
|
/** ISO timestamp. */
|
|
923
936
|
startedAt: string;
|
|
937
|
+
/** sha256 hex of the run's resolved (pre-RAG) system prompt; `null` for a run recorded before this shipped. */
|
|
938
|
+
promptHash: string | null;
|
|
939
|
+
}
|
|
940
|
+
/** One tool call awaiting a HITL decision, for the cross-thread approvals inbox. */
|
|
941
|
+
interface PendingApprovalRow {
|
|
942
|
+
toolCallId: string;
|
|
943
|
+
toolName: string;
|
|
944
|
+
input: unknown;
|
|
945
|
+
threadId: string;
|
|
946
|
+
threadTitle: string;
|
|
947
|
+
/** Who asked — the run's actor. */
|
|
948
|
+
actorRef: string;
|
|
949
|
+
agentName: string | null;
|
|
950
|
+
/** ISO timestamp. */
|
|
951
|
+
requestedAt: string;
|
|
952
|
+
}
|
|
953
|
+
/** Governance rollup for one tool over a range. */
|
|
954
|
+
interface ToolStatRow {
|
|
955
|
+
toolName: string;
|
|
956
|
+
toolType: string;
|
|
957
|
+
calls: number;
|
|
958
|
+
failed: number;
|
|
959
|
+
rejected: number;
|
|
960
|
+
/** p95 of executionMs across executed calls; null when none carry it. */
|
|
961
|
+
p95ExecutionMs: number | null;
|
|
924
962
|
}
|
|
925
963
|
/**
|
|
926
964
|
* The governance read-model. Cost is `inputTokens/1e6 * inputPricePer1m + outputTokens/1e6 *
|
|
@@ -940,6 +978,10 @@ interface AgentGovernanceQueries {
|
|
|
940
978
|
runErrors(range: GovernanceRange): Promise<RunErrorBreakdownRow[]>;
|
|
941
979
|
runTrend(range: GovernanceRange): Promise<RunTrendPoint[]>;
|
|
942
980
|
recentRuns(limit: number): Promise<RecentRunRow[]>;
|
|
981
|
+
/** Tool calls sitting `pending_approval`, oldest first — an inbox drains from the back. Capped at `limit`. */
|
|
982
|
+
pendingApprovals(limit: number): Promise<PendingApprovalRow[]>;
|
|
983
|
+
/** Per-tool call/failure/rejection/latency rollup over the range, highest call count first. */
|
|
984
|
+
toolStats(range: GovernanceRange): Promise<ToolStatRow[]>;
|
|
943
985
|
}
|
|
944
986
|
|
|
945
987
|
/**
|
|
@@ -981,6 +1023,21 @@ interface AttachmentStagingStore {
|
|
|
981
1023
|
stage(input: StageAttachmentInput): Promise<MessageAttachment>;
|
|
982
1024
|
}
|
|
983
1025
|
|
|
1026
|
+
/**
|
|
1027
|
+
* Console-side HITL decisions. Implemented by the agent runtime (the nestjs package binds it to
|
|
1028
|
+
* the same signal path chat approvals use); the dashboard injects it OPTIONALLY — absent = the
|
|
1029
|
+
* approvals inbox renders read-only.
|
|
1030
|
+
*/
|
|
1031
|
+
interface AgentApprovalPort {
|
|
1032
|
+
approve(toolCallId: string, opts?: {
|
|
1033
|
+
executedByRef?: string;
|
|
1034
|
+
}): Promise<void>;
|
|
1035
|
+
reject(toolCallId: string, opts?: {
|
|
1036
|
+
executedByRef?: string;
|
|
1037
|
+
reason?: string;
|
|
1038
|
+
}): Promise<void>;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
984
1041
|
/**
|
|
985
1042
|
* The pure aggregation core shared by every {@link import('../spi/governance-queries.js').AgentGovernanceQueries}
|
|
986
1043
|
* adapter (MikroORM, Drizzle, in-memory). An adapter's only job is the DB-specific row fetch; the
|
|
@@ -1283,5 +1340,28 @@ declare function publishAgentRunFinished(payload: AgentRunFinished): void;
|
|
|
1283
1340
|
declare function publishAgentRunFailed(payload: AgentRunFailed): void;
|
|
1284
1341
|
declare function publishAgentDelegated(payload: AgentDelegated): void;
|
|
1285
1342
|
declare function publishAgentRetrieved(payload: AgentRetrieved): void;
|
|
1343
|
+
/** Every event key declared on `ChannelRegistry['agent']` above — derived, not hand-copied. */
|
|
1344
|
+
type AgentDiagnosticEvent = keyof ChannelRegistry['agent'];
|
|
1345
|
+
/**
|
|
1346
|
+
* All 8 events on `ChannelRegistry['agent']`, in a stable order — handy for wiring subscribers
|
|
1347
|
+
* (mirrors nestjs-media's `MEDIA_DIAGNOSTIC_EVENTS`). A drift between this list and the registry is
|
|
1348
|
+
* a compile error in both directions: an extra/misspelled entry fails this array's own
|
|
1349
|
+
* `readonly AgentDiagnosticEvent[]` annotation immediately; a missing entry fails the
|
|
1350
|
+
* {@link AgentDiagnosticEventsCoverAllKeys} check below.
|
|
1351
|
+
*/
|
|
1352
|
+
declare const AGENT_DIAGNOSTIC_EVENTS: readonly AgentDiagnosticEvent[];
|
|
1353
|
+
/**
|
|
1354
|
+
* The telescope key for an agent diagnostics channel — `agent:<event>`. This is the key the
|
|
1355
|
+
* `@dudousxd/nestjs-diagnostics-telescope` generic bridge matches its `exclude` option against,
|
|
1356
|
+
* and the label its "Busiest events" panel shows. Distinct from the `aviary:agent:<event>` channel
|
|
1357
|
+
* name used on the wire. Mirrors `mediaDiagnosticKey`.
|
|
1358
|
+
*/
|
|
1359
|
+
type AgentDiagnosticKey = `agent:${AgentDiagnosticEvent}`;
|
|
1360
|
+
/**
|
|
1361
|
+
* Compose the telescope key for an agent event, typed against {@link AgentDiagnosticEvent} so a
|
|
1362
|
+
* misspelled event is a compile error. Feed the result to `nestjsDiagnosticsTelescope({ exclude:
|
|
1363
|
+
* [...] })` to mute a noisy channel, e.g. `agentDiagnosticKey('message')`.
|
|
1364
|
+
*/
|
|
1365
|
+
declare function agentDiagnosticKey(event: AgentDiagnosticEvent): AgentDiagnosticKey;
|
|
1286
1366
|
|
|
1287
|
-
export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_DURABLE_RUNNER, AGENT_EMBEDDING_PROVIDER, AGENT_GOVERNANCE_QUERIES, AGENT_MODEL, AGENT_OPTIONS, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_RETRIEVER, AGENT_ROLES_POLICY, AGENT_RUNNER, AGENT_SINK, AGENT_STORE, AGENT_TOOL_REGISTRY, type Actor, type ActorDirectory, type ActorResolver, type ActorSpendRow, type AgentCatalogEntry, type AgentDefinition, type AgentDelegated, type AgentGovernanceQueries, type AgentLoopDeps, type AgentLoopHooks, type AgentMessageEvent, type AgentPricingStore, type AgentQuotaExceeded, AgentRegistry, type AgentRetrieved, type AgentRunFailed, type AgentRunFinished, type AgentRunInput, type AgentRunStarted, type AgentRunner, type AgentStore, AgentStreamError, type AgentStreamEvent, type AgentToolCallEvent, type AiToolCtx, type AppendMessageInput, type AttachmentStagingStore, type CostUsage, type CreateThreadInput, type CurrentModelPrice, type Decision, DefaultRolesPolicy, type EmbeddingProvider, type GovernanceRange, type GovernanceUsageInput, type LlmStepEnvelope, type MessageAttachment, type MessageRole, type MessageUsage, type ModelMessage, type ModelPrice, type ModelPriceInput, type ModelProvider, type ModelSpendRow, type ModelTurnArgs, type ModelTurnResult, type PageContext, type Passage, type PromptBuilder, type PromptContext, type PromptContributor, QuotaExceededError, type QuotaState, type QuotaStore, type QuotaView, type RecentRunRow, type RecordRunEndInput, type RecordRunStartInput, type RecordToolCallInput, type RecordUsageInput, type RerankOptions, type Reranker, type RetrieveOptions, type Retriever, type RolesPolicy, type RunAgentBreakdownRow, type RunErrorBreakdownRow, type RunMetrics, type RunTrendPoint, type SinkWriter, type StageAttachmentInput, type StoredMessage, type StreamError, type ThreadActivityRow, type ThreadDetail, type ThreadMeta, type ThreadSpendRow, type ThreadSummary, type TokenStreamSink, type ToolCallActivityRow, type ToolCallRequest, type ToolCallStatus, type ToolDefinition, ToolForbiddenError, type ToolHandler, ToolInputInvalidError, type ToolKind, ToolNotFoundError, ToolRegistry, type ToolResult, type ToolSpec, type ToolStepCtx, type ToolStepEnvelope, type UpdateThreadInput, type UpdateToolCallInput, type UsagePurpose, type UsageTrendPoint, bucketByActor, bucketByModel, bucketByThread, bucketUsageTrend, dayBoundsUtc, encodeStreamEvent, estimateCost, filterToolsByAllowList, filterToolsByRole, publishAgentDelegated, publishAgentMessage, publishAgentQuotaExceeded, publishAgentRetrieved, publishAgentRunFailed, publishAgentRunFinished, publishAgentRunStarted, publishAgentToolCall, runAgentLoop, seedModelPrices, withToolTimeout };
|
|
1367
|
+
export { AGENT_ACTOR_DIRECTORY, AGENT_ACTOR_RESOLVER, AGENT_APPROVAL_PORT, AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_DIAGNOSTIC_EVENTS, AGENT_DURABLE_RUNNER, AGENT_EMBEDDING_PROVIDER, AGENT_GOVERNANCE_QUERIES, AGENT_MODEL, AGENT_OPTIONS, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_RETRIEVER, AGENT_ROLES_POLICY, AGENT_RUNNER, AGENT_SINK, AGENT_STORE, AGENT_TOOL_REGISTRY, type Actor, type ActorDirectory, type ActorResolver, type ActorSpendRow, type AgentApprovalPort, type AgentCatalogEntry, type AgentDefinition, type AgentDelegated, type AgentDiagnosticEvent, type AgentDiagnosticKey, type AgentGovernanceQueries, type AgentLoopDeps, type AgentLoopHooks, type AgentMessageEvent, type AgentPricingStore, type AgentQuotaExceeded, AgentRegistry, type AgentRetrieved, type AgentRunFailed, type AgentRunFinished, type AgentRunInput, type AgentRunStarted, type AgentRunner, type AgentStore, AgentStreamError, type AgentStreamEvent, type AgentToolCallEvent, type AiToolCtx, type AppendMessageInput, type AttachmentStagingStore, type CostUsage, type CreateThreadInput, type CurrentModelPrice, type Decision, DefaultRolesPolicy, type EmbeddingProvider, type GovernanceRange, type GovernanceUsageInput, type LlmStepEnvelope, type MessageAttachment, type MessageRole, type MessageUsage, type ModelMessage, type ModelPrice, type ModelPriceInput, type ModelProvider, type ModelSpendRow, type ModelTurnArgs, type ModelTurnResult, type PageContext, type Passage, type PendingApprovalRow, type PromptBuilder, type PromptContext, type PromptContributor, QuotaExceededError, type QuotaState, type QuotaStore, type QuotaView, type RecentRunRow, type RecordRunEndInput, type RecordRunStartInput, type RecordToolCallInput, type RecordUsageInput, type RerankOptions, type Reranker, type RetrieveOptions, type Retriever, type RolesPolicy, type RunAgentBreakdownRow, type RunErrorBreakdownRow, type RunMetrics, type RunTrendPoint, type SinkWriter, type StageAttachmentInput, type StoredMessage, type StreamError, type ThreadActivityRow, type ThreadDetail, type ThreadMeta, type ThreadSpendRow, type ThreadSummary, type TokenStreamSink, type ToolCallActivityRow, type ToolCallRequest, type ToolCallStatus, type ToolDefinition, ToolForbiddenError, type ToolHandler, ToolInputInvalidError, type ToolKind, ToolNotFoundError, ToolRegistry, type ToolResult, type ToolSpec, type ToolStatRow, type ToolStepCtx, type ToolStepEnvelope, type UpdateThreadInput, type UpdateToolCallInput, type UsagePurpose, type UsageTrendPoint, agentDiagnosticKey, bucketByActor, bucketByModel, bucketByThread, bucketUsageTrend, dayBoundsUtc, encodeStreamEvent, estimateCost, filterToolsByAllowList, filterToolsByRole, publishAgentDelegated, publishAgentMessage, publishAgentQuotaExceeded, publishAgentRetrieved, publishAgentRunFailed, publishAgentRunFinished, publishAgentRunStarted, publishAgentToolCall, runAgentLoop, seedModelPrices, withToolTimeout };
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var AGENT_DEPS_FACTORY = Symbol.for("@dudousxd/nestjs-agent:deps-factory");
|
|
|
21
21
|
var AGENT_PROMPT_CONTRIBUTORS = Symbol.for("@dudousxd/nestjs-agent:prompt-contributors");
|
|
22
22
|
var AGENT_ACTOR_DIRECTORY = Symbol.for("@dudousxd/nestjs-agent:actor-directory");
|
|
23
23
|
var AGENT_ATTACHMENT_STAGING = Symbol.for("@dudousxd/nestjs-agent:attachment-staging");
|
|
24
|
+
var AGENT_APPROVAL_PORT = Symbol.for("@dudousxd/nestjs-agent:approval-port");
|
|
24
25
|
|
|
25
26
|
// src/spi/token-stream-sink.ts
|
|
26
27
|
var AgentStreamError = class extends Error {
|
|
@@ -324,6 +325,9 @@ var DefaultRolesPolicy = class {
|
|
|
324
325
|
}
|
|
325
326
|
};
|
|
326
327
|
|
|
328
|
+
// src/agent-loop.ts
|
|
329
|
+
import { createHash } from "node:crypto";
|
|
330
|
+
|
|
327
331
|
// src/diagnostics.ts
|
|
328
332
|
import { emit } from "@dudousxd/nestjs-diagnostics";
|
|
329
333
|
function publishAgentRunStarted(payload) {
|
|
@@ -358,6 +362,20 @@ function publishAgentRetrieved(payload) {
|
|
|
358
362
|
emit("agent", "retrieved", payload);
|
|
359
363
|
}
|
|
360
364
|
__name(publishAgentRetrieved, "publishAgentRetrieved");
|
|
365
|
+
var AGENT_DIAGNOSTIC_EVENTS = [
|
|
366
|
+
"run.started",
|
|
367
|
+
"message",
|
|
368
|
+
"tool-call",
|
|
369
|
+
"quota.exceeded",
|
|
370
|
+
"run.finished",
|
|
371
|
+
"run.failed",
|
|
372
|
+
"delegated",
|
|
373
|
+
"retrieved"
|
|
374
|
+
];
|
|
375
|
+
function agentDiagnosticKey(event) {
|
|
376
|
+
return `agent:${event}`;
|
|
377
|
+
}
|
|
378
|
+
__name(agentDiagnosticKey, "agentDiagnosticKey");
|
|
361
379
|
|
|
362
380
|
// src/agent-loop.ts
|
|
363
381
|
function resolveCostUsd(usage, reportedCostUsd, price) {
|
|
@@ -555,13 +573,15 @@ async function runAgentLoop(deps, input, hooks) {
|
|
|
555
573
|
});
|
|
556
574
|
const startedAt = await hooks.step("run:started-at", () => Promise.resolve(Date.now()));
|
|
557
575
|
await hooks.step("persist:run:start", async () => {
|
|
576
|
+
const promptHash = createHash("sha256").update(system).digest("hex");
|
|
558
577
|
await deps.store.recordRunStart?.({
|
|
559
578
|
runId: hooks.runId,
|
|
560
579
|
threadId: input.threadId,
|
|
561
580
|
actorRef: input.actor.id,
|
|
562
581
|
...input.agentName !== void 0 ? {
|
|
563
582
|
agentName: input.agentName
|
|
564
|
-
} : {}
|
|
583
|
+
} : {},
|
|
584
|
+
promptHash
|
|
565
585
|
});
|
|
566
586
|
});
|
|
567
587
|
let injectedPassages;
|
|
@@ -790,6 +810,7 @@ ${buildContextBlock(passages)}`;
|
|
|
790
810
|
});
|
|
791
811
|
continue;
|
|
792
812
|
}
|
|
813
|
+
let deciderRef = input.actor.id;
|
|
793
814
|
if (toolType === "action") {
|
|
794
815
|
await hooks.step(`persist:toolcall:${call.id}`, () => deps.store.recordToolCall({
|
|
795
816
|
toolCallId: call.id,
|
|
@@ -800,10 +821,12 @@ ${buildContextBlock(passages)}`;
|
|
|
800
821
|
status: "pending_approval"
|
|
801
822
|
}));
|
|
802
823
|
const decision = await hooks.awaitApproval(call, ctx);
|
|
824
|
+
deciderRef = decision.executedByRef ?? input.actor.id;
|
|
803
825
|
if (!decision.approved) {
|
|
804
826
|
await hooks.step(`persist:toolreject:${call.id}`, () => deps.store.updateToolCall({
|
|
805
827
|
toolCallId: call.id,
|
|
806
828
|
status: "rejected",
|
|
829
|
+
executedByRef: deciderRef,
|
|
807
830
|
...decision.reason !== void 0 ? {
|
|
808
831
|
error: decision.reason
|
|
809
832
|
} : {}
|
|
@@ -871,7 +894,7 @@ ${buildContextBlock(passages)}`;
|
|
|
871
894
|
output,
|
|
872
895
|
executionMs,
|
|
873
896
|
...toolType === "action" ? {
|
|
874
|
-
executedByRef:
|
|
897
|
+
executedByRef: deciderRef
|
|
875
898
|
} : {}
|
|
876
899
|
}));
|
|
877
900
|
results.push({
|
|
@@ -961,8 +984,10 @@ __name(runAgentLoop, "runAgentLoop");
|
|
|
961
984
|
export {
|
|
962
985
|
AGENT_ACTOR_DIRECTORY,
|
|
963
986
|
AGENT_ACTOR_RESOLVER,
|
|
987
|
+
AGENT_APPROVAL_PORT,
|
|
964
988
|
AGENT_ATTACHMENT_STAGING,
|
|
965
989
|
AGENT_DEPS_FACTORY,
|
|
990
|
+
AGENT_DIAGNOSTIC_EVENTS,
|
|
966
991
|
AGENT_DURABLE_RUNNER,
|
|
967
992
|
AGENT_EMBEDDING_PROVIDER,
|
|
968
993
|
AGENT_GOVERNANCE_QUERIES,
|
|
@@ -986,6 +1011,7 @@ export {
|
|
|
986
1011
|
ToolInputInvalidError,
|
|
987
1012
|
ToolNotFoundError,
|
|
988
1013
|
ToolRegistry,
|
|
1014
|
+
agentDiagnosticKey,
|
|
989
1015
|
bucketByActor,
|
|
990
1016
|
bucketByModel,
|
|
991
1017
|
bucketByThread,
|