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.',
|
||||
},
|
||||
],
|
||||
// Shown on the connection label in the Zap editor.
|
||||
connectionLabel: 'Mem0',
|
||||
// Shown on the connection label in the Zap editor. Uses the account email
|
||||
// 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 { captureEvent } from '../telemetry';
|
||||
|
||||
const POLL_INTERVAL_MS = 1500;
|
||||
// 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> = {
|
||||
messages: [{ role: bundle.inputData.role || 'user', content: bundle.inputData.content }],
|
||||
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.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.excludes) body.excludes = bundle.inputData.excludes;
|
||||
|
||||
captureEvent('zapier.add_memory', bundle.authData?.apiKey, { infer, wait });
|
||||
|
||||
const response = await z.request({
|
||||
url: '/v3/memories/add/',
|
||||
method: 'POST',
|
||||
@@ -97,7 +96,7 @@ export default {
|
||||
noun: 'Memory',
|
||||
display: {
|
||||
label: 'Add Memory',
|
||||
description: 'Extract and store memories from a message.',
|
||||
description: 'Extracts and stores memories from a message.',
|
||||
},
|
||||
operation: {
|
||||
perform,
|
||||
|
||||
@@ -14,7 +14,7 @@ export default {
|
||||
noun: 'Memory',
|
||||
display: {
|
||||
label: 'Delete Memory',
|
||||
description: 'Delete a single memory by its ID.',
|
||||
description: 'Deletes a memory by its ID.',
|
||||
},
|
||||
operation: {
|
||||
perform,
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { ZObject, Bundle, Memory } from '../types';
|
||||
import { captureEvent } from '../telemetry';
|
||||
|
||||
const perform = async (z: ZObject, bundle: Bundle): Promise<Memory[]> => {
|
||||
const body: Record<string, unknown> = {};
|
||||
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({
|
||||
url: '/v3/memories/',
|
||||
method: 'POST',
|
||||
@@ -25,8 +22,8 @@ export default {
|
||||
key: 'get_memories',
|
||||
noun: 'Memory',
|
||||
display: {
|
||||
label: 'Get Memories',
|
||||
description: 'List stored memories for a user.',
|
||||
label: 'Find Memories by User',
|
||||
description: 'Finds all stored memories for a user.',
|
||||
},
|
||||
operation: {
|
||||
perform,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { ZObject, Bundle, Memory } from '../types';
|
||||
import { captureEvent } from '../telemetry';
|
||||
|
||||
const perform = async (z: ZObject, bundle: Bundle): Promise<Memory[]> => {
|
||||
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 };
|
||||
|
||||
captureEvent('zapier.search_memories', bundle.authData?.apiKey);
|
||||
|
||||
const response = await z.request({
|
||||
url: '/v3/memories/search/',
|
||||
method: 'POST',
|
||||
@@ -25,8 +22,8 @@ export default {
|
||||
key: 'search_memories',
|
||||
noun: 'Memory',
|
||||
display: {
|
||||
label: 'Search Memories',
|
||||
description: 'Semantic search over stored memories.',
|
||||
label: 'Find Memories',
|
||||
description: 'Finds memories matching a semantic query.',
|
||||
},
|
||||
operation: {
|
||||
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
|
||||
// (and so the fire-and-forget fetch cannot leave an open handle after tests).
|
||||
process.env.MEM0_TELEMETRY = 'false';
|
||||
// Jest setup file. Usage attribution is recorded server-side by the Mem0 API
|
||||
// from the `source: "ZAPIER"` tag on writes (see src/creates/add_memory.ts), so
|
||||
// there is nothing to disable here during tests.
|
||||
export {};
|
||||
|
||||
Reference in New Issue
Block a user