dooers-agents-client 0.2.4 → 0.2.6

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/dist/main.cjs CHANGED
@@ -18,6 +18,7 @@ function toUser(w) {
18
18
  userId: w.user_id,
19
19
  userName: w.user_name,
20
20
  userEmail: w.user_email,
21
+ identityIds: w.identity_ids,
21
22
  systemRole: w.system_role,
22
23
  organizationRole: w.organization_role,
23
24
  workspaceRole: w.workspace_role
@@ -159,6 +160,7 @@ var WorkerClient = class {
159
160
  callbacks;
160
161
  onError = null;
161
162
  url = "";
163
+ httpBaseUrl = "";
162
164
  workerId = "";
163
165
  uploadUrl;
164
166
  config = {
@@ -223,6 +225,16 @@ var WorkerClient = class {
223
225
  this.workerId = workerId;
224
226
  this.config = config ?? { organizationId: "", workspaceId: "", userId: "" };
225
227
  this.isIntentionallyClosed = false;
228
+ try {
229
+ const parsed = new URL(url);
230
+ parsed.protocol = parsed.protocol === "wss:" ? "https:" : "http:";
231
+ parsed.pathname = "";
232
+ parsed.search = "";
233
+ parsed.hash = "";
234
+ this.httpBaseUrl = parsed.toString().replace(/\/$/, "");
235
+ } catch {
236
+ this.httpBaseUrl = "";
237
+ }
226
238
  this.callbacks.setConnectionStatus("connecting");
227
239
  this.createConnection();
228
240
  }
@@ -282,7 +294,7 @@ var WorkerClient = class {
282
294
  }
283
295
  loadMoreThreads(limit) {
284
296
  const cursor = this.lastThreadListCursor;
285
- if (!cursor) return;
297
+ if (!cursor || this.isLoadingMore) return;
286
298
  this.isLoadingMore = true;
287
299
  this.send("thread.list", { cursor, limit });
288
300
  }
@@ -350,6 +362,7 @@ var WorkerClient = class {
350
362
  userId: this.config.userId ?? "",
351
363
  userName: this.config.userName,
352
364
  userEmail: this.config.userEmail,
365
+ identityIds: this.config.identityIds,
353
366
  systemRole: this.config.systemRole ?? "user",
354
367
  organizationRole: this.config.organizationRole ?? "member",
355
368
  workspaceRole: this.config.workspaceRole ?? "member"
@@ -423,6 +436,7 @@ var WorkerClient = class {
423
436
  user_id: this.config.userId ?? "",
424
437
  user_name: this.config.userName ?? null,
425
438
  user_email: this.config.userEmail ?? null,
439
+ identity_ids: this.config.identityIds ?? [],
426
440
  system_role: this.config.systemRole ?? "user",
427
441
  organization_role: this.config.organizationRole ?? "member",
428
442
  workspace_role: this.config.workspaceRole ?? "member"
@@ -474,7 +488,7 @@ var WorkerClient = class {
474
488
  }
475
489
  case "thread.snapshot": {
476
490
  const thread = toThread(frame.payload.thread);
477
- const events = frame.payload.events.map(toThreadEvent);
491
+ const events = this.resolveEventUrls(frame.payload.events.map(toThreadEvent));
478
492
  const runs = (frame.payload.runs ?? []).map(toRun);
479
493
  const lastEvent = events[events.length - 1];
480
494
  if (lastEvent) {
@@ -488,7 +502,7 @@ var WorkerClient = class {
488
502
  break;
489
503
  }
490
504
  case "event.append": {
491
- const events = frame.payload.events.map(toThreadEvent);
505
+ const events = this.resolveEventUrls(frame.payload.events.map(toThreadEvent));
492
506
  const resolvedClientEventIds = [];
493
507
  for (const event of events) {
494
508
  if (event.clientEventId && this.pendingOptimistic.has(event.clientEventId)) {
@@ -516,7 +530,7 @@ var WorkerClient = class {
516
530
  break;
517
531
  }
518
532
  case "event.list.result": {
519
- const events = frame.payload.events.map(toThreadEvent);
533
+ const events = this.resolveEventUrls(frame.payload.events.map(toThreadEvent));
520
534
  this.eventPaginationCursors.set(frame.payload.thread_id, frame.payload.cursor);
521
535
  this.callbacks.onEventListResult(
522
536
  frame.payload.thread_id,
@@ -582,6 +596,20 @@ var WorkerClient = class {
582
596
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
583
597
  this.ws.send(JSON.stringify(frame));
584
598
  }
599
+ /** Resolve relative URLs in event content parts against the agent's HTTP base. */
600
+ resolveEventUrls(events) {
601
+ if (!this.httpBaseUrl) return events;
602
+ const base = this.httpBaseUrl;
603
+ return events.map((event) => {
604
+ if (!event.content?.some((p) => "url" in p && p.url?.startsWith("/"))) return event;
605
+ return {
606
+ ...event,
607
+ content: event.content.map(
608
+ (part) => "url" in part && part.url?.startsWith("/") ? { ...part, url: `${base}${part.url}` } : part
609
+ )
610
+ };
611
+ });
612
+ }
585
613
  };
586
614
  function createWorkerStore() {
587
615
  return vanilla.createStore()((set) => ({
@@ -714,9 +742,18 @@ function createWorkerStore() {
714
742
  onEventAppend: (threadId, newEvents) => set((s) => {
715
743
  const existing = s.events[threadId] ?? [];
716
744
  const existingIds = new Set(existing.map((e) => e.id));
717
- const unique = newEvents.filter((e) => !existingIds.has(e.id));
745
+ const updates = /* @__PURE__ */ new Map();
746
+ const appends = [];
747
+ for (const e of newEvents) {
748
+ if (existingIds.has(e.id)) {
749
+ updates.set(e.id, e);
750
+ } else {
751
+ appends.push(e);
752
+ }
753
+ }
754
+ const merged = updates.size > 0 ? existing.map((e) => updates.get(e.id) ?? e) : existing;
718
755
  return {
719
- events: { ...s.events, [threadId]: [...existing, ...unique] }
756
+ events: { ...s.events, [threadId]: [...merged, ...appends] }
720
757
  };
721
758
  }),
722
759
  reconcileEvents: (threadId, newEvents, resolvedClientEventIds) => set((s) => {
@@ -851,6 +888,7 @@ function WorkerProvider({
851
888
  userId,
852
889
  userName,
853
890
  userEmail,
891
+ identityIds,
854
892
  systemRole,
855
893
  organizationRole,
856
894
  workspaceRole,
@@ -871,6 +909,7 @@ function WorkerProvider({
871
909
  react.useEffect(() => {
872
910
  clientRef.current?.setUploadUrl(uploadUrl);
873
911
  }, [uploadUrl]);
912
+ const identityIdsKey = identityIds?.join(",") ?? "";
874
913
  react.useEffect(() => {
875
914
  if (!url || !workerId) return;
876
915
  clientRef.current?.connect(url, workerId, {
@@ -879,6 +918,7 @@ function WorkerProvider({
879
918
  userId,
880
919
  userName,
881
920
  userEmail,
921
+ identityIds: identityIdsKey ? identityIdsKey.split(",") : void 0,
882
922
  systemRole,
883
923
  organizationRole,
884
924
  workspaceRole,
@@ -893,6 +933,7 @@ function WorkerProvider({
893
933
  userId,
894
934
  userName,
895
935
  userEmail,
936
+ identityIdsKey,
896
937
  systemRole,
897
938
  organizationRole,
898
939
  workspaceRole,