@agentworkforce/delivery 0.1.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/dist/delivery.d.ts +22 -0
- package/dist/delivery.d.ts.map +1 -0
- package/dist/delivery.js +173 -0
- package/dist/delivery.js.map +1 -0
- package/dist/helpers.d.ts +25 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +80 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +31 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { WorkforceCtx } from '@agentworkforce/runtime';
|
|
2
|
+
import { type DeliveryClient, type DeliveryTransports } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create a delivery client that auto-discovers configured transports from
|
|
5
|
+
* the persona context and sends to all of them.
|
|
6
|
+
*
|
|
7
|
+
* Blocking mode (the default):
|
|
8
|
+
* const heads = await delivery.send(header);
|
|
9
|
+
* await delivery.send(body, { replyTo: heads });
|
|
10
|
+
*
|
|
11
|
+
* Non-blocking parentRef mode (zero receipt round-trips):
|
|
12
|
+
* const heads = await delivery.publish(header);
|
|
13
|
+
* await delivery.send(body, { replyTo: heads, nonBlocking: true });
|
|
14
|
+
*
|
|
15
|
+
* Pass `transports` to inject mock clients for testing — the same injected
|
|
16
|
+
* client is used for both blocking and non-blocking paths (tests supply
|
|
17
|
+
* their own mock that short-circuits the writeback).
|
|
18
|
+
*/
|
|
19
|
+
export declare function createDelivery(ctx: WorkforceCtx, transports?: DeliveryTransports,
|
|
20
|
+
/** Override which transports to target (defaults to all configured). */
|
|
21
|
+
onlyTargets?: ReadonlyArray<'slack' | 'telegram'>): DeliveryClient;
|
|
22
|
+
//# sourceMappingURL=delivery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery.d.ts","sourceRoot":"","sources":["../src/delivery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAIL,KAAK,cAAc,EAGnB,KAAK,kBAAkB,EAGxB,MAAM,YAAY,CAAC;AAIpB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,YAAY,EACjB,UAAU,CAAC,EAAE,kBAAkB;AAC/B,wEAAwE;AACxE,WAAW,CAAC,EAAE,aAAa,CAAC,OAAO,GAAG,UAAU,CAAC,GAChD,cAAc,CA8BhB"}
|
package/dist/delivery.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { slackClient, telegramClient } from '@relayfile/relay-helpers';
|
|
2
|
+
import { resolveDeliveryTargets, slackChannel, telegramChat } from './types.js';
|
|
3
|
+
const WRITEBACK_TIMEOUT_MS = 45_000;
|
|
4
|
+
/**
|
|
5
|
+
* Create a delivery client that auto-discovers configured transports from
|
|
6
|
+
* the persona context and sends to all of them.
|
|
7
|
+
*
|
|
8
|
+
* Blocking mode (the default):
|
|
9
|
+
* const heads = await delivery.send(header);
|
|
10
|
+
* await delivery.send(body, { replyTo: heads });
|
|
11
|
+
*
|
|
12
|
+
* Non-blocking parentRef mode (zero receipt round-trips):
|
|
13
|
+
* const heads = await delivery.publish(header);
|
|
14
|
+
* await delivery.send(body, { replyTo: heads, nonBlocking: true });
|
|
15
|
+
*
|
|
16
|
+
* Pass `transports` to inject mock clients for testing — the same injected
|
|
17
|
+
* client is used for both blocking and non-blocking paths (tests supply
|
|
18
|
+
* their own mock that short-circuits the writeback).
|
|
19
|
+
*/
|
|
20
|
+
export function createDelivery(ctx, transports,
|
|
21
|
+
/** Override which transports to target (defaults to all configured). */
|
|
22
|
+
onlyTargets) {
|
|
23
|
+
const allTargets = resolveDeliveryTargets(ctx);
|
|
24
|
+
const targets = onlyTargets
|
|
25
|
+
? allTargets.filter((t) => onlyTargets.includes(t))
|
|
26
|
+
: allTargets;
|
|
27
|
+
// Injected transports take priority. When not injected, construct real
|
|
28
|
+
// clients with appropriate timeouts.
|
|
29
|
+
const injectedSlack = transports?.slack;
|
|
30
|
+
const injectedTelegram = transports?.telegram;
|
|
31
|
+
const slackBlocking = injectedSlack ?? (targets.includes('slack')
|
|
32
|
+
? slackClient({ writebackTimeoutMs: WRITEBACK_TIMEOUT_MS })
|
|
33
|
+
: undefined);
|
|
34
|
+
const slackNonBlocking = injectedSlack ?? (targets.includes('slack')
|
|
35
|
+
? slackClient({ writebackTimeoutMs: 0 })
|
|
36
|
+
: undefined);
|
|
37
|
+
const telegramBlocking = injectedTelegram ?? (targets.includes('telegram')
|
|
38
|
+
? telegramClient({ writebackTimeoutMs: WRITEBACK_TIMEOUT_MS })
|
|
39
|
+
: undefined);
|
|
40
|
+
const telegramNonBlocking = injectedTelegram ?? (targets.includes('telegram')
|
|
41
|
+
? telegramClient({ writebackTimeoutMs: 0 })
|
|
42
|
+
: undefined);
|
|
43
|
+
return new DeliveryClientImpl(ctx, targets, {
|
|
44
|
+
slackBlocking,
|
|
45
|
+
slackNonBlocking,
|
|
46
|
+
telegramBlocking,
|
|
47
|
+
telegramNonBlocking
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
class DeliveryClientImpl {
|
|
51
|
+
targets;
|
|
52
|
+
ctx;
|
|
53
|
+
t;
|
|
54
|
+
constructor(ctx, targets, transports) {
|
|
55
|
+
this.ctx = ctx;
|
|
56
|
+
this.targets = targets;
|
|
57
|
+
this.t = transports;
|
|
58
|
+
}
|
|
59
|
+
async send(text, opts) {
|
|
60
|
+
const nonBlocking = opts?.nonBlocking === true;
|
|
61
|
+
const refs = [];
|
|
62
|
+
const errors = [];
|
|
63
|
+
const tasks = [];
|
|
64
|
+
for (const target of this.targets) {
|
|
65
|
+
const parentRef = opts?.replyTo?.refs.find((r) => r.provider === target);
|
|
66
|
+
if (target === 'slack') {
|
|
67
|
+
tasks.push(this.sendSlack(text, parentRef, nonBlocking)
|
|
68
|
+
.then((ref) => { if (ref)
|
|
69
|
+
refs.push(ref); })
|
|
70
|
+
.catch((err) => { errors.push(`slack: ${String(err)}`); }));
|
|
71
|
+
}
|
|
72
|
+
if (target === 'telegram') {
|
|
73
|
+
tasks.push(this.sendTelegram(text, parentRef, nonBlocking)
|
|
74
|
+
.then((ref) => { if (ref)
|
|
75
|
+
refs.push(ref); })
|
|
76
|
+
.catch((err) => { errors.push(`telegram: ${String(err)}`); }));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
await Promise.all(tasks);
|
|
80
|
+
// In non-blocking mode, draft refs always succeed (no receipt wait to fail).
|
|
81
|
+
// Treat any ref as success. In blocking mode, require all targets to succeed.
|
|
82
|
+
const ok = nonBlocking
|
|
83
|
+
? refs.length > 0
|
|
84
|
+
: errors.length === 0 && refs.length === this.targets.length;
|
|
85
|
+
if (!ok && errors.length > 0) {
|
|
86
|
+
this.ctx.log?.('warn', 'delivery.partial-failure', { errors, nonBlocking });
|
|
87
|
+
}
|
|
88
|
+
if (!ok && refs.length === 0) {
|
|
89
|
+
const detail = errors.length > 0 ? errors.join('; ') : 'all sends returned null (no configured targets)';
|
|
90
|
+
throw new Error(`Delivery failed to all targets: ${detail}`);
|
|
91
|
+
}
|
|
92
|
+
return { ok, refs };
|
|
93
|
+
}
|
|
94
|
+
async publish(text) {
|
|
95
|
+
return this.send(text, { nonBlocking: true });
|
|
96
|
+
}
|
|
97
|
+
// ── Slack ──────────────────────────────────────────────────────────────
|
|
98
|
+
async sendSlack(text, parentRef, nonBlocking) {
|
|
99
|
+
const channel = slackChannel(this.ctx);
|
|
100
|
+
if (!channel)
|
|
101
|
+
return null;
|
|
102
|
+
if (nonBlocking) {
|
|
103
|
+
return this.sendSlackNonBlocking(channel, text, parentRef);
|
|
104
|
+
}
|
|
105
|
+
return this.sendSlackBlocking(channel, text, parentRef);
|
|
106
|
+
}
|
|
107
|
+
async sendSlackBlocking(channel, text, parentRef) {
|
|
108
|
+
const client = this.t.slackBlocking;
|
|
109
|
+
if (!client)
|
|
110
|
+
return null;
|
|
111
|
+
const result = parentRef?.draftRef
|
|
112
|
+
? await client.post(channel, text, { replyTo: parentRef.draftRef })
|
|
113
|
+
: await client.post(channel, text);
|
|
114
|
+
if (!result.ts) {
|
|
115
|
+
this.ctx.log?.('warn', 'delivery.slack.no-receipt', { channel });
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
provider: 'slack',
|
|
120
|
+
channel: result.channel,
|
|
121
|
+
ts: result.ts,
|
|
122
|
+
draftRef: result.ref
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Non-blocking Slack: uses messages.write() directly with writebackTimeoutMs:0.
|
|
127
|
+
* The parentRef is embedded in the message body so the cloud orders the message
|
|
128
|
+
* under the parent server-side — zero receipt round-trips. The returned draftRef
|
|
129
|
+
* is the relay path, usable as a parent for subsequent threaded sends.
|
|
130
|
+
*
|
|
131
|
+
* Mirrors the x-reply-radar parentRef threading pattern (internal-agents).
|
|
132
|
+
*/
|
|
133
|
+
async sendSlackNonBlocking(channel, text, parentRef) {
|
|
134
|
+
const client = this.t.slackNonBlocking;
|
|
135
|
+
if (!client)
|
|
136
|
+
return null;
|
|
137
|
+
const body = { text };
|
|
138
|
+
if (parentRef?.draftRef) {
|
|
139
|
+
// Embed parentRef in the body — the cloud lifts it from the streamed head
|
|
140
|
+
// and orders this message under the parent once the parent delivers.
|
|
141
|
+
body.parentRef = parentRef.draftRef;
|
|
142
|
+
}
|
|
143
|
+
const result = await client.messages.write({ channelId: channel }, body);
|
|
144
|
+
return {
|
|
145
|
+
provider: 'slack',
|
|
146
|
+
channel,
|
|
147
|
+
ts: '', // Not available yet (non-blocking)
|
|
148
|
+
draftRef: result.path
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
// ── Telegram ───────────────────────────────────────────────────────────
|
|
152
|
+
async sendTelegram(text, parentRef, nonBlocking) {
|
|
153
|
+
const chatId = telegramChat(this.ctx);
|
|
154
|
+
if (!chatId)
|
|
155
|
+
return null;
|
|
156
|
+
const client = nonBlocking ? this.t.telegramNonBlocking : this.t.telegramBlocking;
|
|
157
|
+
if (!client)
|
|
158
|
+
return null;
|
|
159
|
+
const result = parentRef?.messageId
|
|
160
|
+
? await client.sendMessage(chatId, text, { replyToMessageId: Number(parentRef.messageId) || undefined })
|
|
161
|
+
: await client.sendMessage(chatId, text);
|
|
162
|
+
if (!nonBlocking && !result.ok) {
|
|
163
|
+
this.ctx.log?.('warn', 'delivery.telegram.no-receipt', { chatId });
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
provider: 'telegram',
|
|
168
|
+
chatId: result.chatId != null ? String(result.chatId) : chatId,
|
|
169
|
+
messageId: result.ok ? result.messageId : ''
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=delivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery.js","sourceRoot":"","sources":["../src/delivery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAGvE,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,YAAY,EAOb,MAAM,YAAY,CAAC;AAEpB,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAEpC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAiB,EACjB,UAA+B;AAC/B,wEAAwE;AACxE,WAAiD;IAEjD,MAAM,UAAU,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,WAAW;QACzB,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAE,W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EAAE,EAAE,CAAC;YAC/B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,8BAA8B,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;YACnE,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM;YAC9D,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;SAC7C,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WorkforceCtx } from '@agentworkforce/runtime';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a persona input value from the runtime ctx.
|
|
4
|
+
*
|
|
5
|
+
* Resolution order (mirrors persona-kit): ctx.persona.inputs (already
|
|
6
|
+
* resolved from agent value → env → default by the runtime) → fall back
|
|
7
|
+
* to process.env directly when running outside the full runtime.
|
|
8
|
+
*/
|
|
9
|
+
export declare function input(ctx: WorkforceCtx, name: string): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Split a comma-separated string into trimmed, non-empty entries.
|
|
12
|
+
*/
|
|
13
|
+
export declare function list(raw: string | undefined): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Race a promise against a timeout. On timeout the timer rejects with an
|
|
16
|
+
* Error so the caller can catch and fall back. Always clears the timer.
|
|
17
|
+
*/
|
|
18
|
+
export declare function withTimeout<T>(p: Promise<T>, ms: number, label: string): Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Fetch with an AbortController timeout. Returns the response on success,
|
|
21
|
+
* or undefined on timeout/network error (never throws). Preserves caller-
|
|
22
|
+
* provided signal by racing our abort against it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function fetchWithTimeout(url: string, init?: RequestInit, timeoutMs?: number): Promise<Response | undefined>;
|
|
25
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAazE;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAEtD;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EACb,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,CAAC,CAAC,CAUZ;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,WAAgB,EACtB,SAAS,GAAE,MAAc,GACxB,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAa/B"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a persona input value from the runtime ctx.
|
|
3
|
+
*
|
|
4
|
+
* Resolution order (mirrors persona-kit): ctx.persona.inputs (already
|
|
5
|
+
* resolved from agent value → env → default by the runtime) → fall back
|
|
6
|
+
* to process.env directly when running outside the full runtime.
|
|
7
|
+
*/
|
|
8
|
+
export function input(ctx, name) {
|
|
9
|
+
const spec = ctx.persona.inputSpecs?.[name];
|
|
10
|
+
// ctx.persona.inputs is already resolved by the runtime (agent value →
|
|
11
|
+
// env → default). Check it first since it reflects the canonical value.
|
|
12
|
+
const fromCtx = ctx.persona.inputs?.[name];
|
|
13
|
+
if (fromCtx && String(fromCtx).trim())
|
|
14
|
+
return String(fromCtx).trim();
|
|
15
|
+
// Fall back to raw process.env for local dev outside the full runtime.
|
|
16
|
+
const fromEnv = process.env[spec?.env ?? name];
|
|
17
|
+
if (fromEnv && String(fromEnv).trim())
|
|
18
|
+
return String(fromEnv).trim();
|
|
19
|
+
// Last resort: the spec default.
|
|
20
|
+
const def = spec?.default;
|
|
21
|
+
if (def != null && String(def).trim())
|
|
22
|
+
return String(def).trim();
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Split a comma-separated string into trimmed, non-empty entries.
|
|
27
|
+
*/
|
|
28
|
+
export function list(raw) {
|
|
29
|
+
return (raw ?? '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Race a promise against a timeout. On timeout the timer rejects with an
|
|
33
|
+
* Error so the caller can catch and fall back. Always clears the timer.
|
|
34
|
+
*/
|
|
35
|
+
export async function withTimeout(p, ms, label) {
|
|
36
|
+
let timer;
|
|
37
|
+
const timeout = new Promise((_, rej) => {
|
|
38
|
+
timer = setTimeout(() => rej(new Error(`${label} timed out after ${ms}ms`)), ms);
|
|
39
|
+
});
|
|
40
|
+
try {
|
|
41
|
+
return await Promise.race([p, timeout]);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fetch with an AbortController timeout. Returns the response on success,
|
|
49
|
+
* or undefined on timeout/network error (never throws). Preserves caller-
|
|
50
|
+
* provided signal by racing our abort against it.
|
|
51
|
+
*/
|
|
52
|
+
export async function fetchWithTimeout(url, init = {}, timeoutMs = 8_000) {
|
|
53
|
+
const controller = new AbortController();
|
|
54
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
55
|
+
const signal = init.signal
|
|
56
|
+
? anySignal([controller.signal, init.signal])
|
|
57
|
+
: controller.signal;
|
|
58
|
+
try {
|
|
59
|
+
return await fetch(url, { ...init, signal });
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Combine multiple AbortSignals — any one firing aborts the fetch. */
|
|
69
|
+
function anySignal(signals) {
|
|
70
|
+
const controller = new AbortController();
|
|
71
|
+
for (const sig of signals) {
|
|
72
|
+
if (sig.aborted) {
|
|
73
|
+
controller.abort(sig.reason);
|
|
74
|
+
return controller.signal;
|
|
75
|
+
}
|
|
76
|
+
sig.addEventListener('abort', () => controller.abort(sig.reason), { once: true });
|
|
77
|
+
}
|
|
78
|
+
return controller.signal;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAC,GAAiB,EAAE,IAAY;IACnD,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC;IAC5C,uEAAuE;IACvE,wEAAwE;IACxE,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE;QAAE,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACrE,uEAAuE;IACvE,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC;IAC/C,IAAI,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE;QAAE,OAAO,MAAM,CAAC,OAAO,CAAC,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,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM;QACxB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;IACtB,IAAI,CAAC;QACH,OAAO,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC;AAED,uEAAuE;AACvE,SAAS,SAAS,CAAC,OAAsB;IACvC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAChB,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAC7B,OAAO,UAAU,CAAC,MAAM,CAAC;QAC3B,CAAC;QACD,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACpF,CAAC;IACD,OAAO,UAAU,CAAC,MAAM,CAAC;AAC3B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createDelivery } from './delivery.js';
|
|
2
|
+
export { resolveDeliveryTargets, slackChannel, telegramChat, type DeliveryClient, type DeliveryOptions, type DeliveryResult, type DeliveryTransports, type MessageRef, type SlackRef, type TelegramRef } from './types.js';
|
|
3
|
+
export { input, list, withTimeout, fetchWithTimeout } from './helpers.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,YAAY,EAQb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { WorkforceCtx } from '@agentworkforce/runtime';
|
|
2
|
+
import type { SlackClient } from '@relayfile/relay-helpers';
|
|
3
|
+
import type { TelegramClient } from '@relayfile/relay-helpers';
|
|
4
|
+
export interface SlackRef {
|
|
5
|
+
provider: 'slack';
|
|
6
|
+
channel: string;
|
|
7
|
+
/** Delivered message ts (set after the writeback receipt arrives). */
|
|
8
|
+
ts: string;
|
|
9
|
+
/** Draft ref for cloud-side replyTo threading. */
|
|
10
|
+
draftRef: string;
|
|
11
|
+
}
|
|
12
|
+
export interface TelegramRef {
|
|
13
|
+
provider: 'telegram';
|
|
14
|
+
chatId: string;
|
|
15
|
+
/** Delivered message id (set after the writeback receipt arrives). */
|
|
16
|
+
messageId: string;
|
|
17
|
+
}
|
|
18
|
+
export type MessageRef = SlackRef | TelegramRef;
|
|
19
|
+
export interface DeliveryResult {
|
|
20
|
+
ok: boolean;
|
|
21
|
+
refs: MessageRef[];
|
|
22
|
+
}
|
|
23
|
+
export interface DeliveryOptions {
|
|
24
|
+
/** Thread the message under a prior delivery result. */
|
|
25
|
+
replyTo?: DeliveryResult;
|
|
26
|
+
/**
|
|
27
|
+
* When true, don't wait for the writeback receipt. Returns draft refs
|
|
28
|
+
* immediately and relies on the cloud's server-side ordering for
|
|
29
|
+
* threading (Slack parentRef pattern, Telegram sendMessage with 0ms
|
|
30
|
+
* timeout). The returned refs have empty ts/messageId but valid
|
|
31
|
+
* draftRef for use as a parent in subsequent threaded sends.
|
|
32
|
+
*
|
|
33
|
+
* Use this for the header in a header+threaded-body pattern so the
|
|
34
|
+
* digest never blocks on a receipt — the cloud orders the threaded
|
|
35
|
+
* body under the header server-side.
|
|
36
|
+
*/
|
|
37
|
+
nonBlocking?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface DeliveryTransports {
|
|
40
|
+
/** Injected Slack client (used for both blocking and non-blocking paths). */
|
|
41
|
+
slack?: SlackClient;
|
|
42
|
+
/** Injected Telegram client (used for both blocking and non-blocking paths). */
|
|
43
|
+
telegram?: TelegramClient;
|
|
44
|
+
}
|
|
45
|
+
export interface DeliveryClient {
|
|
46
|
+
/**
|
|
47
|
+
* Send a message to all configured targets.
|
|
48
|
+
*
|
|
49
|
+
* When `opts.replyTo` is set the message is threaded under the targets
|
|
50
|
+
* from that prior `DeliveryResult`, each using its transport's native
|
|
51
|
+
* threading mechanism.
|
|
52
|
+
*
|
|
53
|
+
* In blocking mode (default): waits for the writeback receipt and returns
|
|
54
|
+
* the delivered ts/messageId. In non-blocking mode (`opts.nonBlocking: true`):
|
|
55
|
+
* returns draft refs immediately with the relay path as draftRef — zero
|
|
56
|
+
* receipt round-trips, cloud-side server ordering handles threading.
|
|
57
|
+
*/
|
|
58
|
+
send(text: string, opts?: DeliveryOptions): Promise<DeliveryResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Convenience: same as `send(text, { nonBlocking: true })`.
|
|
61
|
+
* Publish a message without waiting for a receipt. Returns draft refs
|
|
62
|
+
* immediately for use as a threading parent.
|
|
63
|
+
*/
|
|
64
|
+
publish(text: string): Promise<DeliveryResult>;
|
|
65
|
+
/** Which providers are configured. */
|
|
66
|
+
readonly targets: ReadonlyArray<'slack' | 'telegram'>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve which transport targets are configured for the given persona ctx.
|
|
70
|
+
* Uses input() helper for proper resolution order (ctx → env → default).
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveDeliveryTargets(ctx: WorkforceCtx): Array<'slack' | 'telegram'>;
|
|
73
|
+
/**
|
|
74
|
+
* Get the configured slack channel id (bare, without `__name` suffix).
|
|
75
|
+
* Uses input() for proper resolution.
|
|
76
|
+
*/
|
|
77
|
+
export declare function slackChannel(ctx: WorkforceCtx): string | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Get the configured telegram chat id (bare, without `__title` suffix).
|
|
80
|
+
* Uses input() for proper resolution.
|
|
81
|
+
*/
|
|
82
|
+
export declare function telegramChat(ctx: WorkforceCtx): string | undefined;
|
|
83
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAK/D,MAAM,WAAW,QAAQ;IACvB,QAAQ,EA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AED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAGlE"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { input } from './helpers.js';
|
|
2
|
+
// ── configuration discovery ──────────────────────────────────────────────
|
|
3
|
+
/**
|
|
4
|
+
* Resolve which transport targets are configured for the given persona ctx.
|
|
5
|
+
* Uses input() helper for proper resolution order (ctx → env → default).
|
|
6
|
+
*/
|
|
7
|
+
export function resolveDeliveryTargets(ctx) {
|
|
8
|
+
const targets = [];
|
|
9
|
+
if (input(ctx, 'SLACK_CHANNEL'))
|
|
10
|
+
targets.push('slack');
|
|
11
|
+
if (input(ctx, 'TELEGRAM_CHAT'))
|
|
12
|
+
targets.push('telegram');
|
|
13
|
+
return targets;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get the configured slack channel id (bare, without `__name` suffix).
|
|
17
|
+
* Uses input() for proper resolution.
|
|
18
|
+
*/
|
|
19
|
+
export function slackChannel(ctx) {
|
|
20
|
+
const raw = input(ctx, 'SLACK_CHANNEL');
|
|
21
|
+
return raw?.split('__')[0]?.trim() || undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the configured telegram chat id (bare, without `__title` suffix).
|
|
25
|
+
* Uses input() for proper resolution.
|
|
26
|
+
*/
|
|
27
|
+
export function telegramChat(ctx) {
|
|
28
|
+
const raw = input(ctx, 'TELEGRAM_CHAT');
|
|
29
|
+
return raw?.split('__')[0]?.trim() || undefined;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAqFrC,4EAA4E;AAE5E;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAiB;IACtD,MAAM,OAAO,GAAgC,EAAE,CAAC;IAChD,IAAI,KAAK,CAAC,GAAG,EAAE,eAAe,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvD,IAAI,KAAK,CAAC,GAAG,EAAE,eAAe,CAAC;QAAE,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1D,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAAiB;IAC5C,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACxC,OAAO,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;AAClD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,GAAiB;IAC5C,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACxC,OAAO,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;AAClD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentworkforce/delivery",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"package.json"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/AgentWorkforce/workforce",
|
|
22
|
+
"directory": "packages/delivery"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json",
|
|
29
|
+
"dev": "tsc -p tsconfig.json --watch --preserveWatchOutput",
|
|
30
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
31
|
+
"test": "tsc -p tsconfig.json && node --test dist/**/*.test.js dist/*.test.js",
|
|
32
|
+
"lint": "tsc -p tsconfig.json --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@agentworkforce/runtime": "workspace:*",
|
|
36
|
+
"@relayfile/relay-helpers": "^0.4.2"
|
|
37
|
+
}
|
|
38
|
+
}
|