@topolo/sdk 0.16.0 → 0.18.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/README.md CHANGED
@@ -160,6 +160,19 @@ input and resource before sending its canonical base64url representation in
160
160
  `X-Topolo-Actor-Envelope`; the envelope request ID also becomes the transport
161
161
  request ID.
162
162
 
163
+ Use `projectActorAuditEvent` when persisting or rendering immutable audit
164
+ events. The role remains explicit and the friendly label is derived without
165
+ rewriting either identity:
166
+
167
+ ```ts
168
+ const executedBy = projectActorAuditEvent(actorEnvelope, 'executed_by');
169
+ // executedBy.label === 'Ashley Lane via codex'
170
+ ```
171
+
172
+ The frozen projection retains the accountable subject, actual performer,
173
+ delegation, channel, assurance, resource, request, action and canonical input
174
+ hash for consistent application queries and exports.
175
+
163
176
  ## Modules
164
177
 
165
178
  | Surface | Methods |
package/dist/index.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  ACTION_CATALOG_DIGEST_ALGORITHM: () => ACTION_CATALOG_DIGEST_ALGORITHM,
24
+ ACTOR_AUDIT_PROJECTION_VERSION: () => ACTOR_AUDIT_PROJECTION_VERSION,
24
25
  ACTOR_ENVELOPE_VERSION: () => ACTOR_ENVELOPE_VERSION,
25
26
  ActorEnvelopeValidationError: () => ActorEnvelopeValidationError,
26
27
  CrmModule: () => CrmModule,
@@ -81,6 +82,7 @@ __export(index_exports, {
81
82
  preferExactActionMatches: () => preferExactActionMatches,
82
83
  prepareTopoloActionBase64UploadInput: () => prepareTopoloActionBase64UploadInput,
83
84
  prepareTopoloActionUploadInput: () => prepareTopoloActionUploadInput,
85
+ projectActorAuditEvent: () => projectActorAuditEvent,
84
86
  publicTopoloErrorMessage: () => publicTopoloErrorMessage,
85
87
  resolveApplicationDirectoryEntry: () => resolveApplicationDirectoryEntry,
86
88
  resolveCatalogServiceUrl: () => resolveCatalogServiceUrl,
@@ -1381,6 +1383,7 @@ var NEGATIVE_CACHE_TTL_MS = 60 * 1e3;
1381
1383
  var TopoloClient = class _TopoloClient {
1382
1384
  credential;
1383
1385
  agent;
1386
+ actorContext;
1384
1387
  serviceUrls;
1385
1388
  environment;
1386
1389
  appIds;
@@ -1411,6 +1414,11 @@ var TopoloClient = class _TopoloClient {
1411
1414
  if (!options.agent?.clientName) throw new TopoloAuthError("agent.clientName is required");
1412
1415
  this.credential = options.credential;
1413
1416
  this.agent = options.agent;
1417
+ this.actorContext = options.actorContext ? {
1418
+ channel: options.actorContext.channel,
1419
+ taskId: options.actorContext.taskId ?? `task_${generateRequestId()}`,
1420
+ runId: options.actorContext.runId ?? `run_${generateRequestId()}`
1421
+ } : void 0;
1414
1422
  this.environment = options.environment;
1415
1423
  this.serviceUrls = options.environment ? topoloServiceOrigins(options.serviceUrls, options.environment) : options.serviceUrls;
1416
1424
  this.appIds = options.appIds;
@@ -2126,8 +2134,9 @@ var TopoloClient = class _TopoloClient {
2126
2134
  );
2127
2135
  }
2128
2136
  const mapped = mapActionInput(entry, input);
2129
- if (options.actorEnvelope) {
2130
- const actorEnvelope = parseActorEnvelope(options.actorEnvelope);
2137
+ const resolvedActorEnvelope = options.actorEnvelope ?? await this.buildVerifiedAgentActorEnvelope(entry.actionId, input, options.resource);
2138
+ if (resolvedActorEnvelope) {
2139
+ const actorEnvelope = parseActorEnvelope(resolvedActorEnvelope);
2131
2140
  if (actorEnvelope.action.actionId !== entry.actionId) {
2132
2141
  throw new TopoloSdkError("actor_envelope_action_mismatch", "Actor envelope actionId does not match the executed action.");
2133
2142
  }
@@ -2148,7 +2157,7 @@ var TopoloClient = class _TopoloClient {
2148
2157
  ...mapped.query ? { query: mapped.query } : {},
2149
2158
  ...mapped.body !== void 0 ? { body: mapped.body } : {},
2150
2159
  ...options.resource ? { resource: options.resource } : {},
2151
- ...options.actorEnvelope ? { actorEnvelope: options.actorEnvelope } : {},
2160
+ ...resolvedActorEnvelope ? { actorEnvelope: resolvedActorEnvelope } : {},
2152
2161
  headers: {
2153
2162
  [TOPOLO_ACTION_ID_HEADER]: entry.actionId,
2154
2163
  [TOPOLO_ACTION_NAME_HEADER]: entry.name
@@ -2157,6 +2166,56 @@ var TopoloClient = class _TopoloClient {
2157
2166
  });
2158
2167
  return redactActionResult(result);
2159
2168
  }
2169
+ async buildVerifiedAgentActorEnvelope(actionId, input, resource) {
2170
+ if (!this.actorContext) return void 0;
2171
+ const identity = await this.introspect();
2172
+ const principalType = identity.user.principalType;
2173
+ if (principalType !== "agent_employee" && principalType !== "external_agent") return void 0;
2174
+ if (!identity.organization || !identity.user.accountableUserId || !identity.user.principalId) {
2175
+ throw new TopoloSdkError(
2176
+ "incomplete_agent_identity",
2177
+ "Verified agent credentials must resolve an organization, accountable user, and principal id."
2178
+ );
2179
+ }
2180
+ const performer = principalType === "external_agent" ? {
2181
+ principalType: "external_agent",
2182
+ principalId: identity.user.principalId,
2183
+ installationId: identity.user.installationId ?? void 0,
2184
+ provider: identity.user.provider ?? void 0,
2185
+ model: identity.user.model ?? void 0
2186
+ } : {
2187
+ principalType: "managed_agent",
2188
+ principalId: identity.user.principalId,
2189
+ agentInstanceId: identity.user.agentInstanceId ?? void 0,
2190
+ model: identity.user.model ?? void 0
2191
+ };
2192
+ if (performer.principalType === "external_agent" && (!performer.installationId || !performer.provider) || performer.principalType === "managed_agent" && !performer.agentInstanceId) {
2193
+ throw new TopoloSdkError(
2194
+ "incomplete_agent_identity",
2195
+ "Verified agent credentials are missing the performer identity required for provenance."
2196
+ );
2197
+ }
2198
+ return parseActorEnvelope({
2199
+ schemaVersion: 1,
2200
+ organizationId: identity.organization.id,
2201
+ accountableSubject: { principalType: "human", principalId: identity.user.accountableUserId },
2202
+ performer,
2203
+ delegation: {
2204
+ taskId: this.actorContext.taskId,
2205
+ runId: this.actorContext.runId,
2206
+ lineage: [{ principalType: performer.principalType, principalId: performer.principalId }]
2207
+ },
2208
+ channel: this.actorContext.channel,
2209
+ assurance: { level: "workload_identity", methods: ["client_credentials"] },
2210
+ action: {
2211
+ requestId: generateRequestId(),
2212
+ actionId,
2213
+ ...resource ? resource : {},
2214
+ inputHash: await sha256CanonicalValue(input)
2215
+ },
2216
+ issuedAt: (/* @__PURE__ */ new Date()).toISOString()
2217
+ });
2218
+ }
2160
2219
  /**
2161
2220
  * Introspect the current credential. Returns the caller's resolved identity,
2162
2221
  * organization, and permission set. Used by CLI `whoami` and by MCP to gate
@@ -2184,7 +2243,18 @@ var TopoloClient = class _TopoloClient {
2184
2243
  email: user.email,
2185
2244
  name: user.name ?? null,
2186
2245
  role: user.role ?? (kind === "api_key" ? "service" : "member"),
2187
- permissions: payload.permissions ?? user.permissions ?? []
2246
+ permissions: payload.permissions ?? user.permissions ?? [],
2247
+ ...normalizeAgentPrincipalType(user.principalType) ? {
2248
+ principalId: readOptionalString(user.principalId),
2249
+ principalType: normalizeAgentPrincipalType(user.principalType),
2250
+ accountableUserId: readOptionalString(user.accountableUserId),
2251
+ agentInstanceId: readOptionalString(user.agentInstanceId),
2252
+ installationId: readOptionalString(user.installationId),
2253
+ provider: readOptionalString(user.provider),
2254
+ model: readOptionalString(user.model),
2255
+ serviceScopes: stringArray(user.serviceScopes),
2256
+ policyRef: readOptionalString(user.policyRef)
2257
+ } : {}
2188
2258
  },
2189
2259
  organization: organization ? {
2190
2260
  id: organization.id,
@@ -2549,6 +2619,9 @@ function normalizeCredentialAuthorizationMode(value, kind) {
2549
2619
  if (value === "context_rbac" || value === "oauth_scopes" || value === "session_rbac") return value;
2550
2620
  return "unknown";
2551
2621
  }
2622
+ function normalizeAgentPrincipalType(value) {
2623
+ return value === "agent_employee" || value === "external_agent" ? value : null;
2624
+ }
2552
2625
  function describeError(body, fallback) {
2553
2626
  if (body && typeof body === "object") {
2554
2627
  const maybe = body;
@@ -3273,6 +3346,43 @@ var IdentityModule = class {
3273
3346
  }
3274
3347
  };
3275
3348
 
3349
+ // src/actor-audit.ts
3350
+ var ACTOR_AUDIT_PROJECTION_VERSION = 1;
3351
+ var EVENT_ROLES = /* @__PURE__ */ new Set([
3352
+ "requested_by",
3353
+ "acting_on_behalf_of",
3354
+ "approved_by",
3355
+ "executed_by"
3356
+ ]);
3357
+ function projectActorAuditEvent(value, role) {
3358
+ if (!EVENT_ROLES.has(role)) throw new TypeError("Unsupported actor audit event role");
3359
+ const envelope = parseActorEnvelope(value);
3360
+ const subjectLabel = envelope.accountableSubject.displayName || envelope.accountableSubject.principalId;
3361
+ const performerLabel = envelope.performer.displayName || envelope.performer.model || envelope.performer.provider || envelope.performer.principalId;
3362
+ const direct = envelope.performer.principalType === envelope.accountableSubject.principalType && envelope.performer.principalId === envelope.accountableSubject.principalId;
3363
+ return deepFreeze({
3364
+ schemaVersion: ACTOR_AUDIT_PROJECTION_VERSION,
3365
+ role,
3366
+ label: direct ? subjectLabel : `${subjectLabel} via ${performerLabel}`,
3367
+ organizationId: envelope.organizationId,
3368
+ accountableSubject: envelope.accountableSubject,
3369
+ performer: envelope.performer,
3370
+ delegation: envelope.delegation,
3371
+ channel: envelope.channel,
3372
+ assurance: envelope.assurance,
3373
+ action: envelope.action,
3374
+ issuedAt: envelope.issuedAt,
3375
+ ...envelope.expiresAt ? { expiresAt: envelope.expiresAt } : {}
3376
+ });
3377
+ }
3378
+ function deepFreeze(value) {
3379
+ if (value && typeof value === "object" && !Object.isFrozen(value)) {
3380
+ Object.freeze(value);
3381
+ for (const nested of Object.values(value)) deepFreeze(nested);
3382
+ }
3383
+ return value;
3384
+ }
3385
+
3276
3386
  // src/modules/workspaces.ts
3277
3387
  var ACTIONS = {
3278
3388
  list: "app_topolo_auth.workspaces.list",
@@ -4764,6 +4874,7 @@ function createTopolo(options) {
4764
4874
  // Annotate the CommonJS export names for ESM import in node:
4765
4875
  0 && (module.exports = {
4766
4876
  ACTION_CATALOG_DIGEST_ALGORITHM,
4877
+ ACTOR_AUDIT_PROJECTION_VERSION,
4767
4878
  ACTOR_ENVELOPE_VERSION,
4768
4879
  ActorEnvelopeValidationError,
4769
4880
  CrmModule,
@@ -4824,6 +4935,7 @@ function createTopolo(options) {
4824
4935
  preferExactActionMatches,
4825
4936
  prepareTopoloActionBase64UploadInput,
4826
4937
  prepareTopoloActionUploadInput,
4938
+ projectActorAuditEvent,
4827
4939
  publicTopoloErrorMessage,
4828
4940
  resolveApplicationDirectoryEntry,
4829
4941
  resolveCatalogServiceUrl,
package/dist/index.d.cts CHANGED
@@ -146,6 +146,12 @@ declare function encodeTopoloActionBase64(bytes: Uint8Array): string;
146
146
  interface TopoloClientOptions {
147
147
  credential: TopoloCredential;
148
148
  agent: AgentIdentity;
149
+ /** Host surface used to attribute actions performed with verified agent credentials. */
150
+ actorContext?: {
151
+ channel: ActorChannel;
152
+ taskId?: string;
153
+ runId?: string;
154
+ };
149
155
  /** Per-service URL overrides. Useful for staging/dev. */
150
156
  serviceUrls?: Record<string, string>;
151
157
  /** Explicit environment used to reject cross-environment service and action origins. */
@@ -403,6 +409,7 @@ interface TopoloCatalogSearchOptions {
403
409
  declare class TopoloClient {
404
410
  private credential;
405
411
  private readonly agent;
412
+ private readonly actorContext?;
406
413
  private readonly serviceUrls?;
407
414
  private readonly environment?;
408
415
  private readonly appIds?;
@@ -534,6 +541,7 @@ declare class TopoloClient {
534
541
  actorEnvelope?: ActorEnvelope;
535
542
  }): Promise<T>;
536
543
  private executeResolvedAction;
544
+ private buildVerifiedAgentActorEnvelope;
537
545
  /**
538
546
  * Introspect the current credential. Returns the caller's resolved identity,
539
547
  * organization, and permission set. Used by CLI `whoami` and by MCP to gate
@@ -554,6 +562,15 @@ interface CredentialIntrospection {
554
562
  name: string | null;
555
563
  role: string;
556
564
  permissions: string[];
565
+ principalId?: string | null;
566
+ principalType?: 'agent_employee' | 'external_agent' | null;
567
+ accountableUserId?: string | null;
568
+ agentInstanceId?: string | null;
569
+ installationId?: string | null;
570
+ provider?: string | null;
571
+ model?: string | null;
572
+ serviceScopes?: string[];
573
+ policyRef?: string | null;
557
574
  };
558
575
  organization: {
559
576
  id: string;
@@ -967,6 +984,24 @@ declare class IdentityModule {
967
984
  whoami(): Promise<CredentialIntrospection>;
968
985
  }
969
986
 
987
+ declare const ACTOR_AUDIT_PROJECTION_VERSION: 1;
988
+ type ActorAuditEventRole = 'requested_by' | 'acting_on_behalf_of' | 'approved_by' | 'executed_by';
989
+ interface ActorAuditProjection {
990
+ readonly schemaVersion: typeof ACTOR_AUDIT_PROJECTION_VERSION;
991
+ readonly role: ActorAuditEventRole;
992
+ readonly label: string;
993
+ readonly organizationId: string;
994
+ readonly accountableSubject: Readonly<AccountableSubject>;
995
+ readonly performer: Readonly<ActorIdentity>;
996
+ readonly delegation: Readonly<NonNullable<ActorEnvelope['delegation']>> | null;
997
+ readonly channel: ActorEnvelope['channel'];
998
+ readonly assurance: Readonly<ActorEnvelope['assurance']>;
999
+ readonly action: Readonly<ActorEnvelope['action']>;
1000
+ readonly issuedAt: string;
1001
+ readonly expiresAt?: string;
1002
+ }
1003
+ declare function projectActorAuditEvent(value: unknown, role: ActorAuditEventRole): ActorAuditProjection;
1004
+
970
1005
  interface TopoloWorkspace {
971
1006
  id: string;
972
1007
  appId: string;
@@ -1659,4 +1694,4 @@ declare function createTopolo(options: TopoloClientOptions): {
1659
1694
  };
1660
1695
  type Topolo = ReturnType<typeof createTopolo>;
1661
1696
 
1662
- export { ACTION_CATALOG_DIGEST_ALGORITHM, ACTOR_ENVELOPE_VERSION, type AccountableSubject, type AccountableSubjectType, type ActionContractManifest, type ActionContractSource, type ActorAssurance, type ActorChannel, type ActorDelegationHop, type ActorEnvelope, ActorEnvelopeValidationError, type ActorIdentity, type ActorPrincipalType, type AgentIdentity, type AppApiId, type ApplicationCatalogEntry, type ApplicationDeployTarget, type ApplicationDirectory, type ApplicationDirectoryApplication, type ApplicationDirectoryClient, type ApplicationDirectorySource, type ApplicationId, type CredentialIntrospection, type CrmContactSummary, CrmModule, DEFAULT_APP_URLS, type DeviceAuthorizationResponse, IdentityModule, type ListContactsOptions, type ListContactsResult, type OAuthHelperOptions, type P2PActionDetail, type P2PActionRequestInput, type P2PActionRequestResult, type P2PActionRow, type P2PActionRun, type P2PCapability, type P2PConnection, type P2PHold, type P2PLedgerEntry, P2PModule, type P2PPolicy, type P2PPricingModel, type P2PSettlementBatch, type P2PSettlementGroup, type PublishCapabilityInput, type RequestOptions, type ServiceCatalogUrlEntry, TOPOLO_ACTOR_ENVELOPE_HEADER, TOPOLO_ENVIRONMENT_SERVICE_URLS, TOPOLO_RUNTIME_ENVIRONMENTS, TOPOLO_WIDGET_CONTRACT_VERSION, TOPOLO_WIDGET_ENDPOINT, TOPOLO_WIDGET_OUTPUT_SCHEMA, TOPOLO_WIDGET_REFRESH_INTERVAL_MS, type TokenResponse, type Topolo, type TopoloActionAgentContract, type TopoloActionCatalogEntry, type TopoloActionCatalogSummary, type TopoloActionDigestInput, type TopoloActionPlan, type TopoloActionPreparation, type TopoloActionUploadOptions, type TopoloActionValidationIssue, type TopoloActionValidationResult, type TopoloActionsWidget, type TopoloActivityWidget, type TopoloAgentExecutionContext, type TopoloApiKeyResourceMetadata, TopoloAuthError, type TopoloBinaryResponse, type TopoloBindableResource, type TopoloBindableResourceCatalog, type TopoloChartWidget, TopoloClient, type TopoloClientOptions, TopoloConfirmationRequiredError, type TopoloCredential, type TopoloDebugEvent, TopoloHttpError, type TopoloInlineBase64UploadContract, type TopoloJsonSchema, type TopoloNotificationsWidget, TopoloOAuth, TopoloPermissionError, type TopoloRuntimeEnvironment, TopoloSdkError, type TopoloServiceCatalogEntry, type TopoloStatsWidget, type TopoloWidget, type TopoloWidgetAccessibility, type TopoloWidgetActionBinding, type TopoloWidgetActionRecovery, type TopoloWidgetActivityItem, type TopoloWidgetApiError, type TopoloWidgetApiErrorResponse, type TopoloWidgetApiResponse, type TopoloWidgetApiSuccessResponse, type TopoloWidgetBase, type TopoloWidgetConfig, type TopoloWidgetConfiguration, type TopoloWidgetConfigurationField, type TopoloWidgetConfigurationOption, type TopoloWidgetContext, type TopoloWidgetContribution, type TopoloWidgetDatasetDefinition, type TopoloWidgetDimension, type TopoloWidgetDimensionDefinition, type TopoloWidgetDraft, type TopoloWidgetDrilldown, type TopoloWidgetErrorResponseOptions, type TopoloWidgetEventDefinition, type TopoloWidgetLifecycleStage, type TopoloWidgetLocalization, type TopoloWidgetMetric, type TopoloWidgetMetricAggregation, type TopoloWidgetMetricComparison, type TopoloWidgetMetricDefinition, type TopoloWidgetMetricSemantic, type TopoloWidgetNotificationItem, type TopoloWidgetPeriod, type TopoloWidgetPresentation, type TopoloWidgetRefreshPolicy, type TopoloWidgetResourceBinding, type TopoloWidgetResponseOptions, type TopoloWidgetSeries, type TopoloWidgetSeriesDefinition, type TopoloWidgetSeriesPoint, type TopoloWidgetSize, type TopoloWidgetState, type TopoloWidgetStatus, type TopoloWidgetType, type TopoloWidgetValidationResult, type TopoloWidgetVisualizationFamily, type TopoloWidgetWorkspaceSelector, type TopoloWorkspace, type TopoloWorkspaceListResult, type TopoloWorkspaceMutationResult, type TopoloWorkspacePolicy, WorkspacesModule, actionContractCompleteness, applicationEntryFromCatalog, assertTopoloServiceUrlEnvironment, canonicalJson, canonicalTopoloErrorCode, canonicalTopoloRequestId, canonicalTopoloRequired, canonicalTopoloRetryAfter, canonicalizeActorEnvelope, compactActionCatalogEntry, compactActionPlan, compactActionPreparation, compactActionResult, compactActionValidation, createTopolo, createTopoloAgentExecutionContext, createTopoloWidgetError, createTopoloWidgetResponse, decodeActorEnvelopeHeader, defineTopoloActionsWidget, defineTopoloActivityWidget, defineTopoloChartWidget, defineTopoloNotificationsWidget, defineTopoloStatsWidget, digestTopoloActionCatalog, encodeActorEnvelopeHeader, encodeTopoloActionBase64, enrichActionContract, extractTopoloServiceErrorCode, extractTopoloServiceErrorDetails, formatDirectoryApplicationIds, friendlyAppId, isTopoloWidgetOutputSchema, listApplicationDirectory, parseActorEnvelope, parseTopoloActionUploadContract, preferExactActionMatches, prepareTopoloActionBase64UploadInput, prepareTopoloActionUploadInput, publicTopoloErrorMessage, resolveApplicationDirectoryEntry, resolveCatalogServiceUrl, resolveServiceUrl, sha256CanonicalValue, topoloErrorHint, topoloServiceOrigins, validateTopoloActionInput, validateTopoloWidgetResponse };
1697
+ export { ACTION_CATALOG_DIGEST_ALGORITHM, ACTOR_AUDIT_PROJECTION_VERSION, ACTOR_ENVELOPE_VERSION, type AccountableSubject, type AccountableSubjectType, type ActionContractManifest, type ActionContractSource, type ActorAssurance, type ActorAuditEventRole, type ActorAuditProjection, type ActorChannel, type ActorDelegationHop, type ActorEnvelope, ActorEnvelopeValidationError, type ActorIdentity, type ActorPrincipalType, type AgentIdentity, type AppApiId, type ApplicationCatalogEntry, type ApplicationDeployTarget, type ApplicationDirectory, type ApplicationDirectoryApplication, type ApplicationDirectoryClient, type ApplicationDirectorySource, type ApplicationId, type CredentialIntrospection, type CrmContactSummary, CrmModule, DEFAULT_APP_URLS, type DeviceAuthorizationResponse, IdentityModule, type ListContactsOptions, type ListContactsResult, type OAuthHelperOptions, type P2PActionDetail, type P2PActionRequestInput, type P2PActionRequestResult, type P2PActionRow, type P2PActionRun, type P2PCapability, type P2PConnection, type P2PHold, type P2PLedgerEntry, P2PModule, type P2PPolicy, type P2PPricingModel, type P2PSettlementBatch, type P2PSettlementGroup, type PublishCapabilityInput, type RequestOptions, type ServiceCatalogUrlEntry, TOPOLO_ACTOR_ENVELOPE_HEADER, TOPOLO_ENVIRONMENT_SERVICE_URLS, TOPOLO_RUNTIME_ENVIRONMENTS, TOPOLO_WIDGET_CONTRACT_VERSION, TOPOLO_WIDGET_ENDPOINT, TOPOLO_WIDGET_OUTPUT_SCHEMA, TOPOLO_WIDGET_REFRESH_INTERVAL_MS, type TokenResponse, type Topolo, type TopoloActionAgentContract, type TopoloActionCatalogEntry, type TopoloActionCatalogSummary, type TopoloActionDigestInput, type TopoloActionPlan, type TopoloActionPreparation, type TopoloActionUploadOptions, type TopoloActionValidationIssue, type TopoloActionValidationResult, type TopoloActionsWidget, type TopoloActivityWidget, type TopoloAgentExecutionContext, type TopoloApiKeyResourceMetadata, TopoloAuthError, type TopoloBinaryResponse, type TopoloBindableResource, type TopoloBindableResourceCatalog, type TopoloChartWidget, TopoloClient, type TopoloClientOptions, TopoloConfirmationRequiredError, type TopoloCredential, type TopoloDebugEvent, TopoloHttpError, type TopoloInlineBase64UploadContract, type TopoloJsonSchema, type TopoloNotificationsWidget, TopoloOAuth, TopoloPermissionError, type TopoloRuntimeEnvironment, TopoloSdkError, type TopoloServiceCatalogEntry, type TopoloStatsWidget, type TopoloWidget, type TopoloWidgetAccessibility, type TopoloWidgetActionBinding, type TopoloWidgetActionRecovery, type TopoloWidgetActivityItem, type TopoloWidgetApiError, type TopoloWidgetApiErrorResponse, type TopoloWidgetApiResponse, type TopoloWidgetApiSuccessResponse, type TopoloWidgetBase, type TopoloWidgetConfig, type TopoloWidgetConfiguration, type TopoloWidgetConfigurationField, type TopoloWidgetConfigurationOption, type TopoloWidgetContext, type TopoloWidgetContribution, type TopoloWidgetDatasetDefinition, type TopoloWidgetDimension, type TopoloWidgetDimensionDefinition, type TopoloWidgetDraft, type TopoloWidgetDrilldown, type TopoloWidgetErrorResponseOptions, type TopoloWidgetEventDefinition, type TopoloWidgetLifecycleStage, type TopoloWidgetLocalization, type TopoloWidgetMetric, type TopoloWidgetMetricAggregation, type TopoloWidgetMetricComparison, type TopoloWidgetMetricDefinition, type TopoloWidgetMetricSemantic, type TopoloWidgetNotificationItem, type TopoloWidgetPeriod, type TopoloWidgetPresentation, type TopoloWidgetRefreshPolicy, type TopoloWidgetResourceBinding, type TopoloWidgetResponseOptions, type TopoloWidgetSeries, type TopoloWidgetSeriesDefinition, type TopoloWidgetSeriesPoint, type TopoloWidgetSize, type TopoloWidgetState, type TopoloWidgetStatus, type TopoloWidgetType, type TopoloWidgetValidationResult, type TopoloWidgetVisualizationFamily, type TopoloWidgetWorkspaceSelector, type TopoloWorkspace, type TopoloWorkspaceListResult, type TopoloWorkspaceMutationResult, type TopoloWorkspacePolicy, WorkspacesModule, actionContractCompleteness, applicationEntryFromCatalog, assertTopoloServiceUrlEnvironment, canonicalJson, canonicalTopoloErrorCode, canonicalTopoloRequestId, canonicalTopoloRequired, canonicalTopoloRetryAfter, canonicalizeActorEnvelope, compactActionCatalogEntry, compactActionPlan, compactActionPreparation, compactActionResult, compactActionValidation, createTopolo, createTopoloAgentExecutionContext, createTopoloWidgetError, createTopoloWidgetResponse, decodeActorEnvelopeHeader, defineTopoloActionsWidget, defineTopoloActivityWidget, defineTopoloChartWidget, defineTopoloNotificationsWidget, defineTopoloStatsWidget, digestTopoloActionCatalog, encodeActorEnvelopeHeader, encodeTopoloActionBase64, enrichActionContract, extractTopoloServiceErrorCode, extractTopoloServiceErrorDetails, formatDirectoryApplicationIds, friendlyAppId, isTopoloWidgetOutputSchema, listApplicationDirectory, parseActorEnvelope, parseTopoloActionUploadContract, preferExactActionMatches, prepareTopoloActionBase64UploadInput, prepareTopoloActionUploadInput, projectActorAuditEvent, publicTopoloErrorMessage, resolveApplicationDirectoryEntry, resolveCatalogServiceUrl, resolveServiceUrl, sha256CanonicalValue, topoloErrorHint, topoloServiceOrigins, validateTopoloActionInput, validateTopoloWidgetResponse };
package/dist/index.d.ts CHANGED
@@ -146,6 +146,12 @@ declare function encodeTopoloActionBase64(bytes: Uint8Array): string;
146
146
  interface TopoloClientOptions {
147
147
  credential: TopoloCredential;
148
148
  agent: AgentIdentity;
149
+ /** Host surface used to attribute actions performed with verified agent credentials. */
150
+ actorContext?: {
151
+ channel: ActorChannel;
152
+ taskId?: string;
153
+ runId?: string;
154
+ };
149
155
  /** Per-service URL overrides. Useful for staging/dev. */
150
156
  serviceUrls?: Record<string, string>;
151
157
  /** Explicit environment used to reject cross-environment service and action origins. */
@@ -403,6 +409,7 @@ interface TopoloCatalogSearchOptions {
403
409
  declare class TopoloClient {
404
410
  private credential;
405
411
  private readonly agent;
412
+ private readonly actorContext?;
406
413
  private readonly serviceUrls?;
407
414
  private readonly environment?;
408
415
  private readonly appIds?;
@@ -534,6 +541,7 @@ declare class TopoloClient {
534
541
  actorEnvelope?: ActorEnvelope;
535
542
  }): Promise<T>;
536
543
  private executeResolvedAction;
544
+ private buildVerifiedAgentActorEnvelope;
537
545
  /**
538
546
  * Introspect the current credential. Returns the caller's resolved identity,
539
547
  * organization, and permission set. Used by CLI `whoami` and by MCP to gate
@@ -554,6 +562,15 @@ interface CredentialIntrospection {
554
562
  name: string | null;
555
563
  role: string;
556
564
  permissions: string[];
565
+ principalId?: string | null;
566
+ principalType?: 'agent_employee' | 'external_agent' | null;
567
+ accountableUserId?: string | null;
568
+ agentInstanceId?: string | null;
569
+ installationId?: string | null;
570
+ provider?: string | null;
571
+ model?: string | null;
572
+ serviceScopes?: string[];
573
+ policyRef?: string | null;
557
574
  };
558
575
  organization: {
559
576
  id: string;
@@ -967,6 +984,24 @@ declare class IdentityModule {
967
984
  whoami(): Promise<CredentialIntrospection>;
968
985
  }
969
986
 
987
+ declare const ACTOR_AUDIT_PROJECTION_VERSION: 1;
988
+ type ActorAuditEventRole = 'requested_by' | 'acting_on_behalf_of' | 'approved_by' | 'executed_by';
989
+ interface ActorAuditProjection {
990
+ readonly schemaVersion: typeof ACTOR_AUDIT_PROJECTION_VERSION;
991
+ readonly role: ActorAuditEventRole;
992
+ readonly label: string;
993
+ readonly organizationId: string;
994
+ readonly accountableSubject: Readonly<AccountableSubject>;
995
+ readonly performer: Readonly<ActorIdentity>;
996
+ readonly delegation: Readonly<NonNullable<ActorEnvelope['delegation']>> | null;
997
+ readonly channel: ActorEnvelope['channel'];
998
+ readonly assurance: Readonly<ActorEnvelope['assurance']>;
999
+ readonly action: Readonly<ActorEnvelope['action']>;
1000
+ readonly issuedAt: string;
1001
+ readonly expiresAt?: string;
1002
+ }
1003
+ declare function projectActorAuditEvent(value: unknown, role: ActorAuditEventRole): ActorAuditProjection;
1004
+
970
1005
  interface TopoloWorkspace {
971
1006
  id: string;
972
1007
  appId: string;
@@ -1659,4 +1694,4 @@ declare function createTopolo(options: TopoloClientOptions): {
1659
1694
  };
1660
1695
  type Topolo = ReturnType<typeof createTopolo>;
1661
1696
 
1662
- export { ACTION_CATALOG_DIGEST_ALGORITHM, ACTOR_ENVELOPE_VERSION, type AccountableSubject, type AccountableSubjectType, type ActionContractManifest, type ActionContractSource, type ActorAssurance, type ActorChannel, type ActorDelegationHop, type ActorEnvelope, ActorEnvelopeValidationError, type ActorIdentity, type ActorPrincipalType, type AgentIdentity, type AppApiId, type ApplicationCatalogEntry, type ApplicationDeployTarget, type ApplicationDirectory, type ApplicationDirectoryApplication, type ApplicationDirectoryClient, type ApplicationDirectorySource, type ApplicationId, type CredentialIntrospection, type CrmContactSummary, CrmModule, DEFAULT_APP_URLS, type DeviceAuthorizationResponse, IdentityModule, type ListContactsOptions, type ListContactsResult, type OAuthHelperOptions, type P2PActionDetail, type P2PActionRequestInput, type P2PActionRequestResult, type P2PActionRow, type P2PActionRun, type P2PCapability, type P2PConnection, type P2PHold, type P2PLedgerEntry, P2PModule, type P2PPolicy, type P2PPricingModel, type P2PSettlementBatch, type P2PSettlementGroup, type PublishCapabilityInput, type RequestOptions, type ServiceCatalogUrlEntry, TOPOLO_ACTOR_ENVELOPE_HEADER, TOPOLO_ENVIRONMENT_SERVICE_URLS, TOPOLO_RUNTIME_ENVIRONMENTS, TOPOLO_WIDGET_CONTRACT_VERSION, TOPOLO_WIDGET_ENDPOINT, TOPOLO_WIDGET_OUTPUT_SCHEMA, TOPOLO_WIDGET_REFRESH_INTERVAL_MS, type TokenResponse, type Topolo, type TopoloActionAgentContract, type TopoloActionCatalogEntry, type TopoloActionCatalogSummary, type TopoloActionDigestInput, type TopoloActionPlan, type TopoloActionPreparation, type TopoloActionUploadOptions, type TopoloActionValidationIssue, type TopoloActionValidationResult, type TopoloActionsWidget, type TopoloActivityWidget, type TopoloAgentExecutionContext, type TopoloApiKeyResourceMetadata, TopoloAuthError, type TopoloBinaryResponse, type TopoloBindableResource, type TopoloBindableResourceCatalog, type TopoloChartWidget, TopoloClient, type TopoloClientOptions, TopoloConfirmationRequiredError, type TopoloCredential, type TopoloDebugEvent, TopoloHttpError, type TopoloInlineBase64UploadContract, type TopoloJsonSchema, type TopoloNotificationsWidget, TopoloOAuth, TopoloPermissionError, type TopoloRuntimeEnvironment, TopoloSdkError, type TopoloServiceCatalogEntry, type TopoloStatsWidget, type TopoloWidget, type TopoloWidgetAccessibility, type TopoloWidgetActionBinding, type TopoloWidgetActionRecovery, type TopoloWidgetActivityItem, type TopoloWidgetApiError, type TopoloWidgetApiErrorResponse, type TopoloWidgetApiResponse, type TopoloWidgetApiSuccessResponse, type TopoloWidgetBase, type TopoloWidgetConfig, type TopoloWidgetConfiguration, type TopoloWidgetConfigurationField, type TopoloWidgetConfigurationOption, type TopoloWidgetContext, type TopoloWidgetContribution, type TopoloWidgetDatasetDefinition, type TopoloWidgetDimension, type TopoloWidgetDimensionDefinition, type TopoloWidgetDraft, type TopoloWidgetDrilldown, type TopoloWidgetErrorResponseOptions, type TopoloWidgetEventDefinition, type TopoloWidgetLifecycleStage, type TopoloWidgetLocalization, type TopoloWidgetMetric, type TopoloWidgetMetricAggregation, type TopoloWidgetMetricComparison, type TopoloWidgetMetricDefinition, type TopoloWidgetMetricSemantic, type TopoloWidgetNotificationItem, type TopoloWidgetPeriod, type TopoloWidgetPresentation, type TopoloWidgetRefreshPolicy, type TopoloWidgetResourceBinding, type TopoloWidgetResponseOptions, type TopoloWidgetSeries, type TopoloWidgetSeriesDefinition, type TopoloWidgetSeriesPoint, type TopoloWidgetSize, type TopoloWidgetState, type TopoloWidgetStatus, type TopoloWidgetType, type TopoloWidgetValidationResult, type TopoloWidgetVisualizationFamily, type TopoloWidgetWorkspaceSelector, type TopoloWorkspace, type TopoloWorkspaceListResult, type TopoloWorkspaceMutationResult, type TopoloWorkspacePolicy, WorkspacesModule, actionContractCompleteness, applicationEntryFromCatalog, assertTopoloServiceUrlEnvironment, canonicalJson, canonicalTopoloErrorCode, canonicalTopoloRequestId, canonicalTopoloRequired, canonicalTopoloRetryAfter, canonicalizeActorEnvelope, compactActionCatalogEntry, compactActionPlan, compactActionPreparation, compactActionResult, compactActionValidation, createTopolo, createTopoloAgentExecutionContext, createTopoloWidgetError, createTopoloWidgetResponse, decodeActorEnvelopeHeader, defineTopoloActionsWidget, defineTopoloActivityWidget, defineTopoloChartWidget, defineTopoloNotificationsWidget, defineTopoloStatsWidget, digestTopoloActionCatalog, encodeActorEnvelopeHeader, encodeTopoloActionBase64, enrichActionContract, extractTopoloServiceErrorCode, extractTopoloServiceErrorDetails, formatDirectoryApplicationIds, friendlyAppId, isTopoloWidgetOutputSchema, listApplicationDirectory, parseActorEnvelope, parseTopoloActionUploadContract, preferExactActionMatches, prepareTopoloActionBase64UploadInput, prepareTopoloActionUploadInput, publicTopoloErrorMessage, resolveApplicationDirectoryEntry, resolveCatalogServiceUrl, resolveServiceUrl, sha256CanonicalValue, topoloErrorHint, topoloServiceOrigins, validateTopoloActionInput, validateTopoloWidgetResponse };
1697
+ export { ACTION_CATALOG_DIGEST_ALGORITHM, ACTOR_AUDIT_PROJECTION_VERSION, ACTOR_ENVELOPE_VERSION, type AccountableSubject, type AccountableSubjectType, type ActionContractManifest, type ActionContractSource, type ActorAssurance, type ActorAuditEventRole, type ActorAuditProjection, type ActorChannel, type ActorDelegationHop, type ActorEnvelope, ActorEnvelopeValidationError, type ActorIdentity, type ActorPrincipalType, type AgentIdentity, type AppApiId, type ApplicationCatalogEntry, type ApplicationDeployTarget, type ApplicationDirectory, type ApplicationDirectoryApplication, type ApplicationDirectoryClient, type ApplicationDirectorySource, type ApplicationId, type CredentialIntrospection, type CrmContactSummary, CrmModule, DEFAULT_APP_URLS, type DeviceAuthorizationResponse, IdentityModule, type ListContactsOptions, type ListContactsResult, type OAuthHelperOptions, type P2PActionDetail, type P2PActionRequestInput, type P2PActionRequestResult, type P2PActionRow, type P2PActionRun, type P2PCapability, type P2PConnection, type P2PHold, type P2PLedgerEntry, P2PModule, type P2PPolicy, type P2PPricingModel, type P2PSettlementBatch, type P2PSettlementGroup, type PublishCapabilityInput, type RequestOptions, type ServiceCatalogUrlEntry, TOPOLO_ACTOR_ENVELOPE_HEADER, TOPOLO_ENVIRONMENT_SERVICE_URLS, TOPOLO_RUNTIME_ENVIRONMENTS, TOPOLO_WIDGET_CONTRACT_VERSION, TOPOLO_WIDGET_ENDPOINT, TOPOLO_WIDGET_OUTPUT_SCHEMA, TOPOLO_WIDGET_REFRESH_INTERVAL_MS, type TokenResponse, type Topolo, type TopoloActionAgentContract, type TopoloActionCatalogEntry, type TopoloActionCatalogSummary, type TopoloActionDigestInput, type TopoloActionPlan, type TopoloActionPreparation, type TopoloActionUploadOptions, type TopoloActionValidationIssue, type TopoloActionValidationResult, type TopoloActionsWidget, type TopoloActivityWidget, type TopoloAgentExecutionContext, type TopoloApiKeyResourceMetadata, TopoloAuthError, type TopoloBinaryResponse, type TopoloBindableResource, type TopoloBindableResourceCatalog, type TopoloChartWidget, TopoloClient, type TopoloClientOptions, TopoloConfirmationRequiredError, type TopoloCredential, type TopoloDebugEvent, TopoloHttpError, type TopoloInlineBase64UploadContract, type TopoloJsonSchema, type TopoloNotificationsWidget, TopoloOAuth, TopoloPermissionError, type TopoloRuntimeEnvironment, TopoloSdkError, type TopoloServiceCatalogEntry, type TopoloStatsWidget, type TopoloWidget, type TopoloWidgetAccessibility, type TopoloWidgetActionBinding, type TopoloWidgetActionRecovery, type TopoloWidgetActivityItem, type TopoloWidgetApiError, type TopoloWidgetApiErrorResponse, type TopoloWidgetApiResponse, type TopoloWidgetApiSuccessResponse, type TopoloWidgetBase, type TopoloWidgetConfig, type TopoloWidgetConfiguration, type TopoloWidgetConfigurationField, type TopoloWidgetConfigurationOption, type TopoloWidgetContext, type TopoloWidgetContribution, type TopoloWidgetDatasetDefinition, type TopoloWidgetDimension, type TopoloWidgetDimensionDefinition, type TopoloWidgetDraft, type TopoloWidgetDrilldown, type TopoloWidgetErrorResponseOptions, type TopoloWidgetEventDefinition, type TopoloWidgetLifecycleStage, type TopoloWidgetLocalization, type TopoloWidgetMetric, type TopoloWidgetMetricAggregation, type TopoloWidgetMetricComparison, type TopoloWidgetMetricDefinition, type TopoloWidgetMetricSemantic, type TopoloWidgetNotificationItem, type TopoloWidgetPeriod, type TopoloWidgetPresentation, type TopoloWidgetRefreshPolicy, type TopoloWidgetResourceBinding, type TopoloWidgetResponseOptions, type TopoloWidgetSeries, type TopoloWidgetSeriesDefinition, type TopoloWidgetSeriesPoint, type TopoloWidgetSize, type TopoloWidgetState, type TopoloWidgetStatus, type TopoloWidgetType, type TopoloWidgetValidationResult, type TopoloWidgetVisualizationFamily, type TopoloWidgetWorkspaceSelector, type TopoloWorkspace, type TopoloWorkspaceListResult, type TopoloWorkspaceMutationResult, type TopoloWorkspacePolicy, WorkspacesModule, actionContractCompleteness, applicationEntryFromCatalog, assertTopoloServiceUrlEnvironment, canonicalJson, canonicalTopoloErrorCode, canonicalTopoloRequestId, canonicalTopoloRequired, canonicalTopoloRetryAfter, canonicalizeActorEnvelope, compactActionCatalogEntry, compactActionPlan, compactActionPreparation, compactActionResult, compactActionValidation, createTopolo, createTopoloAgentExecutionContext, createTopoloWidgetError, createTopoloWidgetResponse, decodeActorEnvelopeHeader, defineTopoloActionsWidget, defineTopoloActivityWidget, defineTopoloChartWidget, defineTopoloNotificationsWidget, defineTopoloStatsWidget, digestTopoloActionCatalog, encodeActorEnvelopeHeader, encodeTopoloActionBase64, enrichActionContract, extractTopoloServiceErrorCode, extractTopoloServiceErrorDetails, formatDirectoryApplicationIds, friendlyAppId, isTopoloWidgetOutputSchema, listApplicationDirectory, parseActorEnvelope, parseTopoloActionUploadContract, preferExactActionMatches, prepareTopoloActionBase64UploadInput, prepareTopoloActionUploadInput, projectActorAuditEvent, publicTopoloErrorMessage, resolveApplicationDirectoryEntry, resolveCatalogServiceUrl, resolveServiceUrl, sha256CanonicalValue, topoloErrorHint, topoloServiceOrigins, validateTopoloActionInput, validateTopoloWidgetResponse };
package/dist/index.js CHANGED
@@ -1286,6 +1286,7 @@ var NEGATIVE_CACHE_TTL_MS = 60 * 1e3;
1286
1286
  var TopoloClient = class _TopoloClient {
1287
1287
  credential;
1288
1288
  agent;
1289
+ actorContext;
1289
1290
  serviceUrls;
1290
1291
  environment;
1291
1292
  appIds;
@@ -1316,6 +1317,11 @@ var TopoloClient = class _TopoloClient {
1316
1317
  if (!options.agent?.clientName) throw new TopoloAuthError("agent.clientName is required");
1317
1318
  this.credential = options.credential;
1318
1319
  this.agent = options.agent;
1320
+ this.actorContext = options.actorContext ? {
1321
+ channel: options.actorContext.channel,
1322
+ taskId: options.actorContext.taskId ?? `task_${generateRequestId()}`,
1323
+ runId: options.actorContext.runId ?? `run_${generateRequestId()}`
1324
+ } : void 0;
1319
1325
  this.environment = options.environment;
1320
1326
  this.serviceUrls = options.environment ? topoloServiceOrigins(options.serviceUrls, options.environment) : options.serviceUrls;
1321
1327
  this.appIds = options.appIds;
@@ -2031,8 +2037,9 @@ var TopoloClient = class _TopoloClient {
2031
2037
  );
2032
2038
  }
2033
2039
  const mapped = mapActionInput(entry, input);
2034
- if (options.actorEnvelope) {
2035
- const actorEnvelope = parseActorEnvelope(options.actorEnvelope);
2040
+ const resolvedActorEnvelope = options.actorEnvelope ?? await this.buildVerifiedAgentActorEnvelope(entry.actionId, input, options.resource);
2041
+ if (resolvedActorEnvelope) {
2042
+ const actorEnvelope = parseActorEnvelope(resolvedActorEnvelope);
2036
2043
  if (actorEnvelope.action.actionId !== entry.actionId) {
2037
2044
  throw new TopoloSdkError("actor_envelope_action_mismatch", "Actor envelope actionId does not match the executed action.");
2038
2045
  }
@@ -2053,7 +2060,7 @@ var TopoloClient = class _TopoloClient {
2053
2060
  ...mapped.query ? { query: mapped.query } : {},
2054
2061
  ...mapped.body !== void 0 ? { body: mapped.body } : {},
2055
2062
  ...options.resource ? { resource: options.resource } : {},
2056
- ...options.actorEnvelope ? { actorEnvelope: options.actorEnvelope } : {},
2063
+ ...resolvedActorEnvelope ? { actorEnvelope: resolvedActorEnvelope } : {},
2057
2064
  headers: {
2058
2065
  [TOPOLO_ACTION_ID_HEADER]: entry.actionId,
2059
2066
  [TOPOLO_ACTION_NAME_HEADER]: entry.name
@@ -2062,6 +2069,56 @@ var TopoloClient = class _TopoloClient {
2062
2069
  });
2063
2070
  return redactActionResult(result);
2064
2071
  }
2072
+ async buildVerifiedAgentActorEnvelope(actionId, input, resource) {
2073
+ if (!this.actorContext) return void 0;
2074
+ const identity = await this.introspect();
2075
+ const principalType = identity.user.principalType;
2076
+ if (principalType !== "agent_employee" && principalType !== "external_agent") return void 0;
2077
+ if (!identity.organization || !identity.user.accountableUserId || !identity.user.principalId) {
2078
+ throw new TopoloSdkError(
2079
+ "incomplete_agent_identity",
2080
+ "Verified agent credentials must resolve an organization, accountable user, and principal id."
2081
+ );
2082
+ }
2083
+ const performer = principalType === "external_agent" ? {
2084
+ principalType: "external_agent",
2085
+ principalId: identity.user.principalId,
2086
+ installationId: identity.user.installationId ?? void 0,
2087
+ provider: identity.user.provider ?? void 0,
2088
+ model: identity.user.model ?? void 0
2089
+ } : {
2090
+ principalType: "managed_agent",
2091
+ principalId: identity.user.principalId,
2092
+ agentInstanceId: identity.user.agentInstanceId ?? void 0,
2093
+ model: identity.user.model ?? void 0
2094
+ };
2095
+ if (performer.principalType === "external_agent" && (!performer.installationId || !performer.provider) || performer.principalType === "managed_agent" && !performer.agentInstanceId) {
2096
+ throw new TopoloSdkError(
2097
+ "incomplete_agent_identity",
2098
+ "Verified agent credentials are missing the performer identity required for provenance."
2099
+ );
2100
+ }
2101
+ return parseActorEnvelope({
2102
+ schemaVersion: 1,
2103
+ organizationId: identity.organization.id,
2104
+ accountableSubject: { principalType: "human", principalId: identity.user.accountableUserId },
2105
+ performer,
2106
+ delegation: {
2107
+ taskId: this.actorContext.taskId,
2108
+ runId: this.actorContext.runId,
2109
+ lineage: [{ principalType: performer.principalType, principalId: performer.principalId }]
2110
+ },
2111
+ channel: this.actorContext.channel,
2112
+ assurance: { level: "workload_identity", methods: ["client_credentials"] },
2113
+ action: {
2114
+ requestId: generateRequestId(),
2115
+ actionId,
2116
+ ...resource ? resource : {},
2117
+ inputHash: await sha256CanonicalValue(input)
2118
+ },
2119
+ issuedAt: (/* @__PURE__ */ new Date()).toISOString()
2120
+ });
2121
+ }
2065
2122
  /**
2066
2123
  * Introspect the current credential. Returns the caller's resolved identity,
2067
2124
  * organization, and permission set. Used by CLI `whoami` and by MCP to gate
@@ -2089,7 +2146,18 @@ var TopoloClient = class _TopoloClient {
2089
2146
  email: user.email,
2090
2147
  name: user.name ?? null,
2091
2148
  role: user.role ?? (kind === "api_key" ? "service" : "member"),
2092
- permissions: payload.permissions ?? user.permissions ?? []
2149
+ permissions: payload.permissions ?? user.permissions ?? [],
2150
+ ...normalizeAgentPrincipalType(user.principalType) ? {
2151
+ principalId: readOptionalString(user.principalId),
2152
+ principalType: normalizeAgentPrincipalType(user.principalType),
2153
+ accountableUserId: readOptionalString(user.accountableUserId),
2154
+ agentInstanceId: readOptionalString(user.agentInstanceId),
2155
+ installationId: readOptionalString(user.installationId),
2156
+ provider: readOptionalString(user.provider),
2157
+ model: readOptionalString(user.model),
2158
+ serviceScopes: stringArray(user.serviceScopes),
2159
+ policyRef: readOptionalString(user.policyRef)
2160
+ } : {}
2093
2161
  },
2094
2162
  organization: organization ? {
2095
2163
  id: organization.id,
@@ -2454,6 +2522,9 @@ function normalizeCredentialAuthorizationMode(value, kind) {
2454
2522
  if (value === "context_rbac" || value === "oauth_scopes" || value === "session_rbac") return value;
2455
2523
  return "unknown";
2456
2524
  }
2525
+ function normalizeAgentPrincipalType(value) {
2526
+ return value === "agent_employee" || value === "external_agent" ? value : null;
2527
+ }
2457
2528
  function describeError(body, fallback) {
2458
2529
  if (body && typeof body === "object") {
2459
2530
  const maybe = body;
@@ -3178,6 +3249,43 @@ var IdentityModule = class {
3178
3249
  }
3179
3250
  };
3180
3251
 
3252
+ // src/actor-audit.ts
3253
+ var ACTOR_AUDIT_PROJECTION_VERSION = 1;
3254
+ var EVENT_ROLES = /* @__PURE__ */ new Set([
3255
+ "requested_by",
3256
+ "acting_on_behalf_of",
3257
+ "approved_by",
3258
+ "executed_by"
3259
+ ]);
3260
+ function projectActorAuditEvent(value, role) {
3261
+ if (!EVENT_ROLES.has(role)) throw new TypeError("Unsupported actor audit event role");
3262
+ const envelope = parseActorEnvelope(value);
3263
+ const subjectLabel = envelope.accountableSubject.displayName || envelope.accountableSubject.principalId;
3264
+ const performerLabel = envelope.performer.displayName || envelope.performer.model || envelope.performer.provider || envelope.performer.principalId;
3265
+ const direct = envelope.performer.principalType === envelope.accountableSubject.principalType && envelope.performer.principalId === envelope.accountableSubject.principalId;
3266
+ return deepFreeze({
3267
+ schemaVersion: ACTOR_AUDIT_PROJECTION_VERSION,
3268
+ role,
3269
+ label: direct ? subjectLabel : `${subjectLabel} via ${performerLabel}`,
3270
+ organizationId: envelope.organizationId,
3271
+ accountableSubject: envelope.accountableSubject,
3272
+ performer: envelope.performer,
3273
+ delegation: envelope.delegation,
3274
+ channel: envelope.channel,
3275
+ assurance: envelope.assurance,
3276
+ action: envelope.action,
3277
+ issuedAt: envelope.issuedAt,
3278
+ ...envelope.expiresAt ? { expiresAt: envelope.expiresAt } : {}
3279
+ });
3280
+ }
3281
+ function deepFreeze(value) {
3282
+ if (value && typeof value === "object" && !Object.isFrozen(value)) {
3283
+ Object.freeze(value);
3284
+ for (const nested of Object.values(value)) deepFreeze(nested);
3285
+ }
3286
+ return value;
3287
+ }
3288
+
3181
3289
  // src/modules/workspaces.ts
3182
3290
  var ACTIONS = {
3183
3291
  list: "app_topolo_auth.workspaces.list",
@@ -4668,6 +4776,7 @@ function createTopolo(options) {
4668
4776
  }
4669
4777
  export {
4670
4778
  ACTION_CATALOG_DIGEST_ALGORITHM,
4779
+ ACTOR_AUDIT_PROJECTION_VERSION,
4671
4780
  ACTOR_ENVELOPE_VERSION,
4672
4781
  ActorEnvelopeValidationError,
4673
4782
  CrmModule,
@@ -4728,6 +4837,7 @@ export {
4728
4837
  preferExactActionMatches,
4729
4838
  prepareTopoloActionBase64UploadInput,
4730
4839
  prepareTopoloActionUploadInput,
4840
+ projectActorAuditEvent,
4731
4841
  publicTopoloErrorMessage,
4732
4842
  resolveApplicationDirectoryEntry,
4733
4843
  resolveCatalogServiceUrl,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@topolo/sdk",
3
3
  "packageManager": "pnpm@10.17.1",
4
- "version": "0.16.0",
5
- "topoloPublishedVersion": "0.16.0",
4
+ "version": "0.18.0",
5
+ "topoloPublishedVersion": "0.18.0",
6
6
  "description": "Typed client SDK for the Topolo platform. Used by TopoloCli, TopoloMCP, and third-party agents.",
7
7
  "license": "UNLICENSED",
8
8
  "author": "Topolo",