@finalai/final-agent-provider 0.7.0 → 0.9.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/HOSTING.md +3 -3
- package/README.md +26 -91
- package/dist/modules/channel-factories.d.mts +5 -6
- package/dist/modules/channel-factories.mjs +7 -11
- package/dist/modules/channel-factories.mjs.map +3 -3
- package/dist/modules/channels/inbound.mjs +2 -2
- package/dist/modules/channels/inbound.mjs.map +2 -2
- package/dist/modules/channels/index.d.mts +0 -7
- package/dist/modules/channels/index.mjs +0 -7
- package/dist/modules/channels/index.mjs.map +2 -2
- package/dist/modules/channels/prompt.d.mts +2 -2
- package/dist/modules/channels/prompt.mjs +3 -3
- package/dist/modules/channels/prompt.mjs.map +2 -2
- package/dist/modules/channels/routing.d.mts +1 -1
- package/dist/modules/channels/routing.mjs +1 -1
- package/dist/modules/channels/routing.mjs.map +1 -1
- package/dist/modules/sandboxes/bytes.d.mts +1 -0
- package/dist/modules/sandboxes/bytes.mjs +7 -1
- package/dist/modules/sandboxes/bytes.mjs.map +2 -2
- package/dist/modules/sandboxes/computer-processes.mjs +5 -3
- package/dist/modules/sandboxes/computer-processes.mjs.map +2 -2
- package/dist/modules/sandboxes/computer.mjs +5 -1
- package/dist/modules/sandboxes/computer.mjs.map +2 -2
- package/dist/modules/sandboxes/computers-api-transport.d.mts +1 -1
- package/dist/modules/sandboxes/computers-api-transport.mjs +8 -0
- package/dist/modules/sandboxes/computers-api-transport.mjs.map +2 -2
- package/dist/modules/sandboxes/device-api.mjs +8 -0
- package/dist/modules/sandboxes/device-api.mjs.map +2 -2
- package/dist/modules/sandboxes/device.mjs +6 -0
- package/dist/modules/sandboxes/device.mjs.map +2 -2
- package/dist/modules/sandboxes/session.d.mts +1 -0
- package/dist/modules/sandboxes/session.mjs +106 -36
- package/dist/modules/sandboxes/session.mjs.map +3 -3
- package/dist/modules/sandboxes/testing/conformance.mjs +3 -0
- package/dist/modules/sandboxes/testing/conformance.mjs.map +2 -2
- package/dist/modules/sandboxes/testing/fake-machine.mjs +11 -0
- package/dist/modules/sandboxes/testing/fake-machine.mjs.map +2 -2
- package/dist/modules/sandboxes/transport.d.mts +1 -0
- package/dist/modules/sandboxes/transport.mjs.map +2 -2
- package/package.json +4 -40
- package/dist/modules/channels/channel-utils.d.mts +0 -132
- package/dist/modules/channels/channel-utils.mjs +0 -445
- package/dist/modules/channels/channel-utils.mjs.map +0 -7
- package/dist/modules/channels/discord-dispatch.d.mts +0 -17
- package/dist/modules/channels/discord-dispatch.mjs +0 -139
- package/dist/modules/channels/discord-dispatch.mjs.map +0 -7
- package/dist/modules/channels/discord-gateway.d.mts +0 -19
- package/dist/modules/channels/discord-gateway.mjs +0 -233
- package/dist/modules/channels/discord-gateway.mjs.map +0 -7
- package/dist/modules/channels/discord.d.mts +0 -9
- package/dist/modules/channels/discord.mjs +0 -904
- package/dist/modules/channels/discord.mjs.map +0 -7
- package/dist/modules/channels/github.d.mts +0 -5
- package/dist/modules/channels/github.mjs +0 -720
- package/dist/modules/channels/github.mjs.map +0 -7
- package/dist/modules/channels/linear.d.mts +0 -4
- package/dist/modules/channels/linear.mjs +0 -621
- package/dist/modules/channels/linear.mjs.map +0 -7
- package/dist/modules/channels/phone.d.mts +0 -8
- package/dist/modules/channels/phone.mjs +0 -382
- package/dist/modules/channels/phone.mjs.map +0 -7
- package/dist/modules/channels/reply-receipts.d.mts +0 -31
- package/dist/modules/channels/reply-receipts.mjs +0 -63
- package/dist/modules/channels/reply-receipts.mjs.map +0 -7
- package/dist/modules/channels/slack.d.mts +0 -7
- package/dist/modules/channels/slack.mjs +0 -1134
- package/dist/modules/channels/slack.mjs.map +0 -7
- package/dist/modules/channels/voice-recording.d.mts +0 -7
- package/dist/modules/channels/voice-recording.mjs +0 -49
- package/dist/modules/channels/voice-recording.mjs.map +0 -7
- package/dist/modules/channels/voice.d.mts +0 -33
- package/dist/modules/channels/voice.mjs +0 -851
- package/dist/modules/channels/voice.mjs.map +0 -7
- package/dist/modules/channels/webhook.d.mts +0 -5
- package/dist/modules/channels/webhook.mjs +0 -76
- package/dist/modules/channels/webhook.mjs.map +0 -7
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import type { ChannelReceiveContextIface, ChannelReceiveResult, JsonObject, JsonValue, PersonHandle, PlaceRef, PrincipalRef, Refusal } from '@finalai/agent-provider';
|
|
2
|
-
import * as z from 'zod';
|
|
3
|
-
export declare const channelBaseUrl: (config: {
|
|
4
|
-
baseUrl?: string;
|
|
5
|
-
}) => string;
|
|
6
|
-
export declare const providerPlaceKey: (place: PlaceRef) => string;
|
|
7
|
-
export declare const parseJson: (text: string) => unknown;
|
|
8
|
-
export declare const textOf: (content: readonly JsonObject[]) => string;
|
|
9
|
-
export declare const replyText: (data: {
|
|
10
|
-
messages?: {
|
|
11
|
-
content: JsonObject[];
|
|
12
|
-
}[];
|
|
13
|
-
content?: JsonObject[];
|
|
14
|
-
}) => string;
|
|
15
|
-
export declare const turnStatus: (data: {
|
|
16
|
-
stopReason?: string | null;
|
|
17
|
-
}) => string | null;
|
|
18
|
-
export declare const completionText: (data: {
|
|
19
|
-
messages?: {
|
|
20
|
-
content: JsonObject[];
|
|
21
|
-
}[];
|
|
22
|
-
content?: JsonObject[];
|
|
23
|
-
stopReason?: string | null;
|
|
24
|
-
}, partial?: string) => string;
|
|
25
|
-
export declare const hexBytes: (hex: string) => Uint8Array | null;
|
|
26
|
-
export declare const verifyHmac: (args: {
|
|
27
|
-
secret: string;
|
|
28
|
-
body: string;
|
|
29
|
-
signature: string;
|
|
30
|
-
algorithm?: "SHA-256" | "SHA-1";
|
|
31
|
-
encoding?: "hex" | "base64";
|
|
32
|
-
}) => Promise<boolean>;
|
|
33
|
-
export declare const freshTimestamp: (timestamp: string | null, now?: number) => timestamp is string;
|
|
34
|
-
export declare const refusal: (result: Refusal) => ChannelReceiveResult;
|
|
35
|
-
export declare const receipt: (result: {
|
|
36
|
-
messageId: string;
|
|
37
|
-
} | {
|
|
38
|
-
inputId: string;
|
|
39
|
-
} | Refusal) => ChannelReceiveResult;
|
|
40
|
-
export declare const personFor: <Config>(ctx: ChannelReceiveContextIface<Config>, principal: PrincipalRef) => Promise<PersonHandle | Refusal>;
|
|
41
|
-
export interface ReceivePersonMessageIface<Config> {
|
|
42
|
-
ctx: ChannelReceiveContextIface<Config>;
|
|
43
|
-
principal: PrincipalRef;
|
|
44
|
-
place: PlaceRef;
|
|
45
|
-
routePlace?: PlaceRef;
|
|
46
|
-
text: string;
|
|
47
|
-
externalKey: string;
|
|
48
|
-
ref?: JsonObject;
|
|
49
|
-
context?: string[];
|
|
50
|
-
loadContext?: () => Promise<string[]>;
|
|
51
|
-
waitForAcceptance?: boolean;
|
|
52
|
-
onAccepted?: (result: {
|
|
53
|
-
turnId?: string;
|
|
54
|
-
}) => Promise<void>;
|
|
55
|
-
resumeAfterLink?: boolean;
|
|
56
|
-
}
|
|
57
|
-
export declare const receivePersonMessage: <Config>(args: ReceivePersonMessageIface<Config>) => Promise<ChannelReceiveResult>;
|
|
58
|
-
export declare const externalKey: (place: PlaceRef, id: string) => string;
|
|
59
|
-
export declare const refString: (ref: JsonObject | undefined, name: string) => string | null;
|
|
60
|
-
export declare const responseJson: (response: Response) => Promise<unknown>;
|
|
61
|
-
export declare const deliveryRetention: {
|
|
62
|
-
ttlSeconds: number;
|
|
63
|
-
};
|
|
64
|
-
export declare const stateKey: (prefix: string, ...values: (string | null)[]) => string;
|
|
65
|
-
export declare const oauthStateSchema: z.ZodObject<{
|
|
66
|
-
ticket: z.ZodString;
|
|
67
|
-
principal: z.ZodObject<{
|
|
68
|
-
id: z.ZodString;
|
|
69
|
-
tenant: z.ZodOptional<z.ZodString>;
|
|
70
|
-
displayName: z.ZodOptional<z.ZodString>;
|
|
71
|
-
}, z.core.$strip>;
|
|
72
|
-
redirectUri: z.ZodString;
|
|
73
|
-
verifier: z.ZodOptional<z.ZodString>;
|
|
74
|
-
}, z.core.$strip>;
|
|
75
|
-
export declare const startOAuth: <Config>(args: {
|
|
76
|
-
ticket: string;
|
|
77
|
-
principal: PrincipalRef;
|
|
78
|
-
authorizeUrl: string;
|
|
79
|
-
clientId: string;
|
|
80
|
-
redirectUri: string;
|
|
81
|
-
scope: string;
|
|
82
|
-
extra?: Record<string, string>;
|
|
83
|
-
pkce?: boolean;
|
|
84
|
-
}, ctx: ChannelReceiveContextIface<Config>) => Promise<URL>;
|
|
85
|
-
export declare const takeOAuth: <Config>(request: Request, ctx: ChannelReceiveContextIface<Config>) => Promise<{
|
|
86
|
-
code: string;
|
|
87
|
-
ticket: string;
|
|
88
|
-
principal: {
|
|
89
|
-
id: string;
|
|
90
|
-
tenant?: string | undefined;
|
|
91
|
-
displayName?: string | undefined;
|
|
92
|
-
};
|
|
93
|
-
redirectUri: string;
|
|
94
|
-
verifier?: string | undefined;
|
|
95
|
-
} | null>;
|
|
96
|
-
export declare const confirmOAuth: <Config>(args: {
|
|
97
|
-
ticket: string;
|
|
98
|
-
expected: PrincipalRef;
|
|
99
|
-
actual: PrincipalRef;
|
|
100
|
-
}, ctx: ChannelReceiveContextIface<Config>) => Promise<Response>;
|
|
101
|
-
export interface DecisionChoiceIface {
|
|
102
|
-
label: string;
|
|
103
|
-
outcome: JsonValue;
|
|
104
|
-
answer: 'approve' | 'deny';
|
|
105
|
-
}
|
|
106
|
-
export declare const decisionSummary: (request: JsonObject) => string;
|
|
107
|
-
export declare const decisionAnswer: (choices: DecisionChoiceIface[], text: string) => DecisionChoiceIface | undefined;
|
|
108
|
-
export declare const decisionChoices: (request: JsonObject) => DecisionChoiceIface[];
|
|
109
|
-
export declare const createQueue: <T>() => {
|
|
110
|
-
push: (value: T) => void;
|
|
111
|
-
close: () => void;
|
|
112
|
-
stream: AsyncGenerator<T, any, any>;
|
|
113
|
-
};
|
|
114
|
-
export declare const inTenant: <Config>(ctx: ChannelReceiveContextIface<Config>, tenant: string) => ChannelReceiveContextIface<Config>;
|
|
115
|
-
export declare const providerOriginSchema: z.ZodObject<{
|
|
116
|
-
place: z.ZodLazy<z.ZodType<PlaceRef, unknown, z.core.$ZodTypeInternals<PlaceRef, unknown>>>;
|
|
117
|
-
externalKey: z.ZodString;
|
|
118
|
-
turnId: z.ZodOptional<z.ZodString>;
|
|
119
|
-
}, z.core.$strip>;
|
|
120
|
-
export declare const abortable: <T>(source: AsyncIterable<T>, signal: AbortSignal) => AsyncGenerator<T>;
|
|
121
|
-
interface SharedReactionArgsIface {
|
|
122
|
-
store: ChannelReceiveContextIface['store'];
|
|
123
|
-
key: string;
|
|
124
|
-
principal: PrincipalRef;
|
|
125
|
-
}
|
|
126
|
-
export declare const addSharedReaction: (args: SharedReactionArgsIface & {
|
|
127
|
-
add(): Promise<boolean>;
|
|
128
|
-
}) => Promise<void>;
|
|
129
|
-
export declare const removeSharedReaction: (args: SharedReactionArgsIface & {
|
|
130
|
-
remove(): Promise<void>;
|
|
131
|
-
}) => Promise<void>;
|
|
132
|
-
export {};
|
|
@@ -1,445 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
placeRefSchema as importPlaceSchema,
|
|
3
|
-
principalRefSchema,
|
|
4
|
-
jsonObjectSchema,
|
|
5
|
-
jsonValueSchema
|
|
6
|
-
} from "@finalai/agent-provider";
|
|
7
|
-
import * as z from "zod";
|
|
8
|
-
const channelBaseUrl = (config) => config.baseUrl ?? "https://agent-session.final.ai";
|
|
9
|
-
const providerPlaceKey = (place) => JSON.stringify([place.tenant ?? null, place.kind, place.id]);
|
|
10
|
-
const parseJson = (text) => {
|
|
11
|
-
try {
|
|
12
|
-
return JSON.parse(text);
|
|
13
|
-
} catch {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
const textOf = (content) => content.flatMap(
|
|
18
|
-
(block) => block.type === "text" && typeof block.text === "string" ? [block.text] : []
|
|
19
|
-
).join("");
|
|
20
|
-
const replyText = (data) => data.messages != null ? data.messages.map((message) => textOf(message.content)).join("\n\n") : textOf(data.content ?? []);
|
|
21
|
-
const turnStatus = (data) => {
|
|
22
|
-
const reason = data.stopReason;
|
|
23
|
-
if (reason == null || reason === "end_turn") return null;
|
|
24
|
-
switch (reason) {
|
|
25
|
-
case "cancelled":
|
|
26
|
-
return "This turn was cancelled.";
|
|
27
|
-
case "error":
|
|
28
|
-
return "The agent could not finish this turn. Open Final to try again.";
|
|
29
|
-
case "timed_out":
|
|
30
|
-
return "The agent timed out before finishing this turn.";
|
|
31
|
-
case "refusal":
|
|
32
|
-
return "The agent declined this request.";
|
|
33
|
-
case "max_tokens":
|
|
34
|
-
return "The reply stopped at its output limit.";
|
|
35
|
-
case "max_turn_requests":
|
|
36
|
-
return "The agent stopped at its request limit.";
|
|
37
|
-
default:
|
|
38
|
-
return `The agent stopped (${reason.replace(/[\r\n]/g, " ").slice(0, 120)}). Open Final for details.`;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const completionText = (data, partial = "") => {
|
|
42
|
-
const reply = replyText(data);
|
|
43
|
-
const text = reply.trim().length === 0 ? partial : reply;
|
|
44
|
-
const status = turnStatus(data);
|
|
45
|
-
const combined = [status, text].filter((part) => part != null && part.trim().length > 0).join("\n\n");
|
|
46
|
-
return combined.length > 0 ? combined : "The turn finished without a text reply. Open Final for details.";
|
|
47
|
-
};
|
|
48
|
-
const hexBytes = (hex) => {
|
|
49
|
-
if (!/^(?:[0-9a-fA-F]{2})+$/.test(hex)) return null;
|
|
50
|
-
return Uint8Array.from(hex.match(/../g) ?? [], (pair) => Number.parseInt(pair, 16));
|
|
51
|
-
};
|
|
52
|
-
const verifyHmac = async (args) => {
|
|
53
|
-
const key = await crypto.subtle.importKey(
|
|
54
|
-
"raw",
|
|
55
|
-
new TextEncoder().encode(args.secret),
|
|
56
|
-
{ name: "HMAC", hash: args.algorithm ?? "SHA-256" },
|
|
57
|
-
false,
|
|
58
|
-
["verify"]
|
|
59
|
-
);
|
|
60
|
-
let signature;
|
|
61
|
-
if (args.encoding === "base64") {
|
|
62
|
-
try {
|
|
63
|
-
signature = Uint8Array.from(atob(args.signature), (char) => char.charCodeAt(0));
|
|
64
|
-
} catch {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
} else signature = hexBytes(args.signature);
|
|
68
|
-
if (signature == null) return false;
|
|
69
|
-
return crypto.subtle.verify(
|
|
70
|
-
"HMAC",
|
|
71
|
-
key,
|
|
72
|
-
new Uint8Array(signature),
|
|
73
|
-
new TextEncoder().encode(args.body)
|
|
74
|
-
);
|
|
75
|
-
};
|
|
76
|
-
const freshTimestamp = (timestamp, now = Date.now()) => timestamp != null && /^\d+$/.test(timestamp) && Math.abs(now / 1e3 - Number(timestamp)) <= 300;
|
|
77
|
-
const refusal = (result) => ({
|
|
78
|
-
accepted: false,
|
|
79
|
-
refusal: result
|
|
80
|
-
});
|
|
81
|
-
const receipt = (result) => "refused" in result ? refusal(result) : { accepted: true };
|
|
82
|
-
const personFor = async (ctx, principal) => {
|
|
83
|
-
const result = await ctx.people.resolve(principal);
|
|
84
|
-
switch (result.kind) {
|
|
85
|
-
case "member":
|
|
86
|
-
return result.person;
|
|
87
|
-
case "unlinked":
|
|
88
|
-
return {
|
|
89
|
-
refused: "unlinked",
|
|
90
|
-
linkUrl: result.linkUrl,
|
|
91
|
-
message: "Link your account in Final to continue."
|
|
92
|
-
};
|
|
93
|
-
case "blocked":
|
|
94
|
-
return { refused: "no-access", message: "This account cannot access this workspace." };
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const receivePersonMessage = async (args) => {
|
|
98
|
-
const { ctx, principal, place } = args;
|
|
99
|
-
const context = () => args.loadContext == null ? args.context : args.loadContext();
|
|
100
|
-
const routePlace = args.routePlace ?? place;
|
|
101
|
-
const accepted = async (result) => {
|
|
102
|
-
if (!("refused" in result)) await args.onAccepted?.(result);
|
|
103
|
-
return receipt(result);
|
|
104
|
-
};
|
|
105
|
-
const person = await personFor(ctx, principal);
|
|
106
|
-
if (typeof person !== "string" && person.refused !== "unlinked") return refusal(person);
|
|
107
|
-
const route = await ctx.places.resolve(routePlace);
|
|
108
|
-
if (typeof person !== "string" && args.resumeAfterLink === true && (route.kind === "unconnected" || route.policy.audience !== "anyone")) {
|
|
109
|
-
const pending = jsonValueSchema.parse({
|
|
110
|
-
principal,
|
|
111
|
-
place,
|
|
112
|
-
text: args.text,
|
|
113
|
-
externalKey: args.externalKey,
|
|
114
|
-
...args.ref == null ? {} : { ref: args.ref }
|
|
115
|
-
});
|
|
116
|
-
if (JSON.stringify(pending).length <= 64 * 1024)
|
|
117
|
-
await ctx.store.set(
|
|
118
|
-
stateKey("pending-link", principal.tenant ?? null, principal.id),
|
|
119
|
-
pending,
|
|
120
|
-
{
|
|
121
|
-
ttlSeconds: 600
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
if (route.kind === "unconnected") {
|
|
126
|
-
if (typeof person !== "string") return refusal(person);
|
|
127
|
-
if (route.defaults == null)
|
|
128
|
-
return refusal({
|
|
129
|
-
refused: "unconnected",
|
|
130
|
-
connectUrl: route.connectUrl,
|
|
131
|
-
message: "Connect this place to a chat in Final."
|
|
132
|
-
});
|
|
133
|
-
let conversation;
|
|
134
|
-
try {
|
|
135
|
-
conversation = await ctx.places.connect(routePlace, {
|
|
136
|
-
by: person,
|
|
137
|
-
create: route.defaults.create
|
|
138
|
-
});
|
|
139
|
-
} catch {
|
|
140
|
-
ctx.log("Channel connection failed.");
|
|
141
|
-
return refusal({
|
|
142
|
-
refused: "unconnected",
|
|
143
|
-
connectUrl: route.connectUrl,
|
|
144
|
-
message: "Open Final to connect this place to a chat you can manage."
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
return accepted(
|
|
148
|
-
await ctx.conversation(conversation).post({
|
|
149
|
-
from: person,
|
|
150
|
-
content: [{ type: "text", text: args.text }],
|
|
151
|
-
context: await context(),
|
|
152
|
-
origin: { place, ref: args.ref },
|
|
153
|
-
idempotencyKey: args.externalKey,
|
|
154
|
-
waitForAcceptance: args.waitForAcceptance
|
|
155
|
-
})
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
const origin = { place, ref: args.ref };
|
|
159
|
-
if (typeof person !== "string") {
|
|
160
|
-
if (route.policy.audience !== "anyone") return refusal(person);
|
|
161
|
-
return accepted(
|
|
162
|
-
await ctx.conversation(route.conversation).input({
|
|
163
|
-
principal,
|
|
164
|
-
label: `From ${principal.displayName ?? principal.id} in ${place.title ?? place.kind}`,
|
|
165
|
-
content: [{ type: "text", text: args.text }],
|
|
166
|
-
context: await context(),
|
|
167
|
-
origin,
|
|
168
|
-
idempotencyKey: args.externalKey,
|
|
169
|
-
waitForAcceptance: args.waitForAcceptance
|
|
170
|
-
})
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
return accepted(
|
|
174
|
-
await ctx.conversation(route.conversation).post({
|
|
175
|
-
from: person,
|
|
176
|
-
content: [{ type: "text", text: args.text }],
|
|
177
|
-
context: await context(),
|
|
178
|
-
origin,
|
|
179
|
-
idempotencyKey: args.externalKey,
|
|
180
|
-
waitForAcceptance: args.waitForAcceptance
|
|
181
|
-
})
|
|
182
|
-
);
|
|
183
|
-
};
|
|
184
|
-
const externalKey = (place, id) => JSON.stringify([place.tenant ?? null, place.id, id]);
|
|
185
|
-
const refString = (ref, name) => typeof ref?.[name] === "string" ? ref[name] : null;
|
|
186
|
-
const responseJson = async (response) => {
|
|
187
|
-
const text = await response.text();
|
|
188
|
-
if (!response.ok)
|
|
189
|
-
throw new Error(`Channel request failed (${response.status}): ${text.slice(0, 500)}`, {
|
|
190
|
-
cause: { status: response.status }
|
|
191
|
-
});
|
|
192
|
-
return parseJson(text);
|
|
193
|
-
};
|
|
194
|
-
const deliveryRetention = { ttlSeconds: 90 * 24 * 60 * 60 };
|
|
195
|
-
const stateKey = (prefix, ...values) => `${prefix}:${JSON.stringify(values)}`;
|
|
196
|
-
const oauthStateSchema = z.object({
|
|
197
|
-
ticket: z.string(),
|
|
198
|
-
principal: z.object({
|
|
199
|
-
id: z.string(),
|
|
200
|
-
tenant: z.string().optional(),
|
|
201
|
-
displayName: z.string().optional()
|
|
202
|
-
}),
|
|
203
|
-
redirectUri: z.string(),
|
|
204
|
-
verifier: z.string().optional()
|
|
205
|
-
});
|
|
206
|
-
const startOAuth = async (args, ctx) => {
|
|
207
|
-
const state = crypto.randomUUID();
|
|
208
|
-
const verifier = args.pkce === true ? crypto.randomUUID() + crypto.randomUUID() : void 0;
|
|
209
|
-
let challenge = null;
|
|
210
|
-
if (verifier != null) {
|
|
211
|
-
const bytes = new Uint8Array(
|
|
212
|
-
await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier))
|
|
213
|
-
);
|
|
214
|
-
challenge = btoa(String.fromCharCode(...bytes)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
215
|
-
}
|
|
216
|
-
await ctx.store.set(
|
|
217
|
-
stateKey("oauth", state),
|
|
218
|
-
{
|
|
219
|
-
ticket: args.ticket,
|
|
220
|
-
principal: { ...args.principal },
|
|
221
|
-
redirectUri: args.redirectUri,
|
|
222
|
-
...verifier == null ? {} : { verifier }
|
|
223
|
-
},
|
|
224
|
-
{ ttlSeconds: 600 }
|
|
225
|
-
);
|
|
226
|
-
const url = new URL(args.authorizeUrl);
|
|
227
|
-
url.search = new URLSearchParams({
|
|
228
|
-
client_id: args.clientId,
|
|
229
|
-
redirect_uri: args.redirectUri,
|
|
230
|
-
response_type: "code",
|
|
231
|
-
state,
|
|
232
|
-
scope: args.scope,
|
|
233
|
-
...challenge == null ? {} : { code_challenge: challenge, code_challenge_method: "S256" },
|
|
234
|
-
...args.extra
|
|
235
|
-
}).toString();
|
|
236
|
-
return url;
|
|
237
|
-
};
|
|
238
|
-
const takeOAuth = async (request, ctx) => {
|
|
239
|
-
const params = new URL(request.url).searchParams;
|
|
240
|
-
const state = params.get("state");
|
|
241
|
-
const code = params.get("code");
|
|
242
|
-
if (state == null || code == null || params.has("error")) return null;
|
|
243
|
-
const key = stateKey("oauth", state);
|
|
244
|
-
const saved = oauthStateSchema.safeParse(await ctx.store.get(key));
|
|
245
|
-
if (!saved.success) return null;
|
|
246
|
-
await ctx.store.set(key, null);
|
|
247
|
-
return { ...saved.data, code };
|
|
248
|
-
};
|
|
249
|
-
const confirmOAuth = async (args, ctx) => {
|
|
250
|
-
if (args.actual.id !== args.expected.id || args.actual.tenant !== args.expected.tenant)
|
|
251
|
-
return new Response("The provider account does not match this link request.", { status: 403 });
|
|
252
|
-
const result = await ctx.people.confirm({ ticket: args.ticket, principal: args.actual });
|
|
253
|
-
if ("refused" in result) return new Response(result.message, { status: 403 });
|
|
254
|
-
const key = stateKey("pending-link", args.actual.tenant ?? null, args.actual.id);
|
|
255
|
-
const pending = z.object({
|
|
256
|
-
principal: principalRefSchema,
|
|
257
|
-
place: importPlaceSchema,
|
|
258
|
-
text: z.string().max(65536),
|
|
259
|
-
externalKey: z.string(),
|
|
260
|
-
ref: jsonObjectSchema.optional()
|
|
261
|
-
}).safeParse(await ctx.store.get(key));
|
|
262
|
-
if (pending.success) {
|
|
263
|
-
const context = pending.data.place.tenant == null ? ctx : inTenant(ctx, pending.data.place.tenant);
|
|
264
|
-
try {
|
|
265
|
-
const replayed = await receivePersonMessage({ ...pending.data, ctx: context });
|
|
266
|
-
if ("accepted" in replayed && replayed.accepted) await ctx.store.set(key, null);
|
|
267
|
-
} catch {
|
|
268
|
-
return new Response("Account linked. Send your message again to continue.");
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return new Response("Account linked. You can return to your conversation.");
|
|
272
|
-
};
|
|
273
|
-
const permissionOptionsSchema = z.object({
|
|
274
|
-
options: z.array(z.object({ optionId: z.string(), name: z.string(), kind: z.string() }))
|
|
275
|
-
});
|
|
276
|
-
const decisionSummary = (request) => {
|
|
277
|
-
const detail = z.object({
|
|
278
|
-
toolCall: z.object({ title: z.string().optional() }).optional(),
|
|
279
|
-
message: z.string().optional()
|
|
280
|
-
}).safeParse(request);
|
|
281
|
-
return detail.success ? (detail.data.toolCall?.title ?? detail.data.message ?? "An action needs your approval.").slice(0, 1500) : "An action needs your approval.";
|
|
282
|
-
};
|
|
283
|
-
const decisionAnswer = (choices, text) => {
|
|
284
|
-
const normalized = text.trim().toLowerCase().replace(/[.!?]$/g, "");
|
|
285
|
-
const exact = choices.filter((choice) => choice.label.toLowerCase() === normalized);
|
|
286
|
-
if (exact.length === 1) return exact[0];
|
|
287
|
-
const answer = ["yes", "approve"].includes(normalized) ? "approve" : ["no", "deny"].includes(normalized) ? "deny" : null;
|
|
288
|
-
const matching = choices.filter((choice) => choice.answer === answer);
|
|
289
|
-
return matching.length === 1 ? matching[0] : void 0;
|
|
290
|
-
};
|
|
291
|
-
const decisionChoices = (request) => {
|
|
292
|
-
const parsed = permissionOptionsSchema.safeParse(request);
|
|
293
|
-
if (!parsed.success) {
|
|
294
|
-
const elicitation = z.object({
|
|
295
|
-
requestedSchema: z.object({ properties: z.record(z.string(), z.unknown()).default({}) })
|
|
296
|
-
}).safeParse(request);
|
|
297
|
-
if (!elicitation.success || Object.keys(elicitation.data.requestedSchema.properties).length !== 0)
|
|
298
|
-
return [];
|
|
299
|
-
return [
|
|
300
|
-
{ label: "Approve", answer: "approve", outcome: { action: "accept", content: {} } },
|
|
301
|
-
{ label: "Deny", answer: "deny", outcome: { action: "decline" } }
|
|
302
|
-
];
|
|
303
|
-
}
|
|
304
|
-
const options = parsed.data.options.filter(
|
|
305
|
-
(option) => option.kind === "allow_once" || option.kind === "reject_once"
|
|
306
|
-
);
|
|
307
|
-
if (!options.some((option) => option.kind === "allow_once")) return [];
|
|
308
|
-
const names = options.map((option) => option.name.trim().slice(0, 75));
|
|
309
|
-
if (names.some((name) => name.length === 0) || new Set(names.map((name) => name.toLowerCase())).size !== names.length)
|
|
310
|
-
return [];
|
|
311
|
-
return options.map((option) => ({
|
|
312
|
-
label: option.name.trim().slice(0, 75),
|
|
313
|
-
answer: option.kind === "allow_once" ? "approve" : "deny",
|
|
314
|
-
outcome: { outcome: "selected", optionId: option.optionId }
|
|
315
|
-
}));
|
|
316
|
-
};
|
|
317
|
-
const createQueue = () => {
|
|
318
|
-
const pending = [];
|
|
319
|
-
let wake = null;
|
|
320
|
-
let ended = false;
|
|
321
|
-
const push = (value) => {
|
|
322
|
-
if (ended) return;
|
|
323
|
-
pending.push(value);
|
|
324
|
-
wake?.();
|
|
325
|
-
wake = null;
|
|
326
|
-
};
|
|
327
|
-
const close = () => {
|
|
328
|
-
ended = true;
|
|
329
|
-
wake?.();
|
|
330
|
-
wake = null;
|
|
331
|
-
};
|
|
332
|
-
async function* stream() {
|
|
333
|
-
while (!ended || pending.length > 0) {
|
|
334
|
-
const value = pending.shift();
|
|
335
|
-
if (value !== void 0) {
|
|
336
|
-
yield value;
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
await new Promise((resolve) => {
|
|
340
|
-
wake = resolve;
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
return { push, close, stream: stream() };
|
|
345
|
-
};
|
|
346
|
-
const inTenant = (ctx, tenant) => ({
|
|
347
|
-
...ctx,
|
|
348
|
-
credentials: {
|
|
349
|
-
...ctx.credentials,
|
|
350
|
-
app: (options) => ctx.credentials.app({ tenant: options?.tenant ?? tenant })
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
const providerOriginSchema = z.object({
|
|
354
|
-
place: z.lazy(() => importPlaceSchema),
|
|
355
|
-
externalKey: z.string(),
|
|
356
|
-
turnId: z.string().optional()
|
|
357
|
-
});
|
|
358
|
-
const abortable = async function* (source, signal) {
|
|
359
|
-
const iterator = source[Symbol.asyncIterator]();
|
|
360
|
-
const stopped = Promise.withResolvers();
|
|
361
|
-
const abort = () => stopped.resolve(null);
|
|
362
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
363
|
-
if (signal.aborted) abort();
|
|
364
|
-
try {
|
|
365
|
-
while (!signal.aborted) {
|
|
366
|
-
const next = await Promise.race([iterator.next(), stopped.promise]);
|
|
367
|
-
if (next == null || next.done) break;
|
|
368
|
-
yield next.value;
|
|
369
|
-
}
|
|
370
|
-
} finally {
|
|
371
|
-
signal.removeEventListener("abort", abort);
|
|
372
|
-
void iterator.return?.().catch(() => void 0);
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
const sharedReactionSchema = z.object({
|
|
376
|
-
principals: z.array(z.string()).max(256),
|
|
377
|
-
overflow: z.boolean(),
|
|
378
|
-
owned: z.boolean()
|
|
379
|
-
});
|
|
380
|
-
const addSharedReaction = async (args) => {
|
|
381
|
-
const principal = JSON.stringify([args.principal.tenant ?? null, args.principal.id]);
|
|
382
|
-
const saved = sharedReactionSchema.safeParse(await args.store.get(args.key));
|
|
383
|
-
if (saved.success) {
|
|
384
|
-
if (saved.data.overflow || saved.data.principals.includes(principal)) return;
|
|
385
|
-
await args.store.set(
|
|
386
|
-
args.key,
|
|
387
|
-
saved.data.principals.length >= 256 ? { ...saved.data, overflow: true } : { ...saved.data, principals: [...saved.data.principals, principal] },
|
|
388
|
-
deliveryRetention
|
|
389
|
-
);
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
const owned = await args.add();
|
|
393
|
-
await args.store.set(
|
|
394
|
-
args.key,
|
|
395
|
-
{ principals: [principal], overflow: false, owned },
|
|
396
|
-
deliveryRetention
|
|
397
|
-
);
|
|
398
|
-
};
|
|
399
|
-
const removeSharedReaction = async (args) => {
|
|
400
|
-
const saved = sharedReactionSchema.safeParse(await args.store.get(args.key));
|
|
401
|
-
const principal = JSON.stringify([args.principal.tenant ?? null, args.principal.id]);
|
|
402
|
-
if (!saved.success || saved.data.overflow || !saved.data.principals.includes(principal)) return;
|
|
403
|
-
const remaining = saved.data.principals.filter((value) => value !== principal);
|
|
404
|
-
if (remaining.length > 0) {
|
|
405
|
-
await args.store.set(args.key, { ...saved.data, principals: remaining }, deliveryRetention);
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
if (saved.data.owned) await args.remove();
|
|
409
|
-
await args.store.set(args.key, null);
|
|
410
|
-
};
|
|
411
|
-
export {
|
|
412
|
-
abortable,
|
|
413
|
-
addSharedReaction,
|
|
414
|
-
channelBaseUrl,
|
|
415
|
-
completionText,
|
|
416
|
-
confirmOAuth,
|
|
417
|
-
createQueue,
|
|
418
|
-
decisionAnswer,
|
|
419
|
-
decisionChoices,
|
|
420
|
-
decisionSummary,
|
|
421
|
-
deliveryRetention,
|
|
422
|
-
externalKey,
|
|
423
|
-
freshTimestamp,
|
|
424
|
-
hexBytes,
|
|
425
|
-
inTenant,
|
|
426
|
-
oauthStateSchema,
|
|
427
|
-
parseJson,
|
|
428
|
-
personFor,
|
|
429
|
-
providerOriginSchema,
|
|
430
|
-
providerPlaceKey,
|
|
431
|
-
receipt,
|
|
432
|
-
receivePersonMessage,
|
|
433
|
-
refString,
|
|
434
|
-
refusal,
|
|
435
|
-
removeSharedReaction,
|
|
436
|
-
replyText,
|
|
437
|
-
responseJson,
|
|
438
|
-
startOAuth,
|
|
439
|
-
stateKey,
|
|
440
|
-
takeOAuth,
|
|
441
|
-
textOf,
|
|
442
|
-
turnStatus,
|
|
443
|
-
verifyHmac
|
|
444
|
-
};
|
|
445
|
-
//# sourceMappingURL=channel-utils.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../../src/channels/channel-utils.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n placeRefSchema as importPlaceSchema,\n principalRefSchema,\n jsonObjectSchema,\n jsonValueSchema,\n} from '@finalai/agent-provider';\nimport type {\n ChannelReceiveContextIface,\n ConversationHandle,\n ChannelReceiveResult,\n JsonObject,\n JsonValue,\n OriginIface,\n PersonHandle,\n PlaceRef,\n PrincipalRef,\n Refusal,\n} from '@finalai/agent-provider';\nimport * as z from 'zod';\n\nexport const channelBaseUrl = (config: { baseUrl?: string }): string =>\n config.baseUrl ?? 'https://agent-session.final.ai';\nexport const providerPlaceKey = (place: PlaceRef): string =>\n JSON.stringify([place.tenant ?? null, place.kind, place.id]);\nexport const parseJson = (text: string): unknown => {\n try {\n return JSON.parse(text);\n } catch {\n return null;\n }\n};\nexport const textOf = (content: readonly JsonObject[]): string =>\n content\n .flatMap((block) =>\n block.type === 'text' && typeof block.text === 'string' ? [block.text] : [],\n )\n .join('');\nexport const replyText = (data: {\n messages?: { content: JsonObject[] }[];\n content?: JsonObject[];\n}): string =>\n data.messages != null\n ? data.messages.map((message) => textOf(message.content)).join('\\n\\n')\n : textOf(data.content ?? []);\nexport const turnStatus = (data: { stopReason?: string | null }): string | null => {\n const reason = data.stopReason;\n if (reason == null || reason === 'end_turn') return null;\n switch (reason) {\n case 'cancelled':\n return 'This turn was cancelled.';\n case 'error':\n return 'The agent could not finish this turn. Open Final to try again.';\n case 'timed_out':\n return 'The agent timed out before finishing this turn.';\n case 'refusal':\n return 'The agent declined this request.';\n case 'max_tokens':\n return 'The reply stopped at its output limit.';\n case 'max_turn_requests':\n return 'The agent stopped at its request limit.';\n default:\n return `The agent stopped (${reason.replace(/[\\r\\n]/g, ' ').slice(0, 120)}). Open Final for details.`;\n }\n};\nexport const completionText = (\n data: {\n messages?: { content: JsonObject[] }[];\n content?: JsonObject[];\n stopReason?: string | null;\n },\n partial = '',\n): string => {\n const reply = replyText(data);\n const text = reply.trim().length === 0 ? partial : reply;\n const status = turnStatus(data);\n const combined = [status, text]\n .filter((part) => part != null && part.trim().length > 0)\n .join('\\n\\n');\n return combined.length > 0\n ? combined\n : 'The turn finished without a text reply. Open Final for details.';\n};\nexport const hexBytes = (hex: string): Uint8Array | null => {\n if (!/^(?:[0-9a-fA-F]{2})+$/.test(hex)) return null;\n return Uint8Array.from(hex.match(/../g) ?? [], (pair) => Number.parseInt(pair, 16));\n};\nexport const verifyHmac = async (args: {\n secret: string;\n body: string;\n signature: string;\n algorithm?: 'SHA-256' | 'SHA-1';\n encoding?: 'hex' | 'base64';\n}): Promise<boolean> => {\n const key = await crypto.subtle.importKey(\n 'raw',\n new TextEncoder().encode(args.secret),\n { name: 'HMAC', hash: args.algorithm ?? 'SHA-256' },\n false,\n ['verify'],\n );\n let signature: Uint8Array | null;\n if (args.encoding === 'base64') {\n try {\n signature = Uint8Array.from(atob(args.signature), (char) => char.charCodeAt(0));\n } catch {\n return false;\n }\n } else signature = hexBytes(args.signature);\n if (signature == null) return false;\n return crypto.subtle.verify(\n 'HMAC',\n key,\n new Uint8Array(signature),\n new TextEncoder().encode(args.body),\n );\n};\nexport const freshTimestamp = (timestamp: string | null, now = Date.now()): timestamp is string =>\n timestamp != null && /^\\d+$/.test(timestamp) && Math.abs(now / 1000 - Number(timestamp)) <= 300;\nexport const refusal = (result: Refusal): ChannelReceiveResult => ({\n accepted: false,\n refusal: result,\n});\nexport const receipt = (\n result: { messageId: string } | { inputId: string } | Refusal,\n): ChannelReceiveResult => ('refused' in result ? refusal(result) : { accepted: true });\nexport const personFor = async <Config>(\n ctx: ChannelReceiveContextIface<Config>,\n principal: PrincipalRef,\n): Promise<PersonHandle | Refusal> => {\n const result = await ctx.people.resolve(principal);\n switch (result.kind) {\n case 'member':\n return result.person;\n case 'unlinked':\n return {\n refused: 'unlinked',\n linkUrl: result.linkUrl,\n message: 'Link your account in Final to continue.',\n };\n case 'blocked':\n return { refused: 'no-access', message: 'This account cannot access this workspace.' };\n }\n};\nexport interface ReceivePersonMessageIface<Config> {\n ctx: ChannelReceiveContextIface<Config>;\n principal: PrincipalRef;\n place: PlaceRef;\n routePlace?: PlaceRef;\n text: string;\n externalKey: string;\n ref?: JsonObject;\n context?: string[];\n loadContext?: () => Promise<string[]>;\n waitForAcceptance?: boolean;\n onAccepted?: (result: { turnId?: string }) => Promise<void>;\n resumeAfterLink?: boolean;\n}\nexport const receivePersonMessage = async <Config>(\n args: ReceivePersonMessageIface<Config>,\n): Promise<ChannelReceiveResult> => {\n const { ctx, principal, place } = args;\n const context = () => (args.loadContext == null ? args.context : args.loadContext());\n const routePlace = args.routePlace ?? place;\n const accepted = async (\n result: { messageId: string; turnId?: string } | { inputId: string; turnId?: string } | Refusal,\n ): Promise<ChannelReceiveResult> => {\n if (!('refused' in result)) await args.onAccepted?.(result);\n return receipt(result);\n };\n const person = await personFor(ctx, principal);\n if (typeof person !== 'string' && person.refused !== 'unlinked') return refusal(person);\n const route = await ctx.places.resolve(routePlace);\n if (\n typeof person !== 'string' &&\n args.resumeAfterLink === true &&\n (route.kind === 'unconnected' || route.policy.audience !== 'anyone')\n ) {\n const pending = jsonValueSchema.parse({\n principal,\n place,\n text: args.text,\n externalKey: args.externalKey,\n ...(args.ref == null ? {} : { ref: args.ref }),\n });\n if (JSON.stringify(pending).length <= 64 * 1024)\n await ctx.store.set(\n stateKey('pending-link', principal.tenant ?? null, principal.id),\n pending,\n {\n ttlSeconds: 600,\n },\n );\n }\n if (route.kind === 'unconnected') {\n if (typeof person !== 'string') return refusal(person);\n if (route.defaults == null)\n return refusal({\n refused: 'unconnected',\n connectUrl: route.connectUrl,\n message: 'Connect this place to a chat in Final.',\n });\n let conversation: ConversationHandle;\n try {\n conversation = await ctx.places.connect(routePlace, {\n by: person,\n create: route.defaults.create,\n });\n } catch {\n ctx.log('Channel connection failed.');\n return refusal({\n refused: 'unconnected',\n connectUrl: route.connectUrl,\n message: 'Open Final to connect this place to a chat you can manage.',\n });\n }\n return accepted(\n await ctx.conversation(conversation).post({\n from: person,\n content: [{ type: 'text', text: args.text }],\n context: await context(),\n origin: { place, ref: args.ref },\n idempotencyKey: args.externalKey,\n waitForAcceptance: args.waitForAcceptance,\n }),\n );\n }\n const origin: OriginIface = { place, ref: args.ref };\n if (typeof person !== 'string') {\n if (route.policy.audience !== 'anyone') return refusal(person);\n return accepted(\n await ctx.conversation(route.conversation).input({\n principal,\n label: `From ${principal.displayName ?? principal.id} in ${place.title ?? place.kind}`,\n content: [{ type: 'text', text: args.text }],\n context: await context(),\n origin,\n idempotencyKey: args.externalKey,\n waitForAcceptance: args.waitForAcceptance,\n }),\n );\n }\n return accepted(\n await ctx.conversation(route.conversation).post({\n from: person,\n content: [{ type: 'text', text: args.text }],\n context: await context(),\n origin,\n idempotencyKey: args.externalKey,\n waitForAcceptance: args.waitForAcceptance,\n }),\n );\n};\nexport const externalKey = (place: PlaceRef, id: string): string =>\n JSON.stringify([place.tenant ?? null, place.id, id]);\nexport const refString = (ref: JsonObject | undefined, name: string): string | null =>\n typeof ref?.[name] === 'string' ? ref[name] : null;\nexport const responseJson = async (response: Response): Promise<unknown> => {\n const text = await response.text();\n if (!response.ok)\n throw new Error(`Channel request failed (${response.status}): ${text.slice(0, 500)}`, {\n cause: { status: response.status },\n });\n return parseJson(text);\n};\nexport const deliveryRetention = { ttlSeconds: 90 * 24 * 60 * 60 };\nexport const stateKey = (prefix: string, ...values: (string | null)[]): string =>\n `${prefix}:${JSON.stringify(values)}`;\nexport const oauthStateSchema = z.object({\n ticket: z.string(),\n principal: z.object({\n id: z.string(),\n tenant: z.string().optional(),\n displayName: z.string().optional(),\n }),\n redirectUri: z.string(),\n verifier: z.string().optional(),\n});\nexport const startOAuth = async <Config>(\n args: {\n ticket: string;\n principal: PrincipalRef;\n authorizeUrl: string;\n clientId: string;\n redirectUri: string;\n scope: string;\n extra?: Record<string, string>;\n pkce?: boolean;\n },\n ctx: ChannelReceiveContextIface<Config>,\n): Promise<URL> => {\n const state = crypto.randomUUID();\n const verifier = args.pkce === true ? crypto.randomUUID() + crypto.randomUUID() : undefined;\n let challenge: string | null = null;\n if (verifier != null) {\n const bytes = new Uint8Array(\n await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier)),\n );\n challenge = btoa(String.fromCharCode(...bytes))\n .replace(/=/g, '')\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_');\n }\n await ctx.store.set(\n stateKey('oauth', state),\n {\n ticket: args.ticket,\n principal: { ...args.principal },\n redirectUri: args.redirectUri,\n ...(verifier == null ? {} : { verifier }),\n },\n { ttlSeconds: 600 },\n );\n const url = new URL(args.authorizeUrl);\n url.search = new URLSearchParams({\n client_id: args.clientId,\n redirect_uri: args.redirectUri,\n response_type: 'code',\n state,\n scope: args.scope,\n ...(challenge == null ? {} : { code_challenge: challenge, code_challenge_method: 'S256' }),\n ...args.extra,\n }).toString();\n return url;\n};\nexport const takeOAuth = async <Config>(\n request: Request,\n ctx: ChannelReceiveContextIface<Config>,\n) => {\n const params = new URL(request.url).searchParams;\n const state = params.get('state');\n const code = params.get('code');\n if (state == null || code == null || params.has('error')) return null;\n const key = stateKey('oauth', state);\n const saved = oauthStateSchema.safeParse(await ctx.store.get(key));\n if (!saved.success) return null;\n await ctx.store.set(key, null);\n return { ...saved.data, code };\n};\nexport const confirmOAuth = async <Config>(\n args: { ticket: string; expected: PrincipalRef; actual: PrincipalRef },\n ctx: ChannelReceiveContextIface<Config>,\n): Promise<Response> => {\n if (args.actual.id !== args.expected.id || args.actual.tenant !== args.expected.tenant)\n return new Response('The provider account does not match this link request.', { status: 403 });\n const result = await ctx.people.confirm({ ticket: args.ticket, principal: args.actual });\n if ('refused' in result) return new Response(result.message, { status: 403 });\n const key = stateKey('pending-link', args.actual.tenant ?? null, args.actual.id);\n const pending = z\n .object({\n principal: principalRefSchema,\n place: importPlaceSchema,\n text: z.string().max(65536),\n externalKey: z.string(),\n ref: jsonObjectSchema.optional(),\n })\n .safeParse(await ctx.store.get(key));\n if (pending.success) {\n const context =\n pending.data.place.tenant == null ? ctx : inTenant(ctx, pending.data.place.tenant);\n try {\n const replayed = await receivePersonMessage({ ...pending.data, ctx: context });\n if ('accepted' in replayed && replayed.accepted) await ctx.store.set(key, null);\n } catch {\n return new Response('Account linked. Send your message again to continue.');\n }\n }\n return new Response('Account linked. You can return to your conversation.');\n};\nconst permissionOptionsSchema = z.object({\n options: z.array(z.object({ optionId: z.string(), name: z.string(), kind: z.string() })),\n});\nexport interface DecisionChoiceIface {\n label: string;\n outcome: JsonValue;\n answer: 'approve' | 'deny';\n}\nexport const decisionSummary = (request: JsonObject): string => {\n const detail = z\n .object({\n toolCall: z.object({ title: z.string().optional() }).optional(),\n message: z.string().optional(),\n })\n .safeParse(request);\n return detail.success\n ? (\n detail.data.toolCall?.title ??\n detail.data.message ??\n 'An action needs your approval.'\n ).slice(0, 1500)\n : 'An action needs your approval.';\n};\nexport const decisionAnswer = (\n choices: DecisionChoiceIface[],\n text: string,\n): DecisionChoiceIface | undefined => {\n const normalized = text\n .trim()\n .toLowerCase()\n .replace(/[.!?]$/g, '');\n const exact = choices.filter((choice) => choice.label.toLowerCase() === normalized);\n if (exact.length === 1) return exact[0];\n const answer = ['yes', 'approve'].includes(normalized)\n ? 'approve'\n : ['no', 'deny'].includes(normalized)\n ? 'deny'\n : null;\n const matching = choices.filter((choice) => choice.answer === answer);\n return matching.length === 1 ? matching[0] : undefined;\n};\nexport const decisionChoices = (request: JsonObject): DecisionChoiceIface[] => {\n const parsed = permissionOptionsSchema.safeParse(request);\n if (!parsed.success) {\n const elicitation = z\n .object({\n requestedSchema: z.object({ properties: z.record(z.string(), z.unknown()).default({}) }),\n })\n .safeParse(request);\n if (\n !elicitation.success ||\n Object.keys(elicitation.data.requestedSchema.properties).length !== 0\n )\n return [];\n return [\n { label: 'Approve', answer: 'approve', outcome: { action: 'accept', content: {} } },\n { label: 'Deny', answer: 'deny', outcome: { action: 'decline' } },\n ];\n }\n const options = parsed.data.options.filter(\n (option) => option.kind === 'allow_once' || option.kind === 'reject_once',\n );\n if (!options.some((option) => option.kind === 'allow_once')) return [];\n const names = options.map((option) => option.name.trim().slice(0, 75));\n if (\n names.some((name) => name.length === 0) ||\n new Set(names.map((name) => name.toLowerCase())).size !== names.length\n )\n return [];\n return options.map((option) => ({\n label: option.name.trim().slice(0, 75),\n answer: option.kind === 'allow_once' ? 'approve' : 'deny',\n outcome: { outcome: 'selected', optionId: option.optionId },\n }));\n};\n\nexport const createQueue = <T>() => {\n const pending: T[] = [];\n let wake: (() => void) | null = null;\n let ended = false;\n const push = (value: T): void => {\n if (ended) return;\n pending.push(value);\n wake?.();\n wake = null;\n };\n const close = (): void => {\n ended = true;\n wake?.();\n wake = null;\n };\n async function* stream(): AsyncGenerator<T> {\n while (!ended || pending.length > 0) {\n const value = pending.shift();\n if (value !== undefined) {\n yield value;\n continue;\n }\n await new Promise<void>((resolve) => {\n wake = resolve;\n });\n }\n }\n return { push, close, stream: stream() };\n};\n\nexport const inTenant = <Config>(\n ctx: ChannelReceiveContextIface<Config>,\n tenant: string,\n): ChannelReceiveContextIface<Config> => ({\n ...ctx,\n credentials: {\n ...ctx.credentials,\n app: (options) => ctx.credentials.app({ tenant: options?.tenant ?? tenant }),\n },\n});\nexport const providerOriginSchema = z.object({\n place: z.lazy(() => importPlaceSchema),\n externalKey: z.string(),\n turnId: z.string().optional(),\n});\n\nexport const abortable = async function* <T>(\n source: AsyncIterable<T>,\n signal: AbortSignal,\n): AsyncGenerator<T> {\n const iterator = source[Symbol.asyncIterator]();\n const stopped = Promise.withResolvers<null>();\n const abort = () => stopped.resolve(null);\n signal.addEventListener('abort', abort, { once: true });\n if (signal.aborted) abort();\n try {\n while (!signal.aborted) {\n const next = await Promise.race([iterator.next(), stopped.promise]);\n if (next == null || next.done) break;\n yield next.value;\n }\n } finally {\n signal.removeEventListener('abort', abort);\n void iterator.return?.().catch(() => undefined);\n }\n};\n\nconst sharedReactionSchema = z.object({\n principals: z.array(z.string()).max(256),\n overflow: z.boolean(),\n owned: z.boolean(),\n});\ninterface SharedReactionArgsIface {\n store: ChannelReceiveContextIface['store'];\n key: string;\n principal: PrincipalRef;\n}\nexport const addSharedReaction = async (\n args: SharedReactionArgsIface & { add(): Promise<boolean> },\n): Promise<void> => {\n const principal = JSON.stringify([args.principal.tenant ?? null, args.principal.id]);\n const saved = sharedReactionSchema.safeParse(await args.store.get(args.key));\n if (saved.success) {\n if (saved.data.overflow || saved.data.principals.includes(principal)) return;\n await args.store.set(\n args.key,\n saved.data.principals.length >= 256\n ? { ...saved.data, overflow: true }\n : { ...saved.data, principals: [...saved.data.principals, principal] },\n deliveryRetention,\n );\n return;\n }\n const owned = await args.add();\n await args.store.set(\n args.key,\n { principals: [principal], overflow: false, owned },\n deliveryRetention,\n );\n};\nexport const removeSharedReaction = async (\n args: SharedReactionArgsIface & { remove(): Promise<void> },\n): Promise<void> => {\n const saved = sharedReactionSchema.safeParse(await args.store.get(args.key));\n const principal = JSON.stringify([args.principal.tenant ?? null, args.principal.id]);\n if (!saved.success || saved.data.overflow || !saved.data.principals.includes(principal)) return;\n const remaining = saved.data.principals.filter((value) => value !== principal);\n if (remaining.length > 0) {\n await args.store.set(args.key, { ...saved.data, principals: remaining }, deliveryRetention);\n return;\n }\n if (saved.data.owned) await args.remove();\n await args.store.set(args.key, null);\n};\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EACE,kBAAkB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAaP,YAAY,OAAO;AAEZ,MAAM,iBAAiB,CAAC,WAC7B,OAAO,WAAW;AACb,MAAM,mBAAmB,CAAC,UAC/B,KAAK,UAAU,CAAC,MAAM,UAAU,MAAM,MAAM,MAAM,MAAM,EAAE,CAAC;AACtD,MAAM,YAAY,CAAC,SAA0B;AAClD,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AACO,MAAM,SAAS,CAAC,YACrB,QACG;AAAA,EAAQ,CAAC,UACR,MAAM,SAAS,UAAU,OAAO,MAAM,SAAS,WAAW,CAAC,MAAM,IAAI,IAAI,CAAC;AAC5E,EACC,KAAK,EAAE;AACL,MAAM,YAAY,CAAC,SAIxB,KAAK,YAAY,OACb,KAAK,SAAS,IAAI,CAAC,YAAY,OAAO,QAAQ,OAAO,CAAC,EAAE,KAAK,MAAM,IACnE,OAAO,KAAK,WAAW,CAAC,CAAC;AACxB,MAAM,aAAa,CAAC,SAAwD;AACjF,QAAM,SAAS,KAAK;AACpB,MAAI,UAAU,QAAQ,WAAW,WAAY,QAAO;AACpD,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAA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AAQ,MAAM,KAAK,IAAI;AAC7B,QAAM,KAAK,MAAM;AAAA,IACf,KAAK;AAAA,IACL,EAAE,YAAY,CAAC,SAAS,GAAG,UAAU,OAAO,MAAM;AAAA,IAClD;AAAA,EACF;AACF;AACO,MAAM,uBAAuB,OAClC,SACkB;AAClB,QAAM,QAAQ,qBAAqB,UAAU,MAAM,KAAK,MAAM,IAAI,KAAK,GAAG,CAAC;AAC3E,QAAM,YAAY,KAAK,UAAU,CAAC,KAAK,UAAU,UAAU,MAAM,KAAK,UAAU,EAAE,CAAC;AACnF,MAAI,CAAC,MAAM,WAAW,MAAM,KAAK,YAAY,CAAC,MAAM,KAAK,WAAW,SAAS,SAAS,EAAG;AACzF,QAAM,YAAY,MAAM,KAAK,WAAW,OAAO,CAAC,UAAU,UAAU,SAAS;AAC7E,MAAI,UAAU,SAAS,GAAG;AACxB,UAAM,KAAK,MAAM,IAAI,KAAK,KAAK,EAAE,GAAG,MAAM,MAAM,YAAY,UAAU,GAAG,iBAAiB;AAC1F;AAAA,EACF;AACA,MAAI,MAAM,KAAK,MAAO,OAAM,KAAK,OAAO;AACxC,QAAM,KAAK,MAAM,IAAI,KAAK,KAAK,IAAI;AACrC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type ChannelReceiveContextIface, type ChannelReceiveResult, type JsonObject, type JsonValue } from '@finalai/agent-provider';
|
|
2
|
-
interface DiscordDispatchOptionsIface {
|
|
3
|
-
store: ChannelReceiveContextIface['store'];
|
|
4
|
-
botId: string;
|
|
5
|
-
receive(input: JsonValue, signal: AbortSignal): Promise<ChannelReceiveResult>;
|
|
6
|
-
request(args: {
|
|
7
|
-
path: string;
|
|
8
|
-
body: JsonObject;
|
|
9
|
-
method?: string;
|
|
10
|
-
signal?: AbortSignal;
|
|
11
|
-
}): Promise<unknown>;
|
|
12
|
-
}
|
|
13
|
-
export declare const createDiscordDispatch: (options: DiscordDispatchOptionsIface) => {
|
|
14
|
-
accepts: (type: string, data: JsonValue, signal?: AbortSignal) => Promise<boolean>;
|
|
15
|
-
receive: (input: JsonValue, signal: AbortSignal) => Promise<ChannelReceiveResult>;
|
|
16
|
-
};
|
|
17
|
-
export {};
|