@schift-io/knowledge-scope 0.1.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/LICENSE +202 -0
- package/README.md +387 -0
- package/dist/context-pack.js +4771 -0
- package/dist/index.js +8044 -0
- package/dist/main.js +7550 -0
- package/dist/types/adapters/evidence-policy.d.ts +3 -0
- package/dist/types/adapters/gates.d.ts +13 -0
- package/dist/types/adapters/http-policy.d.ts +10 -0
- package/dist/types/adapters/open-connector.d.ts +20 -0
- package/dist/types/adapters/provider-port.d.ts +27 -0
- package/dist/types/adapters/response.d.ts +12 -0
- package/dist/types/adapters/schift-search-headers.d.ts +2 -0
- package/dist/types/adapters/schift-search-identity.d.ts +14 -0
- package/dist/types/adapters/schift-search.d.ts +17 -0
- package/dist/types/adapters/types.d.ts +136 -0
- package/dist/types/api-contract.d.ts +164 -0
- package/dist/types/api.d.ts +30 -0
- package/dist/types/application-batch.d.ts +4 -0
- package/dist/types/application-execution.d.ts +30 -0
- package/dist/types/application.d.ts +47 -0
- package/dist/types/authorization.d.ts +228 -0
- package/dist/types/cli-options.d.ts +6 -0
- package/dist/types/cli.d.ts +24 -0
- package/dist/types/client-error.d.ts +5 -0
- package/dist/types/client-validation.d.ts +8 -0
- package/dist/types/client.d.ts +18 -0
- package/dist/types/context-pack/bounded-json.d.ts +3 -0
- package/dist/types/context-pack/canonical.d.ts +12 -0
- package/dist/types/context-pack/index.d.ts +73 -0
- package/dist/types/context-pack/knowledge-scope-admission.d.ts +23 -0
- package/dist/types/context-pack/knowledge-scope-batch.d.ts +85 -0
- package/dist/types/context-pack/knowledge-scope-execution.d.ts +297 -0
- package/dist/types/context-pack/knowledge-scope-lock.d.ts +71 -0
- package/dist/types/context-pack/knowledge-scope-mount.d.ts +1094 -0
- package/dist/types/context-pack/knowledge-scope.d.ts +1843 -0
- package/dist/types/context-pack/scalars.d.ts +13 -0
- package/dist/types/doctor-config.d.ts +6 -0
- package/dist/types/doctor.d.ts +7 -0
- package/dist/types/errors.d.ts +8 -0
- package/dist/types/evaluation/contracts.d.ts +718 -0
- package/dist/types/evaluation.d.ts +20 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/json.d.ts +17 -0
- package/dist/types/limits.d.ts +10 -0
- package/dist/types/main.d.ts +10 -0
- package/dist/types/onboarding-config.d.ts +9 -0
- package/dist/types/portable.d.ts +14 -0
- package/dist/types/quickstart.d.ts +10 -0
- package/dist/types/schema-subset.d.ts +9 -0
- package/dist/types/state-contract.d.ts +2867 -0
- package/dist/types/state-store.d.ts +29 -0
- package/docs/PILOT.md +184 -0
- package/examples/batch-consumer.mjs +19 -0
- package/examples/consumer.mjs +17 -0
- package/examples/evaluation/README.md +34 -0
- package/examples/evaluation/run.mjs +21 -0
- package/examples/evaluation/synthetic.json +59 -0
- package/examples/mount-bindings.json +31 -0
- package/examples/support-scope/schemas/query-input.json +6 -0
- package/examples/support-scope/schemas/result-row.json +6 -0
- package/examples/support-scope/scope.json +48 -0
- package/package.json +58 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AdapterFailure, CitationFact } from "./types.js";
|
|
2
|
+
export declare const validateCitation: (citation: CitationFact) => AdapterFailure | undefined;
|
|
3
|
+
export declare const validateFreshness: (freshness: string, now: Date, maxAgeSeconds: number | undefined) => AdapterFailure | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type JsonValue } from "../json.js";
|
|
2
|
+
import type { AdapterCapability, AdapterFailure, AdapterSourceBinding, SchemaValidator } from "./types.js";
|
|
3
|
+
export declare const GLOBAL_MAX_RESULT_BYTES: number;
|
|
4
|
+
export declare const GLOBAL_MAX_ROWS = 100;
|
|
5
|
+
export declare const validateBinding: (capability: AdapterCapability, binding: AdapterSourceBinding, expectedProviderRef: string) => AdapterFailure | undefined;
|
|
6
|
+
export declare const validateFilters: (allowed: readonly string[] | undefined, filters: Readonly<Record<string, JsonValue>>) => AdapterFailure | undefined;
|
|
7
|
+
export declare const validateProviderScopes: (required: readonly string[] | undefined, granted: readonly string[]) => AdapterFailure | undefined;
|
|
8
|
+
export declare const validateRowCount: (rows: readonly unknown[], maxRows: number | undefined) => AdapterFailure | undefined;
|
|
9
|
+
export declare const canonicalByteLength: (value: JsonValue) => number;
|
|
10
|
+
export declare const validateByteLength: (value: JsonValue, maxBytes: number | undefined) => AdapterFailure | undefined;
|
|
11
|
+
export declare const validateSchema: (validator: SchemaValidator | undefined, schemaRef: string, value: JsonValue, phase: "input" | "result") => Promise<AdapterFailure | undefined>;
|
|
12
|
+
export declare const validateTimeout: (timeoutMs: number) => AdapterFailure | undefined;
|
|
13
|
+
export declare const failure: (code: AdapterFailure["code"], message: string) => AdapterFailure;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AdapterFailure } from "./types.js";
|
|
2
|
+
export type SafeBaseUrlResult = Readonly<{
|
|
3
|
+
ok: true;
|
|
4
|
+
url: URL;
|
|
5
|
+
}> | Readonly<{
|
|
6
|
+
ok: false;
|
|
7
|
+
error: AdapterFailure;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const parseSafeBaseUrl: (value: string) => SafeBaseUrlResult;
|
|
10
|
+
export declare const requestSignal: (signal: AbortSignal | undefined, timeoutMs: number) => AbortSignal;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { JsonValue } from "../json.js";
|
|
2
|
+
import type { AdapterResult, AdapterSourceBinding, HttpTransport, OpenConnectorCapability, OpenConnectorInputMapper, OpenConnectorRowNormalizer, OpenConnectorRuntime, ProviderResultFact, SchemaValidator, TrustedEffectiveScope } from "./types.js";
|
|
3
|
+
export type OpenConnectorAdapterInput = Readonly<{
|
|
4
|
+
capability: OpenConnectorCapability;
|
|
5
|
+
binding: AdapterSourceBinding;
|
|
6
|
+
request: Readonly<{
|
|
7
|
+
input: JsonValue;
|
|
8
|
+
filters: Readonly<Record<string, JsonValue>>;
|
|
9
|
+
effectiveScope: TrustedEffectiveScope;
|
|
10
|
+
idempotencyKey?: string;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}>;
|
|
13
|
+
runtime: OpenConnectorRuntime;
|
|
14
|
+
transport: HttpTransport;
|
|
15
|
+
validateSchema: SchemaValidator | undefined;
|
|
16
|
+
normalizeRow: OpenConnectorRowNormalizer | undefined;
|
|
17
|
+
mapInput?: OpenConnectorInputMapper;
|
|
18
|
+
now?: Date;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const runOpenConnectorAction: (input: OpenConnectorAdapterInput) => Promise<AdapterResult<ProviderResultFact>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ProviderResult } from "@schift-io/knowledge-scope/context-pack";
|
|
2
|
+
import type { ProviderExecutionContext, ProviderExecutionPort } from "../application.js";
|
|
3
|
+
import type { AdapterFailureCode, HttpTransport, OpenConnectorInputMapper, OpenConnectorRowNormalizer, OpenConnectorRuntime, SchiftSearchRuntime } from "./types.js";
|
|
4
|
+
export declare class HttpProviderAdapterError extends Error {
|
|
5
|
+
readonly code: AdapterFailureCode;
|
|
6
|
+
readonly name = "HttpProviderAdapterError";
|
|
7
|
+
constructor(code: AdapterFailureCode);
|
|
8
|
+
}
|
|
9
|
+
type SearchRuntimeResolution = Omit<SchiftSearchRuntime, "tenant">;
|
|
10
|
+
export declare const bindTrustedSearchAuthority: (runtime: SearchRuntimeResolution, trustedTenant: string, trustedOrganizationId: string) => SchiftSearchRuntime;
|
|
11
|
+
export interface HttpProviderRuntimeResolver {
|
|
12
|
+
resolveOpenConnector(context: ProviderExecutionContext): OpenConnectorRuntime | Promise<OpenConnectorRuntime>;
|
|
13
|
+
resolveSchiftSearch(context: ProviderExecutionContext): SearchRuntimeResolution | Promise<SearchRuntimeResolution>;
|
|
14
|
+
}
|
|
15
|
+
export type HttpProviderExecutionOptions = Readonly<{
|
|
16
|
+
transport: HttpTransport;
|
|
17
|
+
runtimeResolver: HttpProviderRuntimeResolver;
|
|
18
|
+
executeRecords?: RecordsOperationExecutor;
|
|
19
|
+
mapOpenConnectorInput?: OpenConnectorInputMapper;
|
|
20
|
+
normalizeOpenConnectorRow?: OpenConnectorRowNormalizer;
|
|
21
|
+
now?: () => Date;
|
|
22
|
+
}>;
|
|
23
|
+
export type RecordsOperationExecutor = (context: ProviderExecutionContext) => Promise<readonly ProviderResult[]>;
|
|
24
|
+
export declare const normalizeDefaultOpenConnectorRow: OpenConnectorRowNormalizer;
|
|
25
|
+
export declare const stableProviderIdempotencyKey: (context: ProviderExecutionContext) => string;
|
|
26
|
+
export declare const createHttpProviderExecutionPort: (options: HttpProviderExecutionOptions) => ProviderExecutionPort;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type JsonValue } from "../json.js";
|
|
3
|
+
import type { AdapterFailure, HttpResponseLike } from "./types.js";
|
|
4
|
+
export type ParsedResponse = Readonly<{
|
|
5
|
+
ok: true;
|
|
6
|
+
value: JsonValue;
|
|
7
|
+
}> | Readonly<{
|
|
8
|
+
ok: false;
|
|
9
|
+
error: AdapterFailure;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const readProviderResponse: (response: HttpResponseLike, maxBytes: number | undefined) => Promise<ParsedResponse>;
|
|
12
|
+
export declare const JsonValueSchema: z.ZodType<JsonValue>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type JsonValue } from "../json.js";
|
|
2
|
+
export type SearchEvidenceIdentity = Readonly<{
|
|
3
|
+
bucket: string;
|
|
4
|
+
source: string;
|
|
5
|
+
document: string;
|
|
6
|
+
chunk: string;
|
|
7
|
+
text: string;
|
|
8
|
+
metadata: Readonly<Record<string, JsonValue>> | null;
|
|
9
|
+
title: string | null;
|
|
10
|
+
page: number | null;
|
|
11
|
+
section: string | null;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const canonicalSearchSrn: (identity: SearchEvidenceIdentity) => string;
|
|
14
|
+
export declare const searchContentRevision: (identity: SearchEvidenceIdentity) => string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { JsonValue } from "../json.js";
|
|
2
|
+
import type { AdapterResult, AdapterSourceBinding, HttpTransport, ProviderResultFact, SchemaValidator, SchiftSearchCapability, SchiftSearchRuntime, TrustedEffectiveScope } from "./types.js";
|
|
3
|
+
export type SchiftSearchAdapterInput = Readonly<{
|
|
4
|
+
capability: SchiftSearchCapability;
|
|
5
|
+
binding: AdapterSourceBinding;
|
|
6
|
+
request: Readonly<{
|
|
7
|
+
input: JsonValue;
|
|
8
|
+
filters: Readonly<Record<string, JsonValue>>;
|
|
9
|
+
effectiveScope: TrustedEffectiveScope;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}>;
|
|
12
|
+
runtime: SchiftSearchRuntime;
|
|
13
|
+
transport: HttpTransport;
|
|
14
|
+
validateSchema: SchemaValidator | undefined;
|
|
15
|
+
now?: Date;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const runSchiftSearch: (input: SchiftSearchAdapterInput) => Promise<AdapterResult<ProviderResultFact>>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { ProviderResult } from "@schift-io/knowledge-scope/context-pack";
|
|
2
|
+
import type { JsonValue } from "../json.js";
|
|
3
|
+
export type SourceClass = "activity_stream" | "document" | "records";
|
|
4
|
+
export type AdapterCapability = Readonly<{
|
|
5
|
+
operationId: string;
|
|
6
|
+
inputSchemaRef: string;
|
|
7
|
+
resultSchemaRef: string;
|
|
8
|
+
allowedFilters?: readonly string[] | undefined;
|
|
9
|
+
limits?: Readonly<{
|
|
10
|
+
maxRows?: number | undefined;
|
|
11
|
+
maxResultBytes?: number | undefined;
|
|
12
|
+
}> | undefined;
|
|
13
|
+
freshness?: Readonly<{
|
|
14
|
+
maxAgeSeconds: number;
|
|
15
|
+
}> | undefined;
|
|
16
|
+
requiredProviderScopes?: readonly string[] | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
export type OpenConnectorCapability = AdapterCapability & Readonly<{
|
|
19
|
+
provider: Readonly<{
|
|
20
|
+
kind: "open_connector_action";
|
|
21
|
+
actionId: string;
|
|
22
|
+
connectorRef: string;
|
|
23
|
+
}>;
|
|
24
|
+
}>;
|
|
25
|
+
export type SchiftSearchCapability = AdapterCapability & Readonly<{
|
|
26
|
+
provider: Readonly<{
|
|
27
|
+
kind: "schift_search";
|
|
28
|
+
indexRef: string;
|
|
29
|
+
}>;
|
|
30
|
+
}>;
|
|
31
|
+
export type AdapterSourceBinding = Readonly<{
|
|
32
|
+
sourceId: string;
|
|
33
|
+
sourceClass: SourceClass;
|
|
34
|
+
providerRef: string;
|
|
35
|
+
connectorRef?: string | undefined;
|
|
36
|
+
operationIds: readonly string[];
|
|
37
|
+
}>;
|
|
38
|
+
export type AdapterExecutionRequest = Readonly<{
|
|
39
|
+
input: JsonValue;
|
|
40
|
+
filters: Readonly<Record<string, JsonValue>>;
|
|
41
|
+
effectiveScope: TrustedEffectiveScope;
|
|
42
|
+
idempotencyKey?: string;
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
}>;
|
|
45
|
+
export type HttpRequest = Readonly<{
|
|
46
|
+
url: string;
|
|
47
|
+
method: "GET" | "POST";
|
|
48
|
+
headers: Readonly<Record<string, string>>;
|
|
49
|
+
body?: string;
|
|
50
|
+
signal: AbortSignal;
|
|
51
|
+
redirect: "error";
|
|
52
|
+
}>;
|
|
53
|
+
export interface HttpResponseLike {
|
|
54
|
+
readonly status: number;
|
|
55
|
+
readonly headers: Readonly<{
|
|
56
|
+
get(name: string): string | null;
|
|
57
|
+
}>;
|
|
58
|
+
readonly body: ReadableStream<Uint8Array> | null;
|
|
59
|
+
text(): Promise<string>;
|
|
60
|
+
}
|
|
61
|
+
export type HttpTransport = (request: HttpRequest) => Promise<HttpResponseLike>;
|
|
62
|
+
export type SchemaValidationResult = Readonly<{
|
|
63
|
+
ok: true;
|
|
64
|
+
}> | Readonly<{
|
|
65
|
+
ok: false;
|
|
66
|
+
code?: string;
|
|
67
|
+
}>;
|
|
68
|
+
export type SchemaValidator = (input: Readonly<{
|
|
69
|
+
schemaRef: string;
|
|
70
|
+
value: JsonValue;
|
|
71
|
+
phase: "input" | "result";
|
|
72
|
+
}>) => SchemaValidationResult | Promise<SchemaValidationResult>;
|
|
73
|
+
export declare const ADAPTER_FAILURE_CODES: readonly ["action_not_read_only", "binding_mismatch", "filter_not_allowed", "input_schema_invalid", "invalid_configuration", "invalid_freshness", "invalid_idempotency_key", "invalid_url", "permission_evidence_missing", "provider_identity_mismatch", "provider_rejected", "provider_response_malformed", "provider_scope_missing", "provider_unavailable", "response_too_large", "result_schema_invalid", "result_stale", "schema_validator_missing", "too_many_rows", "unsafe_citation"];
|
|
74
|
+
export type AdapterFailureCode = (typeof ADAPTER_FAILURE_CODES)[number];
|
|
75
|
+
export type AdapterFailure = Readonly<{
|
|
76
|
+
code: AdapterFailureCode;
|
|
77
|
+
message: string;
|
|
78
|
+
}>;
|
|
79
|
+
export type CitationFact = Readonly<{
|
|
80
|
+
uri: string;
|
|
81
|
+
label?: string;
|
|
82
|
+
}>;
|
|
83
|
+
export type ProviderResultFact = ProviderResult;
|
|
84
|
+
export type OpenConnectorNormalizedRow = Readonly<{
|
|
85
|
+
resultId: string;
|
|
86
|
+
srn?: string;
|
|
87
|
+
revision: string;
|
|
88
|
+
freshness?: string;
|
|
89
|
+
payload: JsonValue;
|
|
90
|
+
citation?: CitationFact;
|
|
91
|
+
}>;
|
|
92
|
+
export type OpenConnectorRowNormalizer = (input: Readonly<{
|
|
93
|
+
row: JsonValue;
|
|
94
|
+
connectorRunId: string;
|
|
95
|
+
actionCorrelationId: string;
|
|
96
|
+
}>) => OpenConnectorNormalizedRow | Promise<OpenConnectorNormalizedRow>;
|
|
97
|
+
export type OpenConnectorInputMapper = (input: Readonly<{
|
|
98
|
+
input: JsonValue;
|
|
99
|
+
filters: Readonly<Record<string, JsonValue>>;
|
|
100
|
+
effectiveScope: TrustedEffectiveScope;
|
|
101
|
+
capability: OpenConnectorCapability;
|
|
102
|
+
binding: AdapterSourceBinding;
|
|
103
|
+
}>) => JsonValue | Promise<JsonValue>;
|
|
104
|
+
export type AdapterResult<TFact> = Readonly<{
|
|
105
|
+
ok: true;
|
|
106
|
+
facts: readonly TFact[];
|
|
107
|
+
}> | Readonly<{
|
|
108
|
+
ok: false;
|
|
109
|
+
error: AdapterFailure;
|
|
110
|
+
}>;
|
|
111
|
+
export type OpenConnectorRuntime = Readonly<{
|
|
112
|
+
baseUrl: string;
|
|
113
|
+
connectorAlias?: string;
|
|
114
|
+
bearerToken?: string;
|
|
115
|
+
grantedProviderScopes: readonly string[];
|
|
116
|
+
readOnlyActions: readonly Readonly<{
|
|
117
|
+
connectorRef: string;
|
|
118
|
+
connectorAlias: string;
|
|
119
|
+
actionId: string;
|
|
120
|
+
}>[];
|
|
121
|
+
timeoutMs: number;
|
|
122
|
+
}>;
|
|
123
|
+
export type SchiftSearchRuntime = Readonly<{
|
|
124
|
+
baseUrl: string;
|
|
125
|
+
tenant: string;
|
|
126
|
+
organizationId: string;
|
|
127
|
+
bearerToken: string;
|
|
128
|
+
grantedProviderScopes: readonly string[];
|
|
129
|
+
timeoutMs: number;
|
|
130
|
+
}>;
|
|
131
|
+
export type TrustedEffectiveScope = Readonly<{
|
|
132
|
+
tenant: string;
|
|
133
|
+
namespace?: string;
|
|
134
|
+
subject?: string;
|
|
135
|
+
session?: string;
|
|
136
|
+
}>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type CapabilityBatchExecutionRequest } from "@schift-io/knowledge-scope/context-pack";
|
|
3
|
+
import type { JsonValue } from "./json.js";
|
|
4
|
+
export declare const RemoteMountRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
5
|
+
definition: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
6
|
+
files: z.ZodRecord<z.ZodString, z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>>;
|
|
7
|
+
lock: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
8
|
+
sourceBindings: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
9
|
+
}, "strict", z.ZodTypeAny, {
|
|
10
|
+
files: Record<string, JsonValue>;
|
|
11
|
+
definition: JsonValue;
|
|
12
|
+
lock: JsonValue;
|
|
13
|
+
sourceBindings: JsonValue;
|
|
14
|
+
}, {
|
|
15
|
+
files: Record<string, JsonValue>;
|
|
16
|
+
definition: JsonValue;
|
|
17
|
+
lock: JsonValue;
|
|
18
|
+
sourceBindings: JsonValue;
|
|
19
|
+
}>>;
|
|
20
|
+
declare const MountRequestSchema: z.ZodReadonly<z.ZodObject<{
|
|
21
|
+
definition: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
22
|
+
files: z.ZodRecord<z.ZodString, z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>>;
|
|
23
|
+
lock: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
24
|
+
scopeAuthority: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
25
|
+
sourceBindings: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
26
|
+
}, "strict", z.ZodTypeAny, {
|
|
27
|
+
scopeAuthority: JsonValue;
|
|
28
|
+
files: Record<string, JsonValue>;
|
|
29
|
+
definition: JsonValue;
|
|
30
|
+
lock: JsonValue;
|
|
31
|
+
sourceBindings: JsonValue;
|
|
32
|
+
}, {
|
|
33
|
+
scopeAuthority: JsonValue;
|
|
34
|
+
files: Record<string, JsonValue>;
|
|
35
|
+
definition: JsonValue;
|
|
36
|
+
lock: JsonValue;
|
|
37
|
+
sourceBindings: JsonValue;
|
|
38
|
+
}>>;
|
|
39
|
+
export declare const RunBodySchema: z.ZodReadonly<z.ZodObject<{
|
|
40
|
+
effectiveScope: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
41
|
+
input: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
42
|
+
filters: z.ZodOptional<z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>>;
|
|
43
|
+
expectedRevision: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
}, "strict", z.ZodTypeAny, {
|
|
45
|
+
effectiveScope: JsonValue;
|
|
46
|
+
input: JsonValue;
|
|
47
|
+
filters?: JsonValue | undefined;
|
|
48
|
+
expectedRevision?: number | undefined;
|
|
49
|
+
}, {
|
|
50
|
+
effectiveScope: JsonValue;
|
|
51
|
+
input: JsonValue;
|
|
52
|
+
filters?: JsonValue | undefined;
|
|
53
|
+
expectedRevision?: number | undefined;
|
|
54
|
+
}>>;
|
|
55
|
+
export declare const RunBatchBodySchema: z.ZodReadonly<z.ZodObject<Omit<{
|
|
56
|
+
installationId: z.ZodBranded<z.ZodString, "InstallationId">;
|
|
57
|
+
effectiveScope: z.ZodReadonly<z.ZodObject<{
|
|
58
|
+
tenant: z.ZodString;
|
|
59
|
+
namespace: z.ZodOptional<z.ZodString>;
|
|
60
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
61
|
+
session: z.ZodOptional<z.ZodString>;
|
|
62
|
+
}, "strict", z.ZodTypeAny, {
|
|
63
|
+
tenant: string;
|
|
64
|
+
namespace?: string | undefined;
|
|
65
|
+
subject?: string | undefined;
|
|
66
|
+
session?: string | undefined;
|
|
67
|
+
}, {
|
|
68
|
+
tenant: string;
|
|
69
|
+
namespace?: string | undefined;
|
|
70
|
+
subject?: string | undefined;
|
|
71
|
+
session?: string | undefined;
|
|
72
|
+
}>>;
|
|
73
|
+
expectedRevision: z.ZodOptional<z.ZodNumber>;
|
|
74
|
+
operations: z.ZodReadonly<z.ZodEffects<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
75
|
+
operationId: z.ZodString;
|
|
76
|
+
input: z.ZodEffects<z.ZodType<import("@schift-io/knowledge-scope/context-pack").JsonValue, z.ZodTypeDef, import("@schift-io/knowledge-scope/context-pack").JsonValue>, import("@schift-io/knowledge-scope/context-pack").JsonValue, import("@schift-io/knowledge-scope/context-pack").JsonValue>;
|
|
77
|
+
filters: z.ZodOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodType<import("@schift-io/knowledge-scope/context-pack").JsonValue, z.ZodTypeDef, import("@schift-io/knowledge-scope/context-pack").JsonValue>, import("@schift-io/knowledge-scope/context-pack").JsonValue, import("@schift-io/knowledge-scope/context-pack").JsonValue>>>>;
|
|
78
|
+
}, "strict", z.ZodTypeAny, {
|
|
79
|
+
operationId: string;
|
|
80
|
+
input: import("../dist/types/context-pack/canonical.js").JsonValue;
|
|
81
|
+
filters?: Readonly<Record<string, import("@schift-io/knowledge-scope/context-pack").JsonValue>> | undefined;
|
|
82
|
+
}, {
|
|
83
|
+
operationId: string;
|
|
84
|
+
input: import("../dist/types/context-pack/canonical.js").JsonValue;
|
|
85
|
+
filters?: Readonly<Record<string, import("@schift-io/knowledge-scope/context-pack").JsonValue>> | undefined;
|
|
86
|
+
}>>, "many">, Readonly<{
|
|
87
|
+
operationId: string;
|
|
88
|
+
input: import("@schift-io/knowledge-scope/context-pack").JsonValue;
|
|
89
|
+
filters?: Readonly<Record<string, import("@schift-io/knowledge-scope/context-pack").JsonValue>> | undefined;
|
|
90
|
+
}>[], Readonly<{
|
|
91
|
+
operationId: string;
|
|
92
|
+
input: import("@schift-io/knowledge-scope/context-pack").JsonValue;
|
|
93
|
+
filters?: Readonly<Record<string, import("@schift-io/knowledge-scope/context-pack").JsonValue>> | undefined;
|
|
94
|
+
}>[]>>;
|
|
95
|
+
}, "installationId">, "strict", z.ZodTypeAny, {
|
|
96
|
+
effectiveScope: Readonly<{
|
|
97
|
+
tenant: string;
|
|
98
|
+
namespace?: string | undefined;
|
|
99
|
+
subject?: string | undefined;
|
|
100
|
+
session?: string | undefined;
|
|
101
|
+
}>;
|
|
102
|
+
operations: readonly Readonly<{
|
|
103
|
+
operationId: string;
|
|
104
|
+
input: import("@schift-io/knowledge-scope/context-pack").JsonValue;
|
|
105
|
+
filters?: Readonly<Record<string, import("@schift-io/knowledge-scope/context-pack").JsonValue>> | undefined;
|
|
106
|
+
}>[];
|
|
107
|
+
expectedRevision?: number | undefined;
|
|
108
|
+
}, {
|
|
109
|
+
effectiveScope: Readonly<{
|
|
110
|
+
tenant: string;
|
|
111
|
+
namespace?: string | undefined;
|
|
112
|
+
subject?: string | undefined;
|
|
113
|
+
session?: string | undefined;
|
|
114
|
+
}>;
|
|
115
|
+
operations: readonly Readonly<{
|
|
116
|
+
operationId: string;
|
|
117
|
+
input: import("@schift-io/knowledge-scope/context-pack").JsonValue;
|
|
118
|
+
filters?: Readonly<Record<string, import("@schift-io/knowledge-scope/context-pack").JsonValue>> | undefined;
|
|
119
|
+
}>[];
|
|
120
|
+
expectedRevision?: number | undefined;
|
|
121
|
+
}>>;
|
|
122
|
+
export declare const AdmitBodySchema: z.ZodUnion<[z.ZodReadonly<z.ZodObject<{
|
|
123
|
+
candidates: z.ZodReadonly<z.ZodArray<z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>, "many">>;
|
|
124
|
+
}, "strict", z.ZodTypeAny, {
|
|
125
|
+
candidates: readonly JsonValue[];
|
|
126
|
+
}, {
|
|
127
|
+
candidates: readonly JsonValue[];
|
|
128
|
+
}>>, z.ZodReadonly<z.ZodObject<{
|
|
129
|
+
candidate: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
130
|
+
}, "strict", z.ZodTypeAny, {
|
|
131
|
+
candidate: JsonValue;
|
|
132
|
+
}, {
|
|
133
|
+
candidate: JsonValue;
|
|
134
|
+
}>>]>;
|
|
135
|
+
export declare const UnmountBodySchema: z.ZodReadonly<z.ZodObject<{
|
|
136
|
+
expectedRevision: z.ZodNumber;
|
|
137
|
+
}, "strict", z.ZodTypeAny, {
|
|
138
|
+
expectedRevision: number;
|
|
139
|
+
}, {
|
|
140
|
+
expectedRevision: number;
|
|
141
|
+
}>>;
|
|
142
|
+
export type MountApplicationRequest = z.infer<typeof MountRequestSchema>;
|
|
143
|
+
export type RunApplicationRequest = Readonly<z.infer<typeof RunBodySchema> & {
|
|
144
|
+
installationId: string;
|
|
145
|
+
operationId: string;
|
|
146
|
+
}>;
|
|
147
|
+
export type RunBatchApplicationRequest = CapabilityBatchExecutionRequest;
|
|
148
|
+
export type AdmitApplicationRequest = Readonly<{
|
|
149
|
+
installationId: string;
|
|
150
|
+
candidates: readonly JsonValue[];
|
|
151
|
+
}>;
|
|
152
|
+
export type UnmountApplicationRequest = Readonly<{
|
|
153
|
+
installationId: string;
|
|
154
|
+
expectedRevision: number;
|
|
155
|
+
}>;
|
|
156
|
+
export interface KnowledgeScopeApplicationPort {
|
|
157
|
+
readonly mount: (request: MountApplicationRequest) => Promise<JsonValue>;
|
|
158
|
+
readonly inspect: (installationId: string) => Promise<JsonValue>;
|
|
159
|
+
readonly run: (request: RunApplicationRequest) => Promise<JsonValue>;
|
|
160
|
+
readonly admit: (request: AdmitApplicationRequest) => Promise<JsonValue>;
|
|
161
|
+
readonly unmount: (request: UnmountApplicationRequest) => Promise<JsonValue>;
|
|
162
|
+
readonly runBatch?: (request: RunBatchApplicationRequest) => Promise<JsonValue>;
|
|
163
|
+
}
|
|
164
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type KnowledgeScopeApplicationPort } from "./api-contract.js";
|
|
2
|
+
export type { MountApplicationRequest, RunApplicationRequest, RunBatchApplicationRequest, AdmitApplicationRequest, UnmountApplicationRequest, KnowledgeScopeApplicationPort } from "./api-contract.js";
|
|
3
|
+
import { type JsonValue } from "./json.js";
|
|
4
|
+
export declare class KnowledgeScopeApiError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly status: number;
|
|
7
|
+
readonly name = "KnowledgeScopeApiError";
|
|
8
|
+
constructor(code: string, status: number);
|
|
9
|
+
}
|
|
10
|
+
type ApiOptions = Readonly<{
|
|
11
|
+
application: KnowledgeScopeApplicationPort;
|
|
12
|
+
mountAuthority: JsonValue | (() => Promise<JsonValue>);
|
|
13
|
+
maxBodyBytes?: number;
|
|
14
|
+
apiToken?: string;
|
|
15
|
+
}>;
|
|
16
|
+
type Api = Readonly<{
|
|
17
|
+
fetch: (request: Request) => Promise<Response>;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const createKnowledgeScopeApi: (options: ApiOptions) => Api;
|
|
20
|
+
export type ServedKnowledgeScopeApi = Readonly<{
|
|
21
|
+
host: string;
|
|
22
|
+
port: number;
|
|
23
|
+
stop: () => void;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const serveKnowledgeScopeApi: (options: ApiOptions & Readonly<{
|
|
26
|
+
host?: string;
|
|
27
|
+
port?: number;
|
|
28
|
+
}>) => Promise<ServedKnowledgeScopeApi>;
|
|
29
|
+
type RequestFunction = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
30
|
+
export declare const createRemoteKnowledgeScopeApplication: (apiUrl: string, request?: RequestFunction, apiToken?: string) => KnowledgeScopeApplicationPort;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CandidateEnvelope, CapabilityBatchExecutionRequest } from "@schift-io/knowledge-scope/context-pack";
|
|
2
|
+
import type { KnowledgeScopeApplicationOptions } from "./application.js";
|
|
3
|
+
import type { StoredKnowledgeScope } from "./state-contract.js";
|
|
4
|
+
export declare const executeBatch: (options: Pick<KnowledgeScopeApplicationOptions, "provider" | "authorization">, stored: StoredKnowledgeScope, request: CapabilityBatchExecutionRequest) => Promise<readonly CandidateEnvelope[]>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type CandidateEnvelope, type CapabilityExecutionRequest, type KnowledgeScopeDefinition, type KnowledgeScopeMount, type QueryCapability } from "@schift-io/knowledge-scope/context-pack";
|
|
2
|
+
import { type KnowledgeScopeAuthorization } from "./authorization.js";
|
|
3
|
+
import { type JsonValue } from "./json.js";
|
|
4
|
+
import { type ExecutionBudget } from "./limits.js";
|
|
5
|
+
import { type SchemaValidationResult } from "./schema-subset.js";
|
|
6
|
+
import type { StoredKnowledgeScope } from "./state-contract.js";
|
|
7
|
+
type SourceBinding = KnowledgeScopeMount["sourceBindings"][number];
|
|
8
|
+
type SchemaValidator = (value: JsonValue) => SchemaValidationResult;
|
|
9
|
+
export type ProviderExecutionContext = Readonly<{
|
|
10
|
+
definition: KnowledgeScopeDefinition;
|
|
11
|
+
mount: KnowledgeScopeMount;
|
|
12
|
+
capability: QueryCapability;
|
|
13
|
+
binding: SourceBinding;
|
|
14
|
+
request: CapabilityExecutionRequest;
|
|
15
|
+
validateInput: SchemaValidator;
|
|
16
|
+
validateResult: SchemaValidator;
|
|
17
|
+
}>;
|
|
18
|
+
export interface ProviderExecutionPort {
|
|
19
|
+
execute(context: ProviderExecutionContext): Promise<readonly unknown[]>;
|
|
20
|
+
}
|
|
21
|
+
export type PreparedExecution = Readonly<{
|
|
22
|
+
budget?: ExecutionBudget;
|
|
23
|
+
capability: QueryCapability;
|
|
24
|
+
bindings: readonly SourceBinding[];
|
|
25
|
+
validateInput: SchemaValidator;
|
|
26
|
+
validateResult: SchemaValidator;
|
|
27
|
+
}>;
|
|
28
|
+
export declare const prepareExecution: (stored: StoredKnowledgeScope, request: CapabilityExecutionRequest) => PreparedExecution;
|
|
29
|
+
export declare const executeAndNormalize: (provider: ProviderExecutionPort, authorization: KnowledgeScopeAuthorization, stored: StoredKnowledgeScope, request: CapabilityExecutionRequest, prepared: PreparedExecution) => Promise<readonly CandidateEnvelope[]>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type CandidateEnvelope, type KnowledgeScopeDefinition, type KnowledgeScopeMount, type ScopeRequirementReceipt } from "@schift-io/knowledge-scope/context-pack";
|
|
2
|
+
import { type KnowledgeScopeAuthorization } from "./authorization.js";
|
|
3
|
+
import type { PortableKnowledgeScope } from "./portable.js";
|
|
4
|
+
import { type ProviderExecutionPort } from "./application-execution.js";
|
|
5
|
+
import type { StoredKnowledgeScope } from "./state-contract.js";
|
|
6
|
+
import type { KnowledgeScopeStateStore } from "./state-store.js";
|
|
7
|
+
export type { ProviderExecutionContext, ProviderExecutionPort } from "./application-execution.js";
|
|
8
|
+
export { GLOBAL_MAX_RESULT_BYTES, GLOBAL_MAX_RESULT_ROWS, MAX_BINDINGS, MAX_CANDIDATES, } from "./limits.js";
|
|
9
|
+
export type MountKnowledgeScopeInput = Readonly<{
|
|
10
|
+
portable: PortableKnowledgeScope;
|
|
11
|
+
scopeAuthority: unknown;
|
|
12
|
+
sourceBindings: unknown;
|
|
13
|
+
}>;
|
|
14
|
+
export type KnowledgeScopeInspection = Readonly<{
|
|
15
|
+
definition: KnowledgeScopeDefinition;
|
|
16
|
+
lock: StoredKnowledgeScope["lock"];
|
|
17
|
+
mount: KnowledgeScopeMount;
|
|
18
|
+
}>;
|
|
19
|
+
export type KnowledgeScopeRunResult = Readonly<{
|
|
20
|
+
status: "ready";
|
|
21
|
+
candidates: readonly CandidateEnvelope[];
|
|
22
|
+
receipt: ScopeRequirementReceipt;
|
|
23
|
+
}> | Readonly<{
|
|
24
|
+
status: "insufficient_evidence";
|
|
25
|
+
candidates: readonly [];
|
|
26
|
+
receipt: ScopeRequirementReceipt;
|
|
27
|
+
}>;
|
|
28
|
+
export type KnowledgeScopeApplicationOptions = Readonly<{
|
|
29
|
+
store: KnowledgeScopeStateStore;
|
|
30
|
+
authorization: KnowledgeScopeAuthorization;
|
|
31
|
+
provider: ProviderExecutionPort;
|
|
32
|
+
now?: () => Date;
|
|
33
|
+
}>;
|
|
34
|
+
export declare class KnowledgeScopeApplication {
|
|
35
|
+
private readonly store;
|
|
36
|
+
private readonly authorization;
|
|
37
|
+
private readonly provider;
|
|
38
|
+
private readonly now;
|
|
39
|
+
constructor(options: KnowledgeScopeApplicationOptions);
|
|
40
|
+
mount(input: MountKnowledgeScopeInput): Promise<KnowledgeScopeMount>;
|
|
41
|
+
inspect(installationId: string): Promise<KnowledgeScopeInspection>;
|
|
42
|
+
unmount(installationId: string, expectedRevision: number): Promise<KnowledgeScopeMount>;
|
|
43
|
+
run(rawRequest: unknown): Promise<KnowledgeScopeRunResult>;
|
|
44
|
+
runBatch(rawRequest: unknown): Promise<KnowledgeScopeRunResult>;
|
|
45
|
+
admit(installationId: string, rawCandidates: readonly unknown[]): Promise<ScopeRequirementReceipt>;
|
|
46
|
+
private findStored;
|
|
47
|
+
}
|