fix(integrations/zapier): address Zapier publishing review (#6985)
This commit is contained in:
@@ -26,6 +26,8 @@ export default {
|
|||||||
helpText: 'Override only for self-hosted or non-default deployments.',
|
helpText: 'Override only for self-hosted or non-default deployments.',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
// Shown on the connection label in the Zap editor.
|
// Shown on the connection label in the Zap editor. Uses the account email
|
||||||
connectionLabel: 'Mem0',
|
// from the /v1/ping/ test response so users with multiple Mem0 connections
|
||||||
|
// can tell them apart.
|
||||||
|
connectionLabel: '{{user_email}}',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import type { ZObject, Bundle, AddResponse, EventResponse } from '../types';
|
import type { ZObject, Bundle, AddResponse, EventResponse } from '../types';
|
||||||
import { captureEvent } from '../telemetry';
|
|
||||||
|
|
||||||
const POLL_INTERVAL_MS = 1500;
|
const POLL_INTERVAL_MS = 1500;
|
||||||
// Bounded to a 60s poll budget, under Zapier's per-step execution timeout.
|
// Bounded to a 60s poll budget, under Zapier's per-step execution timeout.
|
||||||
@@ -38,6 +37,8 @@ const perform = async (z: ZObject, bundle: Bundle): Promise<AddResponse | EventR
|
|||||||
const body: Record<string, unknown> = {
|
const body: Record<string, unknown> = {
|
||||||
messages: [{ role: bundle.inputData.role || 'user', content: bundle.inputData.content }],
|
messages: [{ role: bundle.inputData.role || 'user', content: bundle.inputData.content }],
|
||||||
infer,
|
infer,
|
||||||
|
// Attribution is recorded server-side by Mem0 from this source tag.
|
||||||
|
source: 'ZAPIER',
|
||||||
};
|
};
|
||||||
if (bundle.inputData.user_id) body.user_id = bundle.inputData.user_id;
|
if (bundle.inputData.user_id) body.user_id = bundle.inputData.user_id;
|
||||||
if (bundle.inputData.agent_id) body.agent_id = bundle.inputData.agent_id;
|
if (bundle.inputData.agent_id) body.agent_id = bundle.inputData.agent_id;
|
||||||
@@ -69,8 +70,6 @@ const perform = async (z: ZObject, bundle: Bundle): Promise<AddResponse | EventR
|
|||||||
if (bundle.inputData.includes) body.includes = bundle.inputData.includes;
|
if (bundle.inputData.includes) body.includes = bundle.inputData.includes;
|
||||||
if (bundle.inputData.excludes) body.excludes = bundle.inputData.excludes;
|
if (bundle.inputData.excludes) body.excludes = bundle.inputData.excludes;
|
||||||
|
|
||||||
captureEvent('zapier.add_memory', bundle.authData?.apiKey, { infer, wait });
|
|
||||||
|
|
||||||
const response = await z.request({
|
const response = await z.request({
|
||||||
url: '/v3/memories/add/',
|
url: '/v3/memories/add/',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -97,7 +96,7 @@ export default {
|
|||||||
noun: 'Memory',
|
noun: 'Memory',
|
||||||
display: {
|
display: {
|
||||||
label: 'Add Memory',
|
label: 'Add Memory',
|
||||||
description: 'Extract and store memories from a message.',
|
description: 'Extracts and stores memories from a message.',
|
||||||
},
|
},
|
||||||
operation: {
|
operation: {
|
||||||
perform,
|
perform,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export default {
|
|||||||
noun: 'Memory',
|
noun: 'Memory',
|
||||||
display: {
|
display: {
|
||||||
label: 'Delete Memory',
|
label: 'Delete Memory',
|
||||||
description: 'Delete a single memory by its ID.',
|
description: 'Deletes a memory by its ID.',
|
||||||
},
|
},
|
||||||
operation: {
|
operation: {
|
||||||
perform,
|
perform,
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import type { ZObject, Bundle, Memory } from '../types';
|
import type { ZObject, Bundle, Memory } from '../types';
|
||||||
import { captureEvent } from '../telemetry';
|
|
||||||
|
|
||||||
const perform = async (z: ZObject, bundle: Bundle): Promise<Memory[]> => {
|
const perform = async (z: ZObject, bundle: Bundle): Promise<Memory[]> => {
|
||||||
const body: Record<string, unknown> = {};
|
const body: Record<string, unknown> = {};
|
||||||
if (bundle.inputData.user_id) body.filters = { user_id: bundle.inputData.user_id };
|
if (bundle.inputData.user_id) body.filters = { user_id: bundle.inputData.user_id };
|
||||||
|
|
||||||
captureEvent('zapier.get_memories', bundle.authData?.apiKey);
|
|
||||||
|
|
||||||
const response = await z.request({
|
const response = await z.request({
|
||||||
url: '/v3/memories/',
|
url: '/v3/memories/',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -25,8 +22,8 @@ export default {
|
|||||||
key: 'get_memories',
|
key: 'get_memories',
|
||||||
noun: 'Memory',
|
noun: 'Memory',
|
||||||
display: {
|
display: {
|
||||||
label: 'Get Memories',
|
label: 'Find Memories by User',
|
||||||
description: 'List stored memories for a user.',
|
description: 'Finds all stored memories for a user.',
|
||||||
},
|
},
|
||||||
operation: {
|
operation: {
|
||||||
perform,
|
perform,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import type { ZObject, Bundle, Memory } from '../types';
|
import type { ZObject, Bundle, Memory } from '../types';
|
||||||
import { captureEvent } from '../telemetry';
|
|
||||||
|
|
||||||
const perform = async (z: ZObject, bundle: Bundle): Promise<Memory[]> => {
|
const perform = async (z: ZObject, bundle: Bundle): Promise<Memory[]> => {
|
||||||
const body: Record<string, unknown> = {
|
const body: Record<string, unknown> = {
|
||||||
@@ -9,8 +8,6 @@ const perform = async (z: ZObject, bundle: Bundle): Promise<Memory[]> => {
|
|||||||
};
|
};
|
||||||
if (bundle.inputData.user_id) body.filters = { user_id: bundle.inputData.user_id };
|
if (bundle.inputData.user_id) body.filters = { user_id: bundle.inputData.user_id };
|
||||||
|
|
||||||
captureEvent('zapier.search_memories', bundle.authData?.apiKey);
|
|
||||||
|
|
||||||
const response = await z.request({
|
const response = await z.request({
|
||||||
url: '/v3/memories/search/',
|
url: '/v3/memories/search/',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -25,8 +22,8 @@ export default {
|
|||||||
key: 'search_memories',
|
key: 'search_memories',
|
||||||
noun: 'Memory',
|
noun: 'Memory',
|
||||||
display: {
|
display: {
|
||||||
label: 'Search Memories',
|
label: 'Find Memories',
|
||||||
description: 'Semantic search over stored memories.',
|
description: 'Finds memories matching a semantic query.',
|
||||||
},
|
},
|
||||||
operation: {
|
operation: {
|
||||||
perform,
|
perform,
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
import { createHash } from 'crypto';
|
|
||||||
|
|
||||||
// Anonymous usage telemetry via PostHog, mirroring the Mem0 CLI / plugins.
|
|
||||||
// Fire-and-forget: never awaited, never throws, so it can neither slow down
|
|
||||||
// nor break an action. Opt out with MEM0_TELEMETRY=false.
|
|
||||||
const POSTHOG_API_KEY = 'phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX';
|
|
||||||
const POSTHOG_HOST = 'https://us.i.posthog.com/i/v0/e/';
|
|
||||||
|
|
||||||
export function captureEvent(
|
|
||||||
event: string,
|
|
||||||
apiKey: string | undefined,
|
|
||||||
properties: Record<string, unknown> = {},
|
|
||||||
): void {
|
|
||||||
if (process.env.MEM0_TELEMETRY === 'false') return;
|
|
||||||
try {
|
|
||||||
// Hash the API key so events are attributable to one account without
|
|
||||||
// ever transmitting the key itself.
|
|
||||||
const distinctId = apiKey ? createHash('md5').update(apiKey).digest('hex') : 'zapier-anon';
|
|
||||||
const payload = {
|
|
||||||
api_key: POSTHOG_API_KEY,
|
|
||||||
event,
|
|
||||||
distinct_id: distinctId,
|
|
||||||
properties: {
|
|
||||||
source: 'ZAPIER',
|
|
||||||
$process_person_profile: false,
|
|
||||||
...properties,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
void fetch(POSTHOG_HOST, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
}).catch(() => {
|
|
||||||
/* swallow — telemetry must never surface to the user */
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
/* swallow — telemetry must never break the action */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
// Disable telemetry during tests so runs never fire real PostHog events
|
// Jest setup file. Usage attribution is recorded server-side by the Mem0 API
|
||||||
// (and so the fire-and-forget fetch cannot leave an open handle after tests).
|
// from the `source: "ZAPIER"` tag on writes (see src/creates/add_memory.ts), so
|
||||||
process.env.MEM0_TELEMETRY = 'false';
|
// there is nothing to disable here during tests.
|
||||||
|
export {};
|
||||||
|
|||||||
Reference in New Issue
Block a user