/** * graphql-schema.ts, the knowledge GraphQL schema text, its JSON scalar, and * the small coercion helpers the resolvers use. * * `graphql` is declared under `optionalDependencies` in * packages/sdk/package.json, and this file imported `GraphQLError`, * `GraphQLScalarType` and `Kind` as VALUES at module init, while * knowledge/graphql.ts ran `buildSchema` and `printSchema` in CLASS-STATIC * initialisers, which also run at module init. The daemon reaches both * through the knowledge service, so an install without `graphql` did not lose * the GraphQL surface, it lost the daemon before it could report anything * (see utils/optional-dependency.ts for the measured failure). * * Everything here is now reached through `graphqlModule()`, and the whole * module is resolved by `primeGraphqlModule()`, a dynamic import written out * literally so a bundler still sees `graphql` and bundles it when it IS * installed. `KnowledgeGraphqlService` primes it at construction, so in a * compiled binary the bundled module is in hand long before an HTTP route * reads `schemaText`. The synchronous fallback below covers an unbundled * caller that reaches a helper first, and when the package is genuinely * absent every entry point throws an error whose message names it. */ import type { DocumentNode, ValueNode, buildSchema } from 'graphql'; import type { KnowledgePacketDetail, KnowledgeProjectionTargetKind } from './types.js'; type GraphqlModule = typeof import('graphql'); /** Whether the knowledge GraphQL surface can run here, and why not. */ export interface KnowledgeGraphqlAvailability { readonly available: boolean; readonly reason?: string; } /** * Resolve `graphql` once per process. Never rejects: an absent package is * reported, and the reason is remembered so the synchronous accessor below * repeats it instead of retrying a resolution that already failed. */ export declare function primeGraphqlModule(): Promise; /** * The resolved `graphql` module, for the synchronous helpers in this file and * the synchronous `schemaText` the daemon-sdk route contract requires. * * Prefers whatever `primeGraphqlModule()` already resolved, which is the * bundled copy inside a compiled binary. Falls back to `createRequire` for a * caller that got here before the prime finished, the same technique * state/sqlite-vec-loader.ts uses for its synchronous constructors. When * neither works the throw carries the standard unavailability message, so the * feature reports itself missing by name rather than failing obscurely. * * A `createRequire` failure is NOT remembered. Inside a compiled binary the * package is bundled and `createRequire` cannot see it at all, only the * dynamic import can, so caching that failure would declare `graphql` * permanently missing in exactly the installation where it is present. Only * `primeGraphqlModule()`, which uses the import a bundler follows, gets to * decide that the package is absent. */ export declare function graphqlModule(): GraphqlModule; export declare const KNOWLEDGE_GRAPHQL_SDL = "\n scalar JSON\n\n enum KnowledgeProjectionKind {\n OVERVIEW\n BUNDLE\n SOURCE\n NODE\n ISSUE\n DASHBOARD\n ROLLUP\n }\n\n enum KnowledgePacketDetail {\n COMPACT\n STANDARD\n DETAILED\n }\n\n enum KnowledgeJobMode {\n INLINE\n BACKGROUND\n }\n\n type KnowledgeStatus {\n ready: Boolean!\n storagePath: String!\n sourceCount: Int!\n nodeCount: Int!\n edgeCount: Int!\n issueCount: Int!\n extractionCount: Int!\n jobRunCount: Int!\n usageCount: Int!\n candidateCount: Int!\n reportCount: Int!\n scheduleCount: Int!\n note: String!\n }\n\n type KnowledgeConnectorSetupField {\n key: String!\n label: String!\n kind: String!\n optional: Boolean\n source: String\n description: String\n }\n\n type KnowledgeConnectorSetup {\n version: String!\n summary: String!\n transportHints: [String!]!\n steps: [String!]!\n fields: [KnowledgeConnectorSetupField!]!\n metadata: JSON\n }\n\n type KnowledgeConnectorDoctorCheck {\n id: String!\n label: String!\n status: String!\n detail: String!\n metadata: JSON\n }\n\n type KnowledgeConnectorDoctorReport {\n connectorId: String!\n ready: Boolean!\n summary: String!\n checks: [KnowledgeConnectorDoctorCheck!]!\n hints: [String!]!\n metadata: JSON\n }\n\n type KnowledgeConnector {\n id: String!\n displayName: String\n version: String\n description: String!\n sourceType: String!\n inputSchema: JSON\n examples: [JSON!]!\n capabilities: [String!]!\n setup: KnowledgeConnectorSetup\n metadata: JSON\n }\n\n type KnowledgeSource {\n id: String!\n connectorId: String!\n sourceType: String!\n title: String\n sourceUri: String\n canonicalUri: String\n summary: String\n description: String\n tags: [String!]!\n folderPath: String\n status: String!\n artifactId: String\n contentHash: String\n lastCrawledAt: Float\n crawlError: String\n sessionId: String\n metadata: JSON\n createdAt: Float!\n updatedAt: Float!\n }\n\n type KnowledgeNode {\n id: String!\n kind: String!\n slug: String!\n title: String!\n summary: String\n aliases: [String!]!\n status: String!\n confidence: Int!\n sourceId: String\n metadata: JSON\n createdAt: Float!\n updatedAt: Float!\n }\n\n type KnowledgeEdge {\n id: String!\n fromKind: String!\n fromId: String!\n toKind: String!\n toId: String!\n relation: String!\n weight: Float!\n metadata: JSON\n createdAt: Float!\n updatedAt: Float!\n }\n\n type KnowledgeIssue {\n id: String!\n severity: String!\n code: String!\n message: String!\n status: String!\n sourceId: String\n nodeId: String\n metadata: JSON\n createdAt: Float!\n updatedAt: Float!\n }\n\n type KnowledgeExtraction {\n id: String!\n sourceId: String!\n artifactId: String\n extractorId: String!\n format: String!\n title: String\n summary: String\n excerpt: String\n sections: [String!]!\n links: [String!]!\n estimatedTokens: Int!\n structure: JSON\n metadata: JSON\n createdAt: Float!\n updatedAt: Float!\n }\n\n type KnowledgeItemView {\n source: KnowledgeSource\n node: KnowledgeNode\n issue: KnowledgeIssue\n relatedEdges: [KnowledgeEdge!]!\n linkedSources: [KnowledgeSource!]!\n linkedNodes: [KnowledgeNode!]!\n }\n\n type KnowledgeSearchResult {\n kind: String!\n id: String!\n score: Float!\n reason: String!\n source: KnowledgeSource\n node: KnowledgeNode\n }\n\n type KnowledgePacketItem {\n kind: String!\n id: String!\n title: String!\n summary: String\n uri: String\n reason: String!\n score: Float!\n estimatedTokens: Int!\n related: [String!]!\n evidence: [String!]!\n metadata: JSON\n }\n\n type KnowledgePacket {\n task: String!\n writeScope: [String!]!\n generatedAt: Float!\n detail: KnowledgePacketDetail!\n strategy: String!\n budgetLimit: Int!\n estimatedTokens: Int!\n truncated: Boolean!\n totalCandidates: Int!\n droppedCount: Int!\n droppedForBudget: Int!\n budgetExhausted: Boolean!\n items: [KnowledgePacketItem!]!\n }\n\n type KnowledgeProjectionTarget {\n targetId: String!\n kind: KnowledgeProjectionKind!\n title: String!\n description: String!\n itemId: String\n defaultPath: String!\n defaultFilename: String!\n metadata: JSON\n }\n\n type KnowledgeProjectionPage {\n path: String!\n title: String!\n format: String!\n content: String!\n itemIds: [String!]!\n metadata: JSON\n }\n\n type KnowledgeProjectionBundle {\n id: String!\n target: KnowledgeProjectionTarget!\n generatedAt: Float!\n pageCount: Int!\n pages: [KnowledgeProjectionPage!]!\n metadata: JSON\n }\n\n type ArtifactDescriptor {\n id: String!\n kind: String!\n mimeType: String!\n filename: String\n sizeBytes: Int!\n sourceUri: String\n createdAt: Float!\n metadata: JSON\n }\n\n type KnowledgeJob {\n id: String!\n label: String!\n description: String!\n defaultMode: KnowledgeJobMode!\n triggerKinds: [String!]!\n lastRunAt: Float\n metadata: JSON\n }\n\n type KnowledgeJobRun {\n id: String!\n jobId: String!\n status: String!\n mode: KnowledgeJobMode!\n requestedAt: Float!\n startedAt: Float\n completedAt: Float\n error: String\n result: JSON\n metadata: JSON\n }\n\n type KnowledgeBatchIngestResult {\n imported: Int!\n failed: Int!\n sources: [KnowledgeSource!]!\n errors: [String!]!\n }\n\n type KnowledgeUsageRecord {\n id: String!\n targetKind: String!\n targetId: String!\n usageKind: String!\n task: String\n sessionId: String\n score: Float\n metadata: JSON\n createdAt: Float!\n }\n\n type KnowledgeConsolidationCandidate {\n id: String!\n candidateType: String!\n status: String!\n subjectKind: String!\n subjectId: String!\n title: String!\n summary: String\n score: Float!\n evidence: [String!]!\n suggestedMemoryClass: String\n suggestedScope: String\n decidedAt: Float\n decidedBy: String\n metadata: JSON\n createdAt: Float!\n updatedAt: Float!\n }\n\n type KnowledgeConsolidationReport {\n id: String!\n kind: String!\n title: String!\n summary: String!\n highlights: [String!]!\n metrics: JSON\n metadata: JSON\n createdAt: Float!\n updatedAt: Float!\n }\n\n type KnowledgeSchedule {\n id: String!\n jobId: String!\n label: String!\n enabled: Boolean!\n schedule: JSON!\n lastRunAt: Float\n nextRunAt: Float\n metadata: JSON\n createdAt: Float!\n updatedAt: Float!\n }\n\n input KnowledgeJobRunInput {\n mode: KnowledgeJobMode\n }\n\n input KnowledgePacketInput {\n task: String!\n writeScope: [String!]\n limit: Int\n detail: KnowledgePacketDetail\n budgetLimit: Int\n knowledgeSpaceId: String\n includeAllSpaces: Boolean\n }\n\n type Query {\n status(knowledgeSpaceId: String, includeAllSpaces: Boolean): KnowledgeStatus!\n connectors: [KnowledgeConnector!]!\n connectorDoctor(id: String!): KnowledgeConnectorDoctorReport\n sources(limit: Int, offset: Int, knowledgeSpaceId: String, includeAllSpaces: Boolean): [KnowledgeSource!]!\n nodes(limit: Int, offset: Int, knowledgeSpaceId: String, includeAllSpaces: Boolean): [KnowledgeNode!]!\n issues(limit: Int, offset: Int, knowledgeSpaceId: String, includeAllSpaces: Boolean): [KnowledgeIssue!]!\n itemView(kind: String!, id: String!): KnowledgeItemView\n extractions(limit: Int, sourceId: String, knowledgeSpaceId: String, includeAllSpaces: Boolean): [KnowledgeExtraction!]!\n neighbors(kind: String!, id: String!, relation: String, limit: Int): [KnowledgeEdge!]!\n search(query: String!, limit: Int, knowledgeSpaceId: String, includeAllSpaces: Boolean): [KnowledgeSearchResult!]!\n packet(task: String!, writeScope: [String!], limit: Int, detail: KnowledgePacketDetail, budgetLimit: Int, knowledgeSpaceId: String, includeAllSpaces: Boolean): KnowledgePacket!\n projectionTargets(limit: Int, knowledgeSpaceId: String, includeAllSpaces: Boolean): [KnowledgeProjectionTarget!]!\n projection(kind: KnowledgeProjectionKind!, id: String, limit: Int, knowledgeSpaceId: String, includeAllSpaces: Boolean): KnowledgeProjectionBundle!\n jobs: [KnowledgeJob!]!\n job(id: String!): KnowledgeJob\n jobRuns(limit: Int, jobId: String): [KnowledgeJobRun!]!\n usage(limit: Int, targetKind: String, targetId: String, usageKind: String): [KnowledgeUsageRecord!]!\n usageRecords(limit: Int, targetKind: String, targetId: String, usageKind: String): [KnowledgeUsageRecord!]!\n consolidationCandidates(limit: Int, status: String): [KnowledgeConsolidationCandidate!]!\n consolidationReports(limit: Int): [KnowledgeConsolidationReport!]!\n schedules(limit: Int): [KnowledgeSchedule!]!\n sourceExtraction(sourceId: String!): KnowledgeExtraction\n }\n\n type Mutation {\n ingestUrl(url: String!, sourceType: String, connectorId: String, folderPath: String, tags: [String!], sessionId: String, allowPrivateHosts: Boolean): KnowledgeSource!\n ingestArtifact(path: String!, connectorId: String, tags: [String!], sessionId: String, allowPrivateHosts: Boolean): KnowledgeSource!\n importBookmarksFromFile(path: String!, sessionId: String, allowPrivateHosts: Boolean): KnowledgeBatchIngestResult!\n importUrlsFromFile(path: String!, sessionId: String, allowPrivateHosts: Boolean): KnowledgeBatchIngestResult!\n ingestBookmarkSeeds(seeds: [String!]!, connectorId: String, sessionId: String): KnowledgeBatchIngestResult!\n ingestWithConnector(connectorId: String!, input: String!, sessionId: String, allowPrivateHosts: Boolean): KnowledgeBatchIngestResult!\n ingestConnectorInput(input: String!, connectorId: String, sessionId: String, allowPrivateHosts: Boolean): KnowledgeBatchIngestResult!\n renderProjection(kind: KnowledgeProjectionKind!, id: String, limit: Int, knowledgeSpaceId: String, includeAllSpaces: Boolean): KnowledgeProjectionBundle!\n materializeProjection(kind: KnowledgeProjectionKind!, id: String, limit: Int, knowledgeSpaceId: String, includeAllSpaces: Boolean): KnowledgeMaterializedProjection!\n reindex: KnowledgeStatus!\n runJob(id: String!, mode: KnowledgeJobMode): KnowledgeJobRun!\n saveSchedule(id: String, jobId: String!, label: String!, enabled: Boolean!, schedule: JSON!, metadata: JSON): KnowledgeSchedule!\n deleteSchedule(id: String!): Boolean!\n setScheduleEnabled(id: String!, enabled: Boolean!): KnowledgeSchedule\n decideConsolidationCandidate(id: String!, status: String!, decidedBy: String): KnowledgeConsolidationCandidate!\n lint: [KnowledgeIssue!]!\n }\n\n type KnowledgeMaterializedProjection {\n artifact: ArtifactDescriptor!\n bundle: KnowledgeProjectionBundle!\n }\n"; export declare function parseJsonAst(node: ValueNode): unknown; export declare function installJsonScalar(schema: ReturnType): void; export declare function toProjectionKind(value: string): KnowledgeProjectionTargetKind; export declare function toProjectionEnum(value: string | undefined): string; export declare function toPacketDetail(value: string | undefined): KnowledgePacketDetail; export declare function toPacketDetailEnum(value: string | undefined): string; export declare function toJobMode(value: string | undefined): 'inline' | 'background'; export declare function toJobModeEnum(value: string | undefined): string; export declare function mapProjectionTarget(target: T): T & { kind: string; }; export declare function mapProjectionBundle(bundle: T): T & { target: { kind: string; }; }; export declare function mapPacket(packet: T): T & { detail: string; }; export declare function mapJob(job: T): T & { defaultMode: string; }; export declare function mapJobRun(run: T): T & { mode: string; }; export declare function clampInt(value: number | null | undefined, fallback: number): number; export declare function clampOffset(value: number | null | undefined): number; export declare function pickOperation(document: DocumentNode, operationName?: string): 'query' | 'mutation'; export {}; //# sourceMappingURL=graphql-schema.d.ts.map