@agen-ai/agent-runtime 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -136,7 +136,7 @@ turn/request ordering, request resolution, steering, interruption, configuration
136
136
  close, and idempotent disposal. Unsupported operations must remain explicit discriminants and
137
137
  must not expose handlers.
138
138
 
139
- The package is at `0.2.0` while the public SPI is being proven with external adapters. Minor
139
+ The package is at `0.2.1` while the public SPI is being proven with external adapters. Minor
140
140
  releases may include breaking changes during this beta period, and those changes will be called out
141
141
  in the release notes.
142
142
 
@@ -84,7 +84,7 @@ function isEventCapabilitySupported(capabilities, event) {
84
84
  case "item.completed": {
85
85
  if (event.payload.itemKind === "context_compaction") {
86
86
  const compaction = capabilities.context.compaction;
87
- return compaction.kind === "supported" && compaction.triggers.includes(event.payload.details.trigger);
87
+ return compaction.kind === "supported" && (event.payload.details.trigger === "unknown" || compaction.triggers.includes(event.payload.details.trigger));
88
88
  }
89
89
  return isItemKindCapabilitySupported(capabilities, event.payload.itemKind);
90
90
  }
@@ -93,15 +93,6 @@ function observeContextUsage(input) {
93
93
  "Provider emitted a duplicate context usage sample."
94
94
  );
95
95
  }
96
- for (const [field, value] of Object.entries(input.usage.cumulative ?? {})) {
97
- const previousValue = previous.cumulative?.[field];
98
- if (previousValue !== void 0 && value < previousValue) {
99
- invalidTurnSequence(
100
- input.providerKey,
101
- "Provider context cumulative counters cannot decrease."
102
- );
103
- }
104
- }
105
96
  if (input.usage.usedTokens < previous.usedTokens && !input.state.compactionReadyScopes.has(input.usage.measurementScope)) {
106
97
  invalidTurnSequence(
107
98
  input.providerKey,
@@ -109,6 +100,26 @@ function observeContextUsage(input) {
109
100
  );
110
101
  }
111
102
  }
103
+ const cumulative = input.usage.cumulative;
104
+ if (cumulative !== void 0) {
105
+ const previousCumulative = input.state.cumulativeByScope.get(
106
+ input.usage.measurementScope
107
+ );
108
+ for (const field of Object.keys(cumulative)) {
109
+ const value = cumulative[field];
110
+ const previousValue = previousCumulative?.[field];
111
+ if (value !== void 0 && previousValue !== void 0 && value < previousValue) {
112
+ invalidTurnSequence(
113
+ input.providerKey,
114
+ "Provider context cumulative counters cannot decrease."
115
+ );
116
+ }
117
+ }
118
+ input.state.cumulativeByScope.set(input.usage.measurementScope, {
119
+ ...previousCumulative,
120
+ ...cumulative
121
+ });
122
+ }
112
123
  input.state.latestByScope.set(input.usage.measurementScope, input.usage);
113
124
  input.state.compactionReadyScopes.delete(input.usage.measurementScope);
114
125
  }
@@ -368,6 +379,7 @@ function validateAgentProviderSession(input) {
368
379
  const openedRequestIds = /* @__PURE__ */ new Set();
369
380
  const contextUsageState = {
370
381
  latestByScope: /* @__PURE__ */ new Map(),
382
+ cumulativeByScope: /* @__PURE__ */ new Map(),
371
383
  compactionReadyScopes: /* @__PURE__ */ new Set()
372
384
  };
373
385
  let activeTurn = null;
@@ -527,7 +539,7 @@ function validateAgentProviderSession(input) {
527
539
  "Provider request resolution does not match the opened request."
528
540
  );
529
541
  }
530
- if (pending.request.expiresAt !== void 0 && Date.parse(pending.request.expiresAt) <= Date.now()) {
542
+ if (pending.request.expiresAt !== void 0 && Date.parse(pending.request.expiresAt) <= Date.now() && resolution.disposition !== "canceled") {
531
543
  throwAgentProviderContractError(
532
544
  providerKey,
533
545
  "request_resolution_mismatch",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agen-ai/agent-runtime",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "private": false,
5
5
  "description": "Provider-neutral driver, instance, adapter, session, output, and conformance contracts for coding-agent runtimes.",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  "./package.json": "./package.json"
28
28
  },
29
29
  "dependencies": {
30
- "@agen-ai/agent-protocol": "^0.2.0"
30
+ "@agen-ai/agent-protocol": "^0.2.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "tsup": "^8.5.0"