@segmentstream/ontology 0.161.0 → 0.163.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/CHANGELOG.md +41 -0
- package/dist/agent-draft.d.ts +21 -0
- package/dist/agent-draft.js +57 -1
- package/dist/deployment.d.ts +13 -1
- package/dist/deployment.js +8 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +7 -6
- package/dist/manifest.js +1 -0
- package/dist/runtime/agent-web.js +42 -3
- package/dist/runtime/agents.js +6 -1
- package/dist/service/agent/authentication.js +9 -2
- package/dist/service/agent/eval-tokens.d.ts +25 -0
- package/dist/service/agent/eval-tokens.js +130 -0
- package/dist/service/agent/protocol.d.ts +20 -5
- package/dist/service/agent/protocol.js +25 -3
- package/dist/service/agent/server.d.ts +11 -0
- package/dist/service/agent/server.js +114 -5
- package/dist/service/agent/web-tokens.d.ts +13 -2
- package/dist/service/agent/web-tokens.js +20 -5
- package/dist/service/authentication.js +3 -2
- package/dist/service/chat/archive.d.ts +15 -1
- package/dist/service/chat/draft-files.d.ts +56 -0
- package/dist/service/chat/draft-files.js +137 -0
- package/dist/service/chat/idempotency.d.ts +6 -1
- package/dist/service/chat/idempotency.js +7 -1
- package/dist/service/chat/providers/custom.js +12 -2
- package/dist/service/chat/providers/email.d.ts +2 -1
- package/dist/service/chat/providers/email.js +48 -4
- package/dist/service/chat/providers/provider.d.ts +49 -1
- package/dist/service/chat/providers/provider.js +18 -1
- package/dist/service/chat/review-delivery.d.ts +2 -0
- package/dist/service/chat/review-delivery.js +73 -4
- package/dist/service/chat/store-delivery.js +13 -0
- package/dist/service/config.js +8 -2
- package/dist/service/runtime-contract.d.ts +33 -0
- package/dist/service/runtime-identity.d.ts +17 -1
- package/dist/service/runtime-identity.js +15 -2
- package/dist/service/service.js +64 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.163.0
|
|
4
|
+
|
|
5
|
+
The ontology of an app preview can serve the workspace's agent, built from the preview's commit,
|
|
6
|
+
for the preview app's web chat and for evals. The platform turns it on by giving the preview the
|
|
7
|
+
runtime identity of its hosting project (`SEGMENTSTREAM_RUNTIME_OIDC_ISSUER` and
|
|
8
|
+
`SEGMENTSTREAM_RUNTIME_OIDC_AUDIENCE`); the deployment observation then says `agent: true`, and
|
|
9
|
+
`previewRunsAgent()` reads it. The preview trusts only its hosting project's function tokens that
|
|
10
|
+
name `preview`, and only with `X-SegmentStream-Ontology-Deployment-Id` naming its own deployment
|
|
11
|
+
(`ONTOLOGY_DEPLOYMENT_HEADER`), because every preview of a workspace shares one hosting project.
|
|
12
|
+
It serves agent tokens, their introspection, the chat store, held replies, and members' attachments
|
|
13
|
+
and files, and still none of channels, pairings, accounts, visitors or tasks. Production never
|
|
14
|
+
trusts a preview's tokens. Manifests advertise `workspace-app-preview-agent-v1`.
|
|
15
|
+
|
|
16
|
+
Evals reach that agent as a test member with an agent token of the new first-party client
|
|
17
|
+
`agent-eval` (`AGENT_EVAL_CLIENT_ID`), on the existing grant and token tables. Only the platform
|
|
18
|
+
issues one, with its workload token bound to the preview, at `POST /api/ontology/agent/eval-tokens`
|
|
19
|
+
(`AGENT_EVAL_TOKENS_PATH`), which only a preview that runs the agent mounts. A token works 30
|
|
20
|
+
minutes by default and an hour at most (`EVAL_TOKEN_DEFAULT_SECONDS`, `EVAL_TOKEN_MAX_SECONDS`),
|
|
21
|
+
never past the preview's expiry, has no refresh token, and issuing another ends the member's earlier
|
|
22
|
+
eval session. Introspection answers it as the member's, with `eval: true`, and counts its turns
|
|
23
|
+
against no limit. Outside such a preview the client is refused: introspection answers its tokens
|
|
24
|
+
`active: false` and the agent cannot act with its grants.
|
|
25
|
+
|
|
26
|
+
## 0.162.0
|
|
27
|
+
|
|
28
|
+
A draft can carry record files. `agent_draft.files` lists each file the reply carries as
|
|
29
|
+
`{ entity, id, property, revisionId, filename, contentType, size }`: the revision its person could
|
|
30
|
+
read when the agent held the reply, snapshotted by `POST /api/ontology/agent/drafts` from its new
|
|
31
|
+
`files` (up to 10 record references, read as that person). A draft of files alone has empty text.
|
|
32
|
+
`POST /api/ontology/agent/drafts/files` runs the same check without holding anything, for the
|
|
33
|
+
agent to ask before it promises a file in a reviewed chat.
|
|
34
|
+
|
|
35
|
+
Approving a draft sends its files with the text in the reply's one delivery, each at the revision
|
|
36
|
+
held and read again as the person: by email in the reply's one message (`EMAIL_FILES_BYTES`), and
|
|
37
|
+
through a workspace channel in the `files` of its one `send`. Before anything is reserved, approval
|
|
38
|
+
refuses with the action's `refusal`: `files_unsupported` (the channel sends no files with a reply
|
|
39
|
+
yet, as Telegram, Slack and WhatsApp until a later release, or the chat is still on the archive in
|
|
40
|
+
Cloud), `too_many_files`, `file_too_large` or `file_unavailable`. The delivery binds the files'
|
|
41
|
+
revisions, and the reply's row of the chat store lists them by name, type and size. Chat providers
|
|
42
|
+
declare their `files` limits and a `refuseFiles` check, and `ChatSend` takes `files`.
|
|
43
|
+
|
|
3
44
|
## 0.161.0
|
|
4
45
|
|
|
5
46
|
Agent drafts name their turn, know whether the person wrote after it, and are decided once.
|
package/dist/agent-draft.d.ts
CHANGED
|
@@ -46,6 +46,23 @@ export declare const AGENT_DRAFT_MODES: readonly [{
|
|
|
46
46
|
}];
|
|
47
47
|
/** The longest reply a draft holds; a provider may accept less in one message. */
|
|
48
48
|
export declare const AGENT_DRAFT_TEXT_LIMIT = 20000;
|
|
49
|
+
/** The most files a draft holds, as many as `attachments_send` sends at once. */
|
|
50
|
+
export declare const AGENT_DRAFT_FILES_LIMIT = 10;
|
|
51
|
+
/**
|
|
52
|
+
* A record file a draft holds, snapshotted when the reply was held: the revision the person may
|
|
53
|
+
* read, which approval sends whatever the record holds by then, with what the inbox shows of it.
|
|
54
|
+
*/
|
|
55
|
+
export interface AgentDraftFile {
|
|
56
|
+
readonly entity: string;
|
|
57
|
+
readonly id: string;
|
|
58
|
+
readonly property: string;
|
|
59
|
+
readonly revisionId: string;
|
|
60
|
+
readonly filename: string;
|
|
61
|
+
readonly contentType: string;
|
|
62
|
+
readonly size: number;
|
|
63
|
+
}
|
|
64
|
+
/** The files a draft holds, in order; none for a value that is no list of them. */
|
|
65
|
+
export declare function draftFilesOf(value: unknown): ReadonlyArray<AgentDraftFile>;
|
|
49
66
|
/** The longest reason a member gives for rejecting a reply. */
|
|
50
67
|
export declare const AGENT_DRAFT_REASON_LIMIT = 2000;
|
|
51
68
|
/** The most drafts one `newer` call answers for. */
|
|
@@ -79,6 +96,7 @@ export declare const AgentDraft: import("./entity.js").Entity<"agent_draft", {
|
|
|
79
96
|
readonly basis: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
80
97
|
readonly message: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
81
98
|
readonly draft: import("./property.js").Property<string, false, false>;
|
|
99
|
+
readonly files: Schema.optionalKey<import("./property.js").Property<Schema.Json, false, false>>;
|
|
82
100
|
readonly text: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
83
101
|
readonly status: import("./property.js").Property<"pending" | "sent" | "uncertain" | "failed" | "rejected" | "superseded" | "dismissed", false, false>;
|
|
84
102
|
readonly mode: import("./property.js").Property<"always" | "whenUnsure", false, false>;
|
|
@@ -162,6 +180,7 @@ export declare const AgentDraft: import("./entity.js").Entity<"agent_draft", {
|
|
|
162
180
|
readonly basis: string | null;
|
|
163
181
|
readonly message: string | null;
|
|
164
182
|
readonly draft: string;
|
|
183
|
+
readonly files: Schema.Json;
|
|
165
184
|
readonly text: string | null;
|
|
166
185
|
readonly status: "pending" | "sent" | "uncertain" | "failed" | "rejected" | "superseded" | "dismissed";
|
|
167
186
|
readonly mode: "always" | "whenUnsure";
|
|
@@ -197,6 +216,7 @@ export declare const AgentReview: import("./entity.js").Entity<"agent_draft", {
|
|
|
197
216
|
readonly basis: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
198
217
|
readonly message: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
199
218
|
readonly draft: import("./property.js").Property<string, false, false>;
|
|
219
|
+
readonly files: Schema.optionalKey<import("./property.js").Property<Schema.Json, false, false>>;
|
|
200
220
|
readonly text: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
201
221
|
readonly status: import("./property.js").Property<"pending" | "sent" | "uncertain" | "failed" | "rejected" | "superseded" | "dismissed", false, false>;
|
|
202
222
|
readonly mode: import("./property.js").Property<"always" | "whenUnsure", false, false>;
|
|
@@ -280,6 +300,7 @@ export declare const AgentReview: import("./entity.js").Entity<"agent_draft", {
|
|
|
280
300
|
readonly basis: string | null;
|
|
281
301
|
readonly message: string | null;
|
|
282
302
|
readonly draft: string;
|
|
303
|
+
readonly files: Schema.Json;
|
|
283
304
|
readonly text: string | null;
|
|
284
305
|
readonly status: "pending" | "sent" | "uncertain" | "failed" | "rejected" | "superseded" | "dismissed";
|
|
285
306
|
readonly mode: "always" | "whenUnsure";
|
package/dist/agent-draft.js
CHANGED
|
@@ -48,6 +48,55 @@ export const AGENT_DRAFT_MODES = [
|
|
|
48
48
|
];
|
|
49
49
|
/** The longest reply a draft holds; a provider may accept less in one message. */
|
|
50
50
|
export const AGENT_DRAFT_TEXT_LIMIT = 20_000;
|
|
51
|
+
/** The most files a draft holds, as many as `attachments_send` sends at once. */
|
|
52
|
+
export const AGENT_DRAFT_FILES_LIMIT = 10;
|
|
53
|
+
const NAME = /^[a-z][a-z0-9_]{0,63}$/;
|
|
54
|
+
const RECORD_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
55
|
+
/** The files a draft holds, in order; none for a value that is no list of them. */
|
|
56
|
+
export function draftFilesOf(value) {
|
|
57
|
+
const list = typeof value === "string" ? parsed(value) : value;
|
|
58
|
+
if (!Array.isArray(list)) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
return list.flatMap((item) => {
|
|
62
|
+
const file = item;
|
|
63
|
+
return file !== null &&
|
|
64
|
+
typeof file === "object" &&
|
|
65
|
+
typeof file.entity === "string" &&
|
|
66
|
+
NAME.test(file.entity) &&
|
|
67
|
+
typeof file.id === "string" &&
|
|
68
|
+
RECORD_ID.test(file.id) &&
|
|
69
|
+
typeof file.property === "string" &&
|
|
70
|
+
NAME.test(file.property) &&
|
|
71
|
+
typeof file.revisionId === "string" &&
|
|
72
|
+
file.revisionId !== "" &&
|
|
73
|
+
typeof file.filename === "string" &&
|
|
74
|
+
typeof file.contentType === "string" &&
|
|
75
|
+
typeof file.size === "number" &&
|
|
76
|
+
Number.isSafeInteger(file.size) &&
|
|
77
|
+
file.size >= 0
|
|
78
|
+
? [
|
|
79
|
+
{
|
|
80
|
+
entity: file.entity,
|
|
81
|
+
id: file.id.toLowerCase(),
|
|
82
|
+
property: file.property,
|
|
83
|
+
revisionId: file.revisionId,
|
|
84
|
+
filename: file.filename,
|
|
85
|
+
contentType: file.contentType,
|
|
86
|
+
size: file.size,
|
|
87
|
+
},
|
|
88
|
+
]
|
|
89
|
+
: [];
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function parsed(text) {
|
|
93
|
+
try {
|
|
94
|
+
return JSON.parse(text);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
51
100
|
/** The longest reason a member gives for rejecting a reply. */
|
|
52
101
|
export const AGENT_DRAFT_REASON_LIMIT = 2_000;
|
|
53
102
|
/** The most drafts one `newer` call answers for. */
|
|
@@ -207,7 +256,14 @@ export const AgentDraft = entity("agent_draft", {
|
|
|
207
256
|
managed: true,
|
|
208
257
|
maxLength: AGENT_DRAFT_TEXT_LIMIT,
|
|
209
258
|
display: "multiline",
|
|
210
|
-
description: "The reply as the agent wrote it, in Markdown.",
|
|
259
|
+
description: "The reply as the agent wrote it, in Markdown; empty when the reply is only its files.",
|
|
260
|
+
}),
|
|
261
|
+
files: p.json({
|
|
262
|
+
optional: true,
|
|
263
|
+
managed: true,
|
|
264
|
+
description: "Record files the reply carries, in order, which approval sends with its text: each " +
|
|
265
|
+
"{ entity, id, property, revisionId, filename, contentType, size }, the revision the " +
|
|
266
|
+
"person could read when the reply was held. Empty when the reply is text alone.",
|
|
211
267
|
}),
|
|
212
268
|
text: p.text({
|
|
213
269
|
optional: true,
|
package/dist/deployment.d.ts
CHANGED
|
@@ -19,9 +19,19 @@ export type DeploymentObservation = {
|
|
|
19
19
|
* Workflow SDK's local world records runs; absent on a hosted preview.
|
|
20
20
|
*/
|
|
21
21
|
readonly host?: "local";
|
|
22
|
+
/**
|
|
23
|
+
* `true` when the platform runs the workspace's agent in this hosted preview, built from the
|
|
24
|
+
* same commit: it answers the preview app's web chat and evals, with no channels, tasks or
|
|
25
|
+
* connections. The platform marks it by giving the preview the runtime identity its agent
|
|
26
|
+
* authenticates with (`SEGMENTSTREAM_RUNTIME_OIDC_ISSUER` and `…_AUDIENCE`). The managed agent
|
|
27
|
+
* capability, `capabilities.agents`, stays `false`.
|
|
28
|
+
*/
|
|
29
|
+
readonly agent?: true;
|
|
22
30
|
readonly capabilities: DeploymentCapabilities;
|
|
23
31
|
};
|
|
24
|
-
export type DeploymentAdmissionCode = "preview_configuration_invalid" | "preview_expired" | "preview_capability_unavailable" | "preview_authentication_unavailable"
|
|
32
|
+
export type DeploymentAdmissionCode = "preview_configuration_invalid" | "preview_expired" | "preview_capability_unavailable" | "preview_authentication_unavailable"
|
|
33
|
+
/** The runtime of another preview of the workspace called this one. */
|
|
34
|
+
| "preview_deployment_mismatch" | "preview_storage_binding_invalid";
|
|
25
35
|
/** Stable codes only: workspace code owns explanations and presentation. */
|
|
26
36
|
export declare class DeploymentAdmissionError extends Error {
|
|
27
37
|
readonly code: DeploymentAdmissionCode;
|
|
@@ -31,5 +41,7 @@ export declare class DeploymentAdmissionError extends Error {
|
|
|
31
41
|
get status(): number;
|
|
32
42
|
}
|
|
33
43
|
export declare function deploymentFromEnv(environment?: Readonly<Record<string, string | undefined>>): DeploymentObservation;
|
|
44
|
+
/** Whether the platform runs the workspace's agent, without channels, in this hosted preview. */
|
|
45
|
+
export declare function previewRunsAgent(deployment: DeploymentObservation | undefined): boolean;
|
|
34
46
|
/** Recheck the deadline on every admission, including a warm process and cached sessions. */
|
|
35
47
|
export declare function requireDeploymentCapability(deployment: DeploymentObservation, capability?: keyof DeploymentCapabilities, now?: number): void;
|
package/dist/deployment.js
CHANGED
|
@@ -45,11 +45,15 @@ export function deploymentFromEnv(environment = process.env) {
|
|
|
45
45
|
!Number.isFinite(Date.parse(expiresAt))) {
|
|
46
46
|
throw new DeploymentAdmissionError("preview_configuration_invalid");
|
|
47
47
|
}
|
|
48
|
+
const agent = host === undefined &&
|
|
49
|
+
Boolean(environment.SEGMENTSTREAM_RUNTIME_OIDC_ISSUER?.trim()) &&
|
|
50
|
+
Boolean(environment.SEGMENTSTREAM_RUNTIME_OIDC_AUDIENCE?.trim());
|
|
48
51
|
return Object.freeze({
|
|
49
52
|
target,
|
|
50
53
|
deploymentId,
|
|
51
54
|
expiresAt,
|
|
52
55
|
...(host === undefined ? {} : { host }),
|
|
56
|
+
...(agent ? { agent: true } : {}),
|
|
53
57
|
capabilities: Object.freeze({
|
|
54
58
|
warehouseRead: true,
|
|
55
59
|
pipelineRuns: false,
|
|
@@ -59,6 +63,10 @@ export function deploymentFromEnv(environment = process.env) {
|
|
|
59
63
|
}),
|
|
60
64
|
});
|
|
61
65
|
}
|
|
66
|
+
/** Whether the platform runs the workspace's agent, without channels, in this hosted preview. */
|
|
67
|
+
export function previewRunsAgent(deployment) {
|
|
68
|
+
return (deployment?.target === "preview" && deployment.agent === true && deployment.host === undefined);
|
|
69
|
+
}
|
|
62
70
|
/** Recheck the deadline on every admission, including a warm process and cached sessions. */
|
|
63
71
|
export function requireDeploymentCapability(deployment, capability, now = Date.now()) {
|
|
64
72
|
if (deployment.target !== "preview") {
|
package/dist/index.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export type { BatchOptions, BatchRecordResult, BatchResult, BatchReturning, Batc
|
|
|
59
59
|
export { User } from "./user.js";
|
|
60
60
|
export type { UserHandle, UserMemberWrites } from "./user.js";
|
|
61
61
|
export { AgentChat } from "./agent-chat.js";
|
|
62
|
-
export { AgentDraft, AGENT_DRAFT_MODES, AGENT_DRAFT_NEWER_LIMIT, AGENT_DRAFT_STATUSES, AGENT_DRAFT_TEXT_LIMIT, AgentReview, AGENT_REVIEW_MODES, AGENT_REVIEW_STATUSES, AGENT_REVIEW_TEXT_LIMIT, } from "./agent-draft.js";
|
|
62
|
+
export { AgentDraft, AGENT_DRAFT_FILES_LIMIT, AGENT_DRAFT_MODES, AGENT_DRAFT_NEWER_LIMIT, AGENT_DRAFT_STATUSES, AGENT_DRAFT_TEXT_LIMIT, AgentReview, AGENT_REVIEW_MODES, AGENT_REVIEW_STATUSES, AGENT_REVIEW_TEXT_LIMIT, draftFilesOf, type AgentDraftFile, } from "./agent-draft.js";
|
|
63
63
|
export { ATTACHABLE_IDENTITY_PROVIDERS, UserIdentity, USER_IDENTITY_ORIGINS, } from "./user-identity.js";
|
|
64
64
|
export type { AttachableIdentityProvider, UserIdentityOrigin } from "./user-identity.js";
|
|
65
65
|
export { AppFeedback, AppFeedbackFile, APP_FEEDBACK_ENTITIES, APP_FEEDBACK_FILE_MAX_BYTES, } from "./app-feedback.js";
|
|
@@ -94,17 +94,18 @@ export type { Decide, DecisionRequest } from "./service/decisions.js";
|
|
|
94
94
|
export { IdentityInUse, NotInvited, OntologyBackend } from "./service/runtime-contract.js";
|
|
95
95
|
export type { AgentIdentity, AgentMember, AgentLimits, AgentLimitScope, ChannelSignInInput, AgentResolution, ResolveIdentityInput, AgentPairing, AgentStore, AgentWebStore, GuestIssue, GuestUpgrade, VisitorSignUp, WebTurnLimit, SeenChat, HeldReplyInput, HeldReview, GeneratedActionsProvider, IdentityProvider, OAuthClient, OAuthClientAuthMethod, OAuthGrant, OAuthDevice, DevicePoll, OAuthRequest, OAuthStore, OAuthToken, OAuthTokenKind, OntologyServiceRuntime, RunActionInput, SignInIdentity, UsedOAuthToken, } from "./service/runtime-contract.js";
|
|
96
96
|
export { createOntologyService, ONTOLOGY_HASH_HEADER, REQUEST_ID_HEADER, } from "./service/service.js";
|
|
97
|
-
export { AGENT_PATH, AGENT_TOKEN_INTROSPECTION_PATH, AGENT_TOKENS_PATH, AGENT_VISITORS_PATH, GUEST_EMAIL_CODE_PATH, GUEST_SIGN_UP_PATH, GUEST_USAGE_PATH, GUEST_LINK_PATH, } from "./service/agent/server.js";
|
|
97
|
+
export { AGENT_PATH, AGENT_TOKEN_INTROSPECTION_PATH, AGENT_EVAL_TOKENS_PATH, AGENT_TOKENS_PATH, AGENT_VISITORS_PATH, GUEST_EMAIL_CODE_PATH, GUEST_SIGN_UP_PATH, GUEST_USAGE_PATH, GUEST_LINK_PATH, } from "./service/agent/server.js";
|
|
98
98
|
export { AGENT_TASK_PATH, AGENT_TASK_RESULT_PATH } from "./service/agent/tasks.js";
|
|
99
99
|
export { WORKSPACE_SOURCE_PATH } from "./service/agent/source.js";
|
|
100
|
-
export { AGENT_WEB_CLIENT_ID, agentResource } from "./service/agent/web-tokens.js";
|
|
101
|
-
export {
|
|
100
|
+
export { AGENT_EVAL_CLIENT_ID, AGENT_WEB_CLIENT_ID, agentResource, } from "./service/agent/web-tokens.js";
|
|
101
|
+
export { EVAL_TOKEN_DEFAULT_SECONDS, EVAL_TOKEN_MAX_SECONDS } from "./service/agent/eval-tokens.js";
|
|
102
|
+
export { ACT_AS_HEADER, ACT_AS_PROVIDER_HEADER, ONTOLOGY_DEPLOYMENT_HEADER, AGENT_GRANT_HEADER, AGENT_TASK_HEADER, WEB_PROVIDER, } from "./service/runtime-identity.js";
|
|
102
103
|
export type { RuntimeIdentityConfig } from "./service/runtime-identity.js";
|
|
103
104
|
export { MCP_PATH, MCP_PROTOCOL_VERSIONS } from "./service/mcp/server.js";
|
|
104
105
|
export { MCP_TOOL_NAME_MAX_LENGTH, mcpToolName } from "./names.js";
|
|
105
106
|
export type { OntologyService } from "./service/service.js";
|
|
106
107
|
export { applyMigration, CatalogInvalid, CatalogMismatch, isNoopMigration, migrate, MIGRATION_REFUSAL_CODES, MIGRATION_STEP_CLASSIFICATIONS, MIGRATION_STEP_KINDS, MigrationFailed, MigrationPlan, MigrationRefusal, MigrationRefused, MigrationStep, OntologyStorage, planMigration, preparePreviewDatabase, readCatalog, readRetainedStorage, readRuntimeTables, readHistoryActivityIndexes, readStorageNames, RetainedEntity, RetainedStorage, } from "./migrate/index.js";
|
|
107
|
-
export { deploymentFromEnv, DeploymentAdmissionError, requireDeploymentCapability, } from "./deployment.js";
|
|
108
|
+
export { deploymentFromEnv, DeploymentAdmissionError, previewRunsAgent, requireDeploymentCapability, } from "./deployment.js";
|
|
108
109
|
export type { DeploymentObservation, DeploymentCapabilities, DeploymentAdmissionCode, } from "./deployment.js";
|
|
109
110
|
export type { ApplyMigrationError, ApplyMigrationOptions, CatalogInput, MigrateInput, MigrationOptions, MigrationRefusalCode, MigrationResult, MigrationStepClassification, MigrationStepKind, PlanMigrationInput, StorageNames, } from "./migrate/index.js";
|
|
110
111
|
export type { BlobStorageBinding } from "./storage/provider.js";
|
package/dist/index.js
CHANGED
|
@@ -34,9 +34,9 @@ export { EMAIL_MARKUP_VALUES, isEmailDocument, unsafeEmailHtml } from "./emails.
|
|
|
34
34
|
export { OntologyActions, OntologyReads, OntologyRuntime, OntologyWrites } from "./runtime.js";
|
|
35
35
|
export { User } from "./user.js";
|
|
36
36
|
export { AgentChat } from "./agent-chat.js";
|
|
37
|
-
export { AgentDraft, AGENT_DRAFT_MODES, AGENT_DRAFT_NEWER_LIMIT, AGENT_DRAFT_STATUSES, AGENT_DRAFT_TEXT_LIMIT,
|
|
37
|
+
export { AgentDraft, AGENT_DRAFT_FILES_LIMIT, AGENT_DRAFT_MODES, AGENT_DRAFT_NEWER_LIMIT, AGENT_DRAFT_STATUSES, AGENT_DRAFT_TEXT_LIMIT,
|
|
38
38
|
// @legacy ontology.agent-review-entity-name
|
|
39
|
-
AgentReview, AGENT_REVIEW_MODES, AGENT_REVIEW_STATUSES, AGENT_REVIEW_TEXT_LIMIT, } from "./agent-draft.js";
|
|
39
|
+
AgentReview, AGENT_REVIEW_MODES, AGENT_REVIEW_STATUSES, AGENT_REVIEW_TEXT_LIMIT, draftFilesOf, } from "./agent-draft.js";
|
|
40
40
|
export { ATTACHABLE_IDENTITY_PROVIDERS, UserIdentity, USER_IDENTITY_ORIGINS, } from "./user-identity.js";
|
|
41
41
|
export { AppFeedback, AppFeedbackFile, APP_FEEDBACK_ENTITIES, APP_FEEDBACK_FILE_MAX_BYTES, } from "./app-feedback.js";
|
|
42
42
|
export { ChatDelivery, ChatHistoryImportInput, ChatHistoryImportResult, ChatHistoryMessage, ChatPostInput, ChatSendInput, ChatTemplate, ChatTemplateMedia, ChatPostResult, } from "./chat.js";
|
|
@@ -63,18 +63,19 @@ export { IdentityInUse, NotInvited, OntologyBackend } from "./service/runtime-co
|
|
|
63
63
|
export { createOntologyService, ONTOLOGY_HASH_HEADER, REQUEST_ID_HEADER, } from "./service/service.js";
|
|
64
64
|
// The app's own agent: pairing channel accounts with members, and acting as them, or as a
|
|
65
65
|
// workflow's user in the tasks workflows hand it.
|
|
66
|
-
export { AGENT_PATH, AGENT_TOKEN_INTROSPECTION_PATH, AGENT_TOKENS_PATH, AGENT_VISITORS_PATH, GUEST_EMAIL_CODE_PATH, GUEST_SIGN_UP_PATH, GUEST_USAGE_PATH, GUEST_LINK_PATH, } from "./service/agent/server.js";
|
|
66
|
+
export { AGENT_PATH, AGENT_TOKEN_INTROSPECTION_PATH, AGENT_EVAL_TOKENS_PATH, AGENT_TOKENS_PATH, AGENT_VISITORS_PATH, GUEST_EMAIL_CODE_PATH, GUEST_SIGN_UP_PATH, GUEST_USAGE_PATH, GUEST_LINK_PATH, } from "./service/agent/server.js";
|
|
67
67
|
export { AGENT_TASK_PATH, AGENT_TASK_RESULT_PATH } from "./service/agent/tasks.js";
|
|
68
68
|
export { WORKSPACE_SOURCE_PATH } from "./service/agent/source.js";
|
|
69
69
|
// Agent tokens: access tokens of a member's grant to the agent, which a browser shows the agent.
|
|
70
|
-
export { AGENT_WEB_CLIENT_ID, agentResource } from "./service/agent/web-tokens.js";
|
|
71
|
-
export {
|
|
70
|
+
export { AGENT_EVAL_CLIENT_ID, AGENT_WEB_CLIENT_ID, agentResource, } from "./service/agent/web-tokens.js";
|
|
71
|
+
export { EVAL_TOKEN_DEFAULT_SECONDS, EVAL_TOKEN_MAX_SECONDS } from "./service/agent/eval-tokens.js";
|
|
72
|
+
export { ACT_AS_HEADER, ACT_AS_PROVIDER_HEADER, ONTOLOGY_DEPLOYMENT_HEADER, AGENT_GRANT_HEADER, AGENT_TASK_HEADER, WEB_PROVIDER, } from "./service/runtime-identity.js";
|
|
72
73
|
// The MCP server the service serves beside the HTTP API.
|
|
73
74
|
export { MCP_PATH, MCP_PROTOCOL_VERSIONS } from "./service/mcp/server.js";
|
|
74
75
|
export { MCP_TOOL_NAME_MAX_LENGTH, mcpToolName } from "./names.js";
|
|
75
76
|
// Migrations: the planner, the applier and the physical mapping they share with the runtime.
|
|
76
77
|
export { applyMigration, CatalogInvalid, CatalogMismatch, isNoopMigration, migrate, MIGRATION_REFUSAL_CODES, MIGRATION_STEP_CLASSIFICATIONS, MIGRATION_STEP_KINDS, MigrationFailed, MigrationPlan, MigrationRefusal, MigrationRefused, MigrationStep, OntologyStorage, planMigration, preparePreviewDatabase, readCatalog, readRetainedStorage, readRuntimeTables, readHistoryActivityIndexes, readStorageNames, RetainedEntity, RetainedStorage, } from "./migrate/index.js";
|
|
77
|
-
export { deploymentFromEnv, DeploymentAdmissionError, requireDeploymentCapability, } from "./deployment.js";
|
|
78
|
+
export { deploymentFromEnv, DeploymentAdmissionError, previewRunsAgent, requireDeploymentCapability, } from "./deployment.js";
|
|
78
79
|
export { runBlobStorageMaintenance } from "./storage/operator.js";
|
|
79
80
|
export { runNewUserHook } from "./runtime/new-user-hook.js";
|
|
80
81
|
export { sqlAgentStore, resolveChannelIdentity, resolveChannelSignIn } from "./runtime/agents.js";
|
package/dist/manifest.js
CHANGED
|
@@ -1098,6 +1098,7 @@ export function buildManifest(input) {
|
|
|
1098
1098
|
"workspace-app-previews-v1",
|
|
1099
1099
|
"workspace-app-preview-workflows-v1",
|
|
1100
1100
|
"workspace-app-local-previews-v1",
|
|
1101
|
+
"workspace-app-preview-agent-v1",
|
|
1101
1102
|
],
|
|
1102
1103
|
entities: input.entities.map((candidate) => entityManifest({ resolved: candidate, warehouseBacked })),
|
|
1103
1104
|
roles: input.roles.map((candidate) => ({
|
|
@@ -3,7 +3,7 @@ import { Effect } from "effect";
|
|
|
3
3
|
import { SqlClient } from "effect/unstable/sql";
|
|
4
4
|
import { signUpRolesOf } from "../manifest.js";
|
|
5
5
|
import { AGENT_GUEST_LINKS_TABLE, CHANNEL_USERS_TABLE, OAUTH_CLIENTS_TABLE, OAUTH_GRANTS_TABLE, OAUTH_TOKENS_TABLE, USER_TABLE, } from "../migrate/storage.js";
|
|
6
|
-
import { AGENT_WEB_CLIENT_ID } from "../service/agent/web-tokens.js";
|
|
6
|
+
import { AGENT_EVAL_CLIENT_ID, AGENT_WEB_CLIENT_ID } from "../service/agent/web-tokens.js";
|
|
7
7
|
import { ACCESS_TOKEN_PREFIX, ACCESS_TOKEN_TTL_MS, FULL_SCOPE, REFRESH_TOKEN_PREFIX, REFRESH_TOKEN_TTL_MS, newSecret, secretHash, } from "../service/oauth/protocol.js";
|
|
8
8
|
import { addGuestSpend, completeAgentLimitNotice, countAgentAttempt, effectiveChannelLimits, guestSpendLimited, } from "./agent-counters.js";
|
|
9
9
|
import { channelUsersAvailable } from "./member-tables.js";
|
|
@@ -157,13 +157,52 @@ export function sqlAgentWebStore(ontology, sql, admission) {
|
|
|
157
157
|
return token;
|
|
158
158
|
}))
|
|
159
159
|
.pipe(Effect.orDie),
|
|
160
|
-
|
|
160
|
+
issueEval: ({ email, resource, expiresAt }) => sql
|
|
161
|
+
.withTransaction(Effect.gen(function* () {
|
|
162
|
+
// Exclusive, so that two sessions issued at once for one member serialize: the second
|
|
163
|
+
// revokes the first's grant.
|
|
164
|
+
const [member] = yield* sql.unsafe(`SELECT "id"::text AS "id", "active" FROM "${USER_TABLE}"
|
|
165
|
+
WHERE "kind" = 'member' AND "email" = $1 LIMIT 1 FOR UPDATE`, [email.trim().toLowerCase()]);
|
|
166
|
+
if (member === undefined) {
|
|
167
|
+
return { status: "not_member" };
|
|
168
|
+
}
|
|
169
|
+
if (!member.active || (yield* isMemberBlocked(sql, member.id))) {
|
|
170
|
+
return { status: "inactive" };
|
|
171
|
+
}
|
|
172
|
+
yield* sql.unsafe(`INSERT INTO "${OAUTH_CLIENTS_TABLE}" ("id", "name", "redirect_uris", "auth_method")
|
|
173
|
+
VALUES ($1, $1, '[]'::jsonb, 'none') ON CONFLICT ("id") DO NOTHING`, [AGENT_EVAL_CLIENT_ID]);
|
|
174
|
+
// One eval session per member at a time: issuing again ends the earlier one.
|
|
175
|
+
yield* sql.unsafe(`UPDATE ${GRANTS} SET "revoked_at" = now()
|
|
176
|
+
WHERE "user_id" = $1::uuid AND "client_id" = $2 AND "revoked_at" IS NULL`, [member.id, AGENT_EVAL_CLIENT_ID]);
|
|
177
|
+
const grantId = randomUUID();
|
|
178
|
+
yield* oauth.saveGrant({
|
|
179
|
+
id: grantId,
|
|
180
|
+
clientId: AGENT_EVAL_CLIENT_ID,
|
|
181
|
+
userId: member.id,
|
|
182
|
+
scope: FULL_SCOPE,
|
|
183
|
+
resource,
|
|
184
|
+
});
|
|
185
|
+
const token = newSecret(ACCESS_TOKEN_PREFIX);
|
|
186
|
+
// No refresh token: a session ends with its access token.
|
|
187
|
+
yield* oauth.saveTokens([
|
|
188
|
+
{ hash: secretHash(token), grantId, kind: "access", expiresAt },
|
|
189
|
+
]);
|
|
190
|
+
return { status: "issued", token, grantId, memberId: member.id };
|
|
191
|
+
}))
|
|
192
|
+
.pipe(Effect.orDie),
|
|
193
|
+
grantMember: ({ grantId, userId, evalGrants }) => Effect.gen(function* () {
|
|
161
194
|
if (!isRecordId(grantId) || !isRecordId(userId)) {
|
|
162
195
|
return undefined;
|
|
163
196
|
}
|
|
164
197
|
const [standing] = yield* sql
|
|
165
198
|
.unsafe(`SELECT 1 FROM ${GRANTS} WHERE "id" = $1::uuid AND "user_id" = $2::uuid
|
|
166
|
-
AND "client_id" = $3 AND "revoked_at" IS NULL`, [
|
|
199
|
+
AND "client_id" = ANY($3::text[]) AND "revoked_at" IS NULL`, [
|
|
200
|
+
grantId,
|
|
201
|
+
userId,
|
|
202
|
+
evalGrants === true
|
|
203
|
+
? [AGENT_WEB_CLIENT_ID, AGENT_EVAL_CLIENT_ID]
|
|
204
|
+
: [AGENT_WEB_CLIENT_ID],
|
|
205
|
+
])
|
|
167
206
|
.pipe(Effect.orDie);
|
|
168
207
|
return standing === undefined ? undefined : yield* oauth.memberPrincipal(userId);
|
|
169
208
|
}),
|
package/dist/runtime/agents.js
CHANGED
|
@@ -6,7 +6,7 @@ import { action } from "../action.js";
|
|
|
6
6
|
import { AgentChat, agentChatKey } from "../agent-chat.js";
|
|
7
7
|
import { chatChannelKind } from "../chat-channel.js";
|
|
8
8
|
import { historyTableName, quoteIdentifier, tableName } from "../migrate/storage.js";
|
|
9
|
-
import { addressesOfDraft, AgentDraft, participantsOfDraft, draftAddresses, draftParticipants, } from "../agent-draft.js";
|
|
9
|
+
import { addressesOfDraft, AgentDraft, participantsOfDraft, draftAddresses, draftFilesOf, draftParticipants, } from "../agent-draft.js";
|
|
10
10
|
import { AGENT_IDENTITIES_TABLE, AGENT_PAIRINGS_TABLE, CHANNEL_USERS_TABLE, IDENTITY_NOTICES_TABLE, USER_TABLE, } from "../migrate/storage.js";
|
|
11
11
|
import { inboxChannelsOf, inboxRolesOf, takeoverChannelsOf, takeoverProvidersOf, } from "../manifest.js";
|
|
12
12
|
import { GUEST_ROLE } from "../names.js";
|
|
@@ -302,6 +302,7 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
302
302
|
? null
|
|
303
303
|
: yield* turnBasis(input.channel, input.chatId, input.turnId),
|
|
304
304
|
draft: input.text,
|
|
305
|
+
files: (input.files ?? []).length === 0 ? null : input.files,
|
|
305
306
|
text: null,
|
|
306
307
|
status: "pending",
|
|
307
308
|
// Select values are stored by their wire names.
|
|
@@ -998,6 +999,10 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
998
999
|
memberId: String(previous.person_id),
|
|
999
1000
|
sessionId: String(previous.session_id),
|
|
1000
1001
|
text: input.text,
|
|
1002
|
+
// A redraft rewrites the text: the files the reply carries stay with it.
|
|
1003
|
+
...(draftFilesOf(previous.files).length === 0
|
|
1004
|
+
? {}
|
|
1005
|
+
: { files: draftFilesOf(previous.files) }),
|
|
1001
1006
|
mode: "always",
|
|
1002
1007
|
confidence: null,
|
|
1003
1008
|
},
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Effect, Redacted } from "effect";
|
|
1
|
+
import { Effect, Option, Redacted } from "effect";
|
|
2
2
|
import { HttpServerRequest } from "effect/unstable/http";
|
|
3
3
|
import { HttpApiBuilder, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
4
4
|
import { RequestId, forbidden, notFound, toServerResponse, unauthorized, unavailable, } from "../errors.js";
|
|
5
5
|
import { API_KEY_PREFIX } from "../../runtime/principals.js";
|
|
6
|
+
import { previewRunsAgent } from "../../deployment.js";
|
|
7
|
+
import { RuntimeDeployment } from "../../runtime/deployment.js";
|
|
6
8
|
import { GUEST_ACT_AS_PREFIX, actingGuestId } from "../../runtime/guests.js";
|
|
7
9
|
import { ACT_AS_HEADER, ACT_AS_PROVIDER_HEADER, AGENT_GRANT_HEADER, AGENT_TASK_HEADER, CHAT, CHAT_HEADER, EARLIER_CHAT_HEADER, SESSION, SESSION_HEADER, WEB_PROVIDER, agentTaskSecret, logRuntimeRejection, } from "../runtime-identity.js";
|
|
8
10
|
export { CHAT_HEADER, SESSION_HEADER } from "../runtime-identity.js";
|
|
@@ -69,7 +71,12 @@ export function webMember(agents, userId, grantId) {
|
|
|
69
71
|
? Effect.succeed(undefined)
|
|
70
72
|
: web.grantGuest(grantId);
|
|
71
73
|
}
|
|
72
|
-
return Effect.
|
|
74
|
+
return Effect.gen(function* () {
|
|
75
|
+
// An eval's grant stands for its test member only in a preview that runs the agent.
|
|
76
|
+
const evalGrants = previewRunsAgent(Option.getOrUndefined(yield* Effect.serviceOption(RuntimeDeployment)));
|
|
77
|
+
const member = yield* web.grantMember({ grantId, userId, evalGrants });
|
|
78
|
+
return member === undefined ? undefined : { ...member, authenticatedVia: WEB_PROVIDER };
|
|
79
|
+
});
|
|
73
80
|
}
|
|
74
81
|
/**
|
|
75
82
|
* The member the runtime acts for: a web member by the grant their agent token stands for, anyone
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
3
|
+
import type { DeploymentObservation } from "../../deployment.js";
|
|
4
|
+
import { type TokenVerifier } from "../authentication.js";
|
|
5
|
+
import { RequestId } from "../errors.js";
|
|
6
|
+
import type { AgentWebStore } from "../runtime-contract.js";
|
|
7
|
+
/** How long an eval session's token works unless the platform asks for less: thirty minutes. */
|
|
8
|
+
export declare const EVAL_TOKEN_DEFAULT_SECONDS: number;
|
|
9
|
+
/** The longest an eval session's token works: an hour, and never past the preview's expiry. */
|
|
10
|
+
export declare const EVAL_TOKEN_MAX_SECONDS: number;
|
|
11
|
+
/**
|
|
12
|
+
* `POST /api/ontology/agent/eval-tokens`, mounted only in a preview that runs the agent, for the
|
|
13
|
+
* platform alone: its workload token bound to this preview, on this deployment's own origin. Body
|
|
14
|
+
* `{ email, origin, expires_in_seconds? }`; answers `{ token, expires_at, member_id, grant_id, chat
|
|
15
|
+
* }`, an agent token of a new `agent-eval` grant for the member with that address, for the agent's
|
|
16
|
+
* resource at `origin`. It works thirty minutes unless asked for less or more, an hour at most and
|
|
17
|
+
* never past the preview's expiry, has no refresh token, and ends the member's earlier eval session.
|
|
18
|
+
* The member must already exist and be active: `eval_member_not_found` (404) and
|
|
19
|
+
* `eval_member_inactive` (409) otherwise. Answers carry no words, only codes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function issueEvalToken(options: {
|
|
22
|
+
readonly deployment: DeploymentObservation;
|
|
23
|
+
readonly verifyToken: TokenVerifier;
|
|
24
|
+
readonly web: AgentWebStore;
|
|
25
|
+
}): (request: HttpServerRequest.HttpServerRequest) => Effect.Effect<HttpServerResponse.HttpServerResponse, never, RequestId | HttpServerRequest.ParsedSearchParams>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Effect, Redacted, Result, Schema } from "effect";
|
|
2
|
+
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
3
|
+
import { HttpApiBuilder, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
4
|
+
import { decodeProtectedHeader } from "jose";
|
|
5
|
+
import { schemaIssues } from "../../runtime/validation.js";
|
|
6
|
+
import { WORKLOAD_TOKEN_TYPE, workloadKind } from "../authentication.js";
|
|
7
|
+
import { RequestId, errorBodyForWire, forbidden, toServerResponse, unauthorized, unavailable, } from "../errors.js";
|
|
8
|
+
import { agentResource, personalChat } from "./web-tokens.js";
|
|
9
|
+
/** How long an eval session's token works unless the platform asks for less: thirty minutes. */
|
|
10
|
+
export const EVAL_TOKEN_DEFAULT_SECONDS = 30 * 60;
|
|
11
|
+
/** The longest an eval session's token works: an hour, and never past the preview's expiry. */
|
|
12
|
+
export const EVAL_TOKEN_MAX_SECONDS = 60 * 60;
|
|
13
|
+
const EvalTokenRequest = Schema.Struct({
|
|
14
|
+
/** The test member's address, which the platform made a member of the preview's branch. */
|
|
15
|
+
email: Schema.String.check(Schema.isMinLength(3), Schema.isMaxLength(320)),
|
|
16
|
+
/** The preview's origin, on which the evals reach the agent: the token's resource is there. */
|
|
17
|
+
origin: Schema.String.check(Schema.isMaxLength(2048)),
|
|
18
|
+
expires_in_seconds: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThanOrEqualTo(60), Schema.isLessThanOrEqualTo(EVAL_TOKEN_MAX_SECONDS))),
|
|
19
|
+
});
|
|
20
|
+
const NO_STORE = { "cache-control": "no-store" };
|
|
21
|
+
function isWorkloadToken(token) {
|
|
22
|
+
try {
|
|
23
|
+
return decodeProtectedHeader(token).typ === WORKLOAD_TOKEN_TYPE;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function requestOrigin(request) {
|
|
30
|
+
return new URL(request.source instanceof Request ? request.source.url : request.url, `https://${request.headers.host ?? "ontology.invalid"}`).origin;
|
|
31
|
+
}
|
|
32
|
+
function refused(status, error, requestId) {
|
|
33
|
+
return HttpServerResponse.jsonUnsafe(errorBodyForWire({ error, detail: error, requestId }), {
|
|
34
|
+
status,
|
|
35
|
+
headers: NO_STORE,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* `POST /api/ontology/agent/eval-tokens`, mounted only in a preview that runs the agent, for the
|
|
40
|
+
* platform alone: its workload token bound to this preview, on this deployment's own origin. Body
|
|
41
|
+
* `{ email, origin, expires_in_seconds? }`; answers `{ token, expires_at, member_id, grant_id, chat
|
|
42
|
+
* }`, an agent token of a new `agent-eval` grant for the member with that address, for the agent's
|
|
43
|
+
* resource at `origin`. It works thirty minutes unless asked for less or more, an hour at most and
|
|
44
|
+
* never past the preview's expiry, has no refresh token, and ends the member's earlier eval session.
|
|
45
|
+
* The member must already exist and be active: `eval_member_not_found` (404) and
|
|
46
|
+
* `eval_member_inactive` (409) otherwise. Answers carry no words, only codes.
|
|
47
|
+
*/
|
|
48
|
+
export function issueEvalToken(options) {
|
|
49
|
+
const issue = options.web.issueEval;
|
|
50
|
+
return (request) => Effect.gen(function* () {
|
|
51
|
+
const requestId = yield* RequestId;
|
|
52
|
+
const bearer = yield* HttpApiBuilder.securityDecode(HttpApiSecurity.bearer).pipe(Effect.provideService(HttpServerRequest.HttpServerRequest, request));
|
|
53
|
+
const token = Redacted.value(bearer);
|
|
54
|
+
if (token === "" || !isWorkloadToken(token)) {
|
|
55
|
+
return toServerResponse(unauthorized(requestId, "The token is not valid."));
|
|
56
|
+
}
|
|
57
|
+
const verification = yield* Effect.promise(() => options.verifyToken(token));
|
|
58
|
+
if (verification.status === "unavailable") {
|
|
59
|
+
return toServerResponse(unavailable(requestId));
|
|
60
|
+
}
|
|
61
|
+
if (verification.status !== "workload") {
|
|
62
|
+
return toServerResponse(unauthorized(requestId, "The token is not valid."));
|
|
63
|
+
}
|
|
64
|
+
const { execution } = verification;
|
|
65
|
+
// The verifier already bound the token to this preview's deployment and expiry; only the
|
|
66
|
+
// platform's own subject, on this deployment's own origin, issues eval sessions.
|
|
67
|
+
if (options.deployment.target !== "preview" ||
|
|
68
|
+
workloadKind({ sub: execution.subject }, execution.workspaceId) !== "platform" ||
|
|
69
|
+
execution.ontologyOrigin !== requestOrigin(request)) {
|
|
70
|
+
return toServerResponse(forbidden(requestId, "This workload may not issue eval tokens."));
|
|
71
|
+
}
|
|
72
|
+
if (issue === undefined) {
|
|
73
|
+
return toServerResponse(unavailable(requestId));
|
|
74
|
+
}
|
|
75
|
+
const body = yield* Effect.map(Effect.orDie(request.text), (text) => {
|
|
76
|
+
try {
|
|
77
|
+
return JSON.parse(text);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const decoded = Schema.decodeUnknownResult(EvalTokenRequest)(body, {
|
|
84
|
+
errors: "all",
|
|
85
|
+
onExcessProperty: "error",
|
|
86
|
+
});
|
|
87
|
+
const origin = Result.isSuccess(decoded) && URL.canParse(decoded.success.origin)
|
|
88
|
+
? new URL(decoded.success.origin)
|
|
89
|
+
: undefined;
|
|
90
|
+
if (Result.isFailure(decoded) ||
|
|
91
|
+
origin === undefined ||
|
|
92
|
+
origin.protocol !== "https:" ||
|
|
93
|
+
origin.origin !== decoded.success.origin.replace(/\/+$/u, "")) {
|
|
94
|
+
return HttpServerResponse.jsonUnsafe(errorBodyForWire({
|
|
95
|
+
error: "invalid_request",
|
|
96
|
+
detail: "The request body is invalid.",
|
|
97
|
+
requestId,
|
|
98
|
+
...(Result.isFailure(decoded) ? { issues: schemaIssues(decoded.failure) } : {}),
|
|
99
|
+
}), { status: 400, headers: NO_STORE });
|
|
100
|
+
}
|
|
101
|
+
const now = Date.now();
|
|
102
|
+
const deadline = Date.parse(options.deployment.expiresAt);
|
|
103
|
+
// An expired preview issues nothing, even to a warm process.
|
|
104
|
+
if (!(now < deadline)) {
|
|
105
|
+
return refused(410, "preview_expired", requestId);
|
|
106
|
+
}
|
|
107
|
+
const seconds = decoded.success.expires_in_seconds ?? EVAL_TOKEN_DEFAULT_SECONDS;
|
|
108
|
+
const expiresAt = new Date(Math.min(now + seconds * 1000, deadline));
|
|
109
|
+
const issued = yield* issue({
|
|
110
|
+
email: decoded.success.email,
|
|
111
|
+
resource: agentResource(origin.origin),
|
|
112
|
+
expiresAt,
|
|
113
|
+
});
|
|
114
|
+
switch (issued.status) {
|
|
115
|
+
case "not_member":
|
|
116
|
+
return refused(404, "eval_member_not_found", requestId);
|
|
117
|
+
case "inactive":
|
|
118
|
+
return refused(409, "eval_member_inactive", requestId);
|
|
119
|
+
case "issued":
|
|
120
|
+
yield* Effect.logInfo("ontology.agent.eval_token_issued").pipe(Effect.annotateLogs({ requestId, grantId: issued.grantId }));
|
|
121
|
+
return HttpServerResponse.jsonUnsafe({
|
|
122
|
+
token: issued.token,
|
|
123
|
+
expires_at: expiresAt.toISOString(),
|
|
124
|
+
member_id: issued.memberId,
|
|
125
|
+
grant_id: issued.grantId,
|
|
126
|
+
chat: personalChat(issued.memberId),
|
|
127
|
+
}, { status: 200, headers: NO_STORE });
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
@@ -138,10 +138,6 @@ export declare const ChatHandoffRequest: Schema.Struct<{
|
|
|
138
138
|
readonly memberId: Schema.String;
|
|
139
139
|
readonly reason: Schema.String;
|
|
140
140
|
}>;
|
|
141
|
-
/**
|
|
142
|
-
* `POST /api/ontology/agent/drafts`: a reply the agent kept for a member to review, for the member
|
|
143
|
-
* it answers. `key` names the reply, so a report repeated after a failure finds its draft.
|
|
144
|
-
*/
|
|
145
141
|
export declare const ReviewRequest: Schema.Struct<{
|
|
146
142
|
readonly key: Schema.String;
|
|
147
143
|
readonly provider: Schema.String;
|
|
@@ -155,12 +151,31 @@ export declare const ReviewRequest: Schema.Struct<{
|
|
|
155
151
|
readonly reply_to: Schema.NullOr<Schema.String>;
|
|
156
152
|
readonly member_id: Schema.String;
|
|
157
153
|
readonly session_id: Schema.String;
|
|
158
|
-
readonly text: Schema.String
|
|
154
|
+
readonly text: Schema.optionalKey<Schema.String>;
|
|
155
|
+
readonly files: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
156
|
+
readonly entity: Schema.String;
|
|
157
|
+
readonly id: Schema.String;
|
|
158
|
+
readonly property: Schema.optionalKey<Schema.String>;
|
|
159
|
+
}>>>;
|
|
159
160
|
readonly mode: Schema.Literals<readonly ["always", "whenUnsure"]>;
|
|
160
161
|
readonly confidence: Schema.NullOr<Schema.Number>;
|
|
161
162
|
readonly turn_id: Schema.optionalKey<Schema.String>;
|
|
162
163
|
}>;
|
|
163
164
|
export type ReviewRequest = typeof ReviewRequest.Type;
|
|
165
|
+
/**
|
|
166
|
+
* `POST /api/ontology/agent/drafts/files`: whether a reply on a channel may carry these files, read
|
|
167
|
+
* as the member it is for, checked as holding it would check them, without holding anything.
|
|
168
|
+
*/
|
|
169
|
+
export declare const DraftFilesRequest: Schema.Struct<{
|
|
170
|
+
readonly provider: Schema.String;
|
|
171
|
+
readonly channel: Schema.optionalKey<Schema.String>;
|
|
172
|
+
readonly member_id: Schema.String;
|
|
173
|
+
readonly files: Schema.$Array<Schema.Struct<{
|
|
174
|
+
readonly entity: Schema.String;
|
|
175
|
+
readonly id: Schema.String;
|
|
176
|
+
readonly property: Schema.optionalKey<Schema.String>;
|
|
177
|
+
}>>;
|
|
178
|
+
}>;
|
|
164
179
|
/**
|
|
165
180
|
* `POST /api/ontology/agent/drafts/revision`: what became of a redraft a member asked for: the new
|
|
166
181
|
* draft, or, without `text`, that the agent could not write one.
|