Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 110 additions & 14 deletions agent/channels/linq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
type LinqChannelConfig,
type LinqChannelCredentials,
} from "eve/channels/linq";
import { parseError } from "evlog";
import { useLogger as getEvlog } from "evlog/eve";
import { z } from "zod";
import { getAuth } from "@/auth";
import { normalizeAuthPhoneNumber } from "@/auth/phone-number";
Expand Down Expand Up @@ -118,21 +120,115 @@ export const linqChannelConfig = {
.map((line) => line.trim())
.find(Boolean) ?? null)
: null;
if (context.thread) {
const messageId = context.thread.toJSON().currentMessage?.id;
if (
messageId &&
context.state.acknowledgedLinqMessageId !== messageId
) {
try {
await context.bot
.getAdapter("linq")
.addReaction(context.thread.id, messageId, "thumbs_up");
context.state.acknowledgedLinqMessageId = messageId;
} catch {
// SMS/RCS and some carrier paths do not support iMessage tapbacks.
}
let log: ReturnType<typeof getEvlog> | undefined;
try {
log = getEvlog(session);
} catch (error) {
console.warn("[linq] evlog unavailable", {
error: parseError(error),
sessionId: session.session.id,
turnId: event.turnId,
});
}
if (!context.thread) {
const reaction = { outcome: "missing-thread" };
if (log) {
log.warn("Linq reaction skipped", {
channel: { linq: { reactions: [reaction] } },
});
} else {
console.warn("[linq] reaction skipped", {
...reaction,
sessionId: session.session.id,
turnId: event.turnId,
});
}
return;
}

const messageId = context.thread.toJSON().currentMessage?.id;
if (!messageId) {
const reaction = {
outcome: "missing-message-id",
threadId: context.thread.id,
};
if (log) {
log.warn("Linq reaction skipped", {
channel: { linq: { reactions: [reaction] } },
});
} else {
console.warn("[linq] reaction skipped", {
...reaction,
sessionId: session.session.id,
turnId: event.turnId,
});
}
return;
}

if (context.state.acknowledgedLinqMessageId === messageId) {
const reaction = {
messageId,
outcome: "already-acknowledged",
threadId: context.thread.id,
};
if (log) {
log.info("Linq reaction skipped", {
channel: { linq: { reactions: [reaction] } },
});
} else {
console.info("[linq] reaction skipped", {
...reaction,
sessionId: session.session.id,
turnId: event.turnId,
});
}
return;
}

try {
await context.bot
.getAdapter("linq")
.addReaction(context.thread.id, messageId, "thumbs_up");
context.state.acknowledgedLinqMessageId = messageId;
const reaction = {
emoji: "thumbs_up",
messageId,
outcome: "accepted",
threadId: context.thread.id,
};
if (log) {
log.set({
channel: { linq: { reactions: [reaction] } },
});
} else {
console.info("[linq] reaction accepted", {
...reaction,
sessionId: session.session.id,
turnId: event.turnId,
});
}
} catch (error) {
const failure = parseError(error);
const reaction = {
emoji: "thumbs_up",
error: failure,
messageId,
outcome: "failed",
threadId: context.thread.id,
};
log?.warn("Linq reaction failed", {
channel: {
linq: {
reactions: [reaction],
},
},
});
console.warn("[linq] reaction failed", {
...reaction,
sessionId: session.session.id,
turnId: event.turnId,
});
}
return;
}
Expand Down
11 changes: 11 additions & 0 deletions agent/hooks/evlog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineEvlogHook } from "evlog/eve";

export default defineEvlogHook({
init: {
env: { service: "open-instinct" },
redact: false,
},
message: "full",
redact: false,
sessionEvent: true,
});
7 changes: 7 additions & 0 deletions agent/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineEvlogInstrumentation } from "evlog/eve";

export default defineEvlogInstrumentation({
recordInputs: true,
recordOutputs: true,
traceChannelRequests: true,
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"credit-card-type": "^10.3.0",
"drizzle-orm": "^0.45.2",
"eve": "^0.46.1",
"evlog": "2.27.1",
"lucide-react": "1.34.0",
"motion": "13.1.1",
"nanoid": "6.0.1",
Expand Down
74 changes: 74 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading