macp-sdk-typescript 0.4.1 → 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.
Files changed (45) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/README.md +17 -6
  3. package/dist/agent/participant.d.ts +2 -0
  4. package/dist/agent/participant.js +1 -0
  5. package/dist/agent/runner.d.ts +1 -0
  6. package/dist/agent/runner.js +1 -0
  7. package/dist/agent/transports.d.ts +10 -0
  8. package/dist/agent/transports.js +13 -0
  9. package/dist/auth.d.ts +10 -5
  10. package/dist/auth.js +15 -15
  11. package/dist/base-session.d.ts +1 -0
  12. package/dist/base-session.js +3 -0
  13. package/dist/client.d.ts +60 -14
  14. package/dist/client.js +88 -30
  15. package/dist/decision.d.ts +1 -0
  16. package/dist/decision.js +2 -0
  17. package/dist/envelope.d.ts +20 -0
  18. package/dist/envelope.js +15 -0
  19. package/dist/errors.d.ts +10 -1
  20. package/dist/errors.js +11 -1
  21. package/dist/handoff.d.ts +1 -0
  22. package/dist/handoff.js +9 -1
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +3 -1
  25. package/dist/policy.d.ts +20 -0
  26. package/dist/policy.js +9 -0
  27. package/dist/projections/handoff.d.ts +12 -0
  28. package/dist/projections/handoff.js +13 -0
  29. package/dist/proposal.d.ts +1 -0
  30. package/dist/proposal.js +2 -0
  31. package/dist/proto-registry.d.ts +10 -0
  32. package/dist/proto-registry.js +34 -1
  33. package/dist/quorum.d.ts +1 -0
  34. package/dist/quorum.js +2 -0
  35. package/dist/retry.d.ts +7 -0
  36. package/dist/task.d.ts +1 -0
  37. package/dist/task.js +2 -0
  38. package/dist/types.d.ts +18 -0
  39. package/dist/validation.d.ts +2 -0
  40. package/dist/validation.js +10 -0
  41. package/dist/version.d.ts +7 -0
  42. package/dist/version.js +10 -0
  43. package/dist/watchers.d.ts +17 -13
  44. package/dist/watchers.js +26 -26
  45. package/package.json +3 -3
package/dist/task.d.ts CHANGED
@@ -30,6 +30,7 @@ export declare class TaskSession {
30
30
  uri: string;
31
31
  name?: string;
32
32
  }[];
33
+ maxSuspendMs?: number;
33
34
  sender?: string;
34
35
  }): Promise<Ack>;
35
36
  requestTask(input: TaskRequestPayload & {
package/dist/task.js CHANGED
@@ -40,6 +40,7 @@ class TaskSession {
40
40
  intent: input.intent,
41
41
  participants: input.participants,
42
42
  ttlMs: input.ttlMs,
43
+ maxSuspendMs: input.maxSuspendMs,
43
44
  modeVersion: this.modeVersion,
44
45
  configurationVersion: this.configurationVersion,
45
46
  });
@@ -47,6 +48,7 @@ class TaskSession {
47
48
  intent: input.intent,
48
49
  participants: input.participants,
49
50
  ttlMs: input.ttlMs,
51
+ maxSuspendMs: input.maxSuspendMs,
50
52
  contextId: input.contextId,
51
53
  extensions: input.extensions,
52
54
  roots: input.roots,
package/dist/types.d.ts CHANGED
@@ -106,6 +106,15 @@ export interface SessionStartPayload {
106
106
  configurationVersion: string;
107
107
  policyVersion?: string;
108
108
  ttlMs: number;
109
+ /**
110
+ * Maximum cumulative suspended duration (ms) before a SUSPENDED session
111
+ * transitions to EXPIRED (RFC-MACP-0001 §7.5, proto ≥ 0.1.5). Bound at
112
+ * session start like {@link ttlMs}: `0` (or absent) selects the runtime's
113
+ * configured default (7 days). The runtime records the resolved cap so
114
+ * replay is deterministic. Negative values are rejected at SessionStart.
115
+ * Decoded as a string (int64) but accepted as `number` on input.
116
+ */
117
+ maxSuspendMs?: number | string;
109
118
  contextId?: string;
110
119
  extensions?: Record<string, Buffer>;
111
120
  roots?: Root[];
@@ -251,6 +260,15 @@ export interface HandoffAcceptPayload {
251
260
  handoffId: string;
252
261
  acceptedBy: string;
253
262
  reason?: string;
263
+ /**
264
+ * Runtime-emitted synthetic accepts ONLY (RFC-MACP-0010 §5.1): `true` on the
265
+ * accept the runtime produces when a handoff's `implicit_accept_timeout_ms`
266
+ * elapses (`message_id` = `implicit-accept:<handoff_id>`, proto ≥ 0.1.6).
267
+ * Read-only — clients MUST NOT submit an accept with `implicit = true`; the
268
+ * runtime rejects it. `HandoffSession.acceptHandoff` strips this field before
269
+ * encoding so a caller can never produce a rejected envelope.
270
+ */
271
+ implicit?: boolean;
254
272
  }
255
273
  export interface HandoffDeclinePayload {
256
274
  handoffId: string;
@@ -6,12 +6,14 @@ export declare function validateSeverity(value: string): string;
6
6
  export declare function validateParticipantCount(count: number): void;
7
7
  export declare function validateSignalType(signalType: string, data?: Buffer | Uint8Array): void;
8
8
  export declare function validateTtlMs(ttlMs: number): void;
9
+ export declare function validateMaxSuspendMs(maxSuspendMs: number): void;
9
10
  export declare function validateParticipants(participants: string[]): void;
10
11
  export declare function validateRequiredField(fieldName: string, value: string): void;
11
12
  export declare function validateSessionStart(input: {
12
13
  intent: string;
13
14
  participants: string[];
14
15
  ttlMs: number;
16
+ maxSuspendMs?: number;
15
17
  modeVersion: string;
16
18
  configurationVersion: string;
17
19
  }): void;
@@ -8,6 +8,7 @@ exports.validateSeverity = validateSeverity;
8
8
  exports.validateParticipantCount = validateParticipantCount;
9
9
  exports.validateSignalType = validateSignalType;
10
10
  exports.validateTtlMs = validateTtlMs;
11
+ exports.validateMaxSuspendMs = validateMaxSuspendMs;
11
12
  exports.validateParticipants = validateParticipants;
12
13
  exports.validateRequiredField = validateRequiredField;
13
14
  exports.validateSessionStart = validateSessionStart;
@@ -65,6 +66,13 @@ function validateTtlMs(ttlMs) {
65
66
  throw new errors_1.MacpSessionError(`ttl_ms must be in [1, ${MAX_TTL_MS}], got ${ttlMs}`);
66
67
  }
67
68
  }
69
+ function validateMaxSuspendMs(maxSuspendMs) {
70
+ // 0 = "use runtime default"; only negatives are rejected (matches the
71
+ // runtime, which rejects negative max_suspend_ms at SessionStart).
72
+ if (!Number.isFinite(maxSuspendMs) || maxSuspendMs < 0) {
73
+ throw new errors_1.MacpSessionError(`max_suspend_ms must be >= 0 (0 = runtime default), got ${maxSuspendMs}`);
74
+ }
75
+ }
68
76
  function validateParticipants(participants) {
69
77
  if (!participants.length) {
70
78
  throw new errors_1.MacpSessionError('participants must be non-empty');
@@ -87,6 +95,8 @@ function validateSessionStart(input) {
87
95
  validateRequiredField('intent', input.intent);
88
96
  validateParticipants(input.participants);
89
97
  validateTtlMs(input.ttlMs);
98
+ if (input.maxSuspendMs !== undefined)
99
+ validateMaxSuspendMs(input.maxSuspendMs);
90
100
  validateRequiredField('modeVersion', input.modeVersion);
91
101
  validateRequiredField('configurationVersion', input.configurationVersion);
92
102
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The installed `macp-sdk-typescript` package version.
3
+ *
4
+ * Kept in sync with package.json by release-please (see the
5
+ * `x-release-please-version` annotation).
6
+ */
7
+ export declare const VERSION = "0.6.0";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = void 0;
4
+ /**
5
+ * The installed `macp-sdk-typescript` package version.
6
+ *
7
+ * Kept in sync with package.json by release-please (see the
8
+ * `x-release-please-version` annotation).
9
+ */
10
+ exports.VERSION = '0.6.0'; // x-release-please-version
@@ -1,5 +1,5 @@
1
1
  import type { AuthConfig } from './auth';
2
- import type { MacpClient } from './client';
2
+ import { type MacpClient } from './client';
3
3
  import type { Envelope, PolicyDescriptor, RegistryChanged, RootsChanged, SessionLifecycleEvent, SessionLifecycleEventType } from './types';
4
4
  /**
5
5
  * The lifecycle event types after which a session emits no further events.
@@ -43,6 +43,16 @@ export declare class RootsWatcher {
43
43
  watch(handler: (change: RootsChanged) => void | Promise<void>): Promise<void>;
44
44
  nextChange(): Promise<RootsChanged>;
45
45
  }
46
+ /**
47
+ * Watches the ambient signal plane. **Requires auth** as of runtime 0.5.0: if
48
+ * no credential is configured on the watcher or the client, iterating
49
+ * {@link SignalWatcher.signals} throws immediately (via `client.watchSignals`).
50
+ *
51
+ * Consumer lag terminates the stream with a coded `MacpTransportError`
52
+ * (`code === 'RESOURCE_EXHAUSTED'`); the correct response is to reconnect.
53
+ * A missing/invalid credential surfaces as `code === 'UNAUTHENTICATED'` — fix
54
+ * auth, do not reconnect.
55
+ */
46
56
  export declare class SignalWatcher {
47
57
  private readonly client;
48
58
  private readonly auth?;
@@ -67,26 +77,20 @@ export declare class PolicyWatcher {
67
77
  watch(handler: (change: PolicyChange) => void | Promise<void>): Promise<void>;
68
78
  nextChange(): Promise<PolicyChange>;
69
79
  }
80
+ /**
81
+ * Watches session lifecycle events (`WatchSessions`). Consumer lag terminates
82
+ * the stream with a coded `MacpTransportError` (`code === 'RESOURCE_EXHAUSTED'`);
83
+ * the correct response is to reconnect and re-sync current state via
84
+ * {@link MacpClient.listSessions}, since events emitted during the gap are lost.
85
+ */
70
86
  export declare class SessionLifecycleWatcher {
71
87
  private readonly client;
72
88
  private readonly auth?;
73
- private deprecatedEventsWarned;
74
- private deprecatedNextEventWarned;
75
89
  constructor(client: MacpClient, options?: {
76
90
  auth?: AuthConfig;
77
91
  });
78
92
  changes(signal?: AbortSignal): AsyncGenerator<SessionLifecycleEvent, void, void>;
79
93
  watch(handler: (event: SessionLifecycleEvent) => void | Promise<void>): Promise<void>;
80
94
  nextChange(): Promise<SessionLifecycleEvent>;
81
- /**
82
- * @deprecated Use {@link changes} — renamed for parity with python-sdk's
83
- * `SessionLifecycleWatcher.changes()` and the uniform `changes()` name
84
- * used by all other watchers in both SDKs. Will be removed in 0.5.0.
85
- */
86
- events(signal?: AbortSignal): AsyncGenerator<SessionLifecycleEvent, void, void>;
87
- /**
88
- * @deprecated Use {@link nextChange}. Will be removed in 0.5.0.
89
- */
90
- nextEvent(): Promise<SessionLifecycleEvent>;
91
95
  }
92
96
  export {};
package/dist/watchers.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SessionLifecycleWatcher = exports.PolicyWatcher = exports.SignalWatcher = exports.RootsWatcher = exports.ModeRegistryWatcher = exports.isTerminalSessionLifecycleEvent = exports.isSessionResumed = exports.isSessionSuspended = exports.isSessionCancelled = exports.isSessionExpired = exports.isSessionResolved = exports.isSessionCreated = exports.TERMINAL_SESSION_LIFECYCLE_EVENT_TYPES = void 0;
4
- const logging_1 = require("./logging");
4
+ const client_1 = require("./client");
5
+ const errors_1 = require("./errors");
5
6
  /**
6
7
  * The lifecycle event types after which a session emits no further events.
7
8
  * `EVENT_TYPE_CANCELLED` (proto 0.1.3) is terminal alongside `RESOLVED` and
@@ -48,7 +49,14 @@ function serverStreamToAsyncGenerator(stream) {
48
49
  }
49
50
  });
50
51
  stream.on('error', (error) => {
51
- queue.push({ error });
52
+ // Wrap the raw gRPC ServiceError into a coded MacpTransportError so
53
+ // consumers can branch on `.code`: consumer lag terminates a watch stream
54
+ // with RESOURCE_EXHAUSTED (reconnect + re-sync), an unauthenticated
55
+ // WatchSignals with UNAUTHENTICATED (fix auth, do NOT reconnect).
56
+ const code = (0, client_1.grpcStatusName)(error.code);
57
+ const serviceErr = error;
58
+ const wrapped = new errors_1.MacpTransportError(serviceErr.details || error.message, code);
59
+ queue.push({ error: wrapped });
52
60
  if (resolve) {
53
61
  resolve();
54
62
  resolve = null;
@@ -148,6 +156,16 @@ class RootsWatcher {
148
156
  }
149
157
  }
150
158
  exports.RootsWatcher = RootsWatcher;
159
+ /**
160
+ * Watches the ambient signal plane. **Requires auth** as of runtime 0.5.0: if
161
+ * no credential is configured on the watcher or the client, iterating
162
+ * {@link SignalWatcher.signals} throws immediately (via `client.watchSignals`).
163
+ *
164
+ * Consumer lag terminates the stream with a coded `MacpTransportError`
165
+ * (`code === 'RESOURCE_EXHAUSTED'`); the correct response is to reconnect.
166
+ * A missing/invalid credential surfaces as `code === 'UNAUTHENTICATED'` — fix
167
+ * auth, do not reconnect.
168
+ */
151
169
  class SignalWatcher {
152
170
  client;
153
171
  auth;
@@ -210,11 +228,15 @@ class PolicyWatcher {
210
228
  }
211
229
  }
212
230
  exports.PolicyWatcher = PolicyWatcher;
231
+ /**
232
+ * Watches session lifecycle events (`WatchSessions`). Consumer lag terminates
233
+ * the stream with a coded `MacpTransportError` (`code === 'RESOURCE_EXHAUSTED'`);
234
+ * the correct response is to reconnect and re-sync current state via
235
+ * {@link MacpClient.listSessions}, since events emitted during the gap are lost.
236
+ */
213
237
  class SessionLifecycleWatcher {
214
238
  client;
215
239
  auth;
216
- deprecatedEventsWarned = false;
217
- deprecatedNextEventWarned = false;
218
240
  constructor(client, options) {
219
241
  this.client = client;
220
242
  this.auth = options?.auth;
@@ -243,27 +265,5 @@ class SessionLifecycleWatcher {
243
265
  throw new Error('stream ended before receiving a session lifecycle event');
244
266
  return result.value;
245
267
  }
246
- /**
247
- * @deprecated Use {@link changes} — renamed for parity with python-sdk's
248
- * `SessionLifecycleWatcher.changes()` and the uniform `changes()` name
249
- * used by all other watchers in both SDKs. Will be removed in 0.5.0.
250
- */
251
- async *events(signal) {
252
- if (!this.deprecatedEventsWarned) {
253
- this.deprecatedEventsWarned = true;
254
- logging_1.logger.warn('[deprecated] SessionLifecycleWatcher.events() — use changes() instead');
255
- }
256
- yield* this.changes(signal);
257
- }
258
- /**
259
- * @deprecated Use {@link nextChange}. Will be removed in 0.5.0.
260
- */
261
- async nextEvent() {
262
- if (!this.deprecatedNextEventWarned) {
263
- this.deprecatedNextEventWarned = true;
264
- logging_1.logger.warn('[deprecated] SessionLifecycleWatcher.nextEvent() — use nextChange() instead');
265
- }
266
- return this.nextChange();
267
- }
268
268
  }
269
269
  exports.SessionLifecycleWatcher = SessionLifecycleWatcher;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "macp-sdk-typescript",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "TypeScript SDK for the MACP Rust runtime",
5
5
  "license": "Apache-2.0",
6
6
  "type": "commonjs",
@@ -39,7 +39,7 @@
39
39
  "prepublishOnly": "npm run check && npm run lint && npm run format:check && npm test && npm run build"
40
40
  },
41
41
  "engines": {
42
- "node": ">=18"
42
+ "node": ">=20"
43
43
  },
44
44
  "keywords": [
45
45
  "macp",
@@ -55,7 +55,7 @@
55
55
  "dependencies": {
56
56
  "@grpc/grpc-js": "^1.14.3",
57
57
  "@grpc/proto-loader": "^0.8.0",
58
- "@multiagentcoordinationprotocol/proto": "^0.1.3",
58
+ "@multiagentcoordinationprotocol/proto": "^0.1.8",
59
59
  "protobufjs": "^8.6.5"
60
60
  },
61
61
  "devDependencies": {