@copilotkit/channels-core 0.5.0 → 0.5.1-canary.1785633429

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 (82) hide show
  1. package/README.md +35 -14
  2. package/dist/action-registry.d.ts +15 -3
  3. package/dist/action-registry.d.ts.map +1 -1
  4. package/dist/action-registry.js +61 -9
  5. package/dist/action-registry.test.js +107 -2
  6. package/dist/action-store.d.ts +23 -0
  7. package/dist/action-store.d.ts.map +1 -1
  8. package/dist/action-store.js +11 -0
  9. package/dist/canonical-run-loop.test.js +6 -1
  10. package/dist/channel-identity.test.d.ts +2 -0
  11. package/dist/channel-identity.test.d.ts.map +1 -0
  12. package/dist/channel-identity.test.js +297 -0
  13. package/dist/channel-memory.test.d.ts +2 -0
  14. package/dist/channel-memory.test.d.ts.map +1 -0
  15. package/dist/channel-memory.test.js +199 -0
  16. package/dist/commands.d.ts +5 -3
  17. package/dist/commands.d.ts.map +1 -1
  18. package/dist/create-channel.d.ts +30 -56
  19. package/dist/create-channel.d.ts.map +1 -1
  20. package/dist/create-channel.foundations.test.js +30 -7
  21. package/dist/create-channel.js +209 -72
  22. package/dist/create-channel.test.js +293 -66
  23. package/dist/hitl-continuation.test.d.ts +2 -0
  24. package/dist/hitl-continuation.test.d.ts.map +1 -0
  25. package/dist/hitl-continuation.test.js +393 -0
  26. package/dist/identity.d.ts +51 -0
  27. package/dist/identity.d.ts.map +1 -0
  28. package/dist/identity.js +56 -0
  29. package/dist/identity.test.d.ts +2 -0
  30. package/dist/identity.test.d.ts.map +1 -0
  31. package/dist/identity.test.js +109 -0
  32. package/dist/index.d.ts +10 -5
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +5 -1
  35. package/dist/managed-v1-await-choice-guard.test.js +4 -1
  36. package/dist/memory.d.ts +23 -0
  37. package/dist/memory.d.ts.map +1 -0
  38. package/dist/memory.js +25 -0
  39. package/dist/modal-submit.test.js +21 -6
  40. package/dist/open-modal.test.js +16 -4
  41. package/dist/platform-adapter.d.ts +29 -6
  42. package/dist/platform-adapter.d.ts.map +1 -1
  43. package/dist/platform-adapter.test.js +2 -0
  44. package/dist/reactions.test.js +49 -11
  45. package/dist/run-loop.test.js +30 -5
  46. package/dist/sanitize-agent-events.test.js +2 -0
  47. package/dist/source-platform.test.js +24 -9
  48. package/dist/state/kv-action-store.d.ts.map +1 -1
  49. package/dist/state/kv-action-store.js +1 -0
  50. package/dist/state/kv-action-store.test.js +11 -0
  51. package/dist/state/memory-store.d.ts +1 -0
  52. package/dist/state/memory-store.d.ts.map +1 -1
  53. package/dist/state/memory-store.js +9 -0
  54. package/dist/state/state-store.d.ts +2 -0
  55. package/dist/state/state-store.d.ts.map +1 -1
  56. package/dist/telemetry/create-channel-telemetry.test.js +4 -2
  57. package/dist/telemetry/e2e-telemetry.test.js +1 -0
  58. package/dist/telemetry/install-id.test.js +5 -0
  59. package/dist/testing/fake-adapter.d.ts +26 -9
  60. package/dist/testing/fake-adapter.d.ts.map +1 -1
  61. package/dist/testing/fake-adapter.js +65 -21
  62. package/dist/testing/state-store-conformance.d.ts.map +1 -1
  63. package/dist/testing/state-store-conformance.js +16 -0
  64. package/dist/thread-capabilities.test.js +29 -9
  65. package/dist/thread-ephemeral.test.js +8 -5
  66. package/dist/thread-promise-contract.test.js +4 -0
  67. package/dist/thread-reactions.test.js +8 -2
  68. package/dist/thread.d.ts +50 -7
  69. package/dist/thread.d.ts.map +1 -1
  70. package/dist/thread.js +163 -17
  71. package/dist/thread.test.js +4 -0
  72. package/dist/tools.d.ts +5 -3
  73. package/dist/tools.d.ts.map +1 -1
  74. package/dist/tools.js +2 -1
  75. package/dist/transcripts.d.ts +6 -13
  76. package/dist/transcripts.d.ts.map +1 -1
  77. package/dist/transcripts.js +12 -12
  78. package/dist/transcripts.test.js +28 -29
  79. package/dist/welcome.test.d.ts +2 -0
  80. package/dist/welcome.test.d.ts.map +1 -0
  81. package/dist/welcome.test.js +53 -0
  82. package/package.json +5 -5
@@ -13,6 +13,8 @@ function setupThreadWithSyncDeleteFailure(failure) {
13
13
  adapter,
14
14
  replyTarget: {},
15
15
  conversationKey: "thread-promise-contract",
16
+ channelName: "test",
17
+ threadId: "thread-promise-contract",
16
18
  registry: new ActionRegistry({ store: new InMemoryActionStore() }),
17
19
  agentFactory: (threadId) => {
18
20
  throw new Error(`agentFactory not needed in this test: ${threadId}`);
@@ -23,6 +25,8 @@ function setupThreadWithSyncDeleteFailure(failure) {
23
25
  registerWaiter: () => undefined,
24
26
  interruptHandlers: new Map(),
25
27
  state: new MemoryStore(),
28
+ user: null,
29
+ actor: { id: "actor", kind: "unknown" },
26
30
  };
27
31
  return new Thread(deps);
28
32
  }
@@ -5,7 +5,10 @@ import { FakeAdapter } from "./testing/fake-adapter.js";
5
5
  describe("Thread.react / unreact", () => {
6
6
  it("delegates to the adapter when supported", async () => {
7
7
  const fake = new FakeAdapter();
8
- const channel = createChannel({ adapters: [fake] });
8
+ const channel = createChannel({
9
+ identifyUser: "platform",
10
+ adapters: [fake],
11
+ });
9
12
  const results = [];
10
13
  channel.onMessage(async ({ thread, message }) => {
11
14
  results.push(await thread.react(message.ref, emoji.thumbs_up));
@@ -24,7 +27,10 @@ describe("Thread.react / unreact", () => {
24
27
  });
25
28
  it("returns { ok: false } without throwing when unsupported", async () => {
26
29
  const fake = new FakeAdapter({ reactions: false });
27
- const channel = createChannel({ adapters: [fake] });
30
+ const channel = createChannel({
31
+ identifyUser: "platform",
32
+ adapters: [fake],
33
+ });
28
34
  let res;
29
35
  channel.onMessage(async ({ thread, message }) => {
30
36
  res = await thread.react(message.ref, emoji.heart);
package/dist/thread.d.ts CHANGED
@@ -1,11 +1,32 @@
1
1
  import type { PlatformAdapter, ReplyTarget } from "./platform-adapter.js";
2
2
  import type { ActionRegistry } from "./action-registry.js";
3
- import type { AgentContentPart, Renderable, MessageRef, PlatformUser, ThreadMessage, IncomingMessage, Thread as ThreadInterface, EmojiValue, EphemeralResult } from "@copilotkit/channels-ui";
3
+ import type { AgentContentPart, Renderable, MessageRef, ProviderActor, ApplicationUser, ThreadMessage, IncomingMessage, Thread as ThreadInterface, EmojiValue, EphemeralResult } from "@copilotkit/channels-ui";
4
4
  import type { Transcripts } from "./transcripts.js";
5
5
  import type { ChannelTool, ContextEntry, AgentToolDescriptor } from "./tools.js";
6
6
  import type { AbstractAgent } from "@ag-ui/client";
7
7
  import type { StateStore } from "./state/state-store.js";
8
8
  import type { StandardSchemaV1 } from "./standard-schema.js";
9
+ import type { MemoryGrant } from "./memory.js";
10
+ /** A Channel run requested Memory without an attached Intelligence backend. */
11
+ export declare class ChannelMemoryUnavailableError extends Error {
12
+ readonly code = "channel_memory_unavailable";
13
+ constructor();
14
+ }
15
+ /** A Channel run requested personal Memory without an application user. */
16
+ export declare class ChannelMemoryUserRequiredError extends Error {
17
+ readonly code = "channel_memory_user_required";
18
+ constructor();
19
+ }
20
+ /** A personal-Memory resume omitted the trusted principal selector. */
21
+ export declare class ChannelMemorySubjectRequiredError extends Error {
22
+ readonly code = "channel_memory_subject_required";
23
+ constructor();
24
+ }
25
+ /** A resume was not triggered by a persisted one-use action capability. */
26
+ export declare class ChannelContinuationRequiredError extends Error {
27
+ readonly code = "channel_continuation_required";
28
+ constructor();
29
+ }
9
30
  export interface ThreadDeps {
10
31
  adapter: PlatformAdapter;
11
32
  /** Source provider for this ingress event; falls back to the adapter identity. */
@@ -21,6 +42,8 @@ export interface ThreadDeps {
21
42
  interruptHandlers: Map<string, (args: {
22
43
  payload: unknown;
23
44
  thread: Thread;
45
+ user: ApplicationUser | null;
46
+ actor: ProviderActor;
24
47
  }) => void | Promise<void>>;
25
48
  /** Pluggable persistence. Injected by createChannel; always required. */
26
49
  state: StateStore;
@@ -31,10 +54,18 @@ export interface ThreadDeps {
31
54
  stateSchema?: StandardSchemaV1;
32
55
  /** Cross-platform transcript store. Present only when `store.transcripts` is configured. */
33
56
  transcripts?: Transcripts;
34
- /** Resolved cross-platform identity key for this turn (if any). */
35
- userKey?: string;
36
57
  /** The inbound message that triggered this turn (for transcript bridging). */
37
58
  message?: IncomingMessage;
59
+ user: ApplicationUser | null;
60
+ actor: ProviderActor;
61
+ /** Declared Channel identity bound to one-use continuations. */
62
+ channelName: string;
63
+ /** Trusted canonical Thread identity bound to one-use continuations. */
64
+ threadId: string;
65
+ /** Action capability that created this interaction Thread. */
66
+ interactionActionId?: string;
67
+ /** Set only when the owning Runtime attached Intelligence Memory. */
68
+ intelligenceMemoryAvailable?: boolean;
38
69
  /**
39
70
  * Optional anonymous telemetry sink. Structural type (not the concrete
40
71
  * ChannelTelemetry) avoids an import cycle; the real ChannelTelemetry satisfies it.
@@ -53,9 +84,13 @@ export declare class Thread implements ThreadInterface {
53
84
  readonly supportsBlockingChoice?: boolean;
54
85
  private readonly store;
55
86
  private implicitInboundConsumed;
87
+ private activeContinuation?;
88
+ private agentRunTail;
56
89
  constructor(deps: ThreadDeps);
57
90
  private bindForPost;
58
91
  private trackOperation;
92
+ /** Keep one Thread's agent runs isolated while preserving failure independence. */
93
+ private enqueueAgentRun;
59
94
  /**
60
95
  * Wire a posted message's `onReaction` to its returned id: cache it for this
61
96
  * process and, when it came from a component, persist a durable snapshot so a
@@ -107,7 +142,7 @@ export declare class Thread implements ThreadInterface {
107
142
  * `true` → DM the user when native ephemeral is unsupported; `false` →
108
143
  * resolve to `null` when native ephemeral is unsupported.
109
144
  */
110
- postEphemeral(user: PlatformUser | string, ui: Renderable, opts: {
145
+ postEphemeral(user: ProviderActor | string, ui: Renderable, opts: {
111
146
  fallbackToDM: boolean;
112
147
  }): Promise<EphemeralResult | null>;
113
148
  /** Record this conversation as subscribed (persisted in state). Proactive delivery to subscribed conversations is not yet wired. */
@@ -123,7 +158,7 @@ export declare class Thread implements ThreadInterface {
123
158
  /** Read the conversation's messages (returns `[]` when the adapter can't read history). */
124
159
  getMessages(): Promise<ThreadMessage[]>;
125
160
  /** Resolve a platform user by free-form query (returns `undefined` when unsupported). */
126
- lookupUser(query: string): Promise<PlatformUser | undefined>;
161
+ lookupUser(query: string): Promise<ProviderActor | undefined>;
127
162
  /** Post a picker and wait until an interaction in this conversation resolves it. */
128
163
  awaitChoice<T = unknown>(ui: Renderable): Promise<T>;
129
164
  runAgent(input?: {
@@ -139,7 +174,7 @@ export declare class Thread implements ThreadInterface {
139
174
  prompt?: string | AgentContentPart[];
140
175
  /**
141
176
  * Auto-bridge cross-platform transcripts for this run. When truthy AND the
142
- * thread has a resolved `userKey` AND a `Transcripts` instance, this:
177
+ * thread has a resolved `userId` AND a `Transcripts` instance, this:
143
178
  * 1. injects prior history (`transcripts.list`, default limit 20) as a
144
179
  * context entry,
145
180
  * 2. appends the current user turn,
@@ -152,8 +187,16 @@ export declare class Thread implements ThreadInterface {
152
187
  transcript?: boolean | {
153
188
  limit?: number;
154
189
  };
190
+ /** Intelligence Memory access for this run only. Omission disables Memory. */
191
+ memory?: MemoryGrant;
192
+ }): Promise<MessageRef | undefined>;
193
+ resume(value: unknown, options?: {
194
+ memory?: MemoryGrant;
195
+ subject?: "initiator" | "actor";
155
196
  }): Promise<MessageRef | undefined>;
156
- resume(value: unknown): Promise<MessageRef | undefined>;
197
+ private resolveResumeMemory;
198
+ private resolveMemory;
199
+ private assertMemoryAvailable;
157
200
  private run;
158
201
  }
159
202
  //# sourceMappingURL=thread.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../src/thread.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,eAAe,EACf,MAAM,IAAI,eAAe,EACzB,UAAU,EACV,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAA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,EAAE,CAAC;QACtB;;;;;;WAMG;QACH,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAC;QACrC;;;;;;;;;;;WAWG;QACH,UAAU,CAAC,EAAE,OAAO,GAAG;YAAE,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC1C,8EAA8E;QAC9E,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAkDnC,MAAM,CACJ,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KACjC,GACA,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAgDlC,OAAO,CAAC,mBAAmB;IAsB3B,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,qBAAqB;YASf,GAAG;CA6MlB"}
package/dist/thread.js CHANGED
@@ -2,6 +2,39 @@ import { runAgentLoop } from "./run-loop.js";
2
2
  import { errorClass, normalizePlatform } from "./telemetry/sanitize-error.js";
3
3
  import { toAgentToolDescriptors } from "./tools.js";
4
4
  import { validateSchema } from "./standard-schema.js";
5
+ import { hasMemoryAccess, resolveMemoryGrant } from "./memory.js";
6
+ /** A Channel run requested Memory without an attached Intelligence backend. */
7
+ export class ChannelMemoryUnavailableError extends Error {
8
+ code = "channel_memory_unavailable";
9
+ constructor() {
10
+ super("Channel Memory requires an attached Intelligence Runtime");
11
+ this.name = "ChannelMemoryUnavailableError";
12
+ }
13
+ }
14
+ /** A Channel run requested personal Memory without an application user. */
15
+ export class ChannelMemoryUserRequiredError extends Error {
16
+ code = "channel_memory_user_required";
17
+ constructor() {
18
+ super("Channel user Memory requires an identified application user");
19
+ this.name = "ChannelMemoryUserRequiredError";
20
+ }
21
+ }
22
+ /** A personal-Memory resume omitted the trusted principal selector. */
23
+ export class ChannelMemorySubjectRequiredError extends Error {
24
+ code = "channel_memory_subject_required";
25
+ constructor() {
26
+ super('Channel user Memory on resume requires subject "initiator" or "actor"');
27
+ this.name = "ChannelMemorySubjectRequiredError";
28
+ }
29
+ }
30
+ /** A resume was not triggered by a persisted one-use action capability. */
31
+ export class ChannelContinuationRequiredError extends Error {
32
+ code = "channel_continuation_required";
33
+ constructor() {
34
+ super("Channel resume requires a valid interaction continuation");
35
+ this.name = "ChannelContinuationRequiredError";
36
+ }
37
+ }
5
38
  /** Stable rejection for surfaces that cannot hold one run open for a choice. */
6
39
  class ChannelAwaitChoiceNotSupportedError extends Error {
7
40
  code = "channel_await_choice_not_supported";
@@ -20,6 +53,8 @@ export class Thread {
20
53
  supportsBlockingChoice;
21
54
  store;
22
55
  implicitInboundConsumed = false;
56
+ activeContinuation;
57
+ agentRunTail = Promise.resolve();
23
58
  constructor(deps) {
24
59
  this.deps = deps;
25
60
  this.platform = deps.platform ?? deps.adapter.platform;
@@ -29,7 +64,7 @@ export class Thread {
29
64
  this.store = deps.state;
30
65
  }
31
66
  async bindForPost(ui) {
32
- return this.deps.registry.bindRenderable(ui, this.deps.conversationKey);
67
+ return this.deps.registry.bindRenderable(ui, this.deps.conversationKey, this.activeContinuation);
33
68
  }
34
69
  trackOperation(operation) {
35
70
  if (!this.deps.adapter.trackThreadOperation) {
@@ -42,6 +77,12 @@ export class Thread {
42
77
  }
43
78
  return this.deps.adapter.trackThreadOperation(this.deps.replyTarget, operation);
44
79
  }
80
+ /** Keep one Thread's agent runs isolated while preserving failure independence. */
81
+ enqueueAgentRun(operation) {
82
+ const result = this.agentRunTail.then(operation, operation);
83
+ this.agentRunTail = result.then(() => undefined, () => undefined);
84
+ return result;
85
+ }
45
86
  /**
46
87
  * Wire a posted message's `onReaction` to its returned id: cache it for this
47
88
  * process and, when it came from a component, persist a durable snapshot so a
@@ -227,7 +268,11 @@ export class Thread {
227
268
  catch (error) {
228
269
  return Promise.reject(error);
229
270
  }
230
- return this.trackOperation(async () => {
271
+ const memoryRequest = input?.memory === undefined
272
+ ? undefined
273
+ : { user: input.memory.user, project: input.memory.project };
274
+ return this.enqueueAgentRun(() => this.trackOperation(async () => {
275
+ const memory = this.resolveMemory(memoryRequest, this.deps.user);
231
276
  const message = this.deps.message;
232
277
  const defaultPrompt = message?.contentParts && message.contentParts.length > 0
233
278
  ? message.contentParts
@@ -239,14 +284,106 @@ export class Thread {
239
284
  if (implicitPrompt && defaultPrompt) {
240
285
  this.implicitInboundConsumed = true;
241
286
  }
242
- return this.run(undefined, {
243
- ...input,
244
- prompt: input?.prompt ?? (!implicitPrompt ? undefined : defaultPrompt),
245
- });
287
+ const continuation = {
288
+ channelName: this.deps.channelName,
289
+ conversationKey: this.deps.conversationKey,
290
+ threadId: this.deps.threadId,
291
+ runChainId: globalThis.crypto.randomUUID(),
292
+ initiator: { user: this.deps.user, actor: this.deps.actor },
293
+ };
294
+ this.activeContinuation = continuation;
295
+ try {
296
+ return await this.run(undefined, {
297
+ ...input,
298
+ memory,
299
+ prompt: input?.prompt ?? (!implicitPrompt ? undefined : defaultPrompt),
300
+ });
301
+ }
302
+ finally {
303
+ if (this.activeContinuation === continuation) {
304
+ this.activeContinuation = undefined;
305
+ }
306
+ }
307
+ }));
308
+ }
309
+ resume(value, options) {
310
+ const memoryRequest = options?.memory === undefined
311
+ ? undefined
312
+ : { user: options.memory.user, project: options.memory.project };
313
+ const subject = options?.subject;
314
+ const actionId = this.deps.interactionActionId;
315
+ if (!actionId) {
316
+ return Promise.reject(new ChannelContinuationRequiredError());
317
+ }
318
+ return this.trackOperation(async () => {
319
+ const binding = {
320
+ channelName: this.deps.channelName,
321
+ conversationKey: this.deps.conversationKey,
322
+ threadId: this.deps.threadId,
323
+ };
324
+ const available = await this.deps.registry.getContinuation(actionId, binding);
325
+ const memory = this.resolveResumeMemory(memoryRequest === undefined && subject === undefined
326
+ ? undefined
327
+ : { memory: memoryRequest, subject }, available);
328
+ const claimed = await this.deps.registry.claimContinuation(actionId, binding);
329
+ const continuation = {
330
+ channelName: claimed.channelName,
331
+ conversationKey: claimed.conversationKey,
332
+ threadId: claimed.threadId,
333
+ runChainId: claimed.runChainId,
334
+ initiator: claimed.initiator,
335
+ };
336
+ this.activeContinuation = continuation;
337
+ try {
338
+ return await this.run({ resume: value }, { memory });
339
+ }
340
+ finally {
341
+ if (this.activeContinuation === continuation) {
342
+ this.activeContinuation = undefined;
343
+ }
344
+ }
246
345
  });
247
346
  }
248
- resume(value) {
249
- return this.trackOperation(() => this.run({ resume: value }));
347
+ resolveResumeMemory(options, continuation) {
348
+ if (options?.memory === undefined)
349
+ return undefined;
350
+ const grant = resolveMemoryGrant(options.memory);
351
+ if (!hasMemoryAccess(grant))
352
+ return undefined;
353
+ let user = null;
354
+ if (grant.user !== "none") {
355
+ if (!options.subject)
356
+ throw new ChannelMemorySubjectRequiredError();
357
+ user =
358
+ options.subject === "initiator"
359
+ ? continuation.initiator.user
360
+ : this.deps.user;
361
+ if (user === null)
362
+ throw new ChannelMemoryUserRequiredError();
363
+ }
364
+ this.assertMemoryAvailable();
365
+ return Object.freeze({ grant, user });
366
+ }
367
+ resolveMemory(requested, user) {
368
+ if (requested === undefined)
369
+ return undefined;
370
+ const grant = resolveMemoryGrant(requested);
371
+ if (!hasMemoryAccess(grant))
372
+ return undefined;
373
+ if (grant.user !== "none" && user === null) {
374
+ throw new ChannelMemoryUserRequiredError();
375
+ }
376
+ this.assertMemoryAvailable();
377
+ return Object.freeze({
378
+ grant,
379
+ user: grant.user === "none" ? null : user,
380
+ });
381
+ }
382
+ assertMemoryAvailable() {
383
+ if (this.deps.intelligenceMemoryAvailable !== true &&
384
+ this.deps.adapter.supportsIntelligenceMemory !== true) {
385
+ throw new ChannelMemoryUnavailableError();
386
+ }
250
387
  }
251
388
  async run(initialResume, extra) {
252
389
  const session = await this.deps.adapter.conversationStore.getOrCreate(this.deps.conversationKey, this.deps.replyTarget, this.deps.agentFactory);
@@ -275,16 +412,16 @@ export class Thread {
275
412
  // bridge — see `runAgent`'s `transcript` doc. No-ops with one warning when
276
413
  // identity/transcripts aren't configured.
277
414
  const transcripts = this.deps.transcripts;
278
- const userKey = this.deps.userKey;
415
+ const userId = this.deps.user?.id;
279
416
  let transcriptContext;
280
417
  if (extra?.transcript) {
281
- if (transcripts && userKey) {
418
+ if (transcripts && userId) {
282
419
  const limit = typeof extra.transcript === "object"
283
420
  ? (extra.transcript.limit ?? 20)
284
421
  : 20;
285
422
  // List BEFORE appending the current user turn so the current message
286
423
  // isn't counted as its own "prior history".
287
- const prior = await transcripts.list({ userKey, limit });
424
+ const prior = await transcripts.list({ userId, limit });
288
425
  if (prior.length > 0) {
289
426
  transcriptContext = {
290
427
  description: `Prior cross-platform conversation history with this user. Current channel: ${this.platform}.`,
@@ -294,7 +431,7 @@ export class Thread {
294
431
  };
295
432
  }
296
433
  if (this.deps.message) {
297
- await transcripts.append(this, this.deps.message, { userKey });
434
+ await transcripts.append(this, this.deps.message, { userId });
298
435
  }
299
436
  }
300
437
  else {
@@ -338,12 +475,20 @@ export class Thread {
338
475
  context,
339
476
  makeToolCtx: () => ({
340
477
  thread: this,
478
+ message: this.deps.message,
479
+ user: this.deps.user,
480
+ actor: this.deps.actor,
341
481
  platform: this.platform,
342
482
  }),
343
483
  handleInterrupt: async (interrupt) => {
344
484
  const h = this.deps.interruptHandlers.get(interrupt.eventName);
345
485
  if (h)
346
- await h({ payload: interrupt.value, thread: this });
486
+ await h({
487
+ payload: interrupt.value,
488
+ thread: this,
489
+ user: this.deps.user,
490
+ actor: this.deps.actor,
491
+ });
347
492
  },
348
493
  initialResume,
349
494
  };
@@ -355,6 +500,7 @@ export class Thread {
355
500
  tools: toolDescriptors,
356
501
  context,
357
502
  isResume: initialResume !== undefined,
503
+ memory: extra?.memory,
358
504
  execute: (subscriber, canonicalRun) => runAgentLoop({
359
505
  ...loopArgs,
360
506
  subscriber,
@@ -365,8 +511,8 @@ export class Thread {
365
511
  stage = "finalize";
366
512
  // Transcript auto-bridge (step 4): capture the assistant text this run
367
513
  // produced and append it. Only when the bridge actually applied (transcripts
368
- // + userKey both present and `transcript` was requested).
369
- if (extra?.transcript && transcripts && userKey) {
514
+ // + userId both present and `transcript` was requested).
515
+ if (extra?.transcript && transcripts && userId) {
370
516
  const produced = session.agent.messages.slice(messagesBefore);
371
517
  const text = produced
372
518
  .filter((m) => m.role === "assistant" &&
@@ -375,7 +521,7 @@ export class Thread {
375
521
  .map((m) => m.content)
376
522
  .join("\n\n");
377
523
  if (text.length > 0) {
378
- await transcripts.append(this, { role: "assistant", text }, { userKey });
524
+ await transcripts.append(this, { role: "assistant", text }, { userId });
379
525
  }
380
526
  }
381
527
  // Turn-end hook: lets a renderer finalize any turn-scoped resource it kept
@@ -434,5 +580,5 @@ function warnTranscriptIgnored() {
434
580
  if (transcriptWarned)
435
581
  return;
436
582
  transcriptWarned = true;
437
- console.warn("[channel] runAgent({ transcript }) ignored — configure store.identity + store.transcripts so a userKey resolves");
583
+ console.warn("[channel] runAgent({ transcript }) ignored — configure store.transcripts and identify the current application user");
438
584
  }
@@ -11,6 +11,8 @@ function makeTestThread(overrides) {
11
11
  adapter,
12
12
  replyTarget: {},
13
13
  conversationKey: overrides.conversationKey ?? "c1",
14
+ channelName: "test",
15
+ threadId: overrides.conversationKey ?? "c1",
14
16
  registry,
15
17
  agentFactory: (id) => {
16
18
  throw new Error(`agentFactory not needed in this test: ${id}`);
@@ -21,6 +23,8 @@ function makeTestThread(overrides) {
21
23
  registerWaiter: () => { },
22
24
  interruptHandlers: new Map(),
23
25
  state: overrides.state,
26
+ user: null,
27
+ actor: { id: "actor", kind: "unknown" },
24
28
  };
25
29
  return new Thread(deps);
26
30
  }
package/dist/tools.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { InferSchemaOutput, ObjectSchema } from "./standard-schema.js";
2
2
  import { validateSchema } from "./standard-schema.js";
3
- import type { Thread, IncomingMessage, PlatformUser } from "@copilotkit/channels-ui";
3
+ import type { Thread, IncomingMessage, ApplicationUser, ProviderActor } from "@copilotkit/channels-ui";
4
4
  export type { ObjectSchema } from "./standard-schema.js";
5
5
  export interface ChannelToolContext {
6
6
  thread: Thread;
7
7
  message?: IncomingMessage;
8
- user?: PlatformUser;
8
+ user: ApplicationUser | null;
9
+ actor: ProviderActor;
9
10
  signal?: AbortSignal;
10
11
  platform: string;
11
12
  }
@@ -35,7 +36,8 @@ export type ChannelTool<Schema extends ObjectSchema = ObjectSchema> = {
35
36
  /**
36
37
  * Define a {@link ChannelTool} with full type inference. The handler's `args` are
37
38
  * inferred from `parameters`, and `ctx` is the generic {@link ChannelToolContext}
38
- * ({@link Thread} + optional message/user/signal + platform). Reach for
39
+ * ({@link Thread} + optional message/signal + application user + provider actor
40
+ * + platform). Reach for
39
41
  * platform power via capability-gated `thread` methods (e.g.
40
42
  * `thread.getMessages()`, `thread.lookupUser(query)`).
41
43
  *
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAgB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EACV,MAAM,EACN,eAAe,EACf,YAAY,EACb,MAAM,yBAAyB,CAAC;AAEjC,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,YAAY,GAAG,YAAY,IAAI;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;;;;;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,aAAa,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,YAAY,GAAG,YAAY,IAAI;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CACL,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAC/B,GAAG,EAAE,kBAAkB,GACtB,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,SAAS,YAAY,EAC3D,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GACxB,WAAW,CAAC,MAAM,CAAC,CAErB;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AACD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,GAChC,mBAAmB,EAAE,CAMvB;AACD,eAAO,MAAM,aAAa,uBAAiB,CAAC;AAC5C,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAI7D"}
package/dist/tools.js CHANGED
@@ -2,7 +2,8 @@ import { toJsonSchema, validateSchema } from "./standard-schema.js";
2
2
  /**
3
3
  * Define a {@link ChannelTool} with full type inference. The handler's `args` are
4
4
  * inferred from `parameters`, and `ctx` is the generic {@link ChannelToolContext}
5
- * ({@link Thread} + optional message/user/signal + platform). Reach for
5
+ * ({@link Thread} + optional message/signal + application user + provider actor
6
+ * + platform). Reach for
6
7
  * platform power via capability-gated `thread` methods (e.g.
7
8
  * `thread.getMessages()`, `thread.lookupUser(query)`).
8
9
  *
@@ -1,18 +1,12 @@
1
1
  import type { StateStore } from "./state/state-store.js";
2
- import type { PlatformUser, IncomingMessage } from "@copilotkit/channels-ui";
3
2
  export interface TranscriptEntry {
4
3
  role: "user" | "assistant";
5
4
  text: string;
6
5
  platform: string;
7
6
  threadId: string;
8
- userKey: string;
7
+ userId: string;
9
8
  ts: number;
10
9
  }
11
- export type Identity = (ctx: {
12
- adapter: string;
13
- author: PlatformUser;
14
- message: IncomingMessage;
15
- }) => string | null | Promise<string | null>;
16
10
  export interface TranscriptsConfig {
17
11
  retention?: string | number;
18
12
  maxPerUser?: number;
@@ -24,7 +18,7 @@ export declare class Transcripts {
24
18
  constructor(state: StateStore, cfg?: TranscriptsConfig);
25
19
  /**
26
20
  * Append a message to the user's transcript.
27
- * No-ops silently when no `userKey` is resolved (from `opts.userKey` or `msg.userKey`).
21
+ * No-ops silently when no canonical application user ID is supplied.
28
22
  */
29
23
  append(thread: {
30
24
  platform: string;
@@ -32,19 +26,18 @@ export declare class Transcripts {
32
26
  }, msg: {
33
27
  role?: "user" | "assistant";
34
28
  text: string;
35
- userKey?: string;
36
- }, opts?: {
37
- userKey?: string;
29
+ }, opts: {
30
+ userId: string | null;
38
31
  }): Promise<void>;
39
32
  list(q: {
40
- userKey: string;
33
+ userId: string;
41
34
  limit?: number;
42
35
  platforms?: string[];
43
36
  threadId?: string;
44
37
  roles?: ("user" | "assistant")[];
45
38
  }): Promise<TranscriptEntry[]>;
46
39
  delete(q: {
47
- userKey: string;
40
+ userId: string;
48
41
  }): Promise<{
49
42
  deleted: number;
50
43
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"transcripts.d.ts","sourceRoot":"","sources":["../src/transcripts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC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