dirac-lang 0.1.32 → 0.1.33

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/README.md CHANGED
@@ -255,3 +255,31 @@ npm install -g dirac-lang
255
255
  ---
256
256
 
257
257
  *"In the quantum realm, a bra meets a ket to produce reality. In Dirac, a declaration meets an LLM to produce execution."*
258
+
259
+ ## PAUL: The Human-Friendly Dirac Dialect
260
+
261
+ Dirac’s XML-based language is designed for robust machine execution and symbolic reasoning. For human authors, we introduce **PAUL** (Programming AI Utility Language)—a concise, bra/ket-inspired notation for writing Dirac programs quickly and intuitively.
262
+
263
+ - PAUL uses bra/ket syntax and positional arguments for readability.
264
+ - It is ideal for human editing, rapid prototyping, and LLM prompts.
265
+ - PAUL scripts are typically saved with the `.bk` extension.
266
+ - The Dirac interpreter translates PAUL to XML Dirac for execution.
267
+
268
+ **Example:**
269
+
270
+ PAUL (.bk):
271
+ ```
272
+ |greet Alice>
273
+ ```
274
+
275
+ Dirac XML (.di):
276
+ ```xml
277
+ <greet name="Alice" />
278
+ ```
279
+
280
+ **Note:**
281
+ - PAUL relies on conventions for mapping positional arguments to named parameters.
282
+ - For machine execution, always convert PAUL to XML Dirac.
283
+ - The `.bk` extension is recommended for PAUL scripts.
284
+
285
+ PAUL is the human-centric dialect of Dirac—optimized for clarity, speed, and LLM interaction.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-YRJ3SODI.js";
3
+ } from "./chunk-HPGONBNW.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
@@ -8,7 +8,7 @@ import {
8
8
  createSession,
9
9
  getAvailableSubroutines,
10
10
  getOutput
11
- } from "./chunk-JIWLKB5O.js";
11
+ } from "./chunk-GLXVY235.js";
12
12
 
13
13
  // src/utils/llm-adapter.ts
14
14
  function createLLMAdapter(session) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  registerSubroutine
3
- } from "./chunk-JIWLKB5O.js";
3
+ } from "./chunk-GLXVY235.js";
4
4
 
5
5
  // src/tags/subroutine.ts
6
6
  function executeSubroutine(session, element) {
@@ -51,6 +51,38 @@ var OllamaProvider = class {
51
51
  }
52
52
  };
53
53
 
54
+ // src/llm/custom.ts
55
+ var CustomLLMProvider = class {
56
+ client;
57
+ model;
58
+ constructor(options = {}) {
59
+ this.client = new CustomLLMClient(options);
60
+ this.model = options.model || "default";
61
+ }
62
+ async complete(prompt, opts = {}) {
63
+ const messages = opts.messages || [
64
+ { role: "user", content: prompt }
65
+ ];
66
+ return await this.client.chat({ messages });
67
+ }
68
+ };
69
+ var CustomLLMClient = class {
70
+ baseUrl;
71
+ constructor({ baseUrl = "http://localhost:5001" } = {}) {
72
+ this.baseUrl = baseUrl;
73
+ }
74
+ async chat({ messages }) {
75
+ const prompt = messages.map((m) => `${m.role}: ${m.content}`).join("\n");
76
+ const res = await fetch(`${this.baseUrl}/chat`, {
77
+ method: "POST",
78
+ headers: { "Content-Type": "application/json" },
79
+ body: JSON.stringify({ message: prompt })
80
+ });
81
+ const data = await res.json();
82
+ return data.response;
83
+ }
84
+ };
85
+
54
86
  // src/runtime/session.ts
55
87
  function substituteAttribute(session, value) {
56
88
  if (typeof value !== "string") return value;
@@ -81,8 +113,12 @@ function createSession(config = {}) {
81
113
  if (!openaiKey) throw new Error("OPENAI_API_KEY required for OpenAI provider");
82
114
  llmClient = new OpenAI({ apiKey: openaiKey });
83
115
  break;
116
+ case "custom":
117
+ const customBaseUrl = config.customLLMUrl || process.env.CUSTOM_LLM_URL || "http://localhost:5001";
118
+ llmClient = new CustomLLMProvider({ baseUrl: customBaseUrl, model: ollamaModel });
119
+ break;
84
120
  default:
85
- throw new Error(`Unknown LLM provider: ${llmProvider}. Use 'ollama', 'anthropic', or 'openai'.`);
121
+ throw new Error(`Unknown LLM provider: ${llmProvider}. Use 'ollama', 'anthropic', 'openai', or 'custom'.`);
86
122
  }
87
123
  }
88
124
  return {
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-HRHAMPOB.js";
4
4
  import {
5
5
  executeSubroutine
6
- } from "./chunk-JMUUPZZA.js";
6
+ } from "./chunk-4QLTSCDG.js";
7
7
  import {
8
8
  cleanSubroutinesToBoundary,
9
9
  cleanToBoundary,
@@ -25,7 +25,7 @@ import {
25
25
  substituteVariables,
26
26
  throwException,
27
27
  unsetExceptionBoundary
28
- } from "./chunk-JIWLKB5O.js";
28
+ } from "./chunk-GLXVY235.js";
29
29
 
30
30
  // src/tags/parameters.ts
31
31
  async function executeParameters(session, element) {
@@ -257,7 +257,7 @@ async function executeCall(session, element) {
257
257
  }
258
258
  }
259
259
  async function registerExtendChain(session, subroutine, currentName) {
260
- const { executeSubroutine: executeSubroutine2 } = await import("./subroutine-I5XXJMFL.js");
260
+ const { executeSubroutine: executeSubroutine2 } = await import("./subroutine-V4D4LQIH.js");
261
261
  const extendsAttr = subroutine.attributes.extends;
262
262
  let parentName;
263
263
  if (extendsAttr) {
@@ -425,12 +425,12 @@ async function executeIf(session, element) {
425
425
  const condition = await evaluatePredicate(session, conditionElement);
426
426
  if (condition) {
427
427
  if (thenElement) {
428
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
428
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-F65BCAYX.js");
429
429
  await integrateChildren2(session, thenElement);
430
430
  }
431
431
  } else {
432
432
  if (elseElement) {
433
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
433
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-F65BCAYX.js");
434
434
  await integrateChildren2(session, elseElement);
435
435
  }
436
436
  }
@@ -443,7 +443,7 @@ async function evaluatePredicate(session, predicateElement) {
443
443
  return await evaluateCondition(session, predicateElement);
444
444
  }
445
445
  const outputLengthBefore = session.output.length;
446
- const { integrate: integrate2 } = await import("./interpreter-WP3KMLST.js");
446
+ const { integrate: integrate2 } = await import("./interpreter-F65BCAYX.js");
447
447
  await integrate2(session, predicateElement);
448
448
  const newOutputChunks = session.output.slice(outputLengthBefore);
449
449
  const result = newOutputChunks.join("").trim();
@@ -466,11 +466,11 @@ async function evaluateCondition(session, condElement) {
466
466
  }
467
467
  const outputLengthBefore = session.output.length;
468
468
  const args = [];
469
- const { integrate: integrate2 } = await import("./interpreter-WP3KMLST.js");
469
+ const { integrate: integrate2 } = await import("./interpreter-F65BCAYX.js");
470
470
  for (const child of condElement.children) {
471
471
  if (child.tag.toLowerCase() === "arg") {
472
472
  const argOutputStart = session.output.length;
473
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
473
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-F65BCAYX.js");
474
474
  await integrateChildren2(session, child);
475
475
  const newChunks = session.output.slice(argOutputStart);
476
476
  const argValue = newChunks.join("");
@@ -531,7 +531,7 @@ function evaluateConditionType(evalType, args) {
531
531
  // src/tags/llm.ts
532
532
  async function executeLLM(session, element) {
533
533
  if (!session.llmClient) {
534
- throw new Error("<llm> tag requires LLM configuration. Set LLM_PROVIDER (ollama/anthropic/openai) and appropriate API keys in environment or config.yml");
534
+ throw new Error("<llm> tag requires LLM configuration. Set LLM_PROVIDER (ollama/anthropic/openai/custom) and appropriate API keys in environment or config.yml");
535
535
  }
536
536
  if (session.limits.currentLLMCalls >= session.limits.maxLLMCalls) {
537
537
  throw new Error("Maximum LLM calls exceeded");
@@ -540,7 +540,8 @@ async function executeLLM(session, element) {
540
540
  const providerName = session.llmClient.constructor.name;
541
541
  const isOpenAI = providerName === "OpenAI";
542
542
  const isOllama = providerName === "OllamaProvider";
543
- const defaultModel = isOpenAI ? "gpt-4.1-2025-04-14" : isOllama ? "llama2" : "claude-sonnet-4-20250514";
543
+ const isCustom = providerName === "CustomLLMProvider";
544
+ const defaultModel = isOpenAI ? "gpt-4.1-2025-04-14" : isOllama ? "llama2" : isCustom ? "custom-model" : "claude-sonnet-4-20250514";
544
545
  const model = element.attributes.model || process.env.DEFAULT_MODEL || defaultModel;
545
546
  const outputVar = element.attributes.output;
546
547
  const contextVar = element.attributes.context;
@@ -579,7 +580,7 @@ async function executeLLM(session, element) {
579
580
  console.error("[LLM] Full prompt sent to LLM (noextra):\n" + prompt + "\n");
580
581
  }
581
582
  } else {
582
- const { getAvailableSubroutines } = await import("./session-UIWHLPTR.js");
583
+ const { getAvailableSubroutines } = await import("./session-UBATJEND.js");
583
584
  const subroutines = getAvailableSubroutines(session);
584
585
  if (session.debug) {
585
586
  console.error(
@@ -647,6 +648,14 @@ then you call it like
647
648
  temperature,
648
649
  max_tokens: maxTokens
649
650
  });
651
+ } else if (isCustom) {
652
+ const customPrompt = dialogHistory.map((m) => `${m.role}: ${m.content}`).join("\n");
653
+ result = await session.llmClient.complete(customPrompt, {
654
+ model,
655
+ temperature,
656
+ max_tokens: maxTokens,
657
+ messages: dialogHistory
658
+ });
650
659
  } else {
651
660
  const response = await session.llmClient.messages.create({
652
661
  model,
@@ -706,7 +715,7 @@ ${result}
706
715
  const parser = new DiracParser();
707
716
  let dynamicAST = parser.parse(diracCode);
708
717
  if (validateTags) {
709
- const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-QX47WU2J.js");
718
+ const { validateDiracCode, applyCorrectedTags } = await import("./tag-validator-3RLLFTY6.js");
710
719
  let validation = await validateDiracCode(session, dynamicAST, { autocorrect });
711
720
  let retryCount = 0;
712
721
  while (!validation.valid && retryCount < maxRetries) {
@@ -735,6 +744,14 @@ Please fix these errors and generate valid Dirac XML again. Remember to only use
735
744
  temperature,
736
745
  max_tokens: maxTokens
737
746
  });
747
+ } else if (isCustom) {
748
+ const customPrompt = dialogHistory.map((m) => `${m.role}: ${m.content}`).join("\n");
749
+ result = await session.llmClient.complete(customPrompt, {
750
+ model,
751
+ temperature,
752
+ max_tokens: maxTokens,
753
+ messages: dialogHistory
754
+ });
738
755
  } else {
739
756
  const response = await session.llmClient.messages.create({
740
757
  model,
@@ -815,6 +832,14 @@ ${feedbackPrompt}
815
832
  temperature,
816
833
  max_tokens: maxTokens
817
834
  });
835
+ } else if (isCustom) {
836
+ const customPrompt = dialogHistory.map((m) => `${m.role}: ${m.content}`).join("\n");
837
+ result = await session.llmClient.complete(customPrompt, {
838
+ model,
839
+ temperature,
840
+ max_tokens: maxTokens,
841
+ messages: dialogHistory
842
+ });
818
843
  } else {
819
844
  const response = await session.llmClient.messages.create({
820
845
  model,
@@ -1237,7 +1262,7 @@ async function getBestTagMatch(candidate, allowed) {
1237
1262
  return { tag: allowed[bestIdx], score: bestScore };
1238
1263
  }
1239
1264
  async function executeTagCheck(session, element) {
1240
- const { getAvailableSubroutines } = await import("./session-UIWHLPTR.js");
1265
+ const { getAvailableSubroutines } = await import("./session-UBATJEND.js");
1241
1266
  const subroutines = getAvailableSubroutines(session);
1242
1267
  const allowed = new Set(subroutines.map((s) => s.name));
1243
1268
  console.error("[tag-check] Allowed subroutines:", Array.from(allowed));
@@ -1330,7 +1355,7 @@ async function executeTagCheck(session, element) {
1330
1355
  const executeTag = correctedTag || tagName;
1331
1356
  console.error(`[tag-check] Executing <${executeTag}/> as all checks passed and execute=true.`);
1332
1357
  const elementToExecute = correctedTag ? { ...child, tag: correctedTag } : child;
1333
- const { integrate: integrate2 } = await import("./interpreter-WP3KMLST.js");
1358
+ const { integrate: integrate2 } = await import("./interpreter-F65BCAYX.js");
1334
1359
  await integrate2(session, elementToExecute);
1335
1360
  }
1336
1361
  }
@@ -1339,7 +1364,7 @@ async function executeTagCheck(session, element) {
1339
1364
  // src/tags/throw.ts
1340
1365
  async function executeThrow(session, element) {
1341
1366
  const exceptionName = element.attributes?.name || "exception";
1342
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
1367
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-F65BCAYX.js");
1343
1368
  const exceptionDom = {
1344
1369
  tag: "exception-content",
1345
1370
  attributes: { name: exceptionName },
@@ -1352,7 +1377,7 @@ async function executeThrow(session, element) {
1352
1377
  // src/tags/try.ts
1353
1378
  async function executeTry(session, element) {
1354
1379
  setExceptionBoundary(session);
1355
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
1380
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-F65BCAYX.js");
1356
1381
  await integrateChildren2(session, element);
1357
1382
  unsetExceptionBoundary(session);
1358
1383
  }
@@ -1362,7 +1387,7 @@ async function executeCatch(session, element) {
1362
1387
  const exceptionName = element.attributes?.name || "exception";
1363
1388
  const caughtCount = lookupException(session, exceptionName);
1364
1389
  if (caughtCount > 0) {
1365
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
1390
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-F65BCAYX.js");
1366
1391
  await integrateChildren2(session, element);
1367
1392
  }
1368
1393
  flushCurrentException(session);
@@ -1371,7 +1396,7 @@ async function executeCatch(session, element) {
1371
1396
  // src/tags/exception.ts
1372
1397
  async function executeException(session, element) {
1373
1398
  const exceptions = getCurrentExceptions(session);
1374
- const { integrateChildren: integrateChildren2 } = await import("./interpreter-WP3KMLST.js");
1399
+ const { integrateChildren: integrateChildren2 } = await import("./interpreter-F65BCAYX.js");
1375
1400
  for (const exceptionDom of exceptions) {
1376
1401
  await integrateChildren2(session, exceptionDom);
1377
1402
  }
@@ -1511,7 +1536,7 @@ async function executeForeach(session, element) {
1511
1536
  const parser2 = new DiracParser2();
1512
1537
  try {
1513
1538
  const fromElement = parser2.parse(fromAttr);
1514
- const { integrate: integrate2 } = await import("./interpreter-WP3KMLST.js");
1539
+ const { integrate: integrate2 } = await import("./interpreter-F65BCAYX.js");
1515
1540
  await integrate2(session, fromElement);
1516
1541
  } catch (e) {
1517
1542
  session.output = savedOutput;
package/dist/cli.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  execute
4
- } from "./chunk-UYDP4ZFS.js";
5
- import "./chunk-YRJ3SODI.js";
4
+ } from "./chunk-4LLFMVOW.js";
5
+ import "./chunk-HPGONBNW.js";
6
6
  import "./chunk-HRHAMPOB.js";
7
- import "./chunk-JMUUPZZA.js";
8
- import "./chunk-JIWLKB5O.js";
7
+ import "./chunk-4QLTSCDG.js";
8
+ import "./chunk-GLXVY235.js";
9
9
 
10
10
  // src/cli.ts
11
11
  import "dotenv/config";
@@ -13,7 +13,7 @@ import "dotenv/config";
13
13
  // package.json
14
14
  var package_default = {
15
15
  name: "dirac-lang",
16
- version: "0.1.32",
16
+ version: "0.1.33",
17
17
  description: "LLM-Augmented Declarative Execution",
18
18
  type: "module",
19
19
  main: "dist/index.js",
package/dist/index.d.ts CHANGED
@@ -94,6 +94,7 @@ interface DiracConfig {
94
94
  filePath?: string;
95
95
  llmProvider?: string;
96
96
  llmModel?: string;
97
+ customLLMUrl?: string;
97
98
  }
98
99
 
99
100
  /**
package/dist/index.js CHANGED
@@ -2,19 +2,19 @@ import {
2
2
  createLLMAdapter,
3
3
  execute,
4
4
  executeUserCommand
5
- } from "./chunk-UYDP4ZFS.js";
5
+ } from "./chunk-4LLFMVOW.js";
6
6
  import {
7
7
  integrate
8
- } from "./chunk-YRJ3SODI.js";
8
+ } from "./chunk-HPGONBNW.js";
9
9
  import {
10
10
  DiracParser
11
11
  } from "./chunk-HRHAMPOB.js";
12
- import "./chunk-JMUUPZZA.js";
12
+ import "./chunk-4QLTSCDG.js";
13
13
  import {
14
14
  createSession,
15
15
  getAvailableSubroutines,
16
16
  getOutput
17
- } from "./chunk-JIWLKB5O.js";
17
+ } from "./chunk-GLXVY235.js";
18
18
  export {
19
19
  DiracParser,
20
20
  createLLMAdapter,
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  integrate,
3
3
  integrateChildren
4
- } from "./chunk-YRJ3SODI.js";
4
+ } from "./chunk-HPGONBNW.js";
5
5
  import "./chunk-HRHAMPOB.js";
6
- import "./chunk-JMUUPZZA.js";
7
- import "./chunk-JIWLKB5O.js";
6
+ import "./chunk-4QLTSCDG.js";
7
+ import "./chunk-GLXVY235.js";
8
8
  export {
9
9
  integrate,
10
10
  integrateChildren
@@ -26,7 +26,7 @@ import {
26
26
  substituteVariables,
27
27
  throwException,
28
28
  unsetExceptionBoundary
29
- } from "./chunk-JIWLKB5O.js";
29
+ } from "./chunk-GLXVY235.js";
30
30
  export {
31
31
  cleanSubroutinesToBoundary,
32
32
  cleanToBoundary,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  executeSubroutine
3
- } from "./chunk-JMUUPZZA.js";
4
- import "./chunk-JIWLKB5O.js";
3
+ } from "./chunk-4QLTSCDG.js";
4
+ import "./chunk-GLXVY235.js";
5
5
  export {
6
6
  executeSubroutine
7
7
  };
@@ -49,7 +49,7 @@ async function getBestTagMatch(candidate, allowed) {
49
49
  }
50
50
  async function validateTag(session, element, options = {}) {
51
51
  const { autocorrect = false, similarityCutoff = SIMILARITY_CUTOFF } = options;
52
- const { getAvailableSubroutines } = await import("./session-UIWHLPTR.js");
52
+ const { getAvailableSubroutines } = await import("./session-UBATJEND.js");
53
53
  const subroutines = getAvailableSubroutines(session);
54
54
  const allowed = new Set(subroutines.map((s) => s.name));
55
55
  const tagName = element.tag;
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  integrate
3
- } from "./chunk-YRJ3SODI.js";
3
+ } from "./chunk-HPGONBNW.js";
4
4
  import {
5
5
  DiracParser
6
6
  } from "./chunk-HRHAMPOB.js";
7
- import "./chunk-JMUUPZZA.js";
7
+ import "./chunk-4QLTSCDG.js";
8
8
  import {
9
9
  createSession,
10
10
  getOutput
11
- } from "./chunk-JIWLKB5O.js";
11
+ } from "./chunk-GLXVY235.js";
12
12
 
13
13
  // src/test-runner.ts
14
14
  import fs from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirac-lang",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "description": "LLM-Augmented Declarative Execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",