@brantrusnak/openclaw-omadeus 1.0.1 → 1.0.3

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 (49) hide show
  1. package/README.md +5 -2
  2. package/dist/_virtual/_rolldown/runtime.js +4 -0
  3. package/dist/api.js +5 -0
  4. package/dist/index.js +14 -0
  5. package/dist/runtime-api.js +15 -0
  6. package/dist/setup-entry.js +7 -0
  7. package/dist/src/allowed-reaction-emojis.js +21 -0
  8. package/dist/src/api/auth.api.js +115 -0
  9. package/dist/src/api/channel.api.js +23 -0
  10. package/dist/src/api/message.api.js +76 -0
  11. package/dist/src/api/nugget.api.js +127 -0
  12. package/dist/src/auth.js +30 -0
  13. package/dist/src/channel.js +626 -0
  14. package/dist/src/config.js +52 -0
  15. package/dist/src/defaults.js +5 -0
  16. package/dist/src/inbound-policy.js +205 -0
  17. package/dist/src/inbound.js +97 -0
  18. package/dist/src/member-resolve.js +53 -0
  19. package/dist/src/message-handler.js +262 -0
  20. package/dist/src/nugget-lookup.js +140 -0
  21. package/dist/src/onboarding.js +363 -0
  22. package/dist/src/outbound.js +17 -0
  23. package/dist/src/reply-dispatcher.js +46 -0
  24. package/dist/src/runtime.js +5 -0
  25. package/dist/src/setup-core.js +46 -0
  26. package/dist/src/setup-surface.js +2 -0
  27. package/dist/src/socket/dolphin.socket.js +18 -0
  28. package/dist/src/socket/jaguar.socket.js +22 -0
  29. package/dist/src/socket/socket.js +153 -0
  30. package/dist/src/store.js +13 -0
  31. package/dist/src/token.js +84 -0
  32. package/dist/src/types.js +15 -0
  33. package/dist/src/utils/http.util.js +43 -0
  34. package/dist/src/utils/jwt.util.js +15 -0
  35. package/openclaw.plugin.json +144 -28
  36. package/package.json +12 -7
  37. package/src/api/auth.api.ts +0 -29
  38. package/src/api/channel.api.ts +29 -0
  39. package/src/api/nugget.api.ts +81 -10
  40. package/src/channel.ts +136 -247
  41. package/src/inbound-policy.ts +250 -0
  42. package/src/inbound.ts +20 -0
  43. package/src/member-resolve.ts +84 -0
  44. package/src/message-handler.ts +99 -53
  45. package/src/nugget-lookup.ts +67 -4
  46. package/src/onboarding.ts +283 -200
  47. package/src/setup-core.ts +10 -1
  48. package/src/socket/socket.ts +24 -11
  49. package/src/types.ts +77 -7
@@ -85,20 +85,23 @@ function extractRows(payload: unknown): Record<string, unknown>[] {
85
85
  }
86
86
 
87
87
  /**
88
- * Dolphin SEARCH on nuggetviews returns an array of nugget/task rows.
89
- * User-facing `N111` corresponds to `number: 111` on each row (not `id`).
88
+ * Dolphin SEARCH on nuggetviews arbitrary text query (e.g. N###, task title, or room id string).
89
+ * Prefer filtering results with `findNuggetRowByNumber` or `findNuggetRowByRoomId`.
90
90
  */
91
- export async function searchNuggetByNumber(
91
+ export async function searchNuggetRowsByTextQuery(
92
92
  opts: OmadeusApiOptions,
93
- params: NuggetSearchParams,
94
- ): Promise<Record<string, unknown> | null> {
95
- const query = `N${params.nuggetNumber}`;
93
+ params: { query: string; take?: number; signal?: AbortSignal },
94
+ ): Promise<Record<string, unknown>[]> {
95
+ const take = params.take ?? 100;
96
+ const q = params.query.trim();
97
+ if (!q) {
98
+ return [];
99
+ }
96
100
  const search = new URLSearchParams();
97
- search.set("take", "100");
98
-
101
+ search.set("take", String(take));
99
102
  const res = await dolphinFetch(opts, `/nuggetviews?${search.toString()}`, {
100
103
  method: "SEARCH",
101
- body: JSON.stringify({ query }),
104
+ body: JSON.stringify({ query: q }),
102
105
  signal: params.signal,
103
106
  });
104
107
  if (!res.ok) {
@@ -106,7 +109,75 @@ export async function searchNuggetByNumber(
106
109
  throw new Error(`Omadeus nugget search failed (${res.status}): ${text.slice(0, 200)}`);
107
110
  }
108
111
  const payload = (await res.json()) as unknown;
109
- const rows = extractRows(payload);
112
+ return extractRows(payload);
113
+ }
114
+
115
+ /**
116
+ * Picks a row whose private/public/shared task room id matches a Jaguar `roomId`.
117
+ */
118
+ export function findNuggetRowByRoomId(
119
+ rows: Record<string, unknown>[],
120
+ roomId: number,
121
+ ): Record<string, unknown> | undefined {
122
+ for (const row of rows) {
123
+ for (const key of ["privateRoomId", "publicRoomId", "sharedRoomId"] as const) {
124
+ if (readNumberField(row, key) === roomId) {
125
+ return row;
126
+ }
127
+ }
128
+ }
129
+ return undefined;
130
+ }
131
+
132
+ export type FindNuggetByTaskRoomParams = {
133
+ roomId: number;
134
+ roomName?: string | null;
135
+ signal?: AbortSignal;
136
+ };
137
+
138
+ /**
139
+ * Resolve the nugget/task row for a Jaguar Task or Nugget **chat room** by matching
140
+ * `privateRoomId` / `publicRoomId` / `sharedRoomId` to `roomId` in Dolphin `nuggetviews` search results.
141
+ * Tries search by `roomName` first (usually matches the task title), then by the numeric `roomId` as text.
142
+ */
143
+ export async function findNuggetByTaskChannelRoom(
144
+ opts: OmadeusApiOptions,
145
+ params: FindNuggetByTaskRoomParams,
146
+ ): Promise<Record<string, unknown> | null> {
147
+ const { roomId, roomName, signal } = params;
148
+ const tryQueries: string[] = [];
149
+ if (typeof roomName === "string" && roomName.trim()) {
150
+ tryQueries.push(roomName.trim());
151
+ }
152
+ tryQueries.push(String(roomId));
153
+ const tried = new Set<string>();
154
+ for (const query of tryQueries) {
155
+ if (tried.has(query)) {
156
+ continue;
157
+ }
158
+ tried.add(query);
159
+ const rows = await searchNuggetRowsByTextQuery(opts, { query, take: 100, signal });
160
+ const match = findNuggetRowByRoomId(rows, roomId);
161
+ if (match) {
162
+ return match;
163
+ }
164
+ }
165
+ return null;
166
+ }
167
+
168
+ /**
169
+ * Dolphin SEARCH on nuggetviews returns an array of nugget/task rows.
170
+ * User-facing `N111` corresponds to `number: 111` on each row (not `id`).
171
+ */
172
+ export async function searchNuggetByNumber(
173
+ opts: OmadeusApiOptions,
174
+ params: NuggetSearchParams,
175
+ ): Promise<Record<string, unknown> | null> {
176
+ const rows = await searchNuggetRowsByTextQuery(opts, {
177
+ query: `N${params.nuggetNumber}`,
178
+ take: 100,
179
+ signal: params.signal,
180
+ });
110
181
  const match = findNuggetRowByNumber(rows, params.nuggetNumber);
111
182
  return match ?? null;
112
183
  }