@softize/opus 8.6.6
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/CHANGELOG.md +1616 -0
- package/LICENSE +21 -0
- package/README.md +113 -0
- package/bin/cli.mjs +528 -0
- package/bin/lib/check.mjs +307 -0
- package/bin/lib/components.mjs +151 -0
- package/bin/lib/create.mjs +208 -0
- package/bin/lib/db-check-runner.mjs +86 -0
- package/bin/lib/db-migrate-runner.mjs +89 -0
- package/bin/lib/db-scaffold-runner.mjs +84 -0
- package/bin/lib/db.mjs +261 -0
- package/bin/lib/docs-include.mjs +48 -0
- package/bin/lib/gen-dicts.mjs +134 -0
- package/bin/lib/gen-docs.mjs +288 -0
- package/bin/lib/gen-manifest.mjs +102 -0
- package/bin/lib/gen-openapi.mjs +195 -0
- package/bin/lib/gen-runner.mjs +472 -0
- package/bin/lib/gen-stubs.mjs +463 -0
- package/bin/lib/gen.mjs +311 -0
- package/bin/lib/init.mjs +514 -0
- package/bin/lib/introspect.mjs +107 -0
- package/bin/lib/mcp.mjs +85 -0
- package/bin/lib/postinstall.mjs +56 -0
- package/docs/chat-event-protocol.md +85 -0
- package/docs/code-style.md +16 -0
- package/docs/data-layer.md +246 -0
- package/docs/ownership-vs-shadcn-lock.md +102 -0
- package/docs/protocol.md +2053 -0
- package/docs/releasing.md +110 -0
- package/docs/shellnav.md +131 -0
- package/package.json +338 -0
- package/registry/hooks/hooks.json +26 -0
- package/registry/hooks/link-memory-on-start.mjs +46 -0
- package/registry/hooks/opus-check-on-stop.mjs +114 -0
- package/registry/skills/create-action/SKILL.md +49 -0
- package/registry/skills/create-action/scaffold.mjs +122 -0
- package/registry/templates/app/_gitignore +3 -0
- package/registry/templates/app/_npmrc +1 -0
- package/registry/templates/app/_opus/_gitignore +5 -0
- package/registry/templates/app/_prettierrc.json +6 -0
- package/registry/templates/app/index.html +13 -0
- package/registry/templates/app/opus.config.ts +16 -0
- package/registry/templates/app/package.json +43 -0
- package/registry/templates/app/pnpm-workspace.yaml +11 -0
- package/registry/templates/app/public/favicon.svg +4 -0
- package/registry/templates/app/src/App.tsx +37 -0
- package/registry/templates/app/src/domains/tasks/actions/list.test.ts +34 -0
- package/registry/templates/app/src/domains/tasks/actions/list.ts +33 -0
- package/registry/templates/app/src/domains/tasks/index.ts +13 -0
- package/registry/templates/app/src/index.css +18 -0
- package/registry/templates/app/src/main.tsx +25 -0
- package/registry/templates/app/tsconfig.json +20 -0
- package/registry/templates/app/vite.config.ts +46 -0
- package/registry/templates/monorepo/_gitignore +3 -0
- package/registry/templates/monorepo/_npmrc +1 -0
- package/registry/templates/monorepo/package.json +9 -0
- package/registry/templates/monorepo/pnpm-workspace.yaml +14 -0
- package/src/ai/ask.ts +64 -0
- package/src/ai/drivers/anthropic.ts +309 -0
- package/src/ai/index.ts +17 -0
- package/src/audit/drivers/console.ts +117 -0
- package/src/audit/drivers/pg.ts +172 -0
- package/src/audit/index.ts +51 -0
- package/src/auth/drivers/better-auth.ts +103 -0
- package/src/auth/drivers/jwt.ts +188 -0
- package/src/auth/index.ts +9 -0
- package/src/client/drivers/fetch.ts +202 -0
- package/src/client/index.ts +22 -0
- package/src/core/actions.ts +110 -0
- package/src/core/audit.ts +239 -0
- package/src/core/contracts.ts +137 -0
- package/src/core/domain.ts +310 -0
- package/src/core/errors.ts +181 -0
- package/src/core/index.ts +174 -0
- package/src/core/logical-type.ts +31 -0
- package/src/core/reactions.ts +81 -0
- package/src/core/runtime.ts +1167 -0
- package/src/core/schedules.ts +41 -0
- package/src/core/types.ts +1356 -0
- package/src/data/drivers/kysely.ts +389 -0
- package/src/data/index.ts +10 -0
- package/src/data/readonly-pool.ts +160 -0
- package/src/dsl/eval.ts +136 -0
- package/src/dsl/index.ts +29 -0
- package/src/dsl/kysely.ts +230 -0
- package/src/dsl/loads.ts +123 -0
- package/src/dsl/parser.ts +423 -0
- package/src/dsl/types.ts +113 -0
- package/src/events/drivers/mitt.ts +70 -0
- package/src/events/index.ts +9 -0
- package/src/log/drivers/pino.ts +57 -0
- package/src/log/index.ts +9 -0
- package/src/mcp/index.ts +62 -0
- package/src/queue/drivers/bullmq.ts +190 -0
- package/src/queue/index.ts +9 -0
- package/src/scheduler/drivers/node-cron.ts +93 -0
- package/src/scheduler/every.ts +45 -0
- package/src/scheduler/index.ts +9 -0
- package/src/schema/drivers/zod.ts +765 -0
- package/src/schema/entity.ts +439 -0
- package/src/schema/format/locale.ts +144 -0
- package/src/schema/index.ts +65 -0
- package/src/schema/openapi.ts +302 -0
- package/src/schema/scaffold.ts +160 -0
- package/src/server/drivers/fastify.ts +224 -0
- package/src/server/drivers/node.ts +386 -0
- package/src/server/index.ts +142 -0
- package/src/storage/drivers/fs.ts +90 -0
- package/src/storage/drivers/s3.ts +117 -0
- package/src/storage/index.ts +27 -0
- package/src/testing/fake.ts +298 -0
- package/src/testing/index.ts +324 -0
- package/src/ui/components/patterns/action-form-card.tsx +48 -0
- package/src/ui/components/patterns/action-list-dialog.tsx +93 -0
- package/src/ui/components/patterns/app-shell.tsx +227 -0
- package/src/ui/components/patterns/confirm.tsx +226 -0
- package/src/ui/components/patterns/data-state.tsx +75 -0
- package/src/ui/components/patterns/form-dialog.tsx +64 -0
- package/src/ui/components/patterns/form.tsx +584 -0
- package/src/ui/components/patterns/list.tsx +1488 -0
- package/src/ui/components/patterns/page.tsx +46 -0
- package/src/ui/components/patterns/section-shell.tsx +246 -0
- package/src/ui/components/patterns/shell-nav.tsx +150 -0
- package/src/ui/components/patterns/sidebar.tsx +89 -0
- package/src/ui/components/patterns/split.tsx +93 -0
- package/src/ui/components/patterns/trigger.tsx +196 -0
- package/src/ui/components/patterns/view.tsx +84 -0
- package/src/ui/components/primitives/accordion.tsx +64 -0
- package/src/ui/components/primitives/alert-dialog.tsx +190 -0
- package/src/ui/components/primitives/alert.tsx +116 -0
- package/src/ui/components/primitives/aspect-ratio.tsx +9 -0
- package/src/ui/components/primitives/avatar.tsx +107 -0
- package/src/ui/components/primitives/badge.tsx +37 -0
- package/src/ui/components/primitives/breadcrumb.tsx +109 -0
- package/src/ui/components/primitives/button-group.tsx +83 -0
- package/src/ui/components/primitives/button.tsx +102 -0
- package/src/ui/components/primitives/calendar.tsx +218 -0
- package/src/ui/components/primitives/card.tsx +56 -0
- package/src/ui/components/primitives/carousel.tsx +239 -0
- package/src/ui/components/primitives/chat.tsx +407 -0
- package/src/ui/components/primitives/checkbox.tsx +30 -0
- package/src/ui/components/primitives/collapsible.tsx +31 -0
- package/src/ui/components/primitives/command.tsx +182 -0
- package/src/ui/components/primitives/composer.tsx +121 -0
- package/src/ui/components/primitives/copyable.tsx +50 -0
- package/src/ui/components/primitives/dialog.tsx +147 -0
- package/src/ui/components/primitives/drawer.tsx +141 -0
- package/src/ui/components/primitives/empty.tsx +104 -0
- package/src/ui/components/primitives/field.tsx +246 -0
- package/src/ui/components/primitives/icon-picker.tsx +180 -0
- package/src/ui/components/primitives/input-group.tsx +168 -0
- package/src/ui/components/primitives/input-otp.tsx +75 -0
- package/src/ui/components/primitives/input.tsx +72 -0
- package/src/ui/components/primitives/item.tsx +193 -0
- package/src/ui/components/primitives/kbd.tsx +28 -0
- package/src/ui/components/primitives/label.tsx +22 -0
- package/src/ui/components/primitives/markdown.tsx +35 -0
- package/src/ui/components/primitives/menu.tsx +255 -0
- package/src/ui/components/primitives/pagination.tsx +127 -0
- package/src/ui/components/primitives/popover.tsx +87 -0
- package/src/ui/components/primitives/progress.tsx +29 -0
- package/src/ui/components/primitives/radio-group.tsx +43 -0
- package/src/ui/components/primitives/resizable.tsx +51 -0
- package/src/ui/components/primitives/scroll-area.tsx +56 -0
- package/src/ui/components/primitives/select.tsx +479 -0
- package/src/ui/components/primitives/separator.tsx +26 -0
- package/src/ui/components/primitives/skeleton.tsx +13 -0
- package/src/ui/components/primitives/slider.tsx +61 -0
- package/src/ui/components/primitives/sonner.tsx +46 -0
- package/src/ui/components/primitives/spinner.tsx +29 -0
- package/src/ui/components/primitives/switch.tsx +33 -0
- package/src/ui/components/primitives/table.tsx +114 -0
- package/src/ui/components/primitives/tabs.tsx +104 -0
- package/src/ui/components/primitives/textarea.tsx +18 -0
- package/src/ui/components/primitives/toggle-group.tsx +81 -0
- package/src/ui/components/primitives/toggle.tsx +45 -0
- package/src/ui/components/primitives/tooltip.tsx +55 -0
- package/src/ui/components/primitives/truncate.tsx +49 -0
- package/src/ui/docs/DocBrowser.tsx +90 -0
- package/src/ui/docs/changelog.tsx +80 -0
- package/src/ui/docs/content/accordion.md +86 -0
- package/src/ui/docs/content/action-form-card.md +24 -0
- package/src/ui/docs/content/action-form-dialog.md +30 -0
- package/src/ui/docs/content/action-form.md +125 -0
- package/src/ui/docs/content/action-list-dialog.md +68 -0
- package/src/ui/docs/content/action-list.md +194 -0
- package/src/ui/docs/content/action-trigger.md +72 -0
- package/src/ui/docs/content/action-view.md +47 -0
- package/src/ui/docs/content/actions.md +138 -0
- package/src/ui/docs/content/ai.md +112 -0
- package/src/ui/docs/content/alert-dialog.md +73 -0
- package/src/ui/docs/content/alert.md +69 -0
- package/src/ui/docs/content/app-shell.md +155 -0
- package/src/ui/docs/content/aspect-ratio.md +66 -0
- package/src/ui/docs/content/audit.md +84 -0
- package/src/ui/docs/content/auth.md +70 -0
- package/src/ui/docs/content/avatar.md +94 -0
- package/src/ui/docs/content/badge.md +48 -0
- package/src/ui/docs/content/breadcrumb.md +87 -0
- package/src/ui/docs/content/button-group.md +71 -0
- package/src/ui/docs/content/button.md +60 -0
- package/src/ui/docs/content/calendar.md +62 -0
- package/src/ui/docs/content/card.md +49 -0
- package/src/ui/docs/content/carousel.md +85 -0
- package/src/ui/docs/content/chat.md +69 -0
- package/src/ui/docs/content/checkbox.md +75 -0
- package/src/ui/docs/content/cli.md +58 -0
- package/src/ui/docs/content/collapsible.md +64 -0
- package/src/ui/docs/content/command.md +56 -0
- package/src/ui/docs/content/composer.md +50 -0
- package/src/ui/docs/content/confirm.md +120 -0
- package/src/ui/docs/content/copyable.md +30 -0
- package/src/ui/docs/content/customization.md +110 -0
- package/src/ui/docs/content/cycle.md +34 -0
- package/src/ui/docs/content/data-state.md +47 -0
- package/src/ui/docs/content/data.md +99 -0
- package/src/ui/docs/content/dialog.md +60 -0
- package/src/ui/docs/content/drawer.md +55 -0
- package/src/ui/docs/content/empty.md +66 -0
- package/src/ui/docs/content/events.md +61 -0
- package/src/ui/docs/content/field.md +58 -0
- package/src/ui/docs/content/getting-started.md +109 -0
- package/src/ui/docs/content/icon-picker.md +51 -0
- package/src/ui/docs/content/input-group.md +78 -0
- package/src/ui/docs/content/input-otp.md +72 -0
- package/src/ui/docs/content/input.md +78 -0
- package/src/ui/docs/content/item.md +84 -0
- package/src/ui/docs/content/kbd.md +62 -0
- package/src/ui/docs/content/label.md +32 -0
- package/src/ui/docs/content/log.md +55 -0
- package/src/ui/docs/content/markdown.md +41 -0
- package/src/ui/docs/content/mcp.md +44 -0
- package/src/ui/docs/content/menu.md +114 -0
- package/src/ui/docs/content/microcopy.md +83 -0
- package/src/ui/docs/content/page.md +34 -0
- package/src/ui/docs/content/pagination.md +99 -0
- package/src/ui/docs/content/popover.md +49 -0
- package/src/ui/docs/content/progress.md +69 -0
- package/src/ui/docs/content/queue.md +62 -0
- package/src/ui/docs/content/radio-group.md +77 -0
- package/src/ui/docs/content/resizable.md +86 -0
- package/src/ui/docs/content/router.md +56 -0
- package/src/ui/docs/content/runtime.md +77 -0
- package/src/ui/docs/content/scheduler.md +66 -0
- package/src/ui/docs/content/scroll-area.md +89 -0
- package/src/ui/docs/content/section-shell.md +121 -0
- package/src/ui/docs/content/select.md +342 -0
- package/src/ui/docs/content/separator.md +33 -0
- package/src/ui/docs/content/sidebar.md +38 -0
- package/src/ui/docs/content/skeleton.md +34 -0
- package/src/ui/docs/content/slider.md +64 -0
- package/src/ui/docs/content/spinner.md +37 -0
- package/src/ui/docs/content/split.md +33 -0
- package/src/ui/docs/content/storage.md +69 -0
- package/src/ui/docs/content/switch.md +69 -0
- package/src/ui/docs/content/table.md +102 -0
- package/src/ui/docs/content/tabs.md +94 -0
- package/src/ui/docs/content/testing.md +89 -0
- package/src/ui/docs/content/textarea.md +30 -0
- package/src/ui/docs/content/toast.md +67 -0
- package/src/ui/docs/content/toggle-group.md +81 -0
- package/src/ui/docs/content/toggle.md +72 -0
- package/src/ui/docs/content/tokens.md +171 -0
- package/src/ui/docs/content/tooltip.md +50 -0
- package/src/ui/docs/content/truncate.md +37 -0
- package/src/ui/docs/content/ui.md +40 -0
- package/src/ui/docs/content/upgrading.md +48 -0
- package/src/ui/docs/doc-client.tsx +214 -0
- package/src/ui/docs/doc.tsx +301 -0
- package/src/ui/docs/folder.tsx +149 -0
- package/src/ui/docs/index.ts +21 -0
- package/src/ui/docs/markdown.tsx +130 -0
- package/src/ui/docs/md-raw.d.ts +4 -0
- package/src/ui/docs/plugin.ts +104 -0
- package/src/ui/docs/registry.tsx +424 -0
- package/src/ui/docs/standalone.tsx +107 -0
- package/src/ui/drivers/react.tsx +627 -0
- package/src/ui/index.ts +92 -0
- package/src/ui/lib/cn.ts +10 -0
- package/src/ui/lib/zod-pt-br.ts +38 -0
- package/src/ui/meta.ts +412 -0
- package/src/ui/react.tsx +235 -0
- package/src/ui/router.ts +96 -0
- package/src/ui/theme.css +234 -0
- package/src/vite/design.ts +652 -0
- package/src/vite/index.ts +8 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tbdlib — Error factory
|
|
3
|
+
*
|
|
4
|
+
* `error()` é a maneira canônica de emitir `ActionError` de dentro de um handler.
|
|
5
|
+
* Aplica defaults sensatos baseados na categoria (severity, retriable) e
|
|
6
|
+
* preserva stack trace via `Error`. Ver §3 do protocolo.
|
|
7
|
+
*
|
|
8
|
+
* Uso:
|
|
9
|
+
* throw error({
|
|
10
|
+
* code: 'deal.archive.notFound',
|
|
11
|
+
* category: 'not_found',
|
|
12
|
+
* message: `Deal ${id} not found`,
|
|
13
|
+
* })
|
|
14
|
+
*
|
|
15
|
+
* Erros não criados via `error()` (ex: `throw new Error(...)`, exceções de driver)
|
|
16
|
+
* são normalizados pelo runtime em `{ category: 'internal', code: 'internal.unhandled' }`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type {
|
|
20
|
+
ActionError,
|
|
21
|
+
ErrorCategory,
|
|
22
|
+
Severity,
|
|
23
|
+
ValidationIssue,
|
|
24
|
+
} from './types.ts'
|
|
25
|
+
|
|
26
|
+
/** Brand interno pra distinguir ActionError construído via `error()` de Error genérico. */
|
|
27
|
+
const ACTION_ERROR_BRAND = Symbol('tbdlib.ActionError')
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Defaults de severity por categoria.
|
|
31
|
+
* Ver tabela em §3 do protocolo.
|
|
32
|
+
*/
|
|
33
|
+
const DEFAULT_SEVERITY_BY_CATEGORY: Record<ErrorCategory, Severity> = {
|
|
34
|
+
validation: 'warning',
|
|
35
|
+
authentication: 'warning',
|
|
36
|
+
authorization: 'warning',
|
|
37
|
+
not_found: 'warning',
|
|
38
|
+
conflict: 'warning',
|
|
39
|
+
rate_limit: 'warning',
|
|
40
|
+
dependency: 'error',
|
|
41
|
+
internal: 'error',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Defaults de retriable por categoria.
|
|
46
|
+
*/
|
|
47
|
+
const DEFAULT_RETRIABLE_BY_CATEGORY: Record<ErrorCategory, boolean> = {
|
|
48
|
+
validation: false,
|
|
49
|
+
authentication: false,
|
|
50
|
+
authorization: false,
|
|
51
|
+
not_found: false,
|
|
52
|
+
conflict: false,
|
|
53
|
+
rate_limit: true,
|
|
54
|
+
dependency: true,
|
|
55
|
+
internal: false,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Input do factory `error()`. Tudo opcional exceto `code` e `category`;
|
|
60
|
+
* defaults são aplicados em runtime baseado na categoria.
|
|
61
|
+
*/
|
|
62
|
+
export interface ErrorInput {
|
|
63
|
+
code: string
|
|
64
|
+
category: ErrorCategory
|
|
65
|
+
message?: string
|
|
66
|
+
severity?: Severity
|
|
67
|
+
retriable?: boolean
|
|
68
|
+
|
|
69
|
+
i18nKey?: string
|
|
70
|
+
i18nParams?: Record<string, unknown>
|
|
71
|
+
|
|
72
|
+
field?: string
|
|
73
|
+
issues?: ValidationIssue[]
|
|
74
|
+
|
|
75
|
+
cause?: unknown
|
|
76
|
+
meta?: Record<string, unknown>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Implementação concreta. Não exportada — consumers usam `error()` e checam via `isActionError()`.
|
|
81
|
+
* Estende `Error` para preservar stack trace e funcionar com try/catch idiomático.
|
|
82
|
+
*/
|
|
83
|
+
class ActionErrorImpl extends Error implements ActionError {
|
|
84
|
+
readonly [ACTION_ERROR_BRAND] = true as const
|
|
85
|
+
|
|
86
|
+
readonly code: string
|
|
87
|
+
readonly category: ErrorCategory
|
|
88
|
+
readonly severity: Severity
|
|
89
|
+
readonly retriable: boolean
|
|
90
|
+
|
|
91
|
+
readonly i18nKey?: string
|
|
92
|
+
readonly i18nParams?: Record<string, unknown>
|
|
93
|
+
readonly field?: string
|
|
94
|
+
readonly issues?: ValidationIssue[]
|
|
95
|
+
override readonly cause?: unknown
|
|
96
|
+
readonly meta?: Record<string, unknown>
|
|
97
|
+
|
|
98
|
+
constructor(input: ErrorInput) {
|
|
99
|
+
const message = input.message ?? defaultMessage(input.code, input.category)
|
|
100
|
+
super(message)
|
|
101
|
+
|
|
102
|
+
this.name = 'ActionError'
|
|
103
|
+
this.code = input.code
|
|
104
|
+
this.category = input.category
|
|
105
|
+
this.severity = input.severity ?? DEFAULT_SEVERITY_BY_CATEGORY[input.category]
|
|
106
|
+
this.retriable = input.retriable ?? DEFAULT_RETRIABLE_BY_CATEGORY[input.category]
|
|
107
|
+
|
|
108
|
+
if (input.i18nKey !== undefined) this.i18nKey = input.i18nKey
|
|
109
|
+
if (input.i18nParams !== undefined) this.i18nParams = input.i18nParams
|
|
110
|
+
if (input.field !== undefined) this.field = input.field
|
|
111
|
+
if (input.issues !== undefined) this.issues = input.issues
|
|
112
|
+
if (input.cause !== undefined) this.cause = input.cause
|
|
113
|
+
if (input.meta !== undefined) this.meta = input.meta
|
|
114
|
+
|
|
115
|
+
// Preserva stack trace de quem chamou error(), não desta constructor.
|
|
116
|
+
// captureStackTrace é V8-only (Node/Chrome); ignora em outros runtimes.
|
|
117
|
+
const ctor = Error as ErrorConstructor & {
|
|
118
|
+
captureStackTrace?: (target: object, ctor?: Function) => void
|
|
119
|
+
}
|
|
120
|
+
if (typeof ctor.captureStackTrace === 'function') {
|
|
121
|
+
ctor.captureStackTrace(this, error)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Constrói um `ActionError` a partir de input parcial.
|
|
128
|
+
* Severity e retriable são derivados da categoria se não passados.
|
|
129
|
+
*
|
|
130
|
+
* O resultado é uma instância de `Error` (preserva stack, funciona com try/catch)
|
|
131
|
+
* que também satisfaz a interface `ActionError`.
|
|
132
|
+
*/
|
|
133
|
+
export function error(input: ErrorInput): ActionError {
|
|
134
|
+
return new ActionErrorImpl(input)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Type guard pra checar se um valor foi construído via `error()`.
|
|
139
|
+
* Runtime usa pra distinguir entre ActionError emitido pelo handler vs
|
|
140
|
+
* exceção genérica que precisa ser normalizada.
|
|
141
|
+
*/
|
|
142
|
+
export function isActionError(value: unknown): value is ActionError {
|
|
143
|
+
return (
|
|
144
|
+
typeof value === 'object' &&
|
|
145
|
+
value !== null &&
|
|
146
|
+
ACTION_ERROR_BRAND in value &&
|
|
147
|
+
(value as { [ACTION_ERROR_BRAND]: unknown })[ACTION_ERROR_BRAND] === true
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Normaliza uma exceção qualquer em ActionError. Usado pelo runtime quando
|
|
153
|
+
* handler lança algo que não foi criado via `error()`.
|
|
154
|
+
*/
|
|
155
|
+
export function normalizeError(thrown: unknown): ActionError {
|
|
156
|
+
if (isActionError(thrown)) return thrown
|
|
157
|
+
|
|
158
|
+
if (thrown instanceof Error) {
|
|
159
|
+
return error({
|
|
160
|
+
code: 'internal.unhandled',
|
|
161
|
+
category: 'internal',
|
|
162
|
+
message: thrown.message,
|
|
163
|
+
cause: thrown.message, // só mensagem; stack não vaza pra wire
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return error({
|
|
168
|
+
code: 'internal.unhandled',
|
|
169
|
+
category: 'internal',
|
|
170
|
+
message: typeof thrown === 'string' ? thrown : 'Unhandled error',
|
|
171
|
+
cause: thrown,
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// =============================================================================
|
|
176
|
+
// Internos
|
|
177
|
+
// =============================================================================
|
|
178
|
+
|
|
179
|
+
function defaultMessage(code: string, category: ErrorCategory): string {
|
|
180
|
+
return `[${category}] ${code}`
|
|
181
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @softize/opus/core — public entry
|
|
3
|
+
*
|
|
4
|
+
* Re-exports da superfície pública. Source of truth: `/docs/protocol.md`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// — Tipos —————————————————————————————————————————————————————————————————————
|
|
8
|
+
export type {
|
|
9
|
+
// primitivos / shared
|
|
10
|
+
I18nRef,
|
|
11
|
+
Unsubscribe,
|
|
12
|
+
Logger,
|
|
13
|
+
ContextBase,
|
|
14
|
+
Schema,
|
|
15
|
+
InferInput,
|
|
16
|
+
InferOutput,
|
|
17
|
+
// erro
|
|
18
|
+
ActionError,
|
|
19
|
+
ErrorCategory,
|
|
20
|
+
Severity,
|
|
21
|
+
ValidationIssue,
|
|
22
|
+
ErrorSpec,
|
|
23
|
+
// result
|
|
24
|
+
ResultMeta,
|
|
25
|
+
ActionResult,
|
|
26
|
+
BackgroundResult,
|
|
27
|
+
Paginated,
|
|
28
|
+
// contexto
|
|
29
|
+
User,
|
|
30
|
+
CanFn,
|
|
31
|
+
EmitFn,
|
|
32
|
+
ActionContext,
|
|
33
|
+
ReactionContext,
|
|
34
|
+
Provenance,
|
|
35
|
+
// audit
|
|
36
|
+
AuditRecord,
|
|
37
|
+
AuditConfig,
|
|
38
|
+
// eventos
|
|
39
|
+
DomainEvent,
|
|
40
|
+
// jobs / background
|
|
41
|
+
JobStatus,
|
|
42
|
+
JobHandle,
|
|
43
|
+
JobSpec,
|
|
44
|
+
BackoffSpec,
|
|
45
|
+
BackgroundConfig,
|
|
46
|
+
ProgressReporter,
|
|
47
|
+
// tipos lógicos
|
|
48
|
+
LogicalTypeMeta,
|
|
49
|
+
// specs (action)
|
|
50
|
+
ConfirmSpec,
|
|
51
|
+
RateLimitSpec,
|
|
52
|
+
AIConfig,
|
|
53
|
+
Example,
|
|
54
|
+
ActionMessages,
|
|
55
|
+
OptionsSpec,
|
|
56
|
+
FieldSpec,
|
|
57
|
+
FilterOp,
|
|
58
|
+
FilterSpec,
|
|
59
|
+
ListColumnSpec,
|
|
60
|
+
SortSpec,
|
|
61
|
+
PeriodSpec,
|
|
62
|
+
ExpandSpec,
|
|
63
|
+
// action union + variants
|
|
64
|
+
ActionKind,
|
|
65
|
+
ActionBase,
|
|
66
|
+
SimpleAction,
|
|
67
|
+
FormAction,
|
|
68
|
+
ListAction,
|
|
69
|
+
ViewAction,
|
|
70
|
+
ActionDef,
|
|
71
|
+
AuthorizeFn,
|
|
72
|
+
AuthorizeSpec,
|
|
73
|
+
HandlerFn,
|
|
74
|
+
LoaderFn,
|
|
75
|
+
LoaderResolver,
|
|
76
|
+
LoadSpec,
|
|
77
|
+
LoadsSpec,
|
|
78
|
+
LoadersSpec,
|
|
79
|
+
// reaction
|
|
80
|
+
ReactionDef,
|
|
81
|
+
ReactionHandlerFn,
|
|
82
|
+
// schedule
|
|
83
|
+
ScheduleDef,
|
|
84
|
+
// adapters
|
|
85
|
+
AdapterKind,
|
|
86
|
+
Adapter,
|
|
87
|
+
RuntimeRef,
|
|
88
|
+
HealthStatus,
|
|
89
|
+
ServerAdapter,
|
|
90
|
+
DataAdapter,
|
|
91
|
+
AuthAdapter,
|
|
92
|
+
AuditSink,
|
|
93
|
+
LoggerAdapter,
|
|
94
|
+
QueueAdapter,
|
|
95
|
+
EventBusAdapter,
|
|
96
|
+
SchedulerAdapter,
|
|
97
|
+
ClientAdapter,
|
|
98
|
+
StorageAdapter,
|
|
99
|
+
StoragePutOptions,
|
|
100
|
+
StorageObject,
|
|
101
|
+
AiAdapter,
|
|
102
|
+
AiCompleteOptions,
|
|
103
|
+
AiTool,
|
|
104
|
+
AiMessage,
|
|
105
|
+
AiRunOptions,
|
|
106
|
+
AiRunResult,
|
|
107
|
+
BoundAi,
|
|
108
|
+
BoundAiRunOptions,
|
|
109
|
+
ChatEvent,
|
|
110
|
+
AskOption,
|
|
111
|
+
AskQuestion,
|
|
112
|
+
AskAnswer,
|
|
113
|
+
EndpointSpec,
|
|
114
|
+
LogsEndpointSpec,
|
|
115
|
+
AuditEndpointSpec,
|
|
116
|
+
LogQuery,
|
|
117
|
+
LogEntry,
|
|
118
|
+
AuditQuery,
|
|
119
|
+
// runtime config
|
|
120
|
+
RuntimeConfig,
|
|
121
|
+
} from './types.ts'
|
|
122
|
+
|
|
123
|
+
// — Erro ——————————————————————————————————————————————————————————————————————
|
|
124
|
+
export { error, isActionError, normalizeError } from './errors.ts'
|
|
125
|
+
export type { ErrorInput } from './errors.ts'
|
|
126
|
+
|
|
127
|
+
// — Logical types ——————————————————————————————————————————————————————————————
|
|
128
|
+
// As factories `t.*` moram em `@softize/opus/schema`; o attach/get da meta é
|
|
129
|
+
// isomórfico e mora AQUI (a UI lê a meta do contrato — fronteira ui→core).
|
|
130
|
+
// `@softize/opus/schema` re-exporta os dois pra manter a API de sempre.
|
|
131
|
+
export { attachLogicalType, getLogicalType } from './logical-type.ts'
|
|
132
|
+
|
|
133
|
+
// — Action ————————————————————————————————————————————————————————————————————
|
|
134
|
+
export {
|
|
135
|
+
defineAction,
|
|
136
|
+
isSimpleAction,
|
|
137
|
+
isFormAction,
|
|
138
|
+
isListAction,
|
|
139
|
+
isViewAction,
|
|
140
|
+
isBackgroundAction,
|
|
141
|
+
} from './actions.ts'
|
|
142
|
+
|
|
143
|
+
// — Contract / bind (split contrato↔handler) ——————————————————————————————————
|
|
144
|
+
export { defineContract, bindAction } from './contracts.ts'
|
|
145
|
+
export type {
|
|
146
|
+
ActionContract,
|
|
147
|
+
ActionBinding,
|
|
148
|
+
SimpleContract,
|
|
149
|
+
FormContract,
|
|
150
|
+
ListContract,
|
|
151
|
+
ViewContract,
|
|
152
|
+
} from './contracts.ts'
|
|
153
|
+
|
|
154
|
+
// — Reaction ——————————————————————————————————————————————————————————————————
|
|
155
|
+
export { defineReaction, defineReactionContract, bindReaction, isReaction } from './reactions.ts'
|
|
156
|
+
export type { ReactionContract, ReactionBinding } from './reactions.ts'
|
|
157
|
+
|
|
158
|
+
// — Schedule ——————————————————————————————————————————————————————————————————
|
|
159
|
+
export { defineSchedule, isSchedule } from './schedules.ts'
|
|
160
|
+
|
|
161
|
+
// — Domain ————————————————————————————————————————————————————————————————————
|
|
162
|
+
export { defineDomain, flattenDomain, isDomainConfig } from './domain.ts'
|
|
163
|
+
export type { DomainConfig, FlattenedDomain } from './domain.ts'
|
|
164
|
+
|
|
165
|
+
// — Audit —————————————————————————————————————————————————————————————————————
|
|
166
|
+
export { AuditEmitter } from './audit.ts'
|
|
167
|
+
|
|
168
|
+
// — Runtime ———————————————————————————————————————————————————————————————————
|
|
169
|
+
export { Runtime, createRuntime } from './runtime.ts'
|
|
170
|
+
export type {
|
|
171
|
+
RuntimeSetup,
|
|
172
|
+
RuntimeSetupConfig,
|
|
173
|
+
ResolvedRuntimeConfig,
|
|
174
|
+
} from './runtime.ts'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata machinery de logical types — attach/get driver-agnostic.
|
|
3
|
+
*
|
|
4
|
+
* Mora no CORE (não em `schema/`) porque o protocolo é isomórfico: a UI resolve
|
|
5
|
+
* labels de dict lendo a meta que viaja no schema do contrato, e a fronteira SPA
|
|
6
|
+
* (gate de arquitetura) só deixa a UI tocar ui/lib/core. O `@softize/opus/schema`
|
|
7
|
+
* re-exporta — a API pública não muda; as factories `t.*` seguem no driver.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { LogicalTypeMeta } from './types.ts'
|
|
11
|
+
|
|
12
|
+
const META = new WeakMap<object, LogicalTypeMeta>()
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Anexa metadata logical type a qualquer schema (objeto). Drivers usam
|
|
16
|
+
* internamente; consumers usam pra registrar tipos lógicos customizados.
|
|
17
|
+
*/
|
|
18
|
+
export function attachLogicalType<S extends object>(
|
|
19
|
+
schema: S,
|
|
20
|
+
meta: LogicalTypeMeta,
|
|
21
|
+
): S {
|
|
22
|
+
META.set(schema, meta)
|
|
23
|
+
return schema
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Lê a metadata logical type anexada. Retorna `undefined` se ausente.
|
|
28
|
+
*/
|
|
29
|
+
export function getLogicalType(schema: object): LogicalTypeMeta | undefined {
|
|
30
|
+
return META.get(schema)
|
|
31
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tbdlib — `defineReaction` factory + type guards
|
|
3
|
+
*
|
|
4
|
+
* `defineReaction` é identity function tipada que aceita uma `ReactionDef`
|
|
5
|
+
* e preserva o tipo do evento pra inferência. Runtime registra no
|
|
6
|
+
* `EventBusAdapter` durante `start()`.
|
|
7
|
+
*
|
|
8
|
+
* Também expõe o SPLIT `defineReactionContract`→`bindReaction` (declaração isomorfa,
|
|
9
|
+
* autorável no design, × handler do handoff), espelhando `defineContract`/`bindAction`.
|
|
10
|
+
*
|
|
11
|
+
* Ver §12 do protocolo.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { BackoffSpec, DomainEvent, ReactionDef, ReactionHandlerFn } from './types.ts'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Constrói uma `ReactionDef`. Identity function pra inferência de tipo.
|
|
18
|
+
*/
|
|
19
|
+
export function defineReaction<Event = unknown>(
|
|
20
|
+
spec: ReactionDef<Event>,
|
|
21
|
+
): ReactionDef<Event> {
|
|
22
|
+
return spec
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// Split contrato/handler (defineReactionContract → bindReaction)
|
|
27
|
+
// =============================================================================
|
|
28
|
+
|
|
29
|
+
/** Campos server-only que o `bindReaction` fornece — o resto é a DECLARAÇÃO (isomorfa). */
|
|
30
|
+
type ReactionBindingKeys = 'handler' | 'retry' | 'timeout' | 'dedup' | 'concurrency'
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A DECLARAÇÃO de uma reação, autorável na sessão de design (isomorfa, SEM efeito): qual
|
|
34
|
+
* evento (`on`), o que significa (`description`), quem pode (`authorize`). O `handler` e a
|
|
35
|
+
* config de entrega ficam de fora — são do handoff (`bindReaction`). Espelha `ActionContract`.
|
|
36
|
+
*/
|
|
37
|
+
export type ReactionContract<Event = unknown> = Omit<ReactionDef<Event>, ReactionBindingKeys>
|
|
38
|
+
|
|
39
|
+
/** Parte server-only amarrada por `bindReaction`: o handler + a config de entrega. */
|
|
40
|
+
export interface ReactionBinding<Event = unknown> {
|
|
41
|
+
handler: ReactionHandlerFn<Event>
|
|
42
|
+
retry?: { attempts: number; backoff?: BackoffSpec }
|
|
43
|
+
timeout?: number
|
|
44
|
+
dedup?: (event: DomainEvent<Event>) => string
|
|
45
|
+
concurrency?: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Constrói a DECLARAÇÃO de uma reação (sem o efeito) — o que a sessão de design autora.
|
|
50
|
+
* Identity function, pra preservar a inferência do tipo do evento.
|
|
51
|
+
*/
|
|
52
|
+
export function defineReactionContract<Event = unknown>(
|
|
53
|
+
contract: ReactionContract<Event>,
|
|
54
|
+
): ReactionContract<Event> {
|
|
55
|
+
return contract
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Amarra o trabalho server-only (`handler` + entrega) à declaração, produzindo uma
|
|
60
|
+
* `ReactionDef` normal — o runtime nem sabe que houve split (igual `bindAction`). É o handoff.
|
|
61
|
+
*/
|
|
62
|
+
export function bindReaction<Event = unknown>(
|
|
63
|
+
contract: ReactionContract<Event>,
|
|
64
|
+
binding: ReactionBinding<Event>,
|
|
65
|
+
): ReactionDef<Event> {
|
|
66
|
+
return { ...contract, ...binding }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Type guard utilitário pra distinguir reactions de actions quando
|
|
71
|
+
* registradas misturadas em `runtime.register([...])`.
|
|
72
|
+
*/
|
|
73
|
+
export function isReaction(value: unknown): value is ReactionDef {
|
|
74
|
+
if (typeof value !== 'object' || value === null) return false
|
|
75
|
+
const candidate = value as { on?: unknown; handler?: unknown; name?: unknown }
|
|
76
|
+
return (
|
|
77
|
+
typeof candidate.name === 'string' &&
|
|
78
|
+
typeof candidate.handler === 'function' &&
|
|
79
|
+
(typeof candidate.on === 'string' || Array.isArray(candidate.on))
|
|
80
|
+
)
|
|
81
|
+
}
|