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.js CHANGED
@@ -16,6 +16,7 @@ function toUser(w) {
16
16
  userId: w.user_id,
17
17
  userName: w.user_name,
18
18
  userEmail: w.user_email,
19
+ identityIds: w.identity_ids,
19
20
  systemRole: w.system_role,
20
21
  organizationRole: w.organization_role,
21
22
  workspaceRole: w.workspace_role
@@ -157,6 +158,7 @@ var WorkerClient = class {
157
158
  callbacks;
158
159
  onError = null;
159
160
  url = "";
161
+ httpBaseUrl = "";
160
162
  workerId = "";
161
163
  uploadUrl;
162
164
  config = {
@@ -221,6 +223,16 @@ var WorkerClient = class {
221
223
  this.workerId = workerId;
222
224
  this.config = config ?? { organizationId: "", workspaceId: "", userId: "" };
223
225
  this.isIntentionallyClosed = false;
226
+ try {
227
+ const parsed = new URL(url);
228
+ parsed.protocol = parsed.protocol === "wss:" ? "https:" : "http:";
229
+ parsed.pathname = "";
230
+ parsed.search = "";
231
+ parsed.hash = "";
232
+ this.httpBaseUrl = parsed.toString().replace(/\/$/, "");
233
+ } catch {
234
+ this.httpBaseUrl = "";
235
+ }
224
236
  this.callbacks.setConnectionStatus("connecting");
225
237
  this.createConnection();
226
238
  }
@@ -280,7 +292,7 @@ var WorkerClient = class {
280
292
  }
281
293
  loadMoreThreads(limit) {
282
294
  const cursor = this.lastThreadListCursor;
283
- if (!cursor) return;
295
+ if (!cursor || this.isLoadingMore) return;
284
296
  this.isLoadingMore = true;
285
297
  this.send("thread.list", { cursor, limit });
286
298
  }
@@ -348,6 +360,7 @@ var WorkerClient = class {
348
360
  userId: this.config.userId ?? "",
349
361
  userName: this.config.userName,
350
362
  userEmail: this.config.userEmail,
363
+ identityIds: this.config.identityIds,
351
364
  systemRole: this.config.systemRole ?? "user",
352
365
  organizationRole: this.config.organizationRole ?? "member",
353
366
  workspaceRole: this.config.workspaceRole ?? "member"
@@ -421,6 +434,7 @@ var WorkerClient = class {
421
434
  user_id: this.config.userId ?? "",
422
435
  user_name: this.config.userName ?? null,
423
436
  user_email: this.config.userEmail ?? null,
437
+ identity_ids: this.config.identityIds ?? [],
424
438
  system_role: this.config.systemRole ?? "user",
425
439
  organization_role: this.config.organizationRole ?? "member",
426
440
  workspace_role: this.config.workspaceRole ?? "member"
@@ -472,7 +486,7 @@ var WorkerClient = class {
472
486
  }
473
487
  case "thread.snapshot": {
474
488
  const thread = toThread(frame.payload.thread);
475
- const events = frame.payload.events.map(toThreadEvent);
489
+ const events = this.resolveEventUrls(frame.payload.events.map(toThreadEvent));
476
490
  const runs = (frame.payload.runs ?? []).map(toRun);
477
491
  const lastEvent = events[events.length - 1];
478
492
  if (lastEvent) {
@@ -486,7 +500,7 @@ var WorkerClient = class {
486
500
  break;
487
501
  }
488
502
  case "event.append": {
489
- const events = frame.payload.events.map(toThreadEvent);
503
+ const events = this.resolveEventUrls(frame.payload.events.map(toThreadEvent));
490
504
  const resolvedClientEventIds = [];
491
505
  for (const event of events) {
492
506
  if (event.clientEventId && this.pendingOptimistic.has(event.clientEventId)) {
@@ -514,7 +528,7 @@ var WorkerClient = class {
514
528
  break;
515
529
  }
516
530
  case "event.list.result": {
517
- const events = frame.payload.events.map(toThreadEvent);
531
+ const events = this.resolveEventUrls(frame.payload.events.map(toThreadEvent));
518
532
  this.eventPaginationCursors.set(frame.payload.thread_id, frame.payload.cursor);
519
533
  this.callbacks.onEventListResult(
520
534
  frame.payload.thread_id,
@@ -580,6 +594,20 @@ var WorkerClient = class {
580
594
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
581
595
  this.ws.send(JSON.stringify(frame));
582
596
  }
597
+ /** Resolve relative URLs in event content parts against the agent's HTTP base. */
598
+ resolveEventUrls(events) {
599
+ if (!this.httpBaseUrl) return events;
600
+ const base = this.httpBaseUrl;
601
+ return events.map((event) => {
602
+ if (!event.content?.some((p) => "url" in p && p.url?.startsWith("/"))) return event;
603
+ return {
604
+ ...event,
605
+ content: event.content.map(
606
+ (part) => "url" in part && part.url?.startsWith("/") ? { ...part, url: `${base}${part.url}` } : part
607
+ )
608
+ };
609
+ });
610
+ }
583
611
  };
584
612
  function createWorkerStore() {
585
613
  return createStore()((set) => ({
@@ -712,9 +740,18 @@ function createWorkerStore() {
712
740
  onEventAppend: (threadId, newEvents) => set((s) => {
713
741
  const existing = s.events[threadId] ?? [];
714
742
  const existingIds = new Set(existing.map((e) => e.id));
715
- const unique = newEvents.filter((e) => !existingIds.has(e.id));
743
+ const updates = /* @__PURE__ */ new Map();
744
+ const appends = [];
745
+ for (const e of newEvents) {
746
+ if (existingIds.has(e.id)) {
747
+ updates.set(e.id, e);
748
+ } else {
749
+ appends.push(e);
750
+ }
751
+ }
752
+ const merged = updates.size > 0 ? existing.map((e) => updates.get(e.id) ?? e) : existing;
716
753
  return {
717
- events: { ...s.events, [threadId]: [...existing, ...unique] }
754
+ events: { ...s.events, [threadId]: [...merged, ...appends] }
718
755
  };
719
756
  }),
720
757
  reconcileEvents: (threadId, newEvents, resolvedClientEventIds) => set((s) => {
@@ -849,6 +886,7 @@ function WorkerProvider({
849
886
  userId,
850
887
  userName,
851
888
  userEmail,
889
+ identityIds,
852
890
  systemRole,
853
891
  organizationRole,
854
892
  workspaceRole,
@@ -869,6 +907,7 @@ function WorkerProvider({
869
907
  useEffect(() => {
870
908
  clientRef.current?.setUploadUrl(uploadUrl);
871
909
  }, [uploadUrl]);
910
+ const identityIdsKey = identityIds?.join(",") ?? "";
872
911
  useEffect(() => {
873
912
  if (!url || !workerId) return;
874
913
  clientRef.current?.connect(url, workerId, {
@@ -877,6 +916,7 @@ function WorkerProvider({
877
916
  userId,
878
917
  userName,
879
918
  userEmail,
919
+ identityIds: identityIdsKey ? identityIdsKey.split(",") : void 0,
880
920
  systemRole,
881
921
  organizationRole,
882
922
  workspaceRole,
@@ -891,6 +931,7 @@ function WorkerProvider({
891
931
  userId,
892
932
  userName,
893
933
  userEmail,
934
+ identityIdsKey,
894
935
  systemRole,
895
936
  organizationRole,
896
937
  workspaceRole,