@vertesia/common 1.6.0-dev.20261009.095813Z → 1.6.0-dev.20261019.172735Z
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/lib/api-contract/components.generated.json +1329 -37
- package/lib/api-schemas/agent-runs.d.ts +410 -0
- package/lib/api-schemas/agent-runs.d.ts.map +1 -1
- package/lib/api-schemas/agent-runs.js +10 -3
- package/lib/api-schemas/agent-runs.js.map +1 -1
- package/lib/api-schemas/app-lifecycle.d.ts +126 -0
- package/lib/api-schemas/app-lifecycle.d.ts.map +1 -1
- package/lib/api-schemas/app-lifecycle.js +134 -1
- package/lib/api-schemas/app-lifecycle.js.map +1 -1
- package/lib/api-schemas/app-runtime.d.ts +948 -6
- package/lib/api-schemas/app-runtime.d.ts.map +1 -1
- package/lib/api-schemas/app-runtime.js +50 -1
- package/lib/api-schemas/app-runtime.js.map +1 -1
- package/lib/api-schemas/apps.d.ts +73 -0
- package/lib/api-schemas/apps.d.ts.map +1 -1
- package/lib/api-schemas/apps.js +41 -0
- package/lib/api-schemas/apps.js.map +1 -1
- package/lib/api-schemas/audit-trail.d.ts.map +1 -1
- package/lib/api-schemas/audit-trail.js +5 -5
- package/lib/api-schemas/audit-trail.js.map +1 -1
- package/lib/api-schemas/content.d.ts +199 -0
- package/lib/api-schemas/content.d.ts.map +1 -1
- package/lib/api-schemas/content.js +19 -5
- package/lib/api-schemas/content.js.map +1 -1
- package/lib/api-schemas/data-store.d.ts +30 -0
- package/lib/api-schemas/data-store.d.ts.map +1 -1
- package/lib/api-schemas/data-store.js +8 -0
- package/lib/api-schemas/data-store.js.map +1 -1
- package/lib/api-schemas/document-processing.d.ts +117 -0
- package/lib/api-schemas/document-processing.d.ts.map +1 -1
- package/lib/api-schemas/events.d.ts +351 -0
- package/lib/api-schemas/events.d.ts.map +1 -1
- package/lib/api-schemas/indexing.d.ts +1 -0
- package/lib/api-schemas/indexing.d.ts.map +1 -1
- package/lib/api-schemas/indexing.js +9 -0
- package/lib/api-schemas/indexing.js.map +1 -1
- package/lib/api-schemas/inference-profile.d.ts +234 -0
- package/lib/api-schemas/inference-profile.d.ts.map +1 -1
- package/lib/api-schemas/interaction.d.ts +3013 -0
- package/lib/api-schemas/interaction.d.ts.map +1 -1
- package/lib/api-schemas/interaction.js +9 -7
- package/lib/api-schemas/interaction.js.map +1 -1
- package/lib/api-schemas/oauth-server.d.ts +128 -0
- package/lib/api-schemas/oauth-server.d.ts.map +1 -1
- package/lib/api-schemas/oauth-server.js +95 -2
- package/lib/api-schemas/oauth-server.js.map +1 -1
- package/lib/api-schemas/process.d.ts +81 -0
- package/lib/api-schemas/process.d.ts.map +1 -1
- package/lib/api-schemas/process.js +29 -0
- package/lib/api-schemas/process.js.map +1 -1
- package/lib/api-schemas/project-configuration.d.ts +390 -0
- package/lib/api-schemas/project-configuration.d.ts.map +1 -1
- package/lib/api-schemas/project.d.ts +591 -6
- package/lib/api-schemas/project.d.ts.map +1 -1
- package/lib/api-schemas/prompt.d.ts.map +1 -1
- package/lib/api-schemas/prompt.js +5 -2
- package/lib/api-schemas/prompt.js.map +1 -1
- package/lib/api-schemas/registry.d.ts +23032 -461
- package/lib/api-schemas/registry.d.ts.map +1 -1
- package/lib/api-schemas/registry.js +38 -3
- package/lib/api-schemas/registry.js.map +1 -1
- package/lib/api-schemas/schema-primitives.d.ts +8 -0
- package/lib/api-schemas/schema-primitives.d.ts.map +1 -1
- package/lib/api-schemas/schema-primitives.js +8 -0
- package/lib/api-schemas/schema-primitives.js.map +1 -1
- package/lib/api-schemas/store.d.ts +1950 -0
- package/lib/api-schemas/store.d.ts.map +1 -1
- package/lib/api-schemas/store.js +3 -3
- package/lib/api-schemas/store.js.map +1 -1
- package/lib/api-schemas/task.d.ts.map +1 -1
- package/lib/api-schemas/task.js +3 -2
- package/lib/api-schemas/task.js.map +1 -1
- package/lib/api-schemas/workflow-runs.d.ts +78 -0
- package/lib/api-schemas/workflow-runs.d.ts.map +1 -1
- package/lib/apikey.d.ts +7 -0
- package/lib/apikey.d.ts.map +1 -1
- package/lib/apikey.js.map +1 -1
- package/lib/apps.d.ts +37 -1
- package/lib/apps.d.ts.map +1 -1
- package/lib/apps.js +74 -3
- package/lib/apps.js.map +1 -1
- package/lib/interaction.d.ts.map +1 -1
- package/lib/interaction.js.map +1 -1
- package/lib/oauth-server.d.ts +5 -0
- package/lib/oauth-server.d.ts.map +1 -1
- package/lib/store/index.d.ts +1 -0
- package/lib/store/index.d.ts.map +1 -1
- package/lib/store/index.js +1 -0
- package/lib/store/index.js.map +1 -1
- package/lib/store/intake-policy-schema.generated.d.ts.map +1 -1
- package/lib/store/intake-policy-schema.generated.js +20 -2
- package/lib/store/intake-policy-schema.generated.js.map +1 -1
- package/lib/store/store.d.ts +1 -0
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js.map +1 -1
- package/lib/store/text-limits.d.ts +18 -0
- package/lib/store/text-limits.d.ts.map +1 -0
- package/lib/store/text-limits.js +56 -0
- package/lib/store/text-limits.js.map +1 -0
- package/lib/vertesia-common.js +4 -2
- package/lib/vertesia-common.js.map +1 -1
- package/lib/wire-types.generated.d.ts +261 -3
- package/lib/wire-types.generated.d.ts.map +1 -1
- package/lib/workflow-analytics.d.ts +19 -1
- package/lib/workflow-analytics.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/api-contract/components.generated.json +1329 -37
- package/src/api-schemas/agent-runs.ts +10 -3
- package/src/api-schemas/app-lifecycle.ts +163 -1
- package/src/api-schemas/app-runtime.ts +54 -0
- package/src/api-schemas/apps.ts +46 -0
- package/src/api-schemas/audit-trail.ts +5 -5
- package/src/api-schemas/content.ts +21 -5
- package/src/api-schemas/data-store.ts +8 -0
- package/src/api-schemas/indexing.ts +10 -0
- package/src/api-schemas/interaction.ts +9 -7
- package/src/api-schemas/oauth-server.ts +103 -2
- package/src/api-schemas/process.ts +32 -0
- package/src/api-schemas/prompt.ts +5 -2
- package/src/api-schemas/registry.ts +59 -6
- package/src/api-schemas/schema-primitives.ts +9 -0
- package/src/api-schemas/store.ts +3 -3
- package/src/api-schemas/task.ts +3 -2
- package/src/apikey.ts +8 -0
- package/src/apps.ts +116 -3
- package/src/interaction.ts +1 -0
- package/src/oauth-server.ts +10 -0
- package/src/store/index.ts +1 -0
- package/src/store/intake-policy-schema.generated.ts +20 -2
- package/src/store/store.ts +2 -0
- package/src/store/text-limits.ts +64 -0
- package/src/wire-types.generated.ts +285 -3
- package/src/workflow-analytics.ts +21 -1
package/src/apps.ts
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
+
import type { AuthTokenPayload } from './apikey.js';
|
|
1
2
|
import type * as Wire from './wire-types.generated.js';
|
|
2
3
|
|
|
3
4
|
/** Allowed values for AppUINavItem.preferredSection */
|
|
4
5
|
export const PREFERRED_SECTIONS = ['default', 'footer', 'settings'] as const;
|
|
5
6
|
|
|
7
|
+
function trimBoundaryHyphens(value: string): string {
|
|
8
|
+
let start = 0;
|
|
9
|
+
let end = value.length;
|
|
10
|
+
while (start < end && value[start] === '-') start++;
|
|
11
|
+
while (end > start && value[end - 1] === '-') end--;
|
|
12
|
+
return value.slice(start, end);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Convert an app display/package name into the canonical persisted app id. */
|
|
16
|
+
export function slugifyAppId(value: string): string {
|
|
17
|
+
const normalized = value
|
|
18
|
+
.trim()
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.replace(/[^a-z0-9._-]+/g, '-');
|
|
21
|
+
const slug = trimBoundaryHyphens(normalized).slice(0, 80);
|
|
22
|
+
if (!slug) throw new Error('App name must contain at least one letter or number');
|
|
23
|
+
return slug;
|
|
24
|
+
}
|
|
25
|
+
|
|
6
26
|
// The app-manifest closure is declared once, as the Zod schemas in `./api-schemas/apps.ts`, and
|
|
7
27
|
// inferred below. The documentation moved with it: what a published component says about a field now
|
|
8
28
|
// comes from the schema's own `.meta({ description })` rather than from a TSDoc comment a generator
|
|
@@ -41,6 +61,7 @@ export interface AppUINavItem {
|
|
|
41
61
|
}
|
|
42
62
|
|
|
43
63
|
export type AppUIConfig = Wire.AppUIConfig;
|
|
64
|
+
export type AppOAuthClientConfig = Wire.AppOAuthClientConfig;
|
|
44
65
|
|
|
45
66
|
export type AppInstallationProjectsQuery = Wire.AppInstallationProjectsQuery;
|
|
46
67
|
|
|
@@ -81,11 +102,24 @@ function deriveMCPCollectionId(input: string): string {
|
|
|
81
102
|
* @param vars - Optional endpoint variables to substitute in URLs
|
|
82
103
|
* @returns Normalized ToolCollectionObject
|
|
83
104
|
*/
|
|
84
|
-
export function normalizeToolCollection(
|
|
105
|
+
export function normalizeToolCollection(
|
|
106
|
+
collection: ToolCollectionObject,
|
|
107
|
+
vars?: Endpoints,
|
|
108
|
+
sharedParameters?: MCPToolCollectionObject['parameters'],
|
|
109
|
+
): ToolCollectionObject {
|
|
85
110
|
if (!collection || typeof collection !== 'object') {
|
|
86
111
|
throw new TypeError('Tool collection must be an object');
|
|
87
112
|
}
|
|
88
|
-
const substitutedUrl =
|
|
113
|
+
const substitutedUrl =
|
|
114
|
+
vars && collection.url
|
|
115
|
+
? substituteEndpoints(
|
|
116
|
+
collection.url,
|
|
117
|
+
vars,
|
|
118
|
+
collection.type === 'mcp'
|
|
119
|
+
? [...Object.keys(sharedParameters ?? {}), ...Object.keys(collection.parameters ?? {})]
|
|
120
|
+
: [],
|
|
121
|
+
)
|
|
122
|
+
: collection.url;
|
|
89
123
|
const urlChanged = substitutedUrl !== collection.url;
|
|
90
124
|
if (collection.type === 'mcp') {
|
|
91
125
|
const fallbackId = deriveMCPCollectionId(collection.id || collection.name || collection.url);
|
|
@@ -191,10 +225,26 @@ export type AppBuildProgress = Wire.AppBuildProgress;
|
|
|
191
225
|
|
|
192
226
|
export type AppScaffoldModule = Wire.AppScaffoldModule;
|
|
193
227
|
|
|
228
|
+
export type AppScaffoldSourceMode = Wire.AppScaffoldSourceMode;
|
|
229
|
+
|
|
194
230
|
export type StartAppScaffoldRequest = Wire.StartAppScaffoldRequest;
|
|
195
231
|
|
|
196
232
|
export type StartAppScaffoldResponse = Wire.StartAppScaffoldResponse;
|
|
197
233
|
|
|
234
|
+
export type AppGithubConfiguration = Wire.AppGithubConfiguration;
|
|
235
|
+
export type StartAppGithubAuthorizationResponse = Wire.StartAppGithubAuthorizationResponse;
|
|
236
|
+
export type ExchangeAppGithubAuthorizationRequest = Wire.ExchangeAppGithubAuthorizationRequest;
|
|
237
|
+
export type AppGithubRepositoriesQuery = Wire.AppGithubRepositoriesQuery;
|
|
238
|
+
export type AppGithubInstallation = Wire.AppGithubInstallation;
|
|
239
|
+
export type AppGithubAccount = Wire.AppGithubAccount;
|
|
240
|
+
export type ExchangeAppGithubAuthorizationResponse = Wire.ExchangeAppGithubAuthorizationResponse;
|
|
241
|
+
export type AppGithubRepository = Wire.AppGithubRepository;
|
|
242
|
+
export type AppGithubRepositoryCreation = Wire.AppGithubRepositoryCreation;
|
|
243
|
+
export type AppGithubRepositoryList = Wire.AppGithubRepositoryList;
|
|
244
|
+
export type AppGithubRepositorySetupQuery = Wire.AppGithubRepositorySetupQuery;
|
|
245
|
+
export type AppGithubBranchState = Wire.AppGithubBranchState;
|
|
246
|
+
export type AppGithubRepositorySetup = Wire.AppGithubRepositorySetup;
|
|
247
|
+
|
|
198
248
|
export type StartAppDevelopmentTaskRequest = Wire.StartAppDevelopmentTaskRequest;
|
|
199
249
|
|
|
200
250
|
export type AppScaffoldProgressStatus = Wire.AppScaffoldProgressStatus;
|
|
@@ -232,6 +282,7 @@ export type AppManifestData = Wire.AppManifestData;
|
|
|
232
282
|
export type UpdateAppPayload = Wire.UpdateAppPayload;
|
|
233
283
|
|
|
234
284
|
export type AppGitSourceConfig = Wire.AppGitSourceConfig;
|
|
285
|
+
export type AppGitSourceProvider = Wire.AppGitSourceProvider;
|
|
235
286
|
|
|
236
287
|
export type AppSourceConfig = Wire.AppSourceConfig;
|
|
237
288
|
|
|
@@ -262,9 +313,11 @@ export interface Endpoints {
|
|
|
262
313
|
* with the unresolved placeholder visible, rather than silently pointing nowhere).
|
|
263
314
|
* Trailing slashes on replacement values are stripped to avoid `//api/...` joins.
|
|
264
315
|
*/
|
|
265
|
-
function substituteEndpoints(url: string, endpoints?: Endpoints): string {
|
|
316
|
+
function substituteEndpoints(url: string, endpoints?: Endpoints, parameterNames: string[] = []): string {
|
|
266
317
|
if (!url || !endpoints) return url;
|
|
267
318
|
return url.replace(/\{\{\s*(\w+)\s*\}\}/g, (match, key: string) => {
|
|
319
|
+
// Explicit installation parameters take precedence over legacy platform endpoint placeholders.
|
|
320
|
+
if (parameterNames.includes(key)) return match;
|
|
268
321
|
const value = (endpoints as Record<string, string | undefined>)[key];
|
|
269
322
|
if (typeof value !== 'string' || !value) return match;
|
|
270
323
|
return trimTrailingSlashes(value);
|
|
@@ -632,3 +685,63 @@ export type ValidateUrlResponse = Wire.ValidateUrlResponse;
|
|
|
632
685
|
export type AppDeleteSummary = Wire.AppDeleteSummary;
|
|
633
686
|
|
|
634
687
|
export type UpdateAppInstallationOAuthApprovalPayload = Wire.UpdateAppInstallationOAuthApprovalPayload;
|
|
688
|
+
|
|
689
|
+
/** Check exact installation grants; legacy app-name grants authorize only the default instance. */
|
|
690
|
+
export function hasAppInstallationAccess(
|
|
691
|
+
token: AuthTokenPayload,
|
|
692
|
+
installation: { id: string; project: string; instance_key?: string; manifest: { name: string } },
|
|
693
|
+
ui = false,
|
|
694
|
+
): boolean {
|
|
695
|
+
if (token.project?.id !== installation.project) return false;
|
|
696
|
+
const grants = token.app_installations;
|
|
697
|
+
if (grants !== undefined) {
|
|
698
|
+
if (grants.version !== 1 || grants.project_id !== installation.project) return false;
|
|
699
|
+
if (grants.ids.includes(installation.id)) {
|
|
700
|
+
return !ui || !grants.ui_restrictions?.includes(installation.id);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
// Default app-name grants survive reinstalling the same app with a new installation ID.
|
|
704
|
+
// Named instances never inherit these grants, including on refreshed running-agent tokens.
|
|
705
|
+
return (
|
|
706
|
+
(!installation.instance_key || installation.instance_key === 'default') &&
|
|
707
|
+
(token.apps ?? []).includes(installation.manifest.name) &&
|
|
708
|
+
(!ui || !token.ui_restrictions?.includes(installation.manifest.name))
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/** Persist this effective collection in catalogs so discovery and execution use the same namespace. */
|
|
713
|
+
export function resolveInstallationCollection(
|
|
714
|
+
collection: ToolCollectionObject,
|
|
715
|
+
installation: Pick<AppInstallation, 'instance_key' | 'namespace_overrides' | 'namespace_conflicts'>,
|
|
716
|
+
): ToolCollectionObject {
|
|
717
|
+
if (collection.type === 'mcp' && installation.namespace_conflicts?.includes(collection.id)) {
|
|
718
|
+
throw new Error(`Namespace conflict for MCP collection '${collection.id}'; resolve it in project app settings`);
|
|
719
|
+
}
|
|
720
|
+
if (collection.type !== 'mcp') return collection;
|
|
721
|
+
const overrides = installation.namespace_overrides;
|
|
722
|
+
if (overrides && Object.hasOwn(overrides, collection.id)) {
|
|
723
|
+
const namespace = overrides[collection.id];
|
|
724
|
+
if (typeof namespace === 'string' && namespace.length > 0) return { ...collection, namespace };
|
|
725
|
+
} else if (!installation.instance_key || installation.instance_key === 'default') {
|
|
726
|
+
return collection;
|
|
727
|
+
}
|
|
728
|
+
throw new Error(`Namespace allocation required for MCP collection '${collection.id}'`);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
export type AppInstanceAvailability = Wire.AppInstanceAvailability;
|
|
732
|
+
export type McpPublicParameter = Wire.McpPublicParameter;
|
|
733
|
+
export type McpSecretParameter = Wire.McpSecretParameter;
|
|
734
|
+
export type McpConnectionParameter = Wire.McpConnectionParameter;
|
|
735
|
+
|
|
736
|
+
/** Whether a manifest can safely back an additional MCP-only installation. */
|
|
737
|
+
export function isMcpOnlyInstanceManifest(
|
|
738
|
+
manifest: Pick<AppManifestData, 'endpoint' | 'ui' | 'capabilities' | 'tool_collections'>,
|
|
739
|
+
): boolean {
|
|
740
|
+
return (
|
|
741
|
+
!manifest.endpoint &&
|
|
742
|
+
!manifest.ui &&
|
|
743
|
+
!manifest.capabilities?.some((capability) => capability !== 'tools') &&
|
|
744
|
+
!!manifest.tool_collections?.length &&
|
|
745
|
+
manifest.tool_collections.every((collection) => normalizeToolCollection(collection).type === 'mcp')
|
|
746
|
+
);
|
|
747
|
+
}
|
package/src/interaction.ts
CHANGED
package/src/oauth-server.ts
CHANGED
|
@@ -62,3 +62,13 @@ export type OAuthLoginPayload = Wire.OAuthLoginPayload;
|
|
|
62
62
|
export type OAuthLoginDecisionResponse = Wire.OAuthLoginDecisionResponse;
|
|
63
63
|
|
|
64
64
|
export type OAuthLoginUserNotFoundResponse = Wire.OAuthLoginUserNotFoundResponse;
|
|
65
|
+
|
|
66
|
+
export type OidcFederationConnectionPayload = Wire.OidcFederationConnectionPayload;
|
|
67
|
+
|
|
68
|
+
export type OidcFederationConnection = Wire.OidcFederationConnection;
|
|
69
|
+
|
|
70
|
+
export type OidcFederationConnectionArray = Wire.OidcFederationConnectionArray;
|
|
71
|
+
|
|
72
|
+
export type OAuthTokenExchangeRequest = Wire.OAuthTokenExchangeRequest;
|
|
73
|
+
|
|
74
|
+
export type OAuthTokenExchangeResponse = Wire.OAuthTokenExchangeResponse;
|
package/src/store/index.ts
CHANGED
|
@@ -509,6 +509,16 @@ export const ContentTypeIntakePolicySchema: JSONObject = {
|
|
|
509
509
|
type: 'string',
|
|
510
510
|
},
|
|
511
511
|
},
|
|
512
|
+
effort: {
|
|
513
|
+
$ref: '#/$defs/ReasoningEffort',
|
|
514
|
+
},
|
|
515
|
+
reasoning_effort: {
|
|
516
|
+
$ref: '#/$defs/ReasoningEffort',
|
|
517
|
+
},
|
|
518
|
+
verbosity: {
|
|
519
|
+
type: 'string',
|
|
520
|
+
enum: ['low', 'medium', 'high'],
|
|
521
|
+
},
|
|
512
522
|
include_thoughts: {
|
|
513
523
|
type: 'boolean',
|
|
514
524
|
},
|
|
@@ -731,6 +741,9 @@ export const ContentTypeIntakePolicySchema: JSONObject = {
|
|
|
731
741
|
type: 'string',
|
|
732
742
|
const: 'bedrock-nova',
|
|
733
743
|
},
|
|
744
|
+
effort: {
|
|
745
|
+
$ref: '#/$defs/ReasoningEffort',
|
|
746
|
+
},
|
|
734
747
|
max_tokens: {
|
|
735
748
|
type: 'number',
|
|
736
749
|
},
|
|
@@ -1223,8 +1236,7 @@ export const ContentTypeIntakePolicySchema: JSONObject = {
|
|
|
1223
1236
|
},
|
|
1224
1237
|
},
|
|
1225
1238
|
effort: {
|
|
1226
|
-
|
|
1227
|
-
enum: ['none', 'high'],
|
|
1239
|
+
$ref: '#/$defs/ReasoningEffort',
|
|
1228
1240
|
},
|
|
1229
1241
|
random_seed: {
|
|
1230
1242
|
type: 'integer',
|
|
@@ -1610,6 +1622,9 @@ export const ContentTypeIntakePolicySchema: JSONObject = {
|
|
|
1610
1622
|
image_generation: {
|
|
1611
1623
|
$ref: '#/$defs/OpenAiImageGenerationOptions',
|
|
1612
1624
|
},
|
|
1625
|
+
seed: {
|
|
1626
|
+
type: 'number',
|
|
1627
|
+
},
|
|
1613
1628
|
max_tokens: {
|
|
1614
1629
|
type: 'number',
|
|
1615
1630
|
},
|
|
@@ -1732,6 +1747,9 @@ export const ContentTypeIntakePolicySchema: JSONObject = {
|
|
|
1732
1747
|
OpenRouterTextOptions: {
|
|
1733
1748
|
type: 'object',
|
|
1734
1749
|
properties: {
|
|
1750
|
+
seed: {
|
|
1751
|
+
type: 'number',
|
|
1752
|
+
},
|
|
1735
1753
|
max_tokens: {
|
|
1736
1754
|
type: 'number',
|
|
1737
1755
|
},
|
package/src/store/store.ts
CHANGED
|
@@ -136,6 +136,8 @@ export type ContentObjectUserPermissions = Wire.ContentObjectUserPermissions;
|
|
|
136
136
|
|
|
137
137
|
export type ContentObjectTextResponse = Wire.ContentObjectTextResponse;
|
|
138
138
|
|
|
139
|
+
export type SetObjectTextPayload = Wire.SetObjectTextPayload;
|
|
140
|
+
|
|
139
141
|
export type DeleteContentObjectResult = Wire.DeleteContentObjectResult;
|
|
140
142
|
|
|
141
143
|
export type SetObjectEmbeddingsResponse = Wire.SetObjectEmbeddingsResponse;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Maximum UTF-8 size persisted for extracted document text. */
|
|
2
|
+
export const MAX_EXTRACTED_TEXT_BYTES = 10 * 1024 * 1024;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Request-body allowance for the JSON envelope carrying extracted text and its source etag.
|
|
6
|
+
* This is transport headroom, not a larger stored-text limit.
|
|
7
|
+
*/
|
|
8
|
+
export const SET_OBJECT_TEXT_BODY_LIMIT_BYTES = 16 * 1024 * 1024;
|
|
9
|
+
|
|
10
|
+
export const EXTRACTED_TEXT_TRUNCATION_MARKER = '\n\n[... truncated at max text limit 10 MiB ...]';
|
|
11
|
+
|
|
12
|
+
export interface ExtractedTextLimitResult {
|
|
13
|
+
text: string;
|
|
14
|
+
truncated: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Retain the largest Unicode-safe prefix that fits together with the truncation marker.
|
|
19
|
+
* The marker is part of the byte budget, so persisted text never exceeds the declared limit.
|
|
20
|
+
*/
|
|
21
|
+
export function truncateExtractedText(text: string): ExtractedTextLimitResult {
|
|
22
|
+
if (utf8PrefixEnd(text, MAX_EXTRACTED_TEXT_BYTES) === text.length) {
|
|
23
|
+
return { text, truncated: false };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const markerBytes = utf8ByteLength(EXTRACTED_TEXT_TRUNCATION_MARKER);
|
|
27
|
+
const prefixEnd = utf8PrefixEnd(text, MAX_EXTRACTED_TEXT_BYTES - markerBytes);
|
|
28
|
+
return {
|
|
29
|
+
text: text.slice(0, prefixEnd) + EXTRACTED_TEXT_TRUNCATION_MARKER,
|
|
30
|
+
truncated: true,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function utf8ByteLength(text: string): number {
|
|
35
|
+
let bytes = 0;
|
|
36
|
+
for (let index = 0; index < text.length; ) {
|
|
37
|
+
const codePoint = text.codePointAt(index) ?? 0;
|
|
38
|
+
bytes += utf8CodePointBytes(codePoint);
|
|
39
|
+
index += codePoint > 0xffff ? 2 : 1;
|
|
40
|
+
}
|
|
41
|
+
return bytes;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function utf8PrefixEnd(text: string, maxBytes: number): number {
|
|
45
|
+
let bytes = 0;
|
|
46
|
+
let index = 0;
|
|
47
|
+
while (index < text.length) {
|
|
48
|
+
const codePoint = text.codePointAt(index) ?? 0;
|
|
49
|
+
const codePointBytes = utf8CodePointBytes(codePoint);
|
|
50
|
+
if (bytes + codePointBytes > maxBytes) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
bytes += codePointBytes;
|
|
54
|
+
index += codePoint > 0xffff ? 2 : 1;
|
|
55
|
+
}
|
|
56
|
+
return index;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function utf8CodePointBytes(codePoint: number): number {
|
|
60
|
+
if (codePoint <= 0x7f) return 1;
|
|
61
|
+
if (codePoint <= 0x7ff) return 2;
|
|
62
|
+
if (codePoint <= 0xffff) return 3;
|
|
63
|
+
return 4;
|
|
64
|
+
}
|