@flytedesk/app-kit 16.2.0 → 16.4.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/README.md +134 -19
- package/dist/chat/owed-replies/constants.d.ts +31 -5
- package/dist/chat/owed-replies/constants.js +41 -11
- package/dist/chat/owed-replies/constants.js.map +1 -1
- package/dist/chat/owed-replies/index.d.ts +5 -4
- package/dist/chat/owed-replies/index.js +1 -1
- package/dist/chat/owed-replies/index.js.map +1 -1
- package/dist/chat/owed-replies/plugin.d.ts +10 -5
- package/dist/chat/owed-replies/plugin.js +13 -5
- package/dist/chat/owed-replies/plugin.js.map +1 -1
- package/dist/chat/owed-replies/state.d.ts +25 -1
- package/dist/chat/owed-replies/state.js +8 -1
- package/dist/chat/owed-replies/state.js.map +1 -1
- package/dist/chat/owed-replies/store.d.ts +146 -9
- package/dist/chat/owed-replies/store.js +367 -64
- package/dist/chat/owed-replies/store.js.map +1 -1
- package/dist/chat/owed-replies/tool.d.ts +16 -4
- package/dist/chat/owed-replies/tool.js +22 -6
- package/dist/chat/owed-replies/tool.js.map +1 -1
- package/dist/chat/tools/index.d.ts +15 -9
- package/dist/chat/tools/index.js +11 -13
- package/dist/chat/tools/index.js.map +1 -1
- package/package.json +1 -1
- package/prisma/fragments/owed-reply.meta.json +1 -1
- package/prisma/fragments/owed-reply.prisma +24 -4
- package/prisma/migrations/0007_app_kit_owed_reply_holds/migration.sql +39 -0
- package/prisma/migrations/manifest.json +7 -0
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* `reply: {server, tool}` ends the run once none is.
|
|
7
7
|
*/
|
|
8
8
|
import { REPLY_META_KEY } from "../mcp-protocol.js";
|
|
9
|
-
import { DEFAULT_REPLY_TOOL_NAME, deliveredText, owedReminder } from "./constants.js";
|
|
9
|
+
import { DEFAULT_REPLY_TOOL_NAME, REFUSALS, deliveredText, owedReminder } from "./constants.js";
|
|
10
|
+
const RESERVED_FIELDS = ["to", "phase", "text"];
|
|
10
11
|
const DEFAULT_DESCRIPTION = 'Your only way to answer a person. Send a short acknowledgement first (phase "ack"), then your complete answer ' +
|
|
11
12
|
'(phase "reply"), which replaces it. `to` is the id of the owed reply you are answering.';
|
|
12
13
|
function parseArguments(args) {
|
|
@@ -24,6 +25,10 @@ function parseArguments(args) {
|
|
|
24
25
|
}
|
|
25
26
|
export function createOwedReplyTool(options) {
|
|
26
27
|
const name = options.name ?? DEFAULT_REPLY_TOOL_NAME;
|
|
28
|
+
const fieldNames = Object.keys(options.replyFields?.properties ?? {});
|
|
29
|
+
const reserved = fieldNames.filter((field) => RESERVED_FIELDS.includes(field));
|
|
30
|
+
if (reserved.length > 0)
|
|
31
|
+
throw new Error(`replyFields.properties cannot redefine ${reserved.join(", ")}`);
|
|
27
32
|
return {
|
|
28
33
|
name,
|
|
29
34
|
description: options.description ?? DEFAULT_DESCRIPTION,
|
|
@@ -37,6 +42,7 @@ export function createOwedReplyTool(options) {
|
|
|
37
42
|
description: '"ack" for a short acknowledgement (send it first; a second one replaces it); "reply" for your complete answer, which replaces the acknowledgement. Send exactly one "reply" per owed reply.',
|
|
38
43
|
},
|
|
39
44
|
text: { type: "string", description: "The message, markdown formatted for a reply." },
|
|
45
|
+
...options.replyFields?.properties,
|
|
40
46
|
},
|
|
41
47
|
required: ["to", "phase", "text"],
|
|
42
48
|
},
|
|
@@ -45,14 +51,24 @@ export function createOwedReplyTool(options) {
|
|
|
45
51
|
if (!parsed.ok)
|
|
46
52
|
return { ok: false, retryable: false, message: parsed.message };
|
|
47
53
|
const { to, phase, text } = parsed.value;
|
|
48
|
-
const
|
|
54
|
+
const given = args;
|
|
55
|
+
const values = Object.fromEntries(fieldNames.filter((field) => given[field] !== undefined).map((field) => [field, given[field]]));
|
|
56
|
+
if (phase === "ack" && Object.keys(values).length > 0)
|
|
57
|
+
return { ok: false, retryable: false, message: REFUSALS.fieldsOnAck };
|
|
58
|
+
const fields = options.replyFields !== undefined && phase === "reply" ? { values, accept: options.replyFields.accept } : undefined;
|
|
59
|
+
const written = await options.store.writeReply({
|
|
60
|
+
dispatchId: options.dispatchId,
|
|
61
|
+
to,
|
|
62
|
+
phase,
|
|
63
|
+
text,
|
|
64
|
+
...(fields === undefined ? {} : { fields }),
|
|
65
|
+
});
|
|
49
66
|
if (!written.ok)
|
|
50
|
-
return { ok: false, retryable:
|
|
51
|
-
|
|
52
|
-
const meta = { owed: written.owed, unheld: written.owed, reminder: owedReminder(name, written.owed) };
|
|
67
|
+
return { ok: false, retryable: written.retryable, message: written.message };
|
|
68
|
+
const meta = { owed: written.owed, unheld: written.unheld, reminder: owedReminder(name, written.owed, written.unheld) };
|
|
53
69
|
return {
|
|
54
70
|
ok: true,
|
|
55
|
-
content: [{ type: "text", text: deliveredText(name, phase, written.owed) }],
|
|
71
|
+
content: [{ type: "text", text: deliveredText(name, phase, written.owed, written.unheld) }],
|
|
56
72
|
_meta: { [REPLY_META_KEY]: meta },
|
|
57
73
|
};
|
|
58
74
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/chat/owed-replies/tool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,cAAc,EAAkB,MAAM,oBAAoB,CAAC;AAEpE,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/chat/owed-replies/tool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,cAAc,EAAkB,MAAM,oBAAoB,CAAC;AAEpE,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAchG,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAchD,MAAM,mBAAmB,GACvB,gHAAgH;IAChH,yFAAyF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BAC3F,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE;aAClC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -35,17 +35,23 @@ export interface RemoteMcpPluginOptions<Context> {
|
|
|
35
35
|
/** The tools this request's context may call. */
|
|
36
36
|
tools: (context: Context) => AppRegisteredTool[];
|
|
37
37
|
/**
|
|
38
|
-
* Opt in to
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* line
|
|
44
|
-
*
|
|
38
|
+
* Opt in to annotating every tool result on this endpoint (AK-80, AK-85): called after the tool
|
|
39
|
+
* ran, with the tool's name and whether it succeeded, it answers one `notice` line (the owed
|
|
40
|
+
* replies not yet answered, for an endpoint serving the owed-reply tool) and the `meta` entries
|
|
41
|
+
* to merge over a success's own `_meta` (the owed-reply state under `flytebot/reply`, so a
|
|
42
|
+
* runner reads it from any tool of the server); each is null for none. One call answers both, so
|
|
43
|
+
* the line and the `_meta` describe one moment. The notice is added as a last text block of a
|
|
44
|
+
* success and to the end of a failure's message; a failure has no `_meta`, so its `meta` is
|
|
45
|
+
* ignored. A throw fails the request loudly: a result is never sent without the annotation the
|
|
46
|
+
* runner depends on. Left out, results are returned exactly as the tools made them, which is
|
|
47
|
+
* what an endpoint with no reply tool wants.
|
|
45
48
|
*/
|
|
46
|
-
|
|
49
|
+
annotateResult?: (context: Context, call: {
|
|
47
50
|
tool: string;
|
|
48
51
|
ok: boolean;
|
|
49
|
-
}) => Promise<
|
|
52
|
+
}) => Promise<{
|
|
53
|
+
notice: string | null;
|
|
54
|
+
meta: Record<string, unknown> | null;
|
|
55
|
+
}>;
|
|
50
56
|
}
|
|
51
57
|
export declare function createRemoteMcpPlugin<Context>(options: RemoteMcpPluginOptions<Context>): FastifyPluginAsync;
|
package/dist/chat/tools/index.js
CHANGED
|
@@ -19,19 +19,17 @@ export function createRemoteMcpPlugin(options) {
|
|
|
19
19
|
error: { code: INVALID_REQUEST, message: "The body must be one JSON-RPC message object." },
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
notice = options.resultNotice === undefined ? null : await options.resultNotice(context, { tool, ok: result.ok });
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
request.log.error({ err: error, tool }, "MCP result notice threw");
|
|
29
|
-
}
|
|
30
|
-
if (notice === null)
|
|
22
|
+
const withAnnotation = async (tool, result) => {
|
|
23
|
+
if (options.annotateResult === undefined)
|
|
31
24
|
return result;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
: { ...result, message: `${result.message}\n${notice}` };
|
|
25
|
+
const { notice, meta } = await options.annotateResult(context, { tool, ok: result.ok });
|
|
26
|
+
if (!result.ok)
|
|
27
|
+
return notice === null ? result : { ...result, message: `${result.message}\n${notice}` };
|
|
28
|
+
return {
|
|
29
|
+
...result,
|
|
30
|
+
...(notice === null ? {} : { content: [...result.content, { type: "text", text: notice }] }),
|
|
31
|
+
...(meta === null ? {} : { _meta: { ...result._meta, ...meta } }),
|
|
32
|
+
};
|
|
35
33
|
};
|
|
36
34
|
// A tool that throws is reported to the model as a tool error and logged here, so
|
|
37
35
|
// an internal message never reaches the agent and one bad tool never drops the endpoint.
|
|
@@ -50,7 +48,7 @@ export function createRemoteMcpPlugin(options) {
|
|
|
50
48
|
message: `Tool "${tool.name}" failed.`,
|
|
51
49
|
};
|
|
52
50
|
}
|
|
53
|
-
return
|
|
51
|
+
return withAnnotation(tool.name, result);
|
|
54
52
|
},
|
|
55
53
|
}));
|
|
56
54
|
const response = await createChatMcpProtocol({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/chat/tools/index.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources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. One OwedReply per message
|
|
8
8
|
// holds the agent's acknowledgement, its reply, or the fixed line shown when the run
|
|
9
9
|
// ended without answering, plus the revision the app's chat message projects. Which run
|
|
10
|
-
// took the message is the row in OwedReplyDispatch.
|
|
11
|
-
//
|
|
12
|
-
//
|
|
10
|
+
// took the message is the row in OwedReplyDispatch. A background job an app starts for an
|
|
11
|
+
// acknowledged message is a row in OwedReplyHold. The state (sent, taken, acked, answered,
|
|
12
|
+
// failed) and whether a message is held are never stored: they are derived on every read
|
|
13
|
+
// from these columns and rows (src/chat/owed-replies/state.ts).
|
|
13
14
|
//
|
|
14
15
|
// Design constraints (the same as every fragment): no `@relation`, since a package that
|
|
15
16
|
// ships models into a consumer's schema cannot see the consumer's own models; no enum;
|
|
16
17
|
// tables prefixed `app_kit_` through `@@map`. The CHECK constraints Prisma's schema
|
|
17
|
-
// language cannot express are in prisma/migrations/0006_app_kit_owed_reply_init
|
|
18
|
+
// language cannot express are in prisma/migrations/0006_app_kit_owed_reply_init and
|
|
19
|
+
// 0007_app_kit_owed_reply_holds.
|
|
18
20
|
|
|
19
21
|
/// One row per message of a person that is owed an answer. `messageRef` is the app's own id
|
|
20
22
|
/// for the message, so a resent message finds its row. `ackText` is replaced by a second
|
|
@@ -26,6 +28,8 @@ model OwedReply {
|
|
|
26
28
|
personRef String @map("person_ref")
|
|
27
29
|
ackText String? @map("ack_text")
|
|
28
30
|
replyText String? @map("reply_text")
|
|
31
|
+
/// What the app's reply fields carried (AK-85), written with `replyText` and never without it.
|
|
32
|
+
replyPayload Json? @map("reply_payload")
|
|
29
33
|
failure String?
|
|
30
34
|
/// Raised on every write, so the app's projected chat message can tell a stale write.
|
|
31
35
|
revision Int @default(0)
|
|
@@ -50,3 +54,19 @@ model OwedReplyDispatch {
|
|
|
50
54
|
@@index([dispatchId])
|
|
51
55
|
@@map("app_kit_owed_reply_dispatch")
|
|
52
56
|
}
|
|
57
|
+
|
|
58
|
+
/// A background job the app started for an acknowledged, unanswered owed reply (AK-85): while a
|
|
59
|
+
/// hold is open, or ended and not yet reported to a wake run, the owed reply is held, and a run
|
|
60
|
+
/// that completes leaves it unanswered instead of failing it. `holdRef` is the app's own id for
|
|
61
|
+
/// the job. A hold is reported when a wake run takes the owed reply, or when the owed reply
|
|
62
|
+
/// fails; `reportedAt` is never set before `endedAt`.
|
|
63
|
+
model OwedReplyHold {
|
|
64
|
+
holdRef String @id @map("hold_ref")
|
|
65
|
+
owedReplyId String @map("owed_reply_id")
|
|
66
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
67
|
+
endedAt DateTime? @map("ended_at")
|
|
68
|
+
reportedAt DateTime? @map("reported_at")
|
|
69
|
+
|
|
70
|
+
@@index([owedReplyId])
|
|
71
|
+
@@map("app_kit_owed_reply_hold")
|
|
72
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
-- @flytedesk/app-kit/chat/owed-replies :: 0007_app_kit_owed_reply_holds
|
|
2
|
+
--
|
|
3
|
+
-- What an app's reply fields and background jobs add to the owed-reply tables (AK-85): the
|
|
4
|
+
-- payload a reply carries beside its text, and one row per background job that holds an
|
|
5
|
+
-- acknowledged owed reply open. Column names, types and defaults match
|
|
6
|
+
-- prisma/fragments/owed-reply.prisma (Prisma's own mapping: JSONB, TEXT, TIMESTAMP(3)), then
|
|
7
|
+
-- the CHECK constraints Prisma's schema language cannot express. One DO block, so the column,
|
|
8
|
+
-- the table, its index and the checks apply together or not at all. For an app that does not
|
|
9
|
+
-- use Prisma migrate; an app that does writes its own migration from the fragment, and
|
|
10
|
+
-- `owed-reply-sync` prints the CHECK lines below for it to append (see sync-engine.ts).
|
|
11
|
+
|
|
12
|
+
DO $owed_reply_holds$
|
|
13
|
+
BEGIN
|
|
14
|
+
SET LOCAL lock_timeout = '5s';
|
|
15
|
+
|
|
16
|
+
-- AlterTable
|
|
17
|
+
ALTER TABLE "app_kit_owed_reply" ADD COLUMN "reply_payload" JSONB;
|
|
18
|
+
|
|
19
|
+
-- CreateTable
|
|
20
|
+
CREATE TABLE "app_kit_owed_reply_hold" (
|
|
21
|
+
"hold_ref" TEXT NOT NULL,
|
|
22
|
+
"owed_reply_id" TEXT NOT NULL,
|
|
23
|
+
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
24
|
+
"ended_at" TIMESTAMP(3),
|
|
25
|
+
"reported_at" TIMESTAMP(3),
|
|
26
|
+
|
|
27
|
+
CONSTRAINT "app_kit_owed_reply_hold_pkey" PRIMARY KEY ("hold_ref")
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
-- CreateIndex
|
|
31
|
+
CREATE INDEX "app_kit_owed_reply_hold_owed_reply_id_idx" ON "app_kit_owed_reply_hold"("owed_reply_id");
|
|
32
|
+
|
|
33
|
+
-- AddCheck: a payload is part of a reply, so it never exists without the reply's text.
|
|
34
|
+
ALTER TABLE "app_kit_owed_reply" ADD CONSTRAINT "app_kit_owed_reply_payload_needs_reply" CHECK ("reply_payload" IS NULL OR "reply_text" IS NOT NULL);
|
|
35
|
+
|
|
36
|
+
-- AddCheck: a hold is reported only after it ended.
|
|
37
|
+
ALTER TABLE "app_kit_owed_reply_hold" ADD CONSTRAINT "app_kit_owed_reply_hold_reported_after_end" CHECK ("reported_at" IS NULL OR "ended_at" IS NOT NULL);
|
|
38
|
+
END
|
|
39
|
+
$owed_reply_holds$;
|
|
@@ -40,5 +40,12 @@
|
|
|
40
40
|
"file": "0006_app_kit_owed_reply_init/migration.sql",
|
|
41
41
|
"checksum": "sha256:7e066dfa5a82cf212ac915a7861476ee6a67967ad94a1f1462480c9d4689a4aa",
|
|
42
42
|
"introducedInFragmentVersion": "1.0.0"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "0007_app_kit_owed_reply_holds",
|
|
46
|
+
"fragment": "owed-reply",
|
|
47
|
+
"file": "0007_app_kit_owed_reply_holds/migration.sql",
|
|
48
|
+
"checksum": "sha256:6dd6893a8591839e2c68aad6ac30191c9de84855dae834cdb1e557fb503ce818",
|
|
49
|
+
"introducedInFragmentVersion": "1.1.0"
|
|
43
50
|
}
|
|
44
51
|
]
|