@segmentstream/agent 0.8.9 → 0.8.11
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/_chunks/{build-metadata-Cq-Li9W7.mjs → build-metadata-zRhAH0hT.mjs} +1 -1
- package/dist/_chunks/{inbound-request-B98tr4Pd.mjs → inbound-request-B8Eyjz1O.mjs} +10 -0
- package/dist/extension/instructions.md +3 -1
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/confirmation-outcome.d.ts +10 -2
- package/dist/extension/lib/ontology-gateway.d.ts +2 -2
- package/dist/extension/lib/ontology-gateway.mjs +13 -12
- package/dist/extension/lib/ontology-metadata-read.d.ts +15 -0
- package/dist/extension/lib/ontology-metadata-read.mjs +126 -0
- package/dist/extension/lib/ontology-tools.d.ts +4 -0
- package/dist/extension/lib/ontology-tools.mjs +33 -4
- package/dist/extension/lib/telegram/adapter.mjs +10 -3
- package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
- package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
- package/dist/extension/lib/telegram/confirmation-expiry.mjs +1 -1
- package/dist/extension/lib/telegram/confirmations.mjs +1 -1
- package/dist/extension/lib/telegram/conversations.mjs +36 -11
- package/dist/extension/lib/telegram/customer-text.mjs +1 -1
- package/dist/extension/lib/telegram/deferred-confirmations.d.ts +1 -1
- package/dist/extension/lib/telegram/deferred-confirmations.mjs +15 -3
- package/dist/extension/lib/telegram/files.mjs +1 -1
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/images.mjs +1 -1
- package/dist/extension/lib/telegram/inbound-request.d.ts +2 -0
- package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.mjs +24 -1
- package/dist/extension/lib/telegram/lifecycle.d.ts +3 -0
- package/dist/extension/lib/telegram/lifecycle.mjs +4 -2
- package/dist/extension/lib/telegram/media-policy.mjs +1 -1
- package/dist/extension/lib/telegram/silent.mjs +1 -1
- package/dist/extension/lib/telegram/turn-errors.mjs +1 -1
- package/dist/extension/lib/telegram/voice.mjs +1 -1
- package/dist/extension/tools/ontology.d.ts +4 -4
- package/package.json +2 -2
|
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
var version = "0.8.
|
|
7
|
+
var version = "0.8.11";
|
|
8
8
|
function agentBuild(environment = process.env) {
|
|
9
9
|
return {
|
|
10
10
|
agent: version,
|
|
@@ -240,6 +240,8 @@ var InboundRequest = class {
|
|
|
240
240
|
stopTyping;
|
|
241
241
|
lifecycle;
|
|
242
242
|
lifecycleKey;
|
|
243
|
+
lifecycleDispatchToken;
|
|
244
|
+
releaseLifecycleDispatch;
|
|
243
245
|
retryReference;
|
|
244
246
|
lifecycleContext;
|
|
245
247
|
monitor;
|
|
@@ -330,6 +332,14 @@ function withReplacedText(source, request) {
|
|
|
330
332
|
turnPolicy: "queue"
|
|
331
333
|
});
|
|
332
334
|
} catch (error) {
|
|
335
|
+
try {
|
|
336
|
+
await request.releaseLifecycleDispatch?.();
|
|
337
|
+
} catch (cleanupError) {
|
|
338
|
+
console.error("[segmentstream] inventory dispatch cleanup failed", {
|
|
339
|
+
cleanupError,
|
|
340
|
+
cause: error
|
|
341
|
+
});
|
|
342
|
+
}
|
|
333
343
|
try {
|
|
334
344
|
await request.finishClaim?.(false);
|
|
335
345
|
await request.deliveryFailed?.(error);
|
|
@@ -97,7 +97,9 @@ If context is missing, do not guess which target changed. Never print, quote, li
|
|
|
97
97
|
technical correlation identifiers in chat. Report the outcome in your own words in the
|
|
98
98
|
conversation's language. Only `done` means completion.
|
|
99
99
|
`approved` means a decision was recorded, with completion still unknown; `failed` may include an
|
|
100
|
-
uncertain external outcome, so never retry automatically
|
|
100
|
+
uncertain external outcome, so never retry automatically, including with a fresh call or key.
|
|
101
|
+
`execution: "uncertain"` requires checking the actual operation state before any new write.
|
|
102
|
+
`execution: "not_started"` means the
|
|
101
103
|
action was prevented before execution; report that it did not run. For `cancelled` or `expired`, say the
|
|
102
104
|
action did not run. If `editRequested` is true, ask what to change with questions_ask and make a
|
|
103
105
|
new call and confirmation. Never repeat raw parameters or technical identifiers from tools.
|
|
@@ -4,5 +4,5 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { t as agentBuild } from "../../_chunks/build-metadata-
|
|
7
|
+
import { t as agentBuild } from "../../_chunks/build-metadata-zRhAH0hT.mjs";
|
|
8
8
|
export { agentBuild };
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import type { DeferredConfirmation } from "./deferred-confirmations.js";
|
|
2
2
|
/** Model-only correlation plus bounded display context; never forward business input or results. */
|
|
3
3
|
export declare function confirmationOutcome(record: DeferredConfirmation, status: Exclude<DeferredConfirmation["status"], "pending">, detail?: {
|
|
4
|
-
readonly execution?: "not_started";
|
|
4
|
+
readonly execution?: "not_started" | "uncertain";
|
|
5
5
|
readonly editRequested?: boolean;
|
|
6
|
+
readonly error?: {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
};
|
|
6
10
|
}): {
|
|
7
|
-
execution?: "not_started";
|
|
11
|
+
execution?: "not_started" | "uncertain";
|
|
8
12
|
editRequested?: boolean;
|
|
13
|
+
error?: {
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
};
|
|
9
17
|
context?: {
|
|
10
18
|
targets?: {
|
|
11
19
|
label: string;
|
|
@@ -12,9 +12,9 @@ export declare function ontologyInspect(memberId: string, input: {
|
|
|
12
12
|
limit?: number;
|
|
13
13
|
}, context: ToolContext, options?: Options): Promise<{
|
|
14
14
|
next_after?: string | undefined;
|
|
15
|
-
tools: {
|
|
15
|
+
tools: (Record<string, unknown> & {
|
|
16
16
|
name: string;
|
|
17
17
|
description: string;
|
|
18
|
-
}[];
|
|
18
|
+
})[];
|
|
19
19
|
}>;
|
|
20
20
|
export {};
|
|
@@ -6,26 +6,27 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { memberIdOf } from "./telegram/principal.mjs";
|
|
8
8
|
import { object } from "./confirmation-description.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import { readOntologyMetadata } from "./ontology-metadata-read.mjs";
|
|
10
10
|
async function ontologyMetadata(memberId, operation, input, context, options = {}) {
|
|
11
11
|
const principal = context.session.auth.current;
|
|
12
12
|
if (memberIdOf(principal) !== memberId) throw new Error("The ontology tool belongs to another member.");
|
|
13
|
-
const result = await
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
13
|
+
const result = await readOntologyMetadata(memberId, {
|
|
14
|
+
method: "tools/call",
|
|
15
|
+
params: {
|
|
16
|
+
name: operation,
|
|
17
|
+
arguments: input
|
|
18
|
+
}
|
|
19
|
+
}, context, options);
|
|
20
20
|
return result.structuredContent === void 0 ? result : object(result.structuredContent);
|
|
21
21
|
}
|
|
22
22
|
async function ontologyInspect(memberId, input, context, options = {}) {
|
|
23
23
|
const principal = context.session.auth.current;
|
|
24
24
|
if (memberIdOf(principal) !== memberId) throw new Error("The ontology tool belongs to another member.");
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
25
|
+
const listing = await readOntologyMetadata(memberId, {
|
|
26
|
+
method: "tools/list",
|
|
27
|
+
params: {}
|
|
28
|
+
}, context, options);
|
|
29
|
+
const tools = (Array.isArray(listing.tools) ? listing.tools.map(object) : []).flatMap((tool) => typeof tool.name === "string" ? [{
|
|
29
30
|
...tool,
|
|
30
31
|
name: tool.name,
|
|
31
32
|
description: String(tool.description ?? "")
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ToolContext } from "eve/tools";
|
|
2
|
+
import { ontologyTools } from "./ontology-tools.js";
|
|
3
|
+
type Options = Omit<NonNullable<Parameters<typeof ontologyTools>[0]>, "principal">;
|
|
4
|
+
/** Only metadata reads enter this boundary. Never cache permission/prepare checks or retry actions. */
|
|
5
|
+
export declare function readOntologyMetadata(memberId: string, request: {
|
|
6
|
+
method: "tools/list";
|
|
7
|
+
params: Record<string, never>;
|
|
8
|
+
} | {
|
|
9
|
+
method: "tools/call";
|
|
10
|
+
params: {
|
|
11
|
+
name: "discover" | "describe";
|
|
12
|
+
arguments: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
}, context: ToolContext, options?: Options): Promise<Record<string, unknown>>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { fileURLToPath as __eveFileURLToPath } from "node:url";
|
|
2
|
+
import { dirname as __eveDirname } from "node:path";
|
|
3
|
+
import { createRequire as __eveCreateRequire } from "node:module";
|
|
4
|
+
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
|
+
__eveDirname(__filename);
|
|
6
|
+
__eveCreateRequire(import.meta.url);
|
|
7
|
+
import { appOrigin } from "./environment.mjs";
|
|
8
|
+
import { memberIdOf } from "./telegram/principal.mjs";
|
|
9
|
+
import { redactDiagnostic } from "./diagnostics.mjs";
|
|
10
|
+
import { object } from "./confirmation-description.mjs";
|
|
11
|
+
import { OntologyToolRejected, ontologyTools } from "./ontology-tools.mjs";
|
|
12
|
+
import { randomUUID } from "node:crypto";
|
|
13
|
+
import { isDeepStrictEqual } from "node:util";
|
|
14
|
+
const scopes = new Map();
|
|
15
|
+
const cache = new Map();
|
|
16
|
+
let cachedBytes = 0;
|
|
17
|
+
const CACHE_BYTES = 8388608;
|
|
18
|
+
const CACHE_TTL = 3e4;
|
|
19
|
+
function remove(key) {
|
|
20
|
+
cachedBytes -= cache.get(key)?.bytes ?? 0;
|
|
21
|
+
cache.delete(key);
|
|
22
|
+
}
|
|
23
|
+
function retryable(error, depth = 0) {
|
|
24
|
+
if (depth > 8) return false;
|
|
25
|
+
const value = object(error);
|
|
26
|
+
if (object(value.structuredContent).error === "internal_error") return true;
|
|
27
|
+
if (typeof value.status === "number") return value.status === 429 || value.status >= 500;
|
|
28
|
+
if ([
|
|
29
|
+
"TypeError",
|
|
30
|
+
"TimeoutError",
|
|
31
|
+
"AbortError"
|
|
32
|
+
].includes(String(value.name))) return true;
|
|
33
|
+
return value.cause !== void 0 && retryable(value.cause, depth + 1);
|
|
34
|
+
}
|
|
35
|
+
function invalidatesSnapshot(error, depth = 0) {
|
|
36
|
+
if (depth > 8) return false;
|
|
37
|
+
const value = object(error);
|
|
38
|
+
return value.status === 401 || value.status === 403 || [
|
|
39
|
+
"ontology_version_mismatch",
|
|
40
|
+
"forbidden",
|
|
41
|
+
"unauthorized",
|
|
42
|
+
"not_invited"
|
|
43
|
+
].includes(String(object(value.structuredContent).error)) || value.cause !== void 0 && invalidatesSnapshot(value.cause, depth + 1);
|
|
44
|
+
}
|
|
45
|
+
async function readOntologyMetadata(memberId, request, context, options = {}) {
|
|
46
|
+
const principal = context.session.auth.current;
|
|
47
|
+
if (memberIdOf(principal) !== memberId) throw new Error("The ontology tool belongs to another member.");
|
|
48
|
+
const session = context.session.id;
|
|
49
|
+
const args = request.method === "tools/call" ? request.params.arguments : {};
|
|
50
|
+
const scope = principal && typeof session === "string" && session !== "" ? JSON.stringify([
|
|
51
|
+
appOrigin(options.environment ?? process.env),
|
|
52
|
+
session,
|
|
53
|
+
memberId
|
|
54
|
+
]) : void 0;
|
|
55
|
+
let state = scope === void 0 ? void 0 : scopes.get(scope);
|
|
56
|
+
if (scope !== void 0 && principal) {
|
|
57
|
+
if (!state || !isDeepStrictEqual(state.principal, principal)) state = {
|
|
58
|
+
principal: structuredClone(principal),
|
|
59
|
+
generation: 0
|
|
60
|
+
};
|
|
61
|
+
scopes.delete(scope);
|
|
62
|
+
scopes.set(scope, state);
|
|
63
|
+
while (scopes.size > 128) scopes.delete(scopes.keys().next().value);
|
|
64
|
+
}
|
|
65
|
+
const generation = state?.generation;
|
|
66
|
+
const key = state && args.expected_hash === void 0 ? JSON.stringify([scope, request]) : void 0;
|
|
67
|
+
const existing = key === void 0 ? void 0 : cache.get(key);
|
|
68
|
+
if (existing && existing.state === state && existing.generation === generation && existing.until > Date.now()) {
|
|
69
|
+
cache.delete(key);
|
|
70
|
+
cache.set(key, existing);
|
|
71
|
+
return structuredClone(existing.value);
|
|
72
|
+
}
|
|
73
|
+
if (key !== void 0) remove(key);
|
|
74
|
+
const client = ontologyTools({
|
|
75
|
+
...options,
|
|
76
|
+
principal
|
|
77
|
+
});
|
|
78
|
+
let attempts = 0;
|
|
79
|
+
for (;;) {
|
|
80
|
+
attempts++;
|
|
81
|
+
try {
|
|
82
|
+
const result = await client.rpc(memberId, request.method, request.params, AbortSignal.timeout(4e3));
|
|
83
|
+
if (key !== void 0 && scope !== void 0 && state && scopes.get(scope) === state && state.generation === generation) {
|
|
84
|
+
const bytes = Buffer.byteLength(JSON.stringify(result));
|
|
85
|
+
if (bytes <= 2097152) {
|
|
86
|
+
while (cache.size && (cache.size >= 128 || cachedBytes + bytes > CACHE_BYTES)) remove(cache.keys().next().value);
|
|
87
|
+
remove(key);
|
|
88
|
+
cache.set(key, {
|
|
89
|
+
state,
|
|
90
|
+
generation: state.generation,
|
|
91
|
+
value: structuredClone(result),
|
|
92
|
+
until: Date.now() + CACHE_TTL,
|
|
93
|
+
bytes
|
|
94
|
+
});
|
|
95
|
+
cachedBytes += bytes;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
} catch (cause) {
|
|
100
|
+
if (state && invalidatesSnapshot(cause)) {
|
|
101
|
+
state.generation++;
|
|
102
|
+
for (const [cachedKey, entry] of cache) if (entry.state === state) remove(cachedKey);
|
|
103
|
+
}
|
|
104
|
+
const mayRetry = retryable(cause);
|
|
105
|
+
if (mayRetry && args.expected_hash === void 0 && attempts < 3) {
|
|
106
|
+
await new Promise((resolve) => setTimeout(resolve, attempts * 100));
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const reference = randomUUID();
|
|
110
|
+
const publicReason = cause instanceof OntologyToolRejected ? `;${cause.message.slice(0, 4096)}` : "";
|
|
111
|
+
const error = Object.assign(new Error(`ontology_metadata_unavailable:${reference};retryable=${mayRetry}${publicReason}`, { cause }), {
|
|
112
|
+
code: "ontology_metadata_unavailable",
|
|
113
|
+
retryable: mayRetry,
|
|
114
|
+
reference,
|
|
115
|
+
attempts
|
|
116
|
+
});
|
|
117
|
+
console.error("[segmentstream] ontology_metadata_unavailable", {
|
|
118
|
+
reference,
|
|
119
|
+
attempts,
|
|
120
|
+
error: redactDiagnostic(error, new Set())
|
|
121
|
+
});
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export { readOntologyMetadata };
|
|
@@ -2,6 +2,10 @@ import type { SessionAuthContext } from "eve/context";
|
|
|
2
2
|
import type { ActionAnnotations } from "./confirmations.js";
|
|
3
3
|
import { type Environment } from "./environment.js";
|
|
4
4
|
import { type RuntimeToken } from "./runtime-token.js";
|
|
5
|
+
/** Only the ontology's public MCP rejection may be carried back to a deferred caller. */
|
|
6
|
+
export declare class OntologyToolRejected extends Error {
|
|
7
|
+
readonly code = "ontology_tool_rejected";
|
|
8
|
+
}
|
|
5
9
|
/** A fresh, permission-filtered catalog. Listing tools cannot run an action's prepare step. */
|
|
6
10
|
export declare function ontologyTools(options?: {
|
|
7
11
|
readonly principal?: SessionAuthContext | null;
|
|
@@ -10,6 +10,10 @@ import { redactDiagnostic } from "./diagnostics.mjs";
|
|
|
10
10
|
import { describeConfirmation, object } from "./confirmation-description.mjs";
|
|
11
11
|
import { describeChatPost, isChatPost, supportsChatPost } from "./chat-post-confirmation.mjs";
|
|
12
12
|
import { runtimeToken } from "./runtime-token.mjs";
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
14
|
+
var OntologyToolRejected = class extends Error {
|
|
15
|
+
code = "ontology_tool_rejected";
|
|
16
|
+
};
|
|
13
17
|
function ontologyTools(options = {}) {
|
|
14
18
|
async function rpc(memberId, method, params, signal) {
|
|
15
19
|
const provider = memberIdOf(options.principal) === memberId ? identityProviderOf(options.principal) : void 0;
|
|
@@ -35,14 +39,39 @@ function ontologyTools(options = {}) {
|
|
|
35
39
|
signal: signal ?? AbortSignal.timeout(15e3),
|
|
36
40
|
redirect: "error"
|
|
37
41
|
});
|
|
38
|
-
if (!response.ok) throw new Error(`Cannot check action permission (HTTP ${response.status}).`, { cause: await response.text() });
|
|
42
|
+
if (!response.ok) throw Object.assign(new Error(`Cannot check action permission (HTTP ${response.status}).`, { cause: await response.text() }), { status: response.status });
|
|
39
43
|
const body = object(await response.json());
|
|
40
44
|
if (body.error !== void 0) throw new Error("Ontology metadata unavailable.", { cause: body.error });
|
|
41
45
|
const result = object(body.result);
|
|
42
|
-
if (result.isError === true)
|
|
46
|
+
if (result.isError === true) {
|
|
47
|
+
const message = (Array.isArray(result.content) ? result.content : []).map(object).filter((part) => part.type === "text" && typeof part.text === "string").map((part) => part.text).join("\n");
|
|
48
|
+
if ([
|
|
49
|
+
"action_rejected",
|
|
50
|
+
"invalid_input",
|
|
51
|
+
"invalid_request",
|
|
52
|
+
"invalid_json",
|
|
53
|
+
"unsupported_media_type",
|
|
54
|
+
"forbidden",
|
|
55
|
+
"unauthorized",
|
|
56
|
+
"not_invited",
|
|
57
|
+
"not_found",
|
|
58
|
+
"conflict",
|
|
59
|
+
"invalid_cursor",
|
|
60
|
+
"ontology_version_mismatch",
|
|
61
|
+
"discovery_too_large"
|
|
62
|
+
].includes(String(object(result.structuredContent).error))) throw new OntologyToolRejected(message || "ontology_operation_rejected", { cause: result });
|
|
63
|
+
throw new Error("ontology_action_outcome_uncertain", { cause: result });
|
|
64
|
+
}
|
|
43
65
|
return result;
|
|
44
66
|
} catch (error) {
|
|
45
|
-
|
|
67
|
+
const diagnostic = redactDiagnostic(error, secrets);
|
|
68
|
+
const reference = randomUUID();
|
|
69
|
+
console.error("[segmentstream] ontology_request_failed", {
|
|
70
|
+
reference,
|
|
71
|
+
error: diagnostic
|
|
72
|
+
});
|
|
73
|
+
if (error instanceof OntologyToolRejected) throw new OntologyToolRejected(String(object(diagnostic).message), { cause: diagnostic });
|
|
74
|
+
throw new Error(`The ontology request failed (${reference}).`, { cause: diagnostic });
|
|
46
75
|
}
|
|
47
76
|
}
|
|
48
77
|
async function toolFor(memberId, action, signal) {
|
|
@@ -189,4 +218,4 @@ function promotionTarget(input) {
|
|
|
189
218
|
}
|
|
190
219
|
};
|
|
191
220
|
}
|
|
192
|
-
export { actionToolName, ontologyToolLabels, ontologyTools, promotionTarget };
|
|
221
|
+
export { OntologyToolRejected, actionToolName, ontologyToolLabels, ontologyTools, promotionTarget };
|
|
@@ -8,10 +8,10 @@ import { manifestOf } from "../../config.mjs";
|
|
|
8
8
|
import { appOrigin, channelsEnabled, proxyEnvironment, runtimeIdentityEnvironment, webhookSecret } from "../environment.mjs";
|
|
9
9
|
import { conversationLanguage, telegramPrincipal } from "./principal.mjs";
|
|
10
10
|
import { chooseModel } from "../../model.mjs";
|
|
11
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
11
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-zRhAH0hT.mjs";
|
|
12
12
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
13
13
|
import { telegramSendScope } from "./send-queue.mjs";
|
|
14
|
-
import { d as failureText, h as withDeliveryLocale, i as withReplacedText, m as safeTelegramFetch, n as currentInboundRequest, p as reportTelegramError, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-
|
|
14
|
+
import { d as failureText, h as withDeliveryLocale, i as withReplacedText, m as safeTelegramFetch, n as currentInboundRequest, p as reportTelegramError, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
15
15
|
import { runtimeToken } from "../runtime-token.mjs";
|
|
16
16
|
import { attachmentLifecycle } from "./lifecycle.mjs";
|
|
17
17
|
import { conversations } from "../conversations.mjs";
|
|
@@ -234,6 +234,7 @@ function segmentstreamTelegram(options) {
|
|
|
234
234
|
connectUrl: (code) => `${appOrigin(environment)}/agent/connect?code=${encodeURIComponent(code)}`
|
|
235
235
|
}
|
|
236
236
|
});
|
|
237
|
+
if (result === null) await inbound?.releaseLifecycleDispatch?.();
|
|
237
238
|
if (inbound !== void 0 && result !== null) {
|
|
238
239
|
inbound.locale = confirmationLocale(result.auth);
|
|
239
240
|
inbound.deliveryFailed = async (error) => {
|
|
@@ -252,6 +253,11 @@ function segmentstreamTelegram(options) {
|
|
|
252
253
|
return result;
|
|
253
254
|
} catch (error) {
|
|
254
255
|
recordGateDecision("inbound_message_failed");
|
|
256
|
+
try {
|
|
257
|
+
await inbound?.releaseLifecycleDispatch?.();
|
|
258
|
+
} catch (cleanupError) {
|
|
259
|
+
reportTelegramError("intake_dispatch_release_failed", cleanupError);
|
|
260
|
+
}
|
|
255
261
|
const errorId = reportTelegramError("inbound_message_failed", error, { chatId: message.chat.id });
|
|
256
262
|
if (inbound?.retryReference !== void 0 || inbound?.lifecycleKey !== void 0) inbound.retryReference = errorId;
|
|
257
263
|
else await context.telegram.post(failureText(errorId));
|
|
@@ -321,7 +327,8 @@ function segmentstreamTelegram(options) {
|
|
|
321
327
|
}
|
|
322
328
|
})("completed", {
|
|
323
329
|
key: taskId,
|
|
324
|
-
...configuration.contextVersion === 2 ? { reply: event.message } : {}
|
|
330
|
+
...configuration.contextVersion === 2 ? { reply: event.message } : {},
|
|
331
|
+
...typeof principal.attributes.attachmentDispatchToken === "string" ? { dispatch_token: principal.attributes.attachmentDispatchToken } : {}
|
|
325
332
|
});
|
|
326
333
|
if (result.message !== void 0 || result.complete === false) event = {
|
|
327
334
|
...event,
|
|
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
7
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
8
8
|
import { describableImage } from "./images.mjs";
|
|
9
9
|
import { MAXIMUM_ROUTING_PDF_CHARACTERS, extractRoutingPdf } from "./pdf-text.mjs";
|
|
10
10
|
import { gateway, generateText } from "ai";
|
|
@@ -9,7 +9,7 @@ import "./principal.mjs";
|
|
|
9
9
|
import { redactDiagnostic } from "../diagnostics.mjs";
|
|
10
10
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
11
11
|
import { inTelegramSendQueue, telegramSendScope } from "./send-queue.mjs";
|
|
12
|
-
import { c as customerCopy, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
12
|
+
import { c as customerCopy, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
13
13
|
import { runtimeToken } from "../runtime-token.mjs";
|
|
14
14
|
import { MAXIMUM_PROXY_BODY_BYTES, connectionProxy } from "../connection-proxy.mjs";
|
|
15
15
|
import { ACT_AS_HEADER } from "../ontology-connection.mjs";
|
|
@@ -6,7 +6,7 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { proxyEnvironment } from "../environment.mjs";
|
|
8
8
|
import { telegramSendScope } from "./send-queue.mjs";
|
|
9
|
-
import { m as safeTelegramFetch, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
9
|
+
import { m as safeTelegramFetch, p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
10
10
|
import { runtimeToken } from "../runtime-token.mjs";
|
|
11
11
|
import { deferredConfirmations } from "../deferred-confirmations.mjs";
|
|
12
12
|
import { conversations } from "../conversations.mjs";
|
|
@@ -8,7 +8,7 @@ import { memberIdOf, telegramPrincipal } from "./principal.mjs";
|
|
|
8
8
|
import { humanText } from "../confirmation-description.mjs";
|
|
9
9
|
import { renderConfirmation, withConfirmationText } from "./confirmation-text.mjs";
|
|
10
10
|
import { chatPostCard, chatPostCardStatus, chatPostReceipt, withChatPostCard } from "./chat-post-card.mjs";
|
|
11
|
-
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
11
|
+
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
12
12
|
import { chatPostOperationId, isChatPost } from "../chat-post-confirmation.mjs";
|
|
13
13
|
import { confirmations } from "../confirmations.mjs";
|
|
14
14
|
import { conversationEvent } from "../conversations.mjs";
|
|
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { n as currentInboundRequest, s as currentThreadId } from "../../../_chunks/inbound-request-
|
|
7
|
+
import { n as currentInboundRequest, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
8
8
|
import { conversationEvent } from "../conversations.mjs";
|
|
9
9
|
import { contentShape, messageContent } from "./content.mjs";
|
|
10
10
|
import { currentConfirmationPrompt, messageMetadata, observedChatKey } from "./observed.mjs";
|
|
@@ -266,6 +266,7 @@ async function captureTelegramWebhook(input) {
|
|
|
266
266
|
capture.decision = "silent";
|
|
267
267
|
capture.reason = "message_already_handled";
|
|
268
268
|
}
|
|
269
|
+
let accepted = false;
|
|
269
270
|
if (inbound !== void 0) {
|
|
270
271
|
inbound.edited = edited !== void 0;
|
|
271
272
|
if (revisionId !== void 0) inbound.claimRevision = async () => {
|
|
@@ -292,7 +293,6 @@ async function captureTelegramWebhook(input) {
|
|
|
292
293
|
const nextClaim = previousClaim === void 0 ? void 0 : createHash("sha256").update(previousClaim.eventId).digest("hex");
|
|
293
294
|
const claimId = previousClaim === void 0 ? `telegram:${message.chat.id}:${message.messageId}:turn` : `telegram:${message.chat.id}:${message.messageId}:turn:${nextClaim}`;
|
|
294
295
|
let claimed = false;
|
|
295
|
-
let accepted = false;
|
|
296
296
|
let dispatchStarted = false;
|
|
297
297
|
const claimEvent = (reason, status, suffix = "") => ({
|
|
298
298
|
...capture.event,
|
|
@@ -336,6 +336,14 @@ async function captureTelegramWebhook(input) {
|
|
|
336
336
|
message: messagePayload
|
|
337
337
|
}) }) : alreadyHandled ? new Request(input.request, { body: JSON.stringify({ update_id: update.update_id }) }) : void 0);
|
|
338
338
|
} catch (error) {
|
|
339
|
+
if (!accepted) try {
|
|
340
|
+
await inbound?.releaseLifecycleDispatch?.();
|
|
341
|
+
} catch (cleanupError) {
|
|
342
|
+
console.error("[segmentstream] inventory dispatch cleanup failed", {
|
|
343
|
+
cleanupError,
|
|
344
|
+
cause: error
|
|
345
|
+
});
|
|
346
|
+
}
|
|
339
347
|
try {
|
|
340
348
|
await capture.persist();
|
|
341
349
|
await inbound?.finishClaim?.(false);
|
|
@@ -357,6 +365,15 @@ async function captureTelegramWebhook(input) {
|
|
|
357
365
|
}
|
|
358
366
|
throw error;
|
|
359
367
|
}
|
|
368
|
+
let dispatchCleanupError;
|
|
369
|
+
let cleanupFailed = false;
|
|
370
|
+
if (!accepted) try {
|
|
371
|
+
await inbound?.releaseLifecycleDispatch?.();
|
|
372
|
+
} catch (error) {
|
|
373
|
+
dispatchCleanupError = error;
|
|
374
|
+
cleanupFailed = true;
|
|
375
|
+
reportTelegramError("inventory_dispatch_cleanup_failed", error);
|
|
376
|
+
}
|
|
360
377
|
await capture.persist();
|
|
361
378
|
await inbound?.finishClaim?.(false);
|
|
362
379
|
await input.archive.append({
|
|
@@ -373,6 +390,7 @@ async function captureTelegramWebhook(input) {
|
|
|
373
390
|
attachments: []
|
|
374
391
|
});
|
|
375
392
|
await finishRevision(capture.reason === "inbound_message_failed" || capture.reason === "decision_model_failed" || capture.reason === "decision_model_timeout" ? "failed" : "completed");
|
|
393
|
+
if (cleanupFailed) throw dispatchCleanupError;
|
|
376
394
|
return response;
|
|
377
395
|
}
|
|
378
396
|
function recordGateDecision(reason, decision = "silent") {
|
|
@@ -468,15 +486,22 @@ function captureTelegramFetch(fetchImpl, archive, identities) {
|
|
|
468
486
|
senderIsBot: true,
|
|
469
487
|
senderId: "agent",
|
|
470
488
|
senderName: "agent",
|
|
471
|
-
argsSummary: JSON.stringify({
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
489
|
+
argsSummary: JSON.stringify({
|
|
490
|
+
telegram: {
|
|
491
|
+
...Array.isArray(body.entities) ? { entities: body.entities } : {},
|
|
492
|
+
...Array.isArray(body.caption_entities) ? { caption_entities: body.caption_entities } : {},
|
|
493
|
+
...typeof body.parse_mode === "string" ? { parse_mode: body.parse_mode } : {}
|
|
494
|
+
},
|
|
495
|
+
routing: {
|
|
496
|
+
...currentConfirmationPrompt() === void 0 ? {} : { confirmation: currentConfirmationPrompt() },
|
|
497
|
+
...capture?.event.chatId === chatId && capture.event.senderId !== null ? { inReplyTo: {
|
|
498
|
+
id: capture.event.senderId,
|
|
499
|
+
author: capture.event.senderName ?? capture.event.senderId,
|
|
500
|
+
...capture.message.from?.username === void 0 ? {} : { username: capture.message.from.username }
|
|
501
|
+
} } : {},
|
|
502
|
+
...currentConfirmationPrompt()?.requester === void 0 ? {} : { inReplyTo: currentConfirmationPrompt()?.requester }
|
|
503
|
+
}
|
|
504
|
+
}),
|
|
480
505
|
participantIds,
|
|
481
506
|
threadId: id(body.message_thread_id) ?? currentThreadId() ?? null,
|
|
482
507
|
replyToMessageId: id(body.reply_to_message_id) ?? id(record(body.reply_parameters).message_id),
|
|
@@ -5,5 +5,5 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { isTechnicalText } from "../customer-text-safety.mjs";
|
|
8
|
-
import { a as TelegramDeliveryError, c as customerCopy, d as failureText, f as formattingRefused, h as withDeliveryLocale, l as customerMessage, m as safeTelegramFetch, o as currentLocale, p as reportTelegramError, s as currentThreadId, u as customerText } from "../../../_chunks/inbound-request-
|
|
8
|
+
import { a as TelegramDeliveryError, c as customerCopy, d as failureText, f as formattingRefused, h as withDeliveryLocale, l as customerMessage, m as safeTelegramFetch, o as currentLocale, p as reportTelegramError, s as currentThreadId, u as customerText } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
9
9
|
export { TelegramDeliveryError, currentLocale, currentThreadId, customerCopy, customerMessage, customerText, failureText, formattingRefused, isTechnicalText, reportTelegramError, safeTelegramFetch, withDeliveryLocale };
|
|
@@ -6,7 +6,7 @@ import type { AgentIdentities } from "../identities.js";
|
|
|
6
6
|
import { type ObservedMessages } from "./observed.js";
|
|
7
7
|
export declare const isDeferredCallback: (data?: string) => boolean;
|
|
8
8
|
export declare const deferredCallback: (record: DeferredConfirmation, choice: "y" | "n" | "e") => string;
|
|
9
|
-
export declare function archiveDeferred(record: DeferredConfirmation, phase: string, archive: Conversations): Promise<void>;
|
|
9
|
+
export declare function archiveDeferred(record: DeferredConfirmation, phase: string, archive: Conversations, errorText?: string): Promise<void>;
|
|
10
10
|
/** Called at the durable tool-result boundary. Pending cards never become eve input requests. */
|
|
11
11
|
export declare function postDeferredCard(id: string, channel: TelegramEventContext, ctx: SessionContext, options: DeferredOptions, archive: Conversations, observed?: ObservedMessages): Promise<void>;
|
|
12
12
|
/** Every callback re-resolves the live identity. The database arbitrates concurrent presses. */
|
|
@@ -8,8 +8,9 @@ import { telegramPrincipal } from "./principal.mjs";
|
|
|
8
8
|
import { humanText } from "../confirmation-description.mjs";
|
|
9
9
|
import { renderConfirmation, withConfirmationText } from "./confirmation-text.mjs";
|
|
10
10
|
import { chatPostCard, chatPostCardStatus, chatPostReceipt, withChatPostCard } from "./chat-post-card.mjs";
|
|
11
|
-
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
11
|
+
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
12
12
|
import { CONFIRMATION_TTL_MS, inputHash } from "../confirmations.mjs";
|
|
13
|
+
import { OntologyToolRejected } from "../ontology-tools.mjs";
|
|
13
14
|
import { confirmationOutcome } from "../confirmation-outcome.mjs";
|
|
14
15
|
import { deferredConfirmations, deferredKey, runDeferredAction } from "../deferred-confirmations.mjs";
|
|
15
16
|
import { conversationEvent } from "../conversations.mjs";
|
|
@@ -52,7 +53,7 @@ function remember(record, text, prompt, observed) {
|
|
|
52
53
|
confirmation: prompt
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
|
-
async function archiveDeferred(record, phase, archive) {
|
|
56
|
+
async function archiveDeferred(record, phase, archive, errorText) {
|
|
56
57
|
await archive.append(conversationEvent({
|
|
57
58
|
eventId: `confirmation:${record.id}:${phase}`,
|
|
58
59
|
provider: "telegram",
|
|
@@ -66,6 +67,7 @@ async function archiveDeferred(record, phase, archive) {
|
|
|
66
67
|
operationId: record.id,
|
|
67
68
|
toolName: record.data.action,
|
|
68
69
|
reason: phase,
|
|
70
|
+
...errorText === void 0 ? {} : { errorText },
|
|
69
71
|
status: phase === "done" ? "completed" : phase === "failed" ? "failed" : phase === "cancelled" || phase === "expired" ? "cancelled" : "requested"
|
|
70
72
|
}));
|
|
71
73
|
}
|
|
@@ -186,6 +188,7 @@ async function handleDeferredCallback(input) {
|
|
|
186
188
|
let status = claimed.status;
|
|
187
189
|
let cardStatus = status === "expired" ? copy.expired : copy.cancelled;
|
|
188
190
|
let execution;
|
|
191
|
+
let failure;
|
|
189
192
|
try {
|
|
190
193
|
await archiveDeferred(claimed, claimed.status, archive);
|
|
191
194
|
} catch (error) {
|
|
@@ -214,6 +217,14 @@ async function handleDeferredCallback(input) {
|
|
|
214
217
|
} catch (error) {
|
|
215
218
|
status = "failed";
|
|
216
219
|
const reference = reportTelegramError("deferred_action_failed", error);
|
|
220
|
+
failure = error instanceof OntologyToolRejected ? {
|
|
221
|
+
code: error.code,
|
|
222
|
+
message: error.message.slice(0, 4096)
|
|
223
|
+
} : {
|
|
224
|
+
code: "deferred_action_failed",
|
|
225
|
+
message: reference
|
|
226
|
+
};
|
|
227
|
+
if (!(error instanceof OntologyToolRejected)) execution = "uncertain";
|
|
217
228
|
cardStatus = `${copy.failed} ${reference}`;
|
|
218
229
|
}
|
|
219
230
|
await store.command({
|
|
@@ -223,7 +234,7 @@ async function handleDeferredCallback(input) {
|
|
|
223
234
|
});
|
|
224
235
|
}
|
|
225
236
|
if (status === "done" || status === "failed") try {
|
|
226
|
-
await archiveDeferred(claimed, status, archive);
|
|
237
|
+
await archiveDeferred(claimed, status, archive, failure?.message);
|
|
227
238
|
} catch (error) {
|
|
228
239
|
reportTelegramError("deferred_outcome_archive_failed", error);
|
|
229
240
|
}
|
|
@@ -245,6 +256,7 @@ async function handleDeferredCallback(input) {
|
|
|
245
256
|
});
|
|
246
257
|
await currentInboundRequest()?.confirmationEvent?.(claimed, confirmationOutcome(claimed, status, {
|
|
247
258
|
...execution === void 0 ? {} : { execution },
|
|
259
|
+
...failure === void 0 ? {} : { error: failure },
|
|
248
260
|
...parts[2] === "e" && status === "cancelled" ? { editRequested: true } : {}
|
|
249
261
|
}), principal);
|
|
250
262
|
}
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { conversationLanguage } from "./principal.mjs";
|
|
8
|
-
import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
8
|
+
import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
9
9
|
import { describableImage, describeReceivedImage } from "./images.mjs";
|
|
10
10
|
import { MAXIMUM_ATTACHMENT_BYTES, attachmentUrl } from "../attachments.mjs";
|
|
11
11
|
function telegramConversation(chatId) {
|
|
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
7
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-zRhAH0hT.mjs";
|
|
8
8
|
import { runtimeRequestFailure } from "./runtime-request.mjs";
|
|
9
9
|
import { GET } from "eve/channels";
|
|
10
10
|
const HEALTH_ROUTE = "/eve/v1/telegram/health";
|
|
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
7
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
8
8
|
import { gateway, generateText } from "ai";
|
|
9
9
|
const MAXIMUM_IMAGE_DESCRIPTION_BYTES = 5242880;
|
|
10
10
|
const MAXIMUM_NATIVE_IMAGE_BYTES = 3145728;
|
|
@@ -37,6 +37,8 @@ export declare class InboundRequest {
|
|
|
37
37
|
stopTyping: (() => void) | undefined;
|
|
38
38
|
lifecycle: ReturnType<typeof import("./lifecycle.js").attachmentLifecycle> | undefined;
|
|
39
39
|
lifecycleKey: string | undefined;
|
|
40
|
+
lifecycleDispatchToken: string | undefined;
|
|
41
|
+
releaseLifecycleDispatch: (() => Promise<unknown>) | undefined;
|
|
40
42
|
/** A routed task must be redelivered if recovery or intake did not reach durable admission. */
|
|
41
43
|
retryReference: string | undefined;
|
|
42
44
|
lifecycleContext: string | undefined;
|
|
@@ -4,5 +4,5 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { i as withReplacedText, n as currentInboundRequest, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-
|
|
7
|
+
import { i as withReplacedText, n as currentInboundRequest, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
8
8
|
export { InboundRequest, currentInboundRequest, runInboundRequest, withReplacedText };
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { conversationLanguage, telegramPrincipal } from "./principal.mjs";
|
|
8
|
-
import { p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
8
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
9
9
|
import { startTypingHeartbeat, typingUntilComplete } from "./lifecycle.mjs";
|
|
10
10
|
import { formatAddress, messageAddress, scopedAddress } from "./sessions.mjs";
|
|
11
11
|
import { contentShape, messageContent } from "./content.mjs";
|
|
@@ -690,6 +690,27 @@ async function handleInboundMessage(input) {
|
|
|
690
690
|
}
|
|
691
691
|
input.request.lifecycleContext = current.context;
|
|
692
692
|
input.request.replyTo = current.replyTo ?? input.request.replyTo;
|
|
693
|
+
if (current.dispatch === false) {
|
|
694
|
+
console.info("[segmentstream] telegram.phase", {
|
|
695
|
+
phase: "workspace_dispatch_coalesced",
|
|
696
|
+
intakeId: key,
|
|
697
|
+
chatId: sent.chat.id,
|
|
698
|
+
messageId: sent.messageId
|
|
699
|
+
});
|
|
700
|
+
return null;
|
|
701
|
+
}
|
|
702
|
+
if (current.dispatchToken !== void 0) {
|
|
703
|
+
const token = current.dispatchToken;
|
|
704
|
+
input.request.lifecycleDispatchToken = token;
|
|
705
|
+
const request = input.request;
|
|
706
|
+
request.releaseLifecycleDispatch = async () => {
|
|
707
|
+
request.releaseLifecycleDispatch = void 0;
|
|
708
|
+
await lifecycle("ready", {
|
|
709
|
+
key,
|
|
710
|
+
release_dispatch: token
|
|
711
|
+
});
|
|
712
|
+
};
|
|
713
|
+
}
|
|
693
714
|
}
|
|
694
715
|
if (routingFile !== void 0 && processedMedia !== void 0) {
|
|
695
716
|
const stored = files.get(routingFile.fileId);
|
|
@@ -828,6 +849,7 @@ async function handleInboundMessage(input) {
|
|
|
828
849
|
...principal,
|
|
829
850
|
attributes: {
|
|
830
851
|
...principal.attributes,
|
|
852
|
+
...input.request?.lifecycleDispatchToken === void 0 ? {} : { attachmentDispatchToken: input.request.lifecycleDispatchToken },
|
|
831
853
|
replyToMessageId: input.request?.replyTo ?? sent.messageId,
|
|
832
854
|
...input.request?.lifecycleKey === void 0 ? {} : {
|
|
833
855
|
taskId: input.request.lifecycleKey,
|
|
@@ -839,6 +861,7 @@ async function handleInboundMessage(input) {
|
|
|
839
861
|
...principal,
|
|
840
862
|
attributes: {
|
|
841
863
|
...principal.attributes,
|
|
864
|
+
...input.request?.lifecycleDispatchToken === void 0 ? {} : { attachmentDispatchToken: input.request.lifecycleDispatchToken },
|
|
842
865
|
replyToMessageId: input.request?.replyTo ?? sent.messageId,
|
|
843
866
|
...input.request?.lifecycleKey === void 0 ? {} : {
|
|
844
867
|
taskId: input.request.lifecycleKey,
|
|
@@ -10,6 +10,9 @@ export interface AttachmentLifecycle {
|
|
|
10
10
|
readonly contextVersion?: 2;
|
|
11
11
|
}
|
|
12
12
|
export interface LifecycleResult {
|
|
13
|
+
/** The workspace has already assigned this retained inventory to another turn. */
|
|
14
|
+
readonly dispatch?: boolean;
|
|
15
|
+
readonly dispatchToken?: string;
|
|
13
16
|
readonly key?: string;
|
|
14
17
|
readonly replyTo?: string;
|
|
15
18
|
readonly acknowledgement?: string;
|
|
@@ -4,9 +4,9 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
7
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-zRhAH0hT.mjs";
|
|
8
8
|
import { object } from "../confirmation-description.mjs";
|
|
9
|
-
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
9
|
+
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
10
10
|
import { needsConfirmation } from "../confirmations.mjs";
|
|
11
11
|
import { actionToolName, ontologyTools } from "../ontology-tools.mjs";
|
|
12
12
|
function attachmentLifecycle(options) {
|
|
@@ -48,6 +48,8 @@ function attachmentLifecycle(options) {
|
|
|
48
48
|
const retention = object(result.retain);
|
|
49
49
|
if (typeof retention.entity === "string" && typeof retention.action === "string" && needsConfirmation(await tools.labels(options.memberId, actionToolName(retention.entity, retention.action), object(retention.input)))) throw new Error("Automatic retention requires a permitted routine storage action.");
|
|
50
50
|
return {
|
|
51
|
+
...typeof result.dispatch === "boolean" ? { dispatch: result.dispatch } : {},
|
|
52
|
+
...typeof result.dispatch_token === "string" ? { dispatchToken: result.dispatch_token } : {},
|
|
51
53
|
...typeof result.key === "string" ? { key: result.key } : {},
|
|
52
54
|
...typeof result.reply_to === "string" && /^[1-9]\d*$/.test(result.reply_to) ? { replyTo: result.reply_to } : {},
|
|
53
55
|
...typeof result.acknowledgement === "string" ? { acknowledgement: result.acknowledgement } : {},
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { DEFAULT_IMAGE_DESCRIPTION_MODEL } from "../../config.mjs";
|
|
8
|
-
import { p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
8
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
9
9
|
function planMedia(capabilities, descriptionModel = null) {
|
|
10
10
|
if (typeof descriptionModel === "string") return {
|
|
11
11
|
images: "describe",
|
|
@@ -8,7 +8,7 @@ import "./principal.mjs";
|
|
|
8
8
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
9
9
|
import { splitTelegramText } from "./format.mjs";
|
|
10
10
|
import { inTelegramSendQueue } from "./send-queue.mjs";
|
|
11
|
-
import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
11
|
+
import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
12
12
|
import { agentMessage, observedChatKey } from "./observed.mjs";
|
|
13
13
|
const SILENT_MARKERS = new Set(["[silent]", "no_reply"]);
|
|
14
14
|
function isSilentReply(text) {
|
|
@@ -6,7 +6,7 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { memberIdOf } from "./principal.mjs";
|
|
8
8
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
9
|
-
import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
9
|
+
import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
10
10
|
const telegramFailureEvents = {
|
|
11
11
|
async "turn.cancelled"(event, channel, context) {
|
|
12
12
|
const errorId = reportTelegramError("turn_cancelled", event, {
|
|
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
-
import { p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
7
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-B8Eyjz1O.mjs";
|
|
8
8
|
import "../connection-proxy.mjs";
|
|
9
9
|
import { gateway, transcribe } from "ai";
|
|
10
10
|
const LABELS = {
|
|
@@ -7,17 +7,17 @@ declare const _default: import("eve").DynamicSentinel<{
|
|
|
7
7
|
};
|
|
8
8
|
ontology_inspect: import("eve/tools").ToolDefinition<Record<string, unknown>, {
|
|
9
9
|
next_after?: string | undefined;
|
|
10
|
-
tools: {
|
|
10
|
+
tools: (Record<string, unknown> & {
|
|
11
11
|
name: string;
|
|
12
12
|
description: string;
|
|
13
|
-
}[];
|
|
13
|
+
})[];
|
|
14
14
|
}> & {
|
|
15
15
|
execute(input: Record<string, unknown>, ctx: import("eve/tools").ToolContext): Promise<{
|
|
16
16
|
next_after?: string | undefined;
|
|
17
|
-
tools: {
|
|
17
|
+
tools: (Record<string, unknown> & {
|
|
18
18
|
name: string;
|
|
19
19
|
description: string;
|
|
20
|
-
}[];
|
|
20
|
+
})[];
|
|
21
21
|
}>;
|
|
22
22
|
};
|
|
23
23
|
ontology_call: import("eve/tools").ToolDefinition<Record<string, unknown>, Record<string, unknown>> & {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/agent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.11",
|
|
4
4
|
"description": "Mount a SegmentStream workspace's agent on eve: the ontology as tools, acting as the member who writes, and Telegram through the workspace's connection.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@chat-adapter/telegram": "4.41.0",
|
|
65
|
-
"@segmentstream-cloud/ontology": "0.
|
|
65
|
+
"@segmentstream-cloud/ontology": "0.36.0",
|
|
66
66
|
"@vercel/oidc": "^3.8.4",
|
|
67
67
|
"ai": "^7.0.128",
|
|
68
68
|
"csv-parse": "^7.0.3",
|