samva 0.46.1 → 0.47.0
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/AGENTS.md +13 -7
- package/README.md +106 -8
- package/dist/agent/index.d.ts +56 -0
- package/dist/agent/index.js +52 -0
- package/dist/agent/runtime.d.ts +3 -0
- package/dist/agent/runtime.js +74 -0
- package/dist/agent/test.d.ts +31 -0
- package/dist/agent/test.js +66 -0
- package/dist/agent/types.d.ts +123 -0
- package/dist/client/sdk.gen.d.ts +40 -160
- package/dist/client/sdk.gen.js +1302 -1598
- package/dist/client/types.gen.d.ts +377 -966
- package/dist/effect/agents.d.ts +340 -8
- package/dist/effect/agents.js +4 -2
- package/dist/effect/campaigns.d.ts +160 -160
- package/dist/effect/contacts.d.ts +8 -0
- package/dist/effect/contacts.js +5 -1
- package/dist/effect/descriptors/agents.d.ts +12 -2
- package/dist/effect/descriptors/agents.js +12 -2
- package/dist/effect/descriptors/contacts.d.ts +20 -0
- package/dist/effect/descriptors/contacts.js +20 -0
- package/dist/effect/generated/accounts.d.ts +10 -0
- package/dist/effect/generated/accounts.js +1 -0
- package/dist/effect/generated/agents.d.ts +2967 -690
- package/dist/effect/generated/agents.js +54 -13
- package/dist/effect/generated/contacts.d.ts +859 -1
- package/dist/effect/generated/contacts.js +62 -3
- package/dist/effect/generated/index.d.ts +1 -5
- package/dist/effect/generated/journeys.d.ts +255 -15
- package/dist/effect/generated/journeys.js +3 -1
- package/dist/effect/generated/mailboxes.d.ts +93 -95
- package/dist/effect/generated/mailboxes.js +21 -25
- package/dist/effect/generated/shared.d.ts +407 -101
- package/dist/effect/generated/shared.js +80 -36
- package/dist/effect/generated/template-registrations.d.ts +1 -4
- package/dist/effect/generated/template-registrations.js +2 -6
- package/dist/effect/generated-metadata.d.ts +18 -84
- package/dist/effect/generated-metadata.js +362 -415
- package/dist/effect/index.d.ts +0 -2
- package/dist/effect/index.js +1 -3
- package/dist/effect/internal/client.js +1 -1
- package/dist/effect/internal/operation.js +4 -1
- package/dist/effect/journeys.d.ts +26 -2
- package/dist/effect/mailboxes.d.ts +41 -41
- package/dist/effect/scheduled-messages.d.ts +350 -350
- package/dist/effect/topics.d.ts +2 -2
- package/dist/package.js +1 -1
- package/dist/promises/client.d.ts +1 -5
- package/dist/promises/client.js +3 -7
- package/dist/promises/types.gen.d.ts +1 -1
- package/dist/service-map.d.ts +18 -75
- package/package.json +10 -22
- package/dist/effect/descriptors/extension-installations.d.ts +0 -90
- package/dist/effect/descriptors/extension-installations.js +0 -90
- package/dist/effect/descriptors/extensions.d.ts +0 -50
- package/dist/effect/descriptors/extensions.js +0 -50
- package/dist/effect/extension-installations.d.ts +0 -132
- package/dist/effect/extension-installations.js +0 -29
- package/dist/effect/extensions.d.ts +0 -102
- package/dist/effect/extensions.js +0 -21
- package/dist/effect/generated/extension-installations.d.ts +0 -2761
- package/dist/effect/generated/extension-installations.js +0 -405
- package/dist/effect/generated/extensions.d.ts +0 -1037
- package/dist/effect/generated/extensions.js +0 -214
- package/dist/mailbox/dispatch.d.ts +0 -10
- package/dist/mailbox/dispatch.js +0 -66
- package/dist/mailbox/index.d.ts +0 -17
- package/dist/mailbox/index.js +0 -30
- package/dist/mailbox/test.d.ts +0 -25
- package/dist/mailbox/test.js +0 -181
- package/dist/mailbox/types.d.ts +0 -221
- package/dist/mailbox/webhook.d.ts +0 -10
- package/dist/mailbox/webhook.js +0 -41
package/dist/mailbox/types.d.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import type { MailboxQuarantinedMessage } from "../client/types.gen.js";
|
|
2
|
-
import type { SamvaClient } from "../promises/client.js";
|
|
3
|
-
export type ExtensionManifest = {
|
|
4
|
-
readonly name: string;
|
|
5
|
-
readonly displayName: string;
|
|
6
|
-
readonly description?: string | undefined;
|
|
7
|
-
readonly version: string;
|
|
8
|
-
readonly runtime: "hosted" | "webhook";
|
|
9
|
-
readonly events: readonly EventType[];
|
|
10
|
-
readonly permissions: readonly ("read" | "update" | "send" | "quarantine.read")[];
|
|
11
|
-
};
|
|
12
|
-
export type Invocation = {
|
|
13
|
-
readonly eventId: string;
|
|
14
|
-
readonly attempt: number;
|
|
15
|
-
readonly body: string;
|
|
16
|
-
};
|
|
17
|
-
export type DispatchResult = {
|
|
18
|
-
readonly ok: boolean;
|
|
19
|
-
readonly error?: string | undefined;
|
|
20
|
-
readonly logs: readonly string[];
|
|
21
|
-
};
|
|
22
|
-
export type MailboxActor = {
|
|
23
|
-
readonly kind: "user" | "apiKey" | "extension" | "externalAgent" | "samvaAgent" | "system";
|
|
24
|
-
readonly id: string;
|
|
25
|
-
readonly displayName?: string | undefined;
|
|
26
|
-
};
|
|
27
|
-
type WebhookActor = MailboxActor & {
|
|
28
|
-
readonly source: "humanUi" | "externalApi" | "externalAgent" | "extension" | "samvaManagedAgent" | "system";
|
|
29
|
-
};
|
|
30
|
-
/** How a held action's approval ended, and who ended it. */
|
|
31
|
-
export type ActionResolution = {
|
|
32
|
-
readonly outcome: "approved" | "denied" | "cancelled";
|
|
33
|
-
readonly actor: WebhookActor;
|
|
34
|
-
readonly resolvedAt: string;
|
|
35
|
-
/** The denial reason; null for an approval or a cancellation. */
|
|
36
|
-
readonly reason: string | null;
|
|
37
|
-
};
|
|
38
|
-
/** Why a mailbox action was allowed, held, or refused. */
|
|
39
|
-
export type ActionDecision = {
|
|
40
|
-
readonly id: string;
|
|
41
|
-
readonly reviewRound: number;
|
|
42
|
-
readonly requirement: "run" | "model" | "person" | "never";
|
|
43
|
-
readonly decider: "rule" | "model" | "person" | "agent";
|
|
44
|
-
readonly outcome: "allow" | "hold" | "refuse";
|
|
45
|
-
readonly reason: string;
|
|
46
|
-
readonly scopes: readonly PolicyScope[];
|
|
47
|
-
readonly rule?: {
|
|
48
|
-
readonly scope: PolicyScope;
|
|
49
|
-
readonly index: number;
|
|
50
|
-
} | undefined;
|
|
51
|
-
readonly guard?: string | undefined;
|
|
52
|
-
readonly guardReason?: string | undefined;
|
|
53
|
-
readonly resolution?: {
|
|
54
|
-
readonly by: string;
|
|
55
|
-
readonly at: string;
|
|
56
|
-
readonly as: "approved" | "edited" | "denied" | "alwaysAllowed";
|
|
57
|
-
readonly diff?: {
|
|
58
|
-
readonly text?: {
|
|
59
|
-
readonly before: string | null;
|
|
60
|
-
readonly after: string | null;
|
|
61
|
-
} | undefined;
|
|
62
|
-
readonly html?: {
|
|
63
|
-
readonly before: string | null;
|
|
64
|
-
readonly after: string | null;
|
|
65
|
-
} | undefined;
|
|
66
|
-
} | undefined;
|
|
67
|
-
} | undefined;
|
|
68
|
-
};
|
|
69
|
-
type PolicyScope = {
|
|
70
|
-
readonly kind: "organization" | "integration" | "mailbox" | "agent" | "apiKey";
|
|
71
|
-
readonly id: string;
|
|
72
|
-
};
|
|
73
|
-
export type CampaignAttribution = {
|
|
74
|
-
readonly campaignId: string;
|
|
75
|
-
readonly runId: string;
|
|
76
|
-
};
|
|
77
|
-
type WebhookMessage = {
|
|
78
|
-
readonly campaign?: CampaignAttribution | undefined;
|
|
79
|
-
readonly id: string;
|
|
80
|
-
/** Deliveries recorded before the field existed omit it; they are email. */
|
|
81
|
-
readonly channel?: "email" | "whatsapp" | "sms";
|
|
82
|
-
readonly threadId: string;
|
|
83
|
-
readonly from: {
|
|
84
|
-
readonly address: string;
|
|
85
|
-
readonly name?: string | undefined;
|
|
86
|
-
};
|
|
87
|
-
readonly to: readonly string[];
|
|
88
|
-
readonly cc: readonly string[];
|
|
89
|
-
readonly subject: string | null;
|
|
90
|
-
readonly text: string | null;
|
|
91
|
-
readonly replyText: string | null;
|
|
92
|
-
readonly attachments: readonly {
|
|
93
|
-
readonly id: string;
|
|
94
|
-
readonly filename: string;
|
|
95
|
-
readonly contentType: string;
|
|
96
|
-
readonly size: number;
|
|
97
|
-
}[];
|
|
98
|
-
readonly occurredAt: string;
|
|
99
|
-
};
|
|
100
|
-
type WebhookThread = {
|
|
101
|
-
readonly id: string;
|
|
102
|
-
/** The endpoint the message arrived at; null once it is removed. */
|
|
103
|
-
readonly endpointId?: string | null;
|
|
104
|
-
readonly subject: string | null;
|
|
105
|
-
readonly preview: string | null;
|
|
106
|
-
};
|
|
107
|
-
type MailboxEventScope = {
|
|
108
|
-
readonly mailboxId: string;
|
|
109
|
-
readonly namespaceId: string | null;
|
|
110
|
-
};
|
|
111
|
-
type QuarantineReason = MailboxQuarantinedMessage["reason"];
|
|
112
|
-
export type EventData = {
|
|
113
|
-
"mailbox.message.received": MailboxEventScope & {
|
|
114
|
-
readonly message: WebhookMessage;
|
|
115
|
-
readonly thread: WebhookThread;
|
|
116
|
-
};
|
|
117
|
-
"mailbox.message.sent": MailboxEventScope & {
|
|
118
|
-
readonly state?: "completed";
|
|
119
|
-
readonly acceptedAt?: string;
|
|
120
|
-
readonly actionId: string;
|
|
121
|
-
readonly actor: WebhookActor;
|
|
122
|
-
readonly message: WebhookMessage;
|
|
123
|
-
};
|
|
124
|
-
"mailbox.action.pending_approval": MailboxEventScope & {
|
|
125
|
-
readonly action: {
|
|
126
|
-
readonly state?: "approvalRequired";
|
|
127
|
-
readonly decision: ActionDecision;
|
|
128
|
-
readonly reviewRound: number;
|
|
129
|
-
readonly id: string;
|
|
130
|
-
readonly type: "sendMessage" | "reply" | "updateDraft" | "createNote" | "assignThread" | "changeThreadState" | "call" | "extensionRequest" | "toolCall" | "handoff";
|
|
131
|
-
readonly threadId: string | null;
|
|
132
|
-
readonly reason: string | null;
|
|
133
|
-
readonly proposedBy: WebhookActor;
|
|
134
|
-
readonly createdAt: string;
|
|
135
|
-
};
|
|
136
|
-
/** Who a held send goes to; null for a held tool call. */
|
|
137
|
-
readonly draft: {
|
|
138
|
-
readonly to: readonly string[];
|
|
139
|
-
readonly cc: readonly string[];
|
|
140
|
-
readonly subject: string | null;
|
|
141
|
-
} | null;
|
|
142
|
-
/** The tool a held tool call runs and its arguments; null for a held send. */
|
|
143
|
-
readonly tool?: {
|
|
144
|
-
readonly name: string;
|
|
145
|
-
readonly argumentsHash: string;
|
|
146
|
-
readonly arguments: {
|
|
147
|
-
readonly [key: string]: unknown;
|
|
148
|
-
};
|
|
149
|
-
} | null;
|
|
150
|
-
};
|
|
151
|
-
"mailbox.action.resolved": MailboxEventScope & {
|
|
152
|
-
readonly action: {
|
|
153
|
-
readonly id: string;
|
|
154
|
-
readonly reviewRound: number;
|
|
155
|
-
readonly type: EventData["mailbox.action.pending_approval"]["action"]["type"];
|
|
156
|
-
readonly threadId: string | null;
|
|
157
|
-
readonly proposedBy: WebhookActor;
|
|
158
|
-
readonly createdAt: string;
|
|
159
|
-
};
|
|
160
|
-
readonly resolution: ActionResolution;
|
|
161
|
-
};
|
|
162
|
-
"mailbox.message.quarantined": MailboxEventScope & {
|
|
163
|
-
readonly disposition: "quarantined" | "isolated";
|
|
164
|
-
readonly reason: QuarantineReason;
|
|
165
|
-
readonly source: "receipt" | "classifier";
|
|
166
|
-
readonly message: {
|
|
167
|
-
readonly id: string;
|
|
168
|
-
readonly from: {
|
|
169
|
-
readonly address: string;
|
|
170
|
-
readonly name?: string | undefined;
|
|
171
|
-
};
|
|
172
|
-
readonly subject: string | null;
|
|
173
|
-
readonly receivedAt: string;
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
"mailbox.message.released": MailboxEventScope & {
|
|
177
|
-
readonly releasedBy: WebhookActor;
|
|
178
|
-
readonly reason: QuarantineReason;
|
|
179
|
-
readonly message: WebhookMessage;
|
|
180
|
-
readonly thread: WebhookThread;
|
|
181
|
-
};
|
|
182
|
-
"mailbox.message.discarded": MailboxEventScope & {
|
|
183
|
-
readonly discardedBy: WebhookActor;
|
|
184
|
-
readonly disposition: "quarantined" | "isolated";
|
|
185
|
-
readonly reason: QuarantineReason;
|
|
186
|
-
readonly message: {
|
|
187
|
-
readonly id: string;
|
|
188
|
-
readonly from: {
|
|
189
|
-
readonly address: string;
|
|
190
|
-
readonly name?: string | undefined;
|
|
191
|
-
};
|
|
192
|
-
readonly subject: string | null;
|
|
193
|
-
readonly receivedAt: string;
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
};
|
|
197
|
-
export type EventType = keyof EventData;
|
|
198
|
-
export type ExtensionEvent<T extends EventType = EventType> = {
|
|
199
|
-
[K in T]: {
|
|
200
|
-
id: string;
|
|
201
|
-
type: K;
|
|
202
|
-
timestamp: string;
|
|
203
|
-
data: EventData[K];
|
|
204
|
-
};
|
|
205
|
-
}[T];
|
|
206
|
-
export interface HandlerContext<T extends EventType = EventType> {
|
|
207
|
-
samva: SamvaClient;
|
|
208
|
-
log: (...args: unknown[]) => void;
|
|
209
|
-
event: ExtensionEvent<T>;
|
|
210
|
-
attempt: number;
|
|
211
|
-
}
|
|
212
|
-
export type ExtensionHandlers<T extends EventType = EventType> = {
|
|
213
|
-
[K in T]?: (event: ExtensionEvent<K>, context: HandlerContext<K>) => void | Promise<void>;
|
|
214
|
-
};
|
|
215
|
-
export interface ExtensionDefinition<T extends EventType = EventType> {
|
|
216
|
-
manifest: ExtensionManifest & {
|
|
217
|
-
events: readonly T[];
|
|
218
|
-
};
|
|
219
|
-
on: ExtensionHandlers<T>;
|
|
220
|
-
}
|
|
221
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createClient } from "../promises/client.js";
|
|
2
|
-
import type { ExtensionDefinition } from "./types.js";
|
|
3
|
-
type Fetch = NonNullable<Parameters<typeof createClient>[0]["fetch"]>;
|
|
4
|
-
export declare function createWebhookHandler(extension: ExtensionDefinition, options: {
|
|
5
|
-
apiKey: string;
|
|
6
|
-
webhookSecret: string;
|
|
7
|
-
apiOrigin?: string;
|
|
8
|
-
fetch?: Fetch;
|
|
9
|
-
}): (request: Request) => Promise<Response>;
|
|
10
|
-
export {};
|
package/dist/mailbox/webhook.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createClient } from "../promises/client.js";
|
|
2
|
-
import { dispatchEvent, errorMessage } from "./dispatch.js";
|
|
3
|
-
import { verifyRequest } from "@samva/webhooks";
|
|
4
|
-
// src/mailbox/webhook.ts
|
|
5
|
-
function createWebhookHandler(extension, options) {
|
|
6
|
-
const client = createClient({
|
|
7
|
-
fetch: options.fetch ?? globalThis.fetch.bind(globalThis),
|
|
8
|
-
baseUrl: options.apiOrigin ?? "https://api.samva.dev",
|
|
9
|
-
apiKey: options.apiKey
|
|
10
|
-
});
|
|
11
|
-
return async (request) => {
|
|
12
|
-
let eventId;
|
|
13
|
-
try {
|
|
14
|
-
eventId = (await verifyRequest(request, options.webhookSecret)).id;
|
|
15
|
-
} catch (error) {
|
|
16
|
-
return Response.json({
|
|
17
|
-
ok: false,
|
|
18
|
-
error: errorMessage(error)
|
|
19
|
-
}, { status: 401 });
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
const result = await dispatchEvent(extension, {
|
|
23
|
-
eventId,
|
|
24
|
-
attempt: 1,
|
|
25
|
-
body: await request.text()
|
|
26
|
-
}, client);
|
|
27
|
-
return Response.json(result.ok ? { ok: true } : {
|
|
28
|
-
ok: false,
|
|
29
|
-
error: result.error
|
|
30
|
-
}, { status: result.ok ? 200 : 500 });
|
|
31
|
-
} catch (error) {
|
|
32
|
-
return Response.json({
|
|
33
|
-
ok: false,
|
|
34
|
-
error: errorMessage(error)
|
|
35
|
-
}, { status: 500 });
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export { createWebhookHandler };
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=webhook.js.map
|