@elizaos/agent 2.0.0-alpha.344 → 2.0.0-alpha.346
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/apps/app-lifeops/src/inbox/message-fetcher.d.ts.map +1 -1
- package/apps/app-lifeops/src/inbox/message-fetcher.js +1 -0
- package/apps/app-lifeops/src/inbox/types.d.ts +2 -0
- package/apps/app-lifeops/src/inbox/types.d.ts.map +1 -1
- package/apps/app-lifeops/src/lifeops/service-mixin-inbox.d.ts.map +1 -1
- package/apps/app-lifeops/src/lifeops/service-mixin-inbox.js +1 -0
- package/package.json +5 -5
- package/packages/agent/src/actions/manage-tasks.d.ts +1 -0
- package/packages/agent/src/actions/manage-tasks.d.ts.map +1 -1
- package/packages/agent/src/actions/manage-tasks.js +24 -0
- package/packages/agent/src/api/conversation-routes.d.ts.map +1 -1
- package/packages/agent/src/api/conversation-routes.js +42 -37
- package/packages/agent/src/api/relationships-routes.d.ts.map +1 -1
- package/packages/agent/src/api/relationships-routes.js +21 -8
- package/packages/agent/src/api/workbench-helpers.d.ts.map +1 -1
- package/packages/agent/src/api/workbench-helpers.js +7 -0
- package/packages/agent/src/runtime/plugin-collector.d.ts.map +1 -1
- package/packages/agent/src/runtime/plugin-collector.js +22 -11
- package/packages/agent/src/triggers/scheduling.d.ts.map +1 -1
- package/packages/agent/src/triggers/scheduling.js +1 -3
- package/packages/app-core/src/api/client-types-core.d.ts +6 -0
- package/packages/app-core/src/api/client-types-core.d.ts.map +1 -1
- package/packages/app-core/src/config/boot-config-store.d.ts +2 -0
- package/packages/app-core/src/config/boot-config-store.d.ts.map +1 -1
- package/packages/shared/src/contracts/lifeops.d.ts +1 -0
- package/packages/shared/src/contracts/lifeops.d.ts.map +1 -1
- package/packages/typescript/src/features/basic-capabilities/providers/actionState.d.ts.map +1 -1
- package/packages/typescript/src/features/basic-capabilities/providers/actionState.js +8 -51
- package/packages/typescript/src/features/basic-capabilities/providers/actions.d.ts.map +1 -1
- package/packages/typescript/src/features/basic-capabilities/providers/actions.js +2 -2
- package/packages/typescript/src/features/basic-capabilities/providers/non-actionable-chatter.d.ts.map +1 -1
- package/packages/typescript/src/features/basic-capabilities/providers/non-actionable-chatter.js +2 -4
- package/packages/typescript/src/features/basic-capabilities/providers/providers.d.ts.map +1 -1
- package/packages/typescript/src/features/basic-capabilities/providers/providers.js +2 -2
- package/packages/typescript/src/features/knowledge/utils.d.ts.map +1 -1
- package/packages/typescript/src/features/knowledge/utils.js +4 -3
- package/packages/typescript/src/runtime.d.ts +2 -0
- package/packages/typescript/src/runtime.d.ts.map +1 -1
- package/packages/typescript/src/runtime.js +80 -0
- package/packages/typescript/src/services/message.d.ts +3 -1
- package/packages/typescript/src/services/message.d.ts.map +1 -1
- package/packages/typescript/src/services/message.js +91 -135
- package/packages/typescript/src/utils/action-results.d.ts +33 -0
- package/packages/typescript/src/utils/action-results.d.ts.map +1 -0
- package/packages/typescript/src/utils/action-results.js +169 -0
- package/packages/typescript/src/utils/context-catalog.d.ts.map +1 -1
- package/packages/typescript/src/utils/context-catalog.js +11 -0
- package/packages/typescript/src/utils/context-routing.d.ts +3 -0
- package/packages/typescript/src/utils/context-routing.d.ts.map +1 -1
- package/packages/typescript/src/utils/context-routing.js +88 -0
- package/packages/typescript/src/utils/message-text.d.ts +5 -0
- package/packages/typescript/src/utils/message-text.d.ts.map +1 -0
- package/packages/typescript/src/utils/message-text.js +24 -0
- package/packages/typescript/src/utils.d.ts +2 -1
- package/packages/typescript/src/utils.d.ts.map +1 -1
- package/packages/typescript/src/utils.js +2 -1
- package/plugins/plugin-imessage/typescript/src/chatdb-reader.d.ts +9 -0
- package/plugins/plugin-imessage/typescript/src/chatdb-reader.d.ts.map +1 -1
- package/plugins/plugin-imessage/typescript/src/chatdb-reader.js +171 -80
- package/plugins/plugin-imessage/typescript/src/index.d.ts +1 -1
- package/plugins/plugin-imessage/typescript/src/index.d.ts.map +1 -1
- package/plugins/plugin-imessage/typescript/src/service.d.ts +7 -1
- package/plugins/plugin-imessage/typescript/src/service.d.ts.map +1 -1
- package/plugins/plugin-imessage/typescript/src/service.js +18 -11
- package/plugins/plugin-imessage/typescript/src/setup-routes.d.ts +2 -1
- package/plugins/plugin-imessage/typescript/src/setup-routes.d.ts.map +1 -1
- package/plugins/plugin-imessage/typescript/src/setup-routes.js +55 -2
- package/plugins/plugin-imessage/typescript/src/types.d.ts +8 -0
- package/plugins/plugin-imessage/typescript/src/types.d.ts.map +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolveActionContexts, resolveProviderContexts, } from "./context-catalog";
|
|
2
|
+
import { normalizeUserMessageText } from "./message-text";
|
|
2
3
|
export const AVAILABLE_CONTEXTS_STATE_KEY = "availableContexts";
|
|
3
4
|
export const CONTEXT_ROUTING_METADATA_KEY = "__responseContext";
|
|
4
5
|
export const CONTEXT_ROUTING_STATE_KEY = "__contextRouting";
|
|
@@ -107,6 +108,9 @@ export function getActiveRoutingContexts(routing) {
|
|
|
107
108
|
contextSet.add("general");
|
|
108
109
|
return Array.from(contextSet);
|
|
109
110
|
}
|
|
111
|
+
export function getActiveRoutingContextsForTurn(state, message) {
|
|
112
|
+
return getActiveRoutingContexts(mergeContextRouting(state, message));
|
|
113
|
+
}
|
|
110
114
|
export function shouldIncludeByContext(declaredContexts, activeContexts) {
|
|
111
115
|
if (!declaredContexts || declaredContexts.length === 0) {
|
|
112
116
|
return true;
|
|
@@ -152,6 +156,90 @@ export function deriveAvailableContexts(actions, providers) {
|
|
|
152
156
|
}
|
|
153
157
|
return Array.from(contextSet).sort((a, b) => `${a}`.localeCompare(`${b}`));
|
|
154
158
|
}
|
|
159
|
+
const CONTEXT_SIGNALS = [
|
|
160
|
+
{
|
|
161
|
+
context: "code",
|
|
162
|
+
patterns: [
|
|
163
|
+
/\b(repo|repository|codebase|branch|commit|pull request|pr|diff|workspace|file|directory)\b/u,
|
|
164
|
+
/\b(code|coding|implement|debug|fix|refactor|patch|test|typecheck|lint|build|component|api|server|client)\b/u,
|
|
165
|
+
/\b(task agents?|sub-?agents?|coding agents?|codex|claude code|spawn an? agent|agent running|what are you working on)\b/u,
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
context: "automation",
|
|
170
|
+
patterns: [
|
|
171
|
+
/\b(schedule|remind|reminder|cron|workflow|automate|automation|run this|execute|deploy|release|monitor)\b/u,
|
|
172
|
+
/\b(task agents?|sub-?agents?|agent running|pause that|resume that|stop that|continue that|what are you working on)\b/u,
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
context: "knowledge",
|
|
177
|
+
patterns: [
|
|
178
|
+
/\b(uploaded|document|file|pdf|knowledge|remember|recall|search|lookup|find|summari[sz]e|analy[sz]e|research)\b/u,
|
|
179
|
+
/\b(what is|what was|where is|tell me about|explain)\b/u,
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
context: "browser",
|
|
184
|
+
patterns: [
|
|
185
|
+
/\b(browser|browse|website|web page|url|click|type into|screenshot|navigate|extract page)\b/u,
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
context: "media",
|
|
190
|
+
patterns: [
|
|
191
|
+
/\b(image|picture|photo|video|audio|voice|transcribe|screenshot|draw|generate an image)\b/u,
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
context: "wallet",
|
|
196
|
+
patterns: [
|
|
197
|
+
/\b(wallet|token|swap|bridge|stake|unstake|balance|portfolio|transaction|sign message|contract)\b/u,
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
context: "social",
|
|
202
|
+
patterns: [
|
|
203
|
+
/\b(message|dm|email|inbox|contact|relationship|follow up|calendar|meeting|call|send .* to)\b/u,
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
context: "system",
|
|
208
|
+
patterns: [
|
|
209
|
+
/\b(settings?|configure|configuration|plugin|secret|api key|model provider|oauth|login|auth)\b/u,
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
];
|
|
213
|
+
export function inferContextRoutingFromText(text) {
|
|
214
|
+
const normalized = normalizeUserMessageText({
|
|
215
|
+
content: { text: text ?? "" },
|
|
216
|
+
});
|
|
217
|
+
if (!normalized) {
|
|
218
|
+
return { primaryContext: "general", secondaryContexts: [] };
|
|
219
|
+
}
|
|
220
|
+
const scored = CONTEXT_SIGNALS.map((signal) => ({
|
|
221
|
+
context: signal.context,
|
|
222
|
+
score: signal.patterns.reduce((score, pattern) => score + (pattern.test(normalized) ? 1 : 0), 0),
|
|
223
|
+
}))
|
|
224
|
+
.filter((entry) => entry.score > 0)
|
|
225
|
+
.sort((left, right) => right.score - left.score);
|
|
226
|
+
if (scored.length === 0) {
|
|
227
|
+
return { primaryContext: "general", secondaryContexts: [] };
|
|
228
|
+
}
|
|
229
|
+
const primaryContext = scored[0].context;
|
|
230
|
+
const secondaryContexts = scored
|
|
231
|
+
.slice(1)
|
|
232
|
+
.filter((entry) => entry.score >= Math.max(1, scored[0].score - 1))
|
|
233
|
+
.map((entry) => entry.context);
|
|
234
|
+
return { primaryContext, secondaryContexts };
|
|
235
|
+
}
|
|
236
|
+
export function inferContextRoutingFromMessage(message) {
|
|
237
|
+
return inferContextRoutingFromText(typeof message.content === "string"
|
|
238
|
+
? message.content
|
|
239
|
+
: typeof message.content?.text === "string"
|
|
240
|
+
? message.content.text
|
|
241
|
+
: "");
|
|
242
|
+
}
|
|
155
243
|
export function attachAvailableContexts(state, runtime) {
|
|
156
244
|
const availableContexts = deriveAvailableContexts(runtime.actions, runtime.providers);
|
|
157
245
|
return {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Memory } from "../types/memory";
|
|
2
|
+
export declare function extractUserText(raw: string): string;
|
|
3
|
+
export declare function getUserMessageText(message: Pick<Memory, "content"> | null | undefined): string;
|
|
4
|
+
export declare function normalizeUserMessageText(message: Pick<Memory, "content"> | null | undefined): string;
|
|
5
|
+
//# sourceMappingURL=message-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-text.d.ts","sourceRoot":"","sources":["../../../../../../typescript/src/utils/message-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAO9C,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CASnD;AAED,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,GACjD,MAAM,CAQR;AAED,wBAAgB,wBAAwB,CACvC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,GACjD,MAAM,CAER"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const KNOWLEDGE_AUGMENTATION_PREFIX = "Answer the user request using the contextual knowledge";
|
|
2
|
+
const USER_REQUEST_WRAPPER = /<user_request>\s*([\s\S]*?)\s*<\/user_request>/i;
|
|
3
|
+
const LANGUAGE_INSTRUCTION_SUFFIX = /\n*\[language instruction:[^\]]*\]\s*$/i;
|
|
4
|
+
export function extractUserText(raw) {
|
|
5
|
+
let text = raw;
|
|
6
|
+
if (text.trimStart().startsWith(KNOWLEDGE_AUGMENTATION_PREFIX)) {
|
|
7
|
+
const match = text.match(USER_REQUEST_WRAPPER);
|
|
8
|
+
if (match?.[1]) {
|
|
9
|
+
text = match[1];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return text.replace(LANGUAGE_INSTRUCTION_SUFFIX, "").trim();
|
|
13
|
+
}
|
|
14
|
+
export function getUserMessageText(message) {
|
|
15
|
+
const raw = typeof message?.content === "string"
|
|
16
|
+
? message.content
|
|
17
|
+
: typeof message?.content?.text === "string"
|
|
18
|
+
? message.content.text
|
|
19
|
+
: "";
|
|
20
|
+
return extractUserText(raw);
|
|
21
|
+
}
|
|
22
|
+
export function normalizeUserMessageText(message) {
|
|
23
|
+
return getUserMessageText(message).toLowerCase().replace(/\s+/g, " ").trim();
|
|
24
|
+
}
|
|
@@ -185,8 +185,9 @@ export declare function stringToUuid(target: string | number): UUID;
|
|
|
185
185
|
*/
|
|
186
186
|
export declare function prewarmUuidCache(values: string[]): Promise<void>;
|
|
187
187
|
export declare const getContentTypeFromMimeType: (mimeType: string) => ContentType | undefined;
|
|
188
|
-
export { AVAILABLE_CONTEXTS_STATE_KEY, attachAvailableContexts, CONTEXT_ROUTING_METADATA_KEY, CONTEXT_ROUTING_STATE_KEY, type ContextRoutingDecision, deriveAvailableContexts, getActiveRoutingContexts, getContextRoutingFromMessage, getContextRoutingFromState, mergeContextRouting, parseContextList, parseContextRoutingMetadata, setContextRoutingMetadata, shouldIncludeByContext, } from "./utils/context-routing";
|
|
188
|
+
export { AVAILABLE_CONTEXTS_STATE_KEY, attachAvailableContexts, CONTEXT_ROUTING_METADATA_KEY, CONTEXT_ROUTING_STATE_KEY, type ContextRoutingDecision, deriveAvailableContexts, getActiveRoutingContexts, getActiveRoutingContextsForTurn, getContextRoutingFromMessage, getContextRoutingFromState, inferContextRoutingFromMessage, inferContextRoutingFromText, mergeContextRouting, parseContextList, parseContextRoutingMetadata, setContextRoutingMetadata, shouldIncludeByContext, } from "./utils/context-routing";
|
|
189
189
|
export { extractAndParseJSONObjectFromText } from "./utils/json-llm";
|
|
190
|
+
export { extractUserText, getUserMessageText, normalizeUserMessageText, } from "./utils/message-text";
|
|
190
191
|
export { getLocalServerUrl } from "./utils/node";
|
|
191
192
|
export { extractFirstSentence, hasFirstSentence } from "./utils/text-splitting";
|
|
192
193
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../typescript/src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEX,MAAM,EACN,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CAmBT;AAWD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAGxD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA0B1D;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAUtE;AAyND,eAAO,MAAM,0BAA0B,GACtC,UAAU,MAAM,KACd,WAAW,GAAG,SAYhB,CAAC;AAEF,OAAO,EACN,4BAA4B,EAC5B,uBAAuB,EACvB,4BAA4B,EAC5B,yBAAyB,EACzB,KAAK,sBAAsB,EAC3B,uBAAuB,EACvB,wBAAwB,EACxB,+BAA+B,EAC/B,4BAA4B,EAC5B,0BAA0B,EAC1B,8BAA8B,EAC9B,2BAA2B,EAC3B,mBAAmB,EACnB,gBAAgB,EAChB,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iCAAiC,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EACN,eAAe,EACf,kBAAkB,EAClB,wBAAwB,GACxB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -1111,8 +1111,9 @@ export const getContentTypeFromMimeType = (mimeType) => {
|
|
|
1111
1111
|
}
|
|
1112
1112
|
return undefined;
|
|
1113
1113
|
};
|
|
1114
|
-
export { AVAILABLE_CONTEXTS_STATE_KEY, attachAvailableContexts, CONTEXT_ROUTING_METADATA_KEY, CONTEXT_ROUTING_STATE_KEY, deriveAvailableContexts, getActiveRoutingContexts, getContextRoutingFromMessage, getContextRoutingFromState, mergeContextRouting, parseContextList, parseContextRoutingMetadata, setContextRoutingMetadata, shouldIncludeByContext, } from "./utils/context-routing";
|
|
1114
|
+
export { AVAILABLE_CONTEXTS_STATE_KEY, attachAvailableContexts, CONTEXT_ROUTING_METADATA_KEY, CONTEXT_ROUTING_STATE_KEY, deriveAvailableContexts, getActiveRoutingContexts, getActiveRoutingContextsForTurn, getContextRoutingFromMessage, getContextRoutingFromState, inferContextRoutingFromMessage, inferContextRoutingFromText, mergeContextRouting, parseContextList, parseContextRoutingMetadata, setContextRoutingMetadata, shouldIncludeByContext, } from "./utils/context-routing";
|
|
1115
1115
|
export { extractAndParseJSONObjectFromText } from "./utils/json-llm";
|
|
1116
|
+
export { extractUserText, getUserMessageText, normalizeUserMessageText, } from "./utils/message-text";
|
|
1116
1117
|
// `export * from "./utils"` (in index.node.ts etc.) resolves to this file, not
|
|
1117
1118
|
// to a `./utils/index.ts`. Any helper in the `utils/` directory that needs to be
|
|
1118
1119
|
// reachable from `@elizaos/core` must be re-exported here.
|
|
@@ -197,6 +197,15 @@ export interface ChatDbReader {
|
|
|
197
197
|
* local Apple account, converted to JavaScript epoch milliseconds.
|
|
198
198
|
*/
|
|
199
199
|
getLatestOwnMessageTimestamp(): number | null;
|
|
200
|
+
/**
|
|
201
|
+
* Return the newest messages in chronological order, optionally scoped
|
|
202
|
+
* to a single chat identifier. Unlike `fetchNewMessages`, this is for
|
|
203
|
+
* ad-hoc inspection and UI reads rather than cursor-based polling.
|
|
204
|
+
*/
|
|
205
|
+
listMessages(options?: {
|
|
206
|
+
chatId?: string;
|
|
207
|
+
limit?: number;
|
|
208
|
+
}): ChatDbMessage[];
|
|
200
209
|
/**
|
|
201
210
|
* List every chat the database knows about, joined with participant
|
|
202
211
|
* handles. Reads from `chat`, `chat_handle_join`, and `handle`. This
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatdb-reader.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/chatdb-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;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WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC7B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,wBAAwB,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IACrE;;;;;OAKG;IACH,cAAc,IAAI,MAAM,CAAC;IACzB;;;OAGG;IACH,4BAA4B,IAAI,MAAM,GAAG,IAAI,CAAC;IAC9C;;;;;OAKG;IACH,SAAS,IAAI,iBAAiB,EAAE,CAAC;IACjC,sDAAsD;IACtD,KAAK,IAAI,IAAI,CAAC;CACf;AAqBD,wBAAgB,wBAAwB,CACtC,MAAM,GAAE,MAA6B,GACpC,iBAAiB,GAAG,IAAI,CAE1B;AAqED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,MAAM,GAAE,MAA6B,GACpC,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"chatdb-reader.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/chatdb-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D;;;GAGG;AACH,eAAO,MAAM,oBAAoB,QAAoD,CAAC;AAEtF,eAAO,MAAM,mCAAmC,6EAC4B,CAAC;AAE7E,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,oBAAoB,GAAG,aAAa,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,E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E,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,CAAC;IACrE;;;;;OAKG;IACH,cAAc,IAAI,MAAM,CAAC;IACzB;;;OAGG;IACH,4BAA4B,IAAI,MAAM,GAAG,IAAI,CAAC;IAC9C;;;;OAIG;IACH,YAAY,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,aAAa,EAAE,CAAC;IAC7E;;;;;OAKG;IACH,SAAS,IAAI,iBAAiB,EAAE,CAAC;IACjC,sDAAsD;IACtD,KAAK,IAAI,IAAI,CAAC;CACf;AAqBD,wBAAgB,wBAAwB,CACtC,MAAM,GAAE,MAA6B,GACpC,iBAAiB,GAAG,IAAI,CAE1B;AAqED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,MAAM,GAAE,MAA6B,GACpC,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAsb9B"}
|
|
@@ -380,6 +380,73 @@ export async function openChatDb(dbPath = DEFAULT_CHAT_DB_PATH) {
|
|
|
380
380
|
// Used once on service start to seed the polling cursor.
|
|
381
381
|
const tipStmt = db.query("SELECT MAX(ROWID) AS max_row_id FROM message");
|
|
382
382
|
const latestOwnMessageStmt = db.query("SELECT MAX(date) AS max_apple_date FROM message WHERE is_from_me = 1");
|
|
383
|
+
const recentMessagesStmt = db.query(`
|
|
384
|
+
SELECT
|
|
385
|
+
m.ROWID AS row_id,
|
|
386
|
+
m.guid AS guid,
|
|
387
|
+
m.text AS text,
|
|
388
|
+
m.attributedBody AS attributed_body,
|
|
389
|
+
m.date AS apple_date,
|
|
390
|
+
m.date_read AS apple_date_read,
|
|
391
|
+
m.date_edited AS apple_date_edited,
|
|
392
|
+
m.date_retracted AS apple_date_retracted,
|
|
393
|
+
m.is_from_me AS is_from_me,
|
|
394
|
+
m.is_read AS is_read,
|
|
395
|
+
m.is_sent AS is_sent,
|
|
396
|
+
m.is_delivered AS is_delivered,
|
|
397
|
+
m.item_type AS item_type,
|
|
398
|
+
m.reply_to_guid AS reply_to_guid,
|
|
399
|
+
m.associated_message_guid AS associated_message_guid,
|
|
400
|
+
m.associated_message_type AS associated_message_type,
|
|
401
|
+
m.associated_message_emoji AS associated_message_emoji,
|
|
402
|
+
m.cache_has_attachments AS cache_has_attachments,
|
|
403
|
+
m.service AS message_service,
|
|
404
|
+
h.id AS handle,
|
|
405
|
+
h.service AS handle_service,
|
|
406
|
+
c.chat_identifier AS chat_identifier,
|
|
407
|
+
c.display_name AS display_name,
|
|
408
|
+
c.style AS chat_style
|
|
409
|
+
FROM message m
|
|
410
|
+
LEFT JOIN handle h ON m.handle_id = h.ROWID
|
|
411
|
+
LEFT JOIN chat_message_join cmj ON m.ROWID = cmj.message_id
|
|
412
|
+
LEFT JOIN chat c ON cmj.chat_id = c.ROWID
|
|
413
|
+
ORDER BY m.ROWID DESC
|
|
414
|
+
LIMIT ?
|
|
415
|
+
`);
|
|
416
|
+
const recentMessagesByChatStmt = db.query(`
|
|
417
|
+
SELECT
|
|
418
|
+
m.ROWID AS row_id,
|
|
419
|
+
m.guid AS guid,
|
|
420
|
+
m.text AS text,
|
|
421
|
+
m.attributedBody AS attributed_body,
|
|
422
|
+
m.date AS apple_date,
|
|
423
|
+
m.date_read AS apple_date_read,
|
|
424
|
+
m.date_edited AS apple_date_edited,
|
|
425
|
+
m.date_retracted AS apple_date_retracted,
|
|
426
|
+
m.is_from_me AS is_from_me,
|
|
427
|
+
m.is_read AS is_read,
|
|
428
|
+
m.is_sent AS is_sent,
|
|
429
|
+
m.is_delivered AS is_delivered,
|
|
430
|
+
m.item_type AS item_type,
|
|
431
|
+
m.reply_to_guid AS reply_to_guid,
|
|
432
|
+
m.associated_message_guid AS associated_message_guid,
|
|
433
|
+
m.associated_message_type AS associated_message_type,
|
|
434
|
+
m.associated_message_emoji AS associated_message_emoji,
|
|
435
|
+
m.cache_has_attachments AS cache_has_attachments,
|
|
436
|
+
m.service AS message_service,
|
|
437
|
+
h.id AS handle,
|
|
438
|
+
h.service AS handle_service,
|
|
439
|
+
c.chat_identifier AS chat_identifier,
|
|
440
|
+
c.display_name AS display_name,
|
|
441
|
+
c.style AS chat_style
|
|
442
|
+
FROM message m
|
|
443
|
+
LEFT JOIN handle h ON m.handle_id = h.ROWID
|
|
444
|
+
LEFT JOIN chat_message_join cmj ON m.ROWID = cmj.message_id
|
|
445
|
+
LEFT JOIN chat c ON cmj.chat_id = c.ROWID
|
|
446
|
+
WHERE c.chat_identifier = ?
|
|
447
|
+
ORDER BY m.ROWID DESC
|
|
448
|
+
LIMIT ?
|
|
449
|
+
`);
|
|
383
450
|
// List-chats statement: every chat joined to handles via
|
|
384
451
|
// chat_handle_join, grouped so each chat returns one row with an
|
|
385
452
|
// aggregated participant list.
|
|
@@ -399,6 +466,88 @@ export async function openChatDb(dbPath = DEFAULT_CHAT_DB_PATH) {
|
|
|
399
466
|
ORDER BY c.last_read_message_timestamp DESC
|
|
400
467
|
`);
|
|
401
468
|
let closed = false;
|
|
469
|
+
function materializeMessages(rows) {
|
|
470
|
+
const out = [];
|
|
471
|
+
let undecodable = 0;
|
|
472
|
+
for (const row of rows) {
|
|
473
|
+
// Resolve the visible text: prefer the plain `text` column, fall
|
|
474
|
+
// back to decoding `attributedBody`, then empty string.
|
|
475
|
+
let text = "";
|
|
476
|
+
if (row.text && row.text.length > 0) {
|
|
477
|
+
text = row.text;
|
|
478
|
+
}
|
|
479
|
+
else if (row.attributed_body) {
|
|
480
|
+
const decoded = decodeAttributedBody(row.attributed_body);
|
|
481
|
+
if (decoded != null) {
|
|
482
|
+
text = decoded;
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
undecodable++;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
// Classify the row. Reactions get their own kind + a parsed
|
|
489
|
+
// reaction payload; system messages (group add/remove/rename)
|
|
490
|
+
// surface as `"system"` so the caller can log or ignore.
|
|
491
|
+
const assocType = row.associated_message_type ?? 0;
|
|
492
|
+
let kind = "text";
|
|
493
|
+
let reaction = null;
|
|
494
|
+
if (assocType >= 2000 && assocType < 4000) {
|
|
495
|
+
kind = "reaction";
|
|
496
|
+
reaction = parseReaction(row);
|
|
497
|
+
}
|
|
498
|
+
else if (row.item_type != null && row.item_type !== 0) {
|
|
499
|
+
kind = "system";
|
|
500
|
+
}
|
|
501
|
+
// Attachments — only fetched when the cache bit indicates any.
|
|
502
|
+
let attachments = [];
|
|
503
|
+
if (row.cache_has_attachments === 1) {
|
|
504
|
+
try {
|
|
505
|
+
const attRows = attachmentsStmt.all(row.row_id);
|
|
506
|
+
attachments = attRows.map((a) => ({
|
|
507
|
+
guid: a.guid,
|
|
508
|
+
filename: a.transfer_name ?? a.filename ?? null,
|
|
509
|
+
uti: a.uti,
|
|
510
|
+
mimeType: a.mime_type,
|
|
511
|
+
totalBytes: a.total_bytes,
|
|
512
|
+
isSticker: a.is_sticker === 1,
|
|
513
|
+
}));
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
logger.debug(`[imessage] attachment query failed for rowid=${row.row_id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
// Service resolution: prefer the message row's own service field,
|
|
520
|
+
// fall back to the handle's service (stable across messages from
|
|
521
|
+
// the same sender), else unknown.
|
|
522
|
+
const service = row.message_service ?? row.handle_service ?? null;
|
|
523
|
+
out.push({
|
|
524
|
+
rowId: row.row_id,
|
|
525
|
+
guid: row.guid,
|
|
526
|
+
text,
|
|
527
|
+
kind,
|
|
528
|
+
handle: row.handle ?? "",
|
|
529
|
+
chatId: row.chat_identifier ?? "",
|
|
530
|
+
chatType: row.chat_style === 43 ? "group" : "direct",
|
|
531
|
+
displayName: row.display_name,
|
|
532
|
+
timestamp: appleDateToJsMs(row.apple_date),
|
|
533
|
+
isFromMe: row.is_from_me === 1,
|
|
534
|
+
service,
|
|
535
|
+
isSent: row.is_sent === 1,
|
|
536
|
+
isDelivered: row.is_delivered === 1,
|
|
537
|
+
isRead: row.is_read === 1,
|
|
538
|
+
dateRead: appleDateToJsMs(row.apple_date_read ?? 0),
|
|
539
|
+
dateEdited: appleDateToJsMs(row.apple_date_edited ?? 0),
|
|
540
|
+
dateRetracted: appleDateToJsMs(row.apple_date_retracted ?? 0),
|
|
541
|
+
replyToGuid: row.reply_to_guid,
|
|
542
|
+
reaction,
|
|
543
|
+
attachments,
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
if (undecodable > 0) {
|
|
547
|
+
logger.debug(`[imessage] chat.db poll: ${undecodable} row(s) had attributedBody that could not be decoded; their text is empty`);
|
|
548
|
+
}
|
|
549
|
+
return out;
|
|
550
|
+
}
|
|
402
551
|
return {
|
|
403
552
|
fetchNewMessages(sinceRowId, limit) {
|
|
404
553
|
if (closed)
|
|
@@ -411,86 +560,7 @@ export async function openChatDb(dbPath = DEFAULT_CHAT_DB_PATH) {
|
|
|
411
560
|
logger.error(`[imessage] chat.db query failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
412
561
|
return [];
|
|
413
562
|
}
|
|
414
|
-
|
|
415
|
-
let undecodable = 0;
|
|
416
|
-
for (const row of rows) {
|
|
417
|
-
// Resolve the visible text: prefer the plain `text` column, fall
|
|
418
|
-
// back to decoding `attributedBody`, then empty string.
|
|
419
|
-
let text = "";
|
|
420
|
-
if (row.text && row.text.length > 0) {
|
|
421
|
-
text = row.text;
|
|
422
|
-
}
|
|
423
|
-
else if (row.attributed_body) {
|
|
424
|
-
const decoded = decodeAttributedBody(row.attributed_body);
|
|
425
|
-
if (decoded != null) {
|
|
426
|
-
text = decoded;
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
undecodable++;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
// Classify the row. Reactions get their own kind + a parsed
|
|
433
|
-
// reaction payload; system messages (group add/remove/rename)
|
|
434
|
-
// surface as `"system"` so the caller can log or ignore.
|
|
435
|
-
const assocType = row.associated_message_type ?? 0;
|
|
436
|
-
let kind = "text";
|
|
437
|
-
let reaction = null;
|
|
438
|
-
if (assocType >= 2000 && assocType < 4000) {
|
|
439
|
-
kind = "reaction";
|
|
440
|
-
reaction = parseReaction(row);
|
|
441
|
-
}
|
|
442
|
-
else if (row.item_type != null && row.item_type !== 0) {
|
|
443
|
-
kind = "system";
|
|
444
|
-
}
|
|
445
|
-
// Attachments — only fetched when the cache bit indicates any.
|
|
446
|
-
let attachments = [];
|
|
447
|
-
if (row.cache_has_attachments === 1) {
|
|
448
|
-
try {
|
|
449
|
-
const attRows = attachmentsStmt.all(row.row_id);
|
|
450
|
-
attachments = attRows.map((a) => ({
|
|
451
|
-
guid: a.guid,
|
|
452
|
-
filename: a.transfer_name ?? a.filename ?? null,
|
|
453
|
-
uti: a.uti,
|
|
454
|
-
mimeType: a.mime_type,
|
|
455
|
-
totalBytes: a.total_bytes,
|
|
456
|
-
isSticker: a.is_sticker === 1,
|
|
457
|
-
}));
|
|
458
|
-
}
|
|
459
|
-
catch (error) {
|
|
460
|
-
logger.debug(`[imessage] attachment query failed for rowid=${row.row_id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
// Service resolution: prefer the message row's own service field,
|
|
464
|
-
// fall back to the handle's service (stable across messages from
|
|
465
|
-
// the same sender), else unknown.
|
|
466
|
-
const service = row.message_service ?? row.handle_service ?? null;
|
|
467
|
-
out.push({
|
|
468
|
-
rowId: row.row_id,
|
|
469
|
-
guid: row.guid,
|
|
470
|
-
text,
|
|
471
|
-
kind,
|
|
472
|
-
handle: row.handle ?? "",
|
|
473
|
-
chatId: row.chat_identifier ?? "",
|
|
474
|
-
chatType: row.chat_style === 43 ? "group" : "direct",
|
|
475
|
-
displayName: row.display_name,
|
|
476
|
-
timestamp: appleDateToJsMs(row.apple_date),
|
|
477
|
-
isFromMe: row.is_from_me === 1,
|
|
478
|
-
service,
|
|
479
|
-
isSent: row.is_sent === 1,
|
|
480
|
-
isDelivered: row.is_delivered === 1,
|
|
481
|
-
isRead: row.is_read === 1,
|
|
482
|
-
dateRead: appleDateToJsMs(row.apple_date_read ?? 0),
|
|
483
|
-
dateEdited: appleDateToJsMs(row.apple_date_edited ?? 0),
|
|
484
|
-
dateRetracted: appleDateToJsMs(row.apple_date_retracted ?? 0),
|
|
485
|
-
replyToGuid: row.reply_to_guid,
|
|
486
|
-
reaction,
|
|
487
|
-
attachments,
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
if (undecodable > 0) {
|
|
491
|
-
logger.debug(`[imessage] chat.db poll: ${undecodable} row(s) had attributedBody that could not be decoded; their text is empty`);
|
|
492
|
-
}
|
|
493
|
-
return out;
|
|
563
|
+
return materializeMessages(rows);
|
|
494
564
|
},
|
|
495
565
|
getLatestRowId() {
|
|
496
566
|
if (closed)
|
|
@@ -517,6 +587,27 @@ export async function openChatDb(dbPath = DEFAULT_CHAT_DB_PATH) {
|
|
|
517
587
|
return null;
|
|
518
588
|
}
|
|
519
589
|
},
|
|
590
|
+
listMessages(options = {}) {
|
|
591
|
+
if (closed)
|
|
592
|
+
return [];
|
|
593
|
+
const chatId = options.chatId?.trim();
|
|
594
|
+
const requestedLimit = typeof options.limit === "number" && Number.isFinite(options.limit) ? options.limit : 50;
|
|
595
|
+
const limit = Math.max(1, Math.trunc(requestedLimit));
|
|
596
|
+
let rows;
|
|
597
|
+
try {
|
|
598
|
+
rows = chatId
|
|
599
|
+
? recentMessagesByChatStmt.all(chatId, limit)
|
|
600
|
+
: recentMessagesStmt.all(limit);
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
logger.error(`[imessage] chat.db listMessages query failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
604
|
+
return [];
|
|
605
|
+
}
|
|
606
|
+
// Queries run DESC for efficiency on "latest N" reads. Reverse
|
|
607
|
+
// back to chronological order so API/UI callers can render in the
|
|
608
|
+
// natural oldest→newest sequence without a second sort.
|
|
609
|
+
return materializeMessages(rows).reverse();
|
|
610
|
+
},
|
|
520
611
|
listChats() {
|
|
521
612
|
if (closed)
|
|
522
613
|
return [];
|
|
@@ -9,7 +9,7 @@ import { sendMessage } from "./actions/index.js";
|
|
|
9
9
|
import { chatContextProvider, contactsProvider } from "./providers/index.js";
|
|
10
10
|
import { chatDbMessageToPublicShape, IMessageService, parseChatsFromAppleScript, parseMessagesFromAppleScript } from "./service.js";
|
|
11
11
|
export { DEFAULT_ACCOUNT_ID, type IMessageAccountConfig, type IMessageGroupConfig, type IMessageMultiAccountConfig, isIMessageMentionRequired, isIMessageUserAllowed, isMultiAccountEnabled, listEnabledIMessageAccounts, listIMessageAccountIds, normalizeAccountId, type ResolvedIMessageAccount, resolveDefaultIMessageAccountId, resolveIMessageAccount, resolveIMessageGroupConfig, } from "./accounts.js";
|
|
12
|
-
export { appleDateToJsMs, type
|
|
12
|
+
export { appleDateToJsMs, type ChatDbAccessIssue, type ChatDbMessage, type ChatDbReader, createFullDiskAccessAction, DEFAULT_CHAT_DB_PATH, getLastChatDbAccessIssue, MACOS_FULL_DISK_ACCESS_SETTINGS_URL, openChatDb, } from "./chatdb-reader.js";
|
|
13
13
|
export { addContact, type ContactPatch, type ContactsMap, deleteContact, type FullContact, listAllContacts, loadContacts, type NewContactInput, normalizeContactHandle, parseContactsOutput, type ResolvedContact, updateContact, } from "./contacts-reader.js";
|
|
14
14
|
export { createIMessageRpcClient, DEFAULT_PROBE_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, getChatInfo, getContactInfo, getMessages, type IMessageAttachment, type IMessageChat, type IMessageContact, type IMessageMessage, IMessageRpcClient, type IMessageRpcClientOptions, type IMessageRpcError, type IMessageRpcNotification, type IMessageRpcResponse, listChats, listContacts, probeIMessageRpc, sendIMessageRpc, } from "./rpc.js";
|
|
15
15
|
export * from "./types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EACL,0BAA0B,EAC1B,eAAe,EACf,yBAAyB,EACzB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAItB,OAAO,EACL,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,+BAA+B,EAC/B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EACL,0BAA0B,EAC1B,eAAe,EACf,yBAAyB,EACzB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAItB,OAAO,EACL,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,yBAAyB,EACzB,qBAAqB,EACrB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,+BAA+B,EAC/B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,eAAe,EACf,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,EACxB,mCAAmC,EACnC,UAAU,GACX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,UAAU,EACV,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,aAAa,EACb,KAAK,WAAW,EAChB,eAAe,EACf,YAAY,EACZ,KAAK,eAAe,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,eAAe,EACpB,aAAa,GACd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,WAAW,EACX,cAAc,EACd,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,UAAU,CAAC;AAElB,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,4BAA4B,EAC5B,WAAW,GACZ,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,cAAc,EAAE,MAiCrB,CAAC;AAEF,eAAe,cAAc,CAAC;AAG9B,YAAY,EACV,cAAc,EACd,gCAAgC,GACjC,MAAM,aAAa,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { type IAgentRuntime, Service } from "@elizaos/core";
|
|
5
5
|
import { type ChatDbMessage } from "./chatdb-reader.js";
|
|
6
6
|
import { type ContactPatch, type ContactsMap, type FullContact, type NewContactInput } from "./contacts-reader.js";
|
|
7
|
-
import { type IIMessageService, type IMessageChat, type
|
|
7
|
+
import { type IIMessageService, type IMessageChat, type IMessageListMessagesOptions, type IMessageMessage, type IMessageSendOptions, type IMessageSendResult, type IMessageServiceStatus, type IMessageSettings } from "./types.js";
|
|
8
8
|
/**
|
|
9
9
|
* iMessage service for ElizaOS agents.
|
|
10
10
|
* Note: This only works on macOS.
|
|
@@ -94,6 +94,12 @@ export declare class IMessageService extends Service implements IIMessageService
|
|
|
94
94
|
* granted, etc.).
|
|
95
95
|
*/
|
|
96
96
|
getRecentMessages(limit?: number): Promise<IMessageMessage[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Return the newest messages in chronological order, optionally scoped
|
|
99
|
+
* to a single chat identifier. Returns an empty array if chat.db is not
|
|
100
|
+
* available and the connector is currently running in send-only mode.
|
|
101
|
+
*/
|
|
102
|
+
getMessages(options?: IMessageListMessagesOptions): Promise<IMessageMessage[]>;
|
|
97
103
|
/**
|
|
98
104
|
* List every chat the Messages.app database knows about, joined with
|
|
99
105
|
* participant handles. Returns an empty list if the chat.db reader is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAQL,KAAK,aAAa,EAIlB,OAAO,EACR,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,KAAK,WAAW,EAGhB,KAAK,eAAe,EAGrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAGL,KAAK,gBAAgB,EAErB,KAAK,YAAY,EAKjB,KAAK,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/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A6GhC;AAkBD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,aAAa,GAAG,eAAe,CAiB9E;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,EAAE,CA0C9E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CA+CxE"}
|
|
@@ -156,9 +156,7 @@ export class IMessageService extends Service {
|
|
|
156
156
|
}
|
|
157
157
|
getStatus() {
|
|
158
158
|
const chatDbAvailable = this.chatDb !== null;
|
|
159
|
-
const accessIssue = chatDbAvailable
|
|
160
|
-
? null
|
|
161
|
-
: getLastChatDbAccessIssue(this.chatDbPath);
|
|
159
|
+
const accessIssue = chatDbAvailable ? null : getLastChatDbAccessIssue(this.chatDbPath);
|
|
162
160
|
return {
|
|
163
161
|
available: true,
|
|
164
162
|
connected: this.connected,
|
|
@@ -233,16 +231,18 @@ export class IMessageService extends Service {
|
|
|
233
231
|
* granted, etc.).
|
|
234
232
|
*/
|
|
235
233
|
async getRecentMessages(limit = 50) {
|
|
234
|
+
return this.getMessages({ limit });
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Return the newest messages in chronological order, optionally scoped
|
|
238
|
+
* to a single chat identifier. Returns an empty array if chat.db is not
|
|
239
|
+
* available and the connector is currently running in send-only mode.
|
|
240
|
+
*/
|
|
241
|
+
async getMessages(options = {}) {
|
|
236
242
|
if (!this.chatDb) {
|
|
237
243
|
return [];
|
|
238
244
|
}
|
|
239
|
-
|
|
240
|
-
// ROWID order, which for chat.db is also message-creation order.
|
|
241
|
-
// For "the most recent N messages" we'd ideally query with a
|
|
242
|
-
// different filter; fetching from 0 and slicing is fine for
|
|
243
|
-
// caller's expected use (startup inspection / debugging) because
|
|
244
|
-
// typical chat.db files have at most a few hundred thousand rows.
|
|
245
|
-
const rows = this.chatDb.fetchNewMessages(0, limit);
|
|
245
|
+
const rows = this.chatDb.listMessages(options);
|
|
246
246
|
return rows.map(chatDbMessageToPublicShape);
|
|
247
247
|
}
|
|
248
248
|
/**
|
|
@@ -1018,7 +1018,14 @@ export function chatDbMessageToPublicShape(row) {
|
|
|
1018
1018
|
chatId: row.chatId,
|
|
1019
1019
|
timestamp: row.timestamp,
|
|
1020
1020
|
isFromMe: row.isFromMe,
|
|
1021
|
-
hasAttachments:
|
|
1021
|
+
hasAttachments: row.attachments.length > 0,
|
|
1022
|
+
...(row.attachments.length > 0
|
|
1023
|
+
? {
|
|
1024
|
+
attachmentPaths: row.attachments
|
|
1025
|
+
.map((attachment) => attachment.filename)
|
|
1026
|
+
.filter((filename) => Boolean(filename)),
|
|
1027
|
+
}
|
|
1028
|
+
: {}),
|
|
1022
1029
|
};
|
|
1023
1030
|
}
|
|
1024
1031
|
/**
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* Routes served (all under `/api/imessage`):
|
|
10
10
|
*
|
|
11
11
|
* GET /api/imessage/status service health + connection state
|
|
12
|
-
* GET /api/imessage/messages
|
|
12
|
+
* GET /api/imessage/messages newest messages from chat.db
|
|
13
|
+
* POST /api/imessage/messages send a message via Messages.app
|
|
13
14
|
* GET /api/imessage/chats list of chats (DMs + groups)
|
|
14
15
|
* GET /api/imessage/contacts every contact with full detail
|
|
15
16
|
* POST /api/imessage/contacts create a new contact
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-routes.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/setup-routes.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"setup-routes.d.ts","sourceRoot":"","sources":["../../../../../../../plugins/plugin-imessage/typescript/src/setup-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAiB,KAAK,EAA+B,MAAM,eAAe,CAAC;AAiZvF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,EAiDtC,CAAC"}
|