@granular-software/sdk 0.4.80 → 0.4.81

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
@@ -889,3 +889,40 @@ MIT
889
889
  ## License
890
890
 
891
891
  MIT
892
+
893
+ ### Transactional source acknowledgements (synchronous SQLite)
894
+
895
+ Use the existing effect/transition commit declaration to connect a source database transaction to canonical record commits:
896
+
897
+ ```ts
898
+ import { defineEffect, sqliteCommitStorage } from "@granular-software/sdk";
899
+
900
+ const storage = sqliteCommitStorage(db); // same connection used by business queries
901
+ const editOrder = defineEffect({
902
+ name: "edit_order",
903
+ className: "order",
904
+ description: "Edit an order using its current version",
905
+ inputSchema: editOrderInputSchema,
906
+ commit: {
907
+ kind: "effect", // use "transition" for an authored state-machine transition
908
+ storage,
909
+ project: (result, invocation) => {
910
+ if (!invocation) throw new Error("This mapper requires invocation input");
911
+ return projectOrderEdit(result, invocation.input);
912
+ },
913
+ },
914
+ handler: (id, input, context) => updateOrder(db, context.user, id, input), // synchronous, source version checked here
915
+ });
916
+
917
+ await granular.ontology(ontologyId).effects.register(editOrder);
918
+ ```
919
+
920
+ With `commit.storage`, the handler returns its product result instead of calling `context.commit.effect/transition`. The SDK runs the handler, projection mapping and source acknowledgement storage in one SQLite transaction. The projection is validated before that transaction commits. A source-journal insertion failure rolls back the business change too. The handler must do synchronous SQL-only work through this database; async handlers are rejected before execution. This adapter is tested with `bun:sqlite`, using a structural driver interface and no Bun runtime import in the SDK.
921
+
922
+ The SDK then sends the acknowledgement through its normal canonical commit transport. Source success followed by failed delivery remains pending in the source database. Registration and the existing effect-host heartbeat retry that exact original acknowledgement, with the original invocation identity and transition outcome. They do not run the business handler or rerun a potentially changed projection mapper. The same canonical commit service owns graph projection and its recovery.
923
+
924
+ Partial projections keep their normal meaning: omitted fields are unchanged and explicit null clears a field. The optional second mapper argument supplies the original invocation input for selecting changed fields. Other projection entry points may call the mapper with only a result, so result-only mappers remain supported. Transition declarations retain their authored outcomes and are still validated against trusted runtime transition context.
925
+
926
+ Existing handlers without `commit.storage` keep the explicit `context.commit.effect/transition` contract. Configure storage in the process that owns the real business transaction; placing it around an HTTP forwarding handler cannot atomically protect a remote database. Customer authorization, source version checks and operation invariants remain business rules. Remote side effects and asynchronous ORM transactions require different adapters and provider contracts.
927
+
928
+ Storage-backed integrations should expose recovery only through their trusted runtime controls. `storage.inspect` reports an absent operation as unknown. `storage.fence` atomically refuses a not-yet-delivered operation, scoped by sandbox, environment, actor and exact operation inputs. The SDK-owned table is a source acknowledgement journal, not an alternative graph or record-commit system. Plan production migration, retention and outbox scheduling before deployment.
@@ -1,4 +1,4 @@
1
- import { n as Prompt, h as RecordObjectOptions, i as ManifestContent, H as EnvironmentSession, m as SessionHeapSnapshot, T as ToolWithHandler, G as Granular, bD as ConnectOptions, bT as CreateEnvironmentData, bB as GranularOptions } from './client-DxLth4N_.mjs';
1
+ import { k as Prompt, e as RecordObjectOptions, f as ManifestContent, D as EnvironmentSession, j as SessionHeapSnapshot, T as ToolWithHandler, G as Granular, c1 as ConnectOptions, ch as CreateEnvironmentData, b$ as GranularOptions } from './client--FEdH24t.mjs';
2
2
  import { GranularAgentToolInfo, GeneratedJobCodeIssue, BuildGranularAgentSystemPromptInput, HarnessRenderedPrompt, HarnessRenderedContinuation, HarnessControllerBudgets } from './agent-harness.mjs';
3
3
  import { G as GranularSpendContext, a as OpenAITokenSpend } from './spend-ZMtzJoMN.mjs';
4
4
  import '@automerge/automerge';
@@ -1,4 +1,4 @@
1
- import { n as Prompt, h as RecordObjectOptions, i as ManifestContent, H as EnvironmentSession, m as SessionHeapSnapshot, T as ToolWithHandler, G as Granular, bD as ConnectOptions, bT as CreateEnvironmentData, bB as GranularOptions } from './client-BtyPOW3M.js';
1
+ import { k as Prompt, e as RecordObjectOptions, f as ManifestContent, D as EnvironmentSession, j as SessionHeapSnapshot, T as ToolWithHandler, G as Granular, c1 as ConnectOptions, ch as CreateEnvironmentData, b$ as GranularOptions } from './client-CQU7xBRK.js';
2
2
  import { GranularAgentToolInfo, GeneratedJobCodeIssue, BuildGranularAgentSystemPromptInput, HarnessRenderedPrompt, HarnessRenderedContinuation, HarnessControllerBudgets } from './agent-harness.js';
3
3
  import { G as GranularSpendContext, a as OpenAITokenSpend } from './spend-ZMtzJoMN.js';
4
4
  import '@automerge/automerge';