@c4a/core 0.4.12-beta.7 → 0.4.15-alpha.1

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.
Files changed (3) hide show
  1. package/README.md +40 -0
  2. package/index.js +283 -56
  3. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @c4a/core
2
+
3
+ `@c4a/core` is the shared foundation package for C4A. It provides reusable types, schemas, error definitions, and utility helpers used across multiple packages.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @c4a/core
9
+ # or
10
+ npm install @c4a/core
11
+ ```
12
+
13
+ ## What It Includes
14
+
15
+ - **Domain types**: common TypeScript types for entities, relations, contents, and sources
16
+ - **Schema definitions**: Zod-based input/output validation models
17
+ - **Error system**: unified error codes and `C4AError`
18
+ - **Ref utilities**: helpers for parsing and building `ref:*` pointers
19
+ - **Shared constants and helpers**: reusable utilities for API, CLI, Daemon, Web, and other packages
20
+
21
+ ## Example
22
+
23
+ ```ts
24
+ import { C4AError, ErrorCode, parseRef } from "@c4a/core";
25
+
26
+ const parsed = parseRef("ref:entity:ent_123");
27
+ if (!parsed) {
28
+ throw new C4AError(ErrorCode.VALIDATION_FAILED, "Invalid ref");
29
+ }
30
+ ```
31
+
32
+ ## Common Use Cases
33
+
34
+ - Reuse a single contract across a monorepo to avoid type drift
35
+ - Validate external inputs with consistent schemas and error handling
36
+ - Parse and build cross-resource reference pointers
37
+
38
+ ## License
39
+
40
+ MIT
package/index.js CHANGED
@@ -7195,7 +7195,8 @@ var DEFAULT_SERVER_CONFIG = {
7195
7195
  openai: {
7196
7196
  api_key: "",
7197
7197
  base_url: "",
7198
- default_model: "gpt-5.3-codex"
7198
+ default_model: "gpt-5.3-codex",
7199
+ wire_api: "chat"
7199
7200
  },
7200
7201
  anthropic: {
7201
7202
  api_key: "",
@@ -10870,23 +10871,23 @@ class ZodEffects extends ZodType {
10870
10871
  }
10871
10872
  if (effect.type === "transform") {
10872
10873
  if (ctx.common.async === false) {
10873
- const base2 = this._def.schema._parseSync({
10874
+ const base = this._def.schema._parseSync({
10874
10875
  data: ctx.data,
10875
10876
  path: ctx.path,
10876
10877
  parent: ctx
10877
10878
  });
10878
- if (!isValid(base2))
10879
+ if (!isValid(base))
10879
10880
  return INVALID;
10880
- const result = effect.transform(base2.value, checkCtx);
10881
+ const result = effect.transform(base.value, checkCtx);
10881
10882
  if (result instanceof Promise) {
10882
10883
  throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
10883
10884
  }
10884
10885
  return { status: status.value, value: result };
10885
10886
  } else {
10886
- return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base2) => {
10887
- if (!isValid(base2))
10887
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
10888
+ if (!isValid(base))
10888
10889
  return INVALID;
10889
- return Promise.resolve(effect.transform(base2.value, checkCtx)).then((result) => ({
10890
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
10890
10891
  status: status.value,
10891
10892
  value: result
10892
10893
  }));
@@ -11300,18 +11301,19 @@ var sourceRefSchema = exports_external.object({
11300
11301
  span: sourceRefSpanSchema.optional()
11301
11302
  });
11302
11303
  var sourceRefsSchema = exports_external.array(sourceRefSchema).optional();
11304
+
11303
11305
  // src/schemas/atomsSchema.ts
11304
11306
  var confidenceAtomSchema = exports_external.number().min(0).max(1).optional();
11305
11307
  var entityAtomSchema = exports_external.object({
11306
11308
  name: exports_external.string(),
11307
- kind: kindSchema.optional(),
11309
+ kind: kindSchema.optional().catch(undefined),
11308
11310
  ref: exports_external.string().optional(),
11309
11311
  confidence: confidenceAtomSchema
11310
11312
  });
11311
11313
  var relationAtomSchema = exports_external.object({
11312
11314
  from: exports_external.string(),
11313
11315
  to: exports_external.string(),
11314
- type: relationTypeSchema,
11316
+ type: exports_external.string(),
11315
11317
  description: exports_external.string().optional(),
11316
11318
  confidence: confidenceAtomSchema
11317
11319
  });
@@ -11384,13 +11386,13 @@ var metricAtomSchema = exports_external.object({
11384
11386
  });
11385
11387
  var roleAtomSchema = exports_external.object({
11386
11388
  name: exports_external.string(),
11387
- kind: exports_external.enum(["human", "team", "persona"]),
11389
+ kind: exports_external.enum(["human", "team", "persona"]).catch("human"),
11388
11390
  performs: exports_external.array(exports_external.string()).optional(),
11389
11391
  description: exports_external.string().optional()
11390
11392
  });
11391
11393
  var constraintAtomSchema = exports_external.object({
11392
11394
  description: exports_external.string(),
11393
- severity: exports_external.enum(["must", "should", "may"]),
11395
+ severity: exports_external.enum(["must", "should", "may"]).catch("must"),
11394
11396
  metric_ref: exports_external.string().optional(),
11395
11397
  confidence: confidenceAtomSchema
11396
11398
  });
@@ -11443,33 +11445,33 @@ var dataAtomsSchema = exports_external.object({
11443
11445
  comparisons: exports_external.array(comparisonAtomSchema).optional(),
11444
11446
  boundaries: exports_external.array(boundaryAtomSchema).optional(),
11445
11447
  claims: exports_external.array(claimAtomSchema).optional()
11446
- }).superRefine((atoms2, ctx) => {
11448
+ }).superRefine((atoms, ctx) => {
11447
11449
  const stateValues = new Set;
11448
11450
  const stateNames = new Set;
11449
- for (const state of atoms2.states ?? []) {
11451
+ for (const state of atoms.states ?? []) {
11450
11452
  stateNames.add(state.name);
11451
11453
  for (const value of state.values) {
11452
11454
  stateValues.add(value);
11453
11455
  }
11454
11456
  }
11455
11457
  const behaviorNames = new Set;
11456
- for (const behavior of atoms2.behaviors ?? []) {
11458
+ for (const behavior of atoms.behaviors ?? []) {
11457
11459
  behaviorNames.add(behavior.name);
11458
11460
  }
11459
11461
  const roleNames = new Set;
11460
- for (const role of atoms2.roles ?? []) {
11462
+ for (const role of atoms.roles ?? []) {
11461
11463
  roleNames.add(role.name);
11462
11464
  }
11463
11465
  const eventNames = new Set;
11464
- for (const event of atoms2.events ?? []) {
11466
+ for (const event of atoms.events ?? []) {
11465
11467
  eventNames.add(event.name);
11466
11468
  }
11467
11469
  const metricNames = new Set;
11468
- for (const metric of atoms2.metrics ?? []) {
11470
+ for (const metric of atoms.metrics ?? []) {
11469
11471
  metricNames.add(metric.name);
11470
11472
  }
11471
- if (atoms2.transitions && atoms2.transitions.length > 0) {
11472
- for (const transition of atoms2.transitions) {
11473
+ if (atoms.transitions && atoms.transitions.length > 0) {
11474
+ for (const transition of atoms.transitions) {
11473
11475
  if (!stateValues.has(transition.from)) {
11474
11476
  ctx.addIssue({
11475
11477
  code: exports_external.ZodIssueCode.custom,
@@ -11499,8 +11501,8 @@ var dataAtomsSchema = exports_external.object({
11499
11501
  }
11500
11502
  }
11501
11503
  }
11502
- if (atoms2.roles && atoms2.roles.length > 0) {
11503
- for (const [index, role] of atoms2.roles.entries()) {
11504
+ if (atoms.roles && atoms.roles.length > 0) {
11505
+ for (const [index, role] of atoms.roles.entries()) {
11504
11506
  for (const perform of role.performs ?? []) {
11505
11507
  if (!behaviorNames.has(perform)) {
11506
11508
  ctx.addIssue({
@@ -11512,8 +11514,8 @@ var dataAtomsSchema = exports_external.object({
11512
11514
  }
11513
11515
  }
11514
11516
  }
11515
- if (atoms2.behaviors && atoms2.behaviors.length > 0) {
11516
- for (const [index, behavior] of atoms2.behaviors.entries()) {
11517
+ if (atoms.behaviors && atoms.behaviors.length > 0) {
11518
+ for (const [index, behavior] of atoms.behaviors.entries()) {
11517
11519
  for (const performer of behavior.performed_by ?? []) {
11518
11520
  if (!roleNames.has(performer)) {
11519
11521
  ctx.addIssue({
@@ -11525,9 +11527,9 @@ var dataAtomsSchema = exports_external.object({
11525
11527
  }
11526
11528
  }
11527
11529
  }
11528
- if (atoms2.rules && atoms2.rules.length > 0) {
11530
+ if (atoms.rules && atoms.rules.length > 0) {
11529
11531
  const allowedDependsOn = new Set([...stateNames, ...metricNames]);
11530
- for (const [index, rule] of atoms2.rules.entries()) {
11532
+ for (const [index, rule] of atoms.rules.entries()) {
11531
11533
  for (const dependency of rule.depends_on ?? []) {
11532
11534
  if (!allowedDependsOn.has(dependency)) {
11533
11535
  ctx.addIssue({
@@ -11539,8 +11541,8 @@ var dataAtomsSchema = exports_external.object({
11539
11541
  }
11540
11542
  }
11541
11543
  }
11542
- if (atoms2.events && atoms2.events.length > 0) {
11543
- for (const [index, event] of atoms2.events.entries()) {
11544
+ if (atoms.events && atoms.events.length > 0) {
11545
+ for (const [index, event] of atoms.events.entries()) {
11544
11546
  for (const behaviorName of event.trigger_for ?? []) {
11545
11547
  if (!behaviorNames.has(behaviorName)) {
11546
11548
  ctx.addIssue({
@@ -11597,10 +11599,10 @@ var atomsWhitelistByEntityType = {
11597
11599
  ["document" /* Document */]: new Set
11598
11600
  };
11599
11601
  var allowedAtomFieldSchema = atomFieldSchema;
11600
- var validateAtomsWhitelist = (entityType, atoms2) => {
11602
+ var validateAtomsWhitelist = (entityType, atoms) => {
11601
11603
  const allowed = atomsWhitelistByEntityType[entityType] ?? new Set;
11602
11604
  const illegalFields = [];
11603
- for (const [key, value] of Object.entries(atoms2)) {
11605
+ for (const [key, value] of Object.entries(atoms)) {
11604
11606
  if (value === undefined) {
11605
11607
  continue;
11606
11608
  }
@@ -11610,6 +11612,60 @@ var validateAtomsWhitelist = (entityType, atoms2) => {
11610
11612
  }
11611
11613
  return illegalFields;
11612
11614
  };
11615
+
11616
+ // src/types/docDigest.ts
11617
+ var paragraphAtomSchema = exports_external.object({
11618
+ entities: exports_external.array(entityAtomSchema).optional(),
11619
+ relations: exports_external.array(relationAtomSchema).optional(),
11620
+ behaviors: exports_external.array(behaviorAtomSchema).optional(),
11621
+ attributes: exports_external.array(attributeAtomSchema).optional(),
11622
+ states: exports_external.array(stateAtomSchema).optional(),
11623
+ rules: exports_external.array(ruleAtomSchema).optional(),
11624
+ transitions: exports_external.array(transitionAtomSchema).optional(),
11625
+ events: exports_external.array(eventAtomSchema).optional(),
11626
+ decisions: exports_external.array(decisionAtomSchema).optional(),
11627
+ metrics: exports_external.array(metricAtomSchema).optional(),
11628
+ roles: exports_external.array(roleAtomSchema).optional(),
11629
+ constraints: exports_external.array(constraintAtomSchema).optional(),
11630
+ comparisons: exports_external.array(comparisonAtomSchema).optional(),
11631
+ boundaries: exports_external.array(boundaryAtomSchema).optional()
11632
+ });
11633
+ var docParagraphSchema = exports_external.object({
11634
+ text: exports_external.string(),
11635
+ atoms: paragraphAtomSchema
11636
+ });
11637
+ var sectionSchema = exports_external.object({
11638
+ heading: exports_external.string(),
11639
+ level: exports_external.number().int().min(0).max(6),
11640
+ paragraphs: exports_external.array(docParagraphSchema)
11641
+ });
11642
+ var embeddingEntrySchema = exports_external.object({
11643
+ sectionIndex: exports_external.number().int(),
11644
+ paragraphIndex: exports_external.number().int(),
11645
+ vector: exports_external.array(exports_external.number())
11646
+ });
11647
+ var docDigestSchema = exports_external.object({
11648
+ version: exports_external.literal("1"),
11649
+ sections: exports_external.array(sectionSchema),
11650
+ embeddings: exports_external.array(embeddingEntrySchema),
11651
+ metadata: exports_external.object({
11652
+ sourceId: exports_external.string(),
11653
+ hashId: exports_external.string(),
11654
+ sourcePath: exports_external.string(),
11655
+ contentHash: exports_external.string(),
11656
+ chunkCount: exports_external.number().int(),
11657
+ totalTokens: exports_external.number().int(),
11658
+ llmCalls: exports_external.number().int(),
11659
+ processedAt: exports_external.string()
11660
+ })
11661
+ });
11662
+ var docChunkParagraphSchema = exports_external.object({
11663
+ tag: exports_external.string().regex(/^P\d+$/),
11664
+ atoms: paragraphAtomSchema
11665
+ });
11666
+ var docChunkResultSchema = exports_external.object({
11667
+ paragraphs: exports_external.array(docChunkParagraphSchema)
11668
+ });
11613
11669
  // src/schemas/entitySchema.ts
11614
11670
  var baseEntitySchema = exports_external.object({
11615
11671
  id: exports_external.string(),
@@ -11853,8 +11909,36 @@ var ErrorCode;
11853
11909
  ErrorCode2["LLM_NOT_AVAILABLE"] = "LLM_NOT_AVAILABLE";
11854
11910
  ErrorCode2["LLM_CALL_FAILED"] = "LLM_CALL_FAILED";
11855
11911
  ErrorCode2["LLM_AUTH_FAILED"] = "LLM_AUTH_FAILED";
11912
+ ErrorCode2["AUTH_REQUIRED"] = "AUTH_REQUIRED";
11913
+ ErrorCode2["AUTH_INVALID_TOKEN"] = "AUTH_INVALID_TOKEN";
11914
+ ErrorCode2["AUTH_INVALID_API_KEY"] = "AUTH_INVALID_API_KEY";
11915
+ ErrorCode2["AUTH_PROVIDER_ERROR"] = "AUTH_PROVIDER_ERROR";
11916
+ ErrorCode2["AUTH_RESERVED_NAME"] = "AUTH_RESERVED_NAME";
11917
+ ErrorCode2["DAEMON_OFFLINE"] = "DAEMON_OFFLINE";
11918
+ ErrorCode2["SOURCE_NOT_FOUND"] = "SOURCE_NOT_FOUND";
11919
+ ErrorCode2["REPO_PATH_NOT_FOUND"] = "REPO_PATH_NOT_FOUND";
11920
+ ErrorCode2["COMMIT_NOT_FOUND"] = "COMMIT_NOT_FOUND";
11921
+ ErrorCode2["INDEX_IN_PROGRESS"] = "INDEX_IN_PROGRESS";
11922
+ ErrorCode2["DIGEST_NOT_FOUND"] = "DIGEST_NOT_FOUND";
11923
+ ErrorCode2["INVALID_REGEX"] = "INVALID_REGEX";
11924
+ ErrorCode2["SOURCE_ACCESS_DENIED"] = "SOURCE_ACCESS_DENIED";
11925
+ ErrorCode2["WORKSPACE_ISOLATION"] = "WORKSPACE_ISOLATION";
11856
11926
  ErrorCode2["VECTOR_DIMENSION_MISMATCH"] = "VECTOR_DIMENSION_MISMATCH";
11857
11927
  ErrorCode2["VECTOR_REBUILD_PARTIAL"] = "VECTOR_REBUILD_PARTIAL";
11928
+ ErrorCode2["COMMIT_NOT_AVAILABLE"] = "COMMIT_NOT_AVAILABLE";
11929
+ ErrorCode2["DAEMON_AUTO_START_FAILED"] = "DAEMON_AUTO_START_FAILED";
11930
+ ErrorCode2["GIT_ARCHIVE_FAILED"] = "GIT_ARCHIVE_FAILED";
11931
+ ErrorCode2["GIT_HOST_NOT_CONFIGURED"] = "GIT_HOST_NOT_CONFIGURED";
11932
+ ErrorCode2["GIT_API_RATE_LIMITED"] = "GIT_API_RATE_LIMITED";
11933
+ ErrorCode2["GIT_API_TREE_TRUNCATED"] = "GIT_API_TREE_TRUNCATED";
11934
+ ErrorCode2["GIT_API_AUTH_FAILED"] = "GIT_API_AUTH_FAILED";
11935
+ ErrorCode2["GIT_API_REPO_NOT_FOUND"] = "GIT_API_REPO_NOT_FOUND";
11936
+ ErrorCode2["GIT_API_NETWORK_ERROR"] = "GIT_API_NETWORK_ERROR";
11937
+ ErrorCode2["DOC_INDEX_LLM_UNAVAILABLE"] = "DOC_INDEX_LLM_UNAVAILABLE";
11938
+ ErrorCode2["DOC_INDEX_EMBEDDING_UNAVAILABLE"] = "DOC_INDEX_EMBEDDING_UNAVAILABLE";
11939
+ ErrorCode2["DOC_INDEX_CONTENT_MISSING"] = "DOC_INDEX_CONTENT_MISSING";
11940
+ ErrorCode2["DOC_INDEX_PARSE_FAILED"] = "DOC_INDEX_PARSE_FAILED";
11941
+ ErrorCode2["DOC_INDEX_LLM_EXHAUSTED"] = "DOC_INDEX_LLM_EXHAUSTED";
11858
11942
  ErrorCode2["UNKNOWN"] = "UNKNOWN";
11859
11943
  })(ErrorCode ||= {});
11860
11944
  // src/errors/httpStatus.ts
@@ -11865,29 +11949,57 @@ var ERROR_CODE_HTTP_STATUS = {
11865
11949
  ["PARSE_YAML" /* PARSE_YAML */]: 400,
11866
11950
  ["RELATION_INVALID" /* RELATION_INVALID */]: 400,
11867
11951
  ["QUERY_INVALID_PARAMS" /* QUERY_INVALID_PARAMS */]: 400,
11952
+ ["INVALID_REGEX" /* INVALID_REGEX */]: 400,
11868
11953
  ["BACKUP_VERSION_INCOMPATIBLE" /* BACKUP_VERSION_INCOMPATIBLE */]: 400,
11869
11954
  ["BACKUP_MANIFEST_INVALID" /* BACKUP_MANIFEST_INVALID */]: 400,
11870
11955
  ["VECTOR_DIMENSION_MISMATCH" /* VECTOR_DIMENSION_MISMATCH */]: 400,
11871
11956
  ["STORAGE_NOT_FOUND" /* STORAGE_NOT_FOUND */]: 404,
11872
11957
  ["ENTITY_NOT_FOUND" /* ENTITY_NOT_FOUND */]: 404,
11873
11958
  ["BACKUP_DIR_NOT_FOUND" /* BACKUP_DIR_NOT_FOUND */]: 404,
11959
+ ["SOURCE_NOT_FOUND" /* SOURCE_NOT_FOUND */]: 404,
11960
+ ["DIGEST_NOT_FOUND" /* DIGEST_NOT_FOUND */]: 404,
11874
11961
  ["STORAGE_CONFLICT" /* STORAGE_CONFLICT */]: 409,
11875
11962
  ["ENTITY_DUPLICATE" /* ENTITY_DUPLICATE */]: 409,
11963
+ ["INDEX_IN_PROGRESS" /* INDEX_IN_PROGRESS */]: 409,
11876
11964
  ["API_UNAUTHORIZED" /* API_UNAUTHORIZED */]: 401,
11877
11965
  ["LLM_AUTH_FAILED" /* LLM_AUTH_FAILED */]: 401,
11966
+ ["AUTH_REQUIRED" /* AUTH_REQUIRED */]: 401,
11967
+ ["AUTH_INVALID_TOKEN" /* AUTH_INVALID_TOKEN */]: 401,
11968
+ ["AUTH_INVALID_API_KEY" /* AUTH_INVALID_API_KEY */]: 401,
11969
+ ["AUTH_RESERVED_NAME" /* AUTH_RESERVED_NAME */]: 400,
11970
+ ["SOURCE_ACCESS_DENIED" /* SOURCE_ACCESS_DENIED */]: 403,
11971
+ ["REPO_PATH_NOT_FOUND" /* REPO_PATH_NOT_FOUND */]: 422,
11972
+ ["COMMIT_NOT_FOUND" /* COMMIT_NOT_FOUND */]: 422,
11973
+ ["COMMIT_NOT_AVAILABLE" /* COMMIT_NOT_AVAILABLE */]: 422,
11974
+ ["GIT_HOST_NOT_CONFIGURED" /* GIT_HOST_NOT_CONFIGURED */]: 422,
11975
+ ["GIT_API_TREE_TRUNCATED" /* GIT_API_TREE_TRUNCATED */]: 422,
11878
11976
  ["API_RATE_LIMITED" /* API_RATE_LIMITED */]: 429,
11977
+ ["GIT_API_RATE_LIMITED" /* GIT_API_RATE_LIMITED */]: 429,
11879
11978
  ["API_NOT_IMPLEMENTED" /* API_NOT_IMPLEMENTED */]: 501,
11880
11979
  ["BATCH_PARTIAL_FAILURE" /* BATCH_PARTIAL_FAILURE */]: 200,
11881
11980
  ["VECTOR_REBUILD_PARTIAL" /* VECTOR_REBUILD_PARTIAL */]: 200,
11882
11981
  ["STORAGE_FAILED" /* STORAGE_FAILED */]: 500,
11883
11982
  ["EMBEDDING_FAILED" /* EMBEDDING_FAILED */]: 500,
11884
11983
  ["LLM_CALL_FAILED" /* LLM_CALL_FAILED */]: 500,
11984
+ ["GIT_API_NETWORK_ERROR" /* GIT_API_NETWORK_ERROR */]: 502,
11885
11985
  ["BACKUP_FAILED" /* BACKUP_FAILED */]: 500,
11886
11986
  ["RESTORE_FAILED" /* RESTORE_FAILED */]: 500,
11887
11987
  ["PURGE_FAILED" /* PURGE_FAILED */]: 500,
11988
+ ["GIT_ARCHIVE_FAILED" /* GIT_ARCHIVE_FAILED */]: 500,
11888
11989
  ["EMBEDDING_NOT_AVAILABLE" /* EMBEDDING_NOT_AVAILABLE */]: 503,
11889
11990
  ["LLM_NOT_AVAILABLE" /* LLM_NOT_AVAILABLE */]: 503,
11890
- ["UNKNOWN" /* UNKNOWN */]: 500
11991
+ ["DAEMON_OFFLINE" /* DAEMON_OFFLINE */]: 503,
11992
+ ["DAEMON_AUTO_START_FAILED" /* DAEMON_AUTO_START_FAILED */]: 503,
11993
+ ["GIT_API_AUTH_FAILED" /* GIT_API_AUTH_FAILED */]: 502,
11994
+ ["GIT_API_REPO_NOT_FOUND" /* GIT_API_REPO_NOT_FOUND */]: 404,
11995
+ ["AUTH_PROVIDER_ERROR" /* AUTH_PROVIDER_ERROR */]: 502,
11996
+ ["DOC_INDEX_LLM_UNAVAILABLE" /* DOC_INDEX_LLM_UNAVAILABLE */]: 503,
11997
+ ["DOC_INDEX_EMBEDDING_UNAVAILABLE" /* DOC_INDEX_EMBEDDING_UNAVAILABLE */]: 503,
11998
+ ["DOC_INDEX_CONTENT_MISSING" /* DOC_INDEX_CONTENT_MISSING */]: 404,
11999
+ ["DOC_INDEX_PARSE_FAILED" /* DOC_INDEX_PARSE_FAILED */]: 422,
12000
+ ["DOC_INDEX_LLM_EXHAUSTED" /* DOC_INDEX_LLM_EXHAUSTED */]: 502,
12001
+ ["UNKNOWN" /* UNKNOWN */]: 500,
12002
+ ["WORKSPACE_ISOLATION" /* WORKSPACE_ISOLATION */]: 400
11891
12003
  };
11892
12004
  function mapErrorCodeToStatus(code) {
11893
12005
  return ERROR_CODE_HTTP_STATUS[code] ?? 500;
@@ -11944,32 +12056,134 @@ function parseYaml(value) {
11944
12056
  }
11945
12057
  }
11946
12058
  // src/constants.ts
11947
- var DEFAULT_USER_ID = "user_admin";
11948
- var DEFAULT_USER_NAME = "admin";
11949
- var DEFAULT_WORKSPACE_ID = "ws_default";
11950
- var DEFAULT_WORKSPACE_NAME = "默认大脑";
11951
- var DEFAULT_CLOUD_LIBRARY_ID = "lib_cloud_default";
11952
- var DEFAULT_CLOUD_LIBRARY_NAME = "个人云";
12059
+ var DEFAULT_WORKSPACE_NAME = "My Brain";
12060
+ var DEFAULT_CLOUD_LIBRARY_NAME = "My Drive";
12061
+ var SUPERTEST_EMAIL = "supertest@context4ai.org";
12062
+ var SUPERTEST_USER_NAME = "SuperTest";
12063
+ var RESERVED_USER_NAMES = ["SuperTest"];
11953
12064
  var DAEMON_HEARTBEAT_INTERVAL = 30000;
11954
12065
  var DAEMON_OFFLINE_THRESHOLD = 60000;
11955
12066
  var CLOUD_DAEMON_IDLE_TIMEOUT = 300000;
12067
+ // src/contentTypeRegistry.ts
12068
+ var DEFAULT_CONTENT_TYPES = [
12069
+ {
12070
+ id: "markdown",
12071
+ category: "doc",
12072
+ match: { extensions: [".md", ".txt"] },
12073
+ cas: { encoding: "utf8", hashInput: "content" },
12074
+ pipeline: { digest: ["summary", "outline"], extraction: ["entities", "relations"] },
12075
+ display: { icon: "\uD83D\uDCC4", renderer: "text" }
12076
+ },
12077
+ {
12078
+ id: "typescript",
12079
+ category: "code",
12080
+ match: { extensions: [".ts", ".tsx"] },
12081
+ cas: { encoding: "utf8", hashInput: "content" },
12082
+ pipeline: { digest: ["ast", "summary"], extraction: ["entities", "relations"] },
12083
+ display: { icon: "\uD83D\uDCDC", renderer: "code" }
12084
+ },
12085
+ {
12086
+ id: "package",
12087
+ category: "package",
12088
+ match: { filenames: ["package.json", "go.mod", "pyproject.toml", "Cargo.toml", "pom.xml"] },
12089
+ cas: { encoding: "utf8", hashInput: "identity" },
12090
+ pipeline: { digest: ["summary"], extraction: ["entities", "relations"] },
12091
+ display: { icon: "\uD83D\uDCE6", renderer: "package-card" }
12092
+ },
12093
+ {
12094
+ id: "pdf",
12095
+ category: "binary",
12096
+ match: { extensions: [".pdf"] },
12097
+ cas: { encoding: "base64", hashInput: "content" },
12098
+ pipeline: { digest: [], extraction: [] },
12099
+ display: { icon: "\uD83D\uDCD5", renderer: "binary-preview" }
12100
+ },
12101
+ {
12102
+ id: "msword",
12103
+ category: "binary",
12104
+ match: { extensions: [".doc", ".docx"] },
12105
+ cas: { encoding: "base64", hashInput: "content" },
12106
+ pipeline: { digest: [], extraction: [] },
12107
+ display: { icon: "\uD83D\uDCD8", renderer: "binary-preview" }
12108
+ },
12109
+ {
12110
+ id: "mspowerpoint",
12111
+ category: "binary",
12112
+ match: { extensions: [".ppt", ".pptx"] },
12113
+ cas: { encoding: "base64", hashInput: "content" },
12114
+ pipeline: { digest: [], extraction: [] },
12115
+ display: { icon: "\uD83D\uDCD9", renderer: "binary-preview" }
12116
+ }
12117
+ ];
12118
+ var normalizeExtension = (ext) => ext.trim().toLowerCase();
12119
+ var normalizeFilename = (name) => name.trim().toLowerCase();
12120
+
12121
+ class ContentTypeRegistry {
12122
+ definitions;
12123
+ extensionIndex;
12124
+ filenameIndex;
12125
+ constructor(definitions) {
12126
+ this.definitions = definitions;
12127
+ this.extensionIndex = new Map;
12128
+ this.filenameIndex = new Map;
12129
+ for (const def of definitions) {
12130
+ for (const ext of def.match.extensions ?? []) {
12131
+ this.extensionIndex.set(normalizeExtension(ext), def);
12132
+ }
12133
+ for (const name of def.match.filenames ?? []) {
12134
+ this.filenameIndex.set(normalizeFilename(name), def);
12135
+ }
12136
+ }
12137
+ }
12138
+ resolve(filename) {
12139
+ const baseName = filename.includes("/") ? filename.split("/").pop() ?? filename : filename;
12140
+ const normalized = normalizeFilename(baseName);
12141
+ const byName = this.filenameIndex.get(normalized);
12142
+ if (byName)
12143
+ return byName;
12144
+ const dot = normalized.lastIndexOf(".");
12145
+ if (dot < 0)
12146
+ return null;
12147
+ const ext = normalizeExtension(normalized.slice(dot));
12148
+ return this.extensionIndex.get(ext) ?? null;
12149
+ }
12150
+ getManifestFilenames() {
12151
+ const names = new Set;
12152
+ for (const def of this.definitions) {
12153
+ if (def.category !== "package")
12154
+ continue;
12155
+ for (const name of def.match.filenames ?? []) {
12156
+ names.add(normalizeFilename(name));
12157
+ }
12158
+ }
12159
+ return Array.from(names);
12160
+ }
12161
+ getDefinitions() {
12162
+ return [...this.definitions];
12163
+ }
12164
+ }
12165
+ var defaultRegistry = new ContentTypeRegistry(DEFAULT_CONTENT_TYPES);
12166
+ var DEFAULT_CONTENT_TYPE_DEFINITIONS = DEFAULT_CONTENT_TYPES;
11956
12167
  // src/fileTypes.ts
11957
- var INDEXABLE_CODE_EXTENSIONS = new Set([".ts", ".tsx"]);
11958
- var INDEXABLE_DOC_EXTENSIONS = new Set([".md"]);
12168
+ var collectExtensions = (predicate) => {
12169
+ const extensions = new Set;
12170
+ for (const definition of DEFAULT_CONTENT_TYPE_DEFINITIONS) {
12171
+ if (!predicate(definition))
12172
+ continue;
12173
+ for (const ext of definition.match.extensions ?? []) {
12174
+ extensions.add(ext.toLowerCase());
12175
+ }
12176
+ }
12177
+ return extensions;
12178
+ };
12179
+ var INDEXABLE_CODE_EXTENSIONS = collectExtensions((definition) => definition.category === "code");
12180
+ var INDEXABLE_DOC_EXTENSIONS = collectExtensions((definition) => definition.category === "doc");
11959
12181
  var INDEXABLE_EXTENSIONS = new Set([
11960
12182
  ...INDEXABLE_CODE_EXTENSIONS,
11961
12183
  ...INDEXABLE_DOC_EXTENSIONS
11962
12184
  ]);
11963
- var UPLOAD_ALLOWED_EXTENSIONS = new Set([
11964
- ".md",
11965
- ".doc",
11966
- ".docx",
11967
- ".pdf",
11968
- ".ppt",
11969
- ".pptx",
11970
- ".txt"
11971
- ]);
11972
- var TEXT_EXTENSIONS = new Set([".md", ".txt"]);
12185
+ var UPLOAD_ALLOWED_EXTENSIONS = collectExtensions(() => true);
12186
+ var TEXT_EXTENSIONS = collectExtensions((definition) => definition.cas.encoding === "utf8");
11973
12187
  var UPLOAD_MAX_FILE_SIZE = 5 * 1024 * 1024;
11974
12188
  var UPLOAD_MAX_FILES = 10;
11975
12189
  function getFileExtension(name) {
@@ -11978,10 +12192,7 @@ function getFileExtension(name) {
11978
12192
  }
11979
12193
  function isIndexableFile(fileName, manifestFiles) {
11980
12194
  const baseName = fileName.includes("/") ? fileName.split("/").pop() : fileName;
11981
- if (manifestFiles.has(baseName.toLowerCase()))
11982
- return true;
11983
- const ext = getFileExtension(baseName);
11984
- return INDEXABLE_EXTENSIONS.has(ext);
12195
+ return defaultRegistry.resolve(baseName) !== null;
11985
12196
  }
11986
12197
  // src/wsEvents.ts
11987
12198
  var WS_SESSION_STATUS = "ws:session:status";
@@ -11992,6 +12203,10 @@ var WS_DAEMON_CONNECTED = "ws:daemon:connected";
11992
12203
  var WS_DAEMON_STATUS = "ws:daemon:status";
11993
12204
  var WS_DAEMON_HEARTBEAT = "ws:daemon:heartbeat";
11994
12205
  var WS_LIBRARY_UPDATED = "ws:library:updated";
12206
+ var WS_INDEX_PROGRESS = "index/progress";
12207
+ var WS_INDEX_DONE = "index/done";
12208
+ var WS_INDEX_ERROR = "index/error";
12209
+ var WS_INDEX_TIMEOUT = "index/timeout";
11995
12210
  export {
11996
12211
  validateAtomsWhitelist,
11997
12212
  transitionAtomSchema,
@@ -12003,6 +12218,7 @@ export {
12003
12218
  sorEntitySchema,
12004
12219
  sessionDecisionSchema,
12005
12220
  serializeYaml,
12221
+ sectionSchema,
12006
12222
  scopeSchema,
12007
12223
  ruleAtomSchema,
12008
12224
  roleAtomSchema,
@@ -12015,6 +12231,7 @@ export {
12015
12231
  perspectiveSchema,
12016
12232
  parseYaml,
12017
12233
  parseRef,
12234
+ paragraphAtomSchema,
12018
12235
  modelingSessionDataSchema,
12019
12236
  metricMilestoneSchema,
12020
12237
  metricAtomSchema,
@@ -12036,10 +12253,15 @@ export {
12036
12253
  entitySchema,
12037
12254
  entityRefPointerSchema,
12038
12255
  entityAtomSchema,
12256
+ embeddingEntrySchema,
12039
12257
  documentSchema,
12040
12258
  documentModelingEntitySchema,
12041
12259
  documentEntitySchema,
12042
12260
  documentAdrEntitySchema,
12261
+ docDigestSchema,
12262
+ docChunkResultSchema,
12263
+ docChunkParagraphSchema,
12264
+ defaultRegistry,
12043
12265
  decisionPhaseSchema,
12044
12266
  decisionAtomSchema,
12045
12267
  dataAtomsSchema,
@@ -12064,6 +12286,10 @@ export {
12064
12286
  WS_SESSION_STATUS,
12065
12287
  WS_SESSION_PROGRESS,
12066
12288
  WS_LIBRARY_UPDATED,
12289
+ WS_INDEX_TIMEOUT,
12290
+ WS_INDEX_PROGRESS,
12291
+ WS_INDEX_ERROR,
12292
+ WS_INDEX_DONE,
12067
12293
  WS_DAEMON_STATUS,
12068
12294
  WS_DAEMON_HEARTBEAT,
12069
12295
  WS_DAEMON_HANDSHAKE_ACK,
@@ -12073,7 +12299,10 @@ export {
12073
12299
  UPLOAD_MAX_FILES,
12074
12300
  UPLOAD_ALLOWED_EXTENSIONS,
12075
12301
  TEXT_EXTENSIONS,
12302
+ SUPERTEST_USER_NAME,
12303
+ SUPERTEST_EMAIL,
12076
12304
  RelationType,
12305
+ RESERVED_USER_NAMES,
12077
12306
  Perspective,
12078
12307
  Kind,
12079
12308
  INDEXABLE_EXTENSIONS,
@@ -12083,14 +12312,12 @@ export {
12083
12312
  EntityType,
12084
12313
  EDGE_SYNC_RULES,
12085
12314
  DEFAULT_WORKSPACE_NAME,
12086
- DEFAULT_WORKSPACE_ID,
12087
- DEFAULT_USER_NAME,
12088
- DEFAULT_USER_ID,
12089
12315
  DEFAULT_SERVER_CONFIG,
12316
+ DEFAULT_CONTENT_TYPE_DEFINITIONS,
12090
12317
  DEFAULT_CLOUD_LIBRARY_NAME,
12091
- DEFAULT_CLOUD_LIBRARY_ID,
12092
12318
  DAEMON_OFFLINE_THRESHOLD,
12093
12319
  DAEMON_HEARTBEAT_INTERVAL,
12320
+ ContentTypeRegistry,
12094
12321
  CODE_PACKAGE_FILES,
12095
12322
  CLOUD_DAEMON_IDLE_TIMEOUT,
12096
12323
  C4AError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c4a/core",
3
- "version": "0.4.12-beta.7",
3
+ "version": "0.4.15-alpha.1",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "yaml": "^2.4.5",