@canonmsg/agent-sdk 11.1.0 → 11.1.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.
@@ -1,5 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { buildChunkedMessagePartMetadata, buildCanonGroupContext, buildCompactGroupContextLines, CanonClient, CanonStream, createAttachedNativeSession, createRuntimeHeartbeat, createRuntimeStatePublisher, initRTDBAuth, resolveCanonRuntimeConnection, splitTextByUtf8Bytes, verifyCanonRuntimeConnection, } from '@canonmsg/core';
2
+ import { buildChunkedMessagePartMetadata, buildCanonGroupContext, buildCompactGroupContextLines, buildSelfContextPromptLines, CanonClient, CanonStream, createAttachedNativeSession, createRuntimeHeartbeat, createRuntimeStatePublisher, initRTDBAuth, hydrateCanonReplyContext, selectInboundSelfContexts, resolveCanonRuntimeConnection, splitTextByUtf8Bytes, verifyCanonRuntimeConnection, } from '@canonmsg/core';
3
3
  /**
4
4
  * Connect one existing native session to one existing Canon conversation.
5
5
  * This is account-level participation, not a second group member. The caller
@@ -236,9 +236,29 @@ export function createCanonAttachedSession(options) {
236
236
  }
237
237
  const roster = buildCanonGroupContext({ conversation: currentConversation, messages: [message], agentId: binding.agentId, ownerId: currentOwnerId });
238
238
  const rosterLines = roster ? buildCompactGroupContextLines(roster, 'initial') : [];
239
+ const page = await client.getMessagesPage(binding.conversationId, 50).catch(() => null);
240
+ const replyContext = message.replyTo
241
+ ? await hydrateCanonReplyContext({
242
+ client,
243
+ conversationId: binding.conversationId,
244
+ message,
245
+ messages: page?.messages,
246
+ })
247
+ : null;
248
+ const selectedSelfContext = selectInboundSelfContexts({
249
+ selfContexts: [...(page?.selfContexts ?? []), ...(payload.selfContexts ?? [])],
250
+ replyTo: message.replyTo,
251
+ linkedSelfContextId: page?.activeSelfContextIdByMessageId?.[message.id]
252
+ ?? payload.activeSelfContextId,
253
+ messages: page?.messages,
254
+ replyContext,
255
+ });
256
+ const privateContextLines = buildSelfContextPromptLines(selectedSelfContext.selfContexts, {
257
+ activeSelfContextId: selectedSelfContext.activeSelfContextId,
258
+ });
239
259
  const result = await core.submit({
240
260
  messageId: message.id,
241
- text: [...rosterLines, `Canon message from ${message.senderName ?? message.senderId} (${message.senderType}):\n\n${message.text}`].join('\n\n'),
261
+ text: [...rosterLines, ...privateContextLines, `Canon message from ${message.senderName ?? message.senderId} (${message.senderType}):\n\n${message.text}`].join('\n\n'),
242
262
  ...(payload.replyAuthority ? { replyAuthority: payload.replyAuthority } : {}),
243
263
  });
244
264
  // A conclusive provider acknowledgement settles command delivery. Native
@@ -1,4 +1,4 @@
1
- import { ApprovalManager, RuntimeRequestManager, runtimeInputDescriptor, runtimeCardDescriptor, CanonClient, ControlChannelPoller, buildCanonTurnContextV2, buildCanonGroupContext, buildParticipationHistorySnapshot, createTurnOutputController, createRuntimeStatePublisher, createRuntimeHeartbeat, createTypingStatusPublisher, diffCanonMemberIds, FINAL_MESSAGE_HANDOFF_MS, RUNTIME_NEW_SESSION_ACTION, RUNTIME_STOP_ACTION, RUNTIME_STOP_AND_DROP_ACTION, buildRuntimeCardOutcome, buildRuntimeInputOutcome, initRTDBAuth, isChunkedSendMessageError, isPendingCanonOperation, normalizeRuntimeCommandDescriptors, normalizeTurnMetadata, normalizeTurnVerbosityConversationType, reportNoReplyOutcome, hydrateCanonReplyContext, resolveMessageActiveSelfContextId, resolveRuntimeProvenance, resolveTurnVerbosity, resolveConversationPolicyScope, selectActiveSelfContexts, renderCanonHostInboundContent, resolveCanonRuntimeConnection, sendMessageWithRetryChunked, shouldPublishTurnTrail, splitTextByUtf8Bytes, verifyCanonRuntimeConnection, } from '@canonmsg/core';
1
+ import { ApprovalManager, RuntimeRequestManager, runtimeInputDescriptor, runtimeCardDescriptor, CanonClient, ControlChannelPoller, buildCanonTurnContextV2, buildCanonGroupContext, buildParticipationHistorySnapshot, createTurnOutputController, createRuntimeStatePublisher, createRuntimeHeartbeat, createTypingStatusPublisher, diffCanonMemberIds, FINAL_MESSAGE_HANDOFF_MS, RUNTIME_NEW_SESSION_ACTION, RUNTIME_STOP_ACTION, RUNTIME_STOP_AND_DROP_ACTION, buildRuntimeCardOutcome, buildRuntimeInputOutcome, initRTDBAuth, isChunkedSendMessageError, isPendingCanonOperation, normalizeRuntimeCommandDescriptors, normalizeTurnMetadata, normalizeTurnVerbosityConversationType, reportNoReplyOutcome, hydrateCanonReplyContext, resolveRuntimeProvenance, resolveTurnVerbosity, resolveConversationPolicyScope, selectInboundSelfContexts, renderCanonHostInboundContent, resolveCanonRuntimeConnection, sendMessageWithRetryChunked, shouldPublishTurnTrail, splitTextByUtf8Bytes, verifyCanonRuntimeConnection, } from '@canonmsg/core';
2
2
  import { createHash, randomUUID } from 'node:crypto';
3
3
  import { Debouncer } from './debouncer.js';
4
4
  import { disposeInboundHandoffs, selectInboundHandoffs } from './inbound-handoff.js';
@@ -1628,12 +1628,17 @@ export class CanonAgent {
1628
1628
  client: this.apiClient, conversationId, message: latestMessage, messages: history,
1629
1629
  })
1630
1630
  : null;
1631
- const resolvedActiveSelfContextId = resolveMessageActiveSelfContextId({
1632
- messageId: latestMessage?.id,
1633
- activeSelfContextIdByMessageId: page.activeSelfContextIdByMessageId,
1631
+ const selectedSelfContext = selectInboundSelfContexts({
1632
+ selfContexts: page.selfContexts,
1633
+ replyTo: latestMessage?.replyTo,
1634
+ linkedSelfContextId: latestMessage?.id
1635
+ ? page.activeSelfContextIdByMessageId?.[latestMessage.id]
1636
+ : null,
1637
+ messages: page.messages,
1638
+ replyContext,
1634
1639
  });
1635
- const selfContexts = selectActiveSelfContexts(page.selfContexts, resolvedActiveSelfContextId);
1636
- const activeSelfContextId = selfContexts.length > 0 ? resolvedActiveSelfContextId : null;
1640
+ const selfContexts = selectedSelfContext.selfContexts;
1641
+ const activeSelfContextId = selectedSelfContext.activeSelfContextId;
1637
1642
  const withActiveSelfContext = (options) => {
1638
1643
  const base = { ...(options ?? {}) };
1639
1644
  const withContext = base.selfContextId !== undefined || !activeSelfContextId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonmsg/agent-sdk",
3
- "version": "11.1.0",
3
+ "version": "11.1.1",
4
4
  "description": "Canon Agent SDK — build AI agents that participate in Canon conversations",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "node": ">=22.22.3"
29
29
  },
30
30
  "dependencies": {
31
- "@canonmsg/core": "^13.1.0"
31
+ "@canonmsg/core": "^13.2.0"
32
32
  },
33
33
  "repository": {
34
34
  "type": "git",